I loaded an object in Three.js with the AssimpJSONLoader. The object cube_cone is a simple 3D model which contains a cube which has a cone on top of it.
我使用AssimpJSONLoader在Three.js中加载了一个对象。对象cube_cone是一个简单的3D模型,它包含一个立方体,在其上面有一个圆锥体。
var loader1 = new THREE.AssimpJSONLoader();
loader1.load( 'models/assimp/cube_cone.json', function ( object ) {
object.scale.multiplyScalar( 1 );
object.material.color.setHex(0x666666);
scene.add( object );
}, onProgress, onError );
First of all I want to change the color of the object. How do I do it? I tried it with: "object.material.color.setHex(...);".
首先,我想改变对象的颜色。我该怎么做?我尝试过:“object.material.color.setHex(...);”。
Second of all I only want to manipulate the color of a child object, e.g. just the cone. The test_cone.json object has "children" with "name": "3DSMesh_0" and "name": "3DSMesh_1". How can I access them to manipulate just a part of the object and not the whole?
其次,我只想操纵子对象的颜色,例如,只是锥形。 test_cone.json对象具有带“name”的“children”:“3DSMesh_0”和“name”:“3DSMesh_1”。我怎样才能访问它们来操纵对象的一部分而不是整个?
I would be very thankful if you can help me because I am a beginner in Javascript.
如果你能帮助我,我会非常感激,因为我是Javascript的初学者。
1 个解决方案
#1
1
Better to make an example as an answer for your last comment.
最好以一个例子作为你最后评论的答案。
var myObj = new THREE.Group(); //global variable
...
var loader1 = new THREE.AssimpJSONLoader();
loader1.load( 'models/assimp/cube_cone.json', function ( object ) {//onLoad callback
myObj = object; //assign object to the global variable inside the callback
}, onProgress, onError );
...
function animate(){
...
myObj.rotation.y += 0.1;// using the global variable in your animation function
...
}
also you can assign a child of an object
, for example
例如,您也可以指定对象的子对象
myObj = object.getObjectByName("3DSMesh_1", true);
#1
1
Better to make an example as an answer for your last comment.
最好以一个例子作为你最后评论的答案。
var myObj = new THREE.Group(); //global variable
...
var loader1 = new THREE.AssimpJSONLoader();
loader1.load( 'models/assimp/cube_cone.json', function ( object ) {//onLoad callback
myObj = object; //assign object to the global variable inside the callback
}, onProgress, onError );
...
function animate(){
...
myObj.rotation.y += 0.1;// using the global variable in your animation function
...
}
also you can assign a child of an object
, for example
例如,您也可以指定对象的子对象
myObj = object.getObjectByName("3DSMesh_1", true);