Threejs: Store Jsonmodel Into A Class Variable
i want to store a loaded json model in Three.js using classes, i can add it to the scene but i can't use it after. My code looks like this one: class AScene extens THREE.Scene{ co
Solution 1:
The code in createSoldier()
does not work since the actual value of obj
is set in the onLoad()
callback of JSONLoader.load()
. At this time, the method has already returned a null value.
Your current class design does not honor the asynchronous character of JavaScript. I think you should make yourself more familiar with Callbacks and Scopes before you continue your work. In the meantime, you can use this approach.
loader2.load('models/untitled.json',(geometry,materials) => {
var material = newTHREE.MeshBasicMaterial( { color: 0x0000ff } );
this.soldier = newTHREE.Mesh( geometry, material );
});
Post a Comment for "Threejs: Store Jsonmodel Into A Class Variable"