Skip to content

[ENHANCEMENT] Injecting dependencies during initialization? #371

Description

@tanaydimri

Hi all,
Wondering if the sparkjs community would be open to the possibility of injecting the third party dependencies or their subsets like threejs/threejs-addons during the SparkRenderer initialization? Something like:

import {Mesh, Material, ...} from "three";
new SparkRenderer({ THREE: { Mesh, Material, ... } }) // If somebody does want to pass a subset.

OR optionally:

import * as THREE from "three";
new SparkRenderer({ THREE: THREE }) // Should be enough in most of the cases to allow importing from CDN at runtime.

REASON

The reason I am requesting/proposing something like this is to allow users to import sparkjs from CDN without having to import the entire threejs library and it's addons on the webpage. We specifically build web components for our products and do ensure to treeshake three and other libraries as much as possible. With the latest update to 2.x.x and in-lining of the wasm modules, the build size goes up quite a bit with spark js. One options to work around this is to import sparkjs at runtime only within the session where required, but we cannot do that without importing the entire threejs library and it's addons on the webpage itself. Since the sparkjs build assume that "three" is available as a module on the page.

I have seen similar pattern in other threejs libraries. For example: https://github.com/yomotsu/camera-controls
Given that their functionality is a lot simpler than something like SparkJS but (without looking deep into the codebase) I don't see a good reason to not be able to do something like this.

I would even be more than happy to work on this and submit a PR for review if everyone agrees this is in fact possible and could a potential solution for many users.

Thank you for building an amazing library that lets us integrate Splats within threejs with ease.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions