threejs children下能得到geometry
时间: 2023-08-04 22:06:10 浏览: 89
回答: 在Three.js中,可以通过访问一个对象的`children`属性来获取其下的子对象。如果子对象是一个`Mesh`对象,那么可以通过访问其`geometry`属性来获取其几何体。例如,如果`obj`是一个包含子对象的Three.js对象,可以通过`obj.children\[0\].geometry`来获取第一个子对象的几何体。\[1\]
#### 引用[.reference_title]
- *1* *2* *3* [WebGL和ThreeJs学习5--ThreeJS基本功能控件](https://blog.csdn.net/weixin_32067105/article/details/111903147)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关问题
threejs obj
threejs obj模型加载可以通过加载.obj文件或同时加载.obj和.mtl文件来实现。加载.obj文件只加载模型的几何体信息,而不加载材质文件。可以使用THREE.OBJLoader()函数来加载.obj文件,示例如下:
```javascript
var loader = new THREE.OBJLoader();
loader.load('./立方体/box.obj', function (obj) {
console.log(obj);
console.log(obj.children[0].material);
scene.add(obj);
obj.children[0].scale.set(20, 20, 20);
obj.children[0].geometry.center();
obj.children[0].material.color.set(0xff0000);
});
```
同时加载.obj文件和.mtl文件时,可以借助three.js引擎自定义材质对象Material。具体操作可以参考相关的Three.js课程第14章第3小节。
threejs remove
To remove an object from a Three.js scene, you can use the `remove()` method which is available in any object that inherits from `THREE.Object3D`. Here's an example:
```javascript
// create a new mesh object
const mesh = new THREE.Mesh(geometry, material);
// add the mesh to the scene
scene.add(mesh);
// later, remove the mesh from the scene
scene.remove(mesh);
```
In this example, we first create a new mesh object and add it to the scene using the `add()` method. Then, when we want to remove the mesh from the scene, we call the `remove()` method on the scene and pass in the mesh object as an argument.
You can also remove all children from an object by calling the `remove()` method with no arguments:
```javascript
// remove all children from the scene
scene.remove();
```
This will remove all objects that have been added to the scene.
阅读全文