Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
48 views
in Technique[技术] by (71.8m points)

javascript - How to make npm package that uses three.js with no dependece?

The problem is this: I want to make a npm package that creates procedural objects for threejs. But I don't know how to link three.js in my code. I tried to stablish a dependece and using something like

const THREE = require('three');

Function Example(){
return new THREE.TextureLoader()load('./textures/texture.png');
}

module.exports.Example = Example;

This works nice with other constructors, like scenes, and vectors, however for TextureLoader() it generates an error of an undefined document (because there is not document defined for this THREE). I suspect that this is not the architecture that I should use. I saw in some libraries they load THREE with a function like:

var _loader;
myLib.install = function (libs) {
        THREE = libs.THREE;
        _loader = new THREE.TextureLoader();

    };

So in this case there is not actual dependency on three.js, calling installation function is necessary thou; therefore require() function is not needed anymore. I would like to understand how to implement this in my code. Thanks beforehand for the help.

question from:https://stackoverflow.com/questions/65852480/how-to-make-npm-package-that-uses-three-js-with-no-dependece

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...