本文介绍了从 Collada 加载调用克隆 Object3D 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试克隆一个 ThreeJS Object3D 模型.我在这里和 GitHub 上找到了各种代码,但没有任何东西对我有用.下面的代码部分来自 How to clone an object3d in Three.js?

I'm trying to clone an ThreeJS Object3D model. I've found various code here and on GitHub and nothing is working for me. The code below comes in part from How to clone an object3d in Three.js?

var loader = new THREE.ColladaLoader();
loader.load('../Model.dae', function (result) {
    var loadedMesh = // No sure where this comes from

    // Create X of these
    for ( var i = 0; i < 10; i ++ ) {
        var mesh = new THREE.Mesh( loadedMesh.geometry, loadedMesh.material );
        mesh.position.set( i * 100, 0, 0 );
        scene.add( mesh );
    }
}

你能帮忙填空吗?

推荐答案

这最终奏效了:

var loader = new THREE.ColladaLoader();
loader.load('../Turn.dae', function colladaReady(result) {
    var piece = result.scene.children[0];
    for (var i = 0; i < 10; i++) {
        var newPiece = new THREE.Object3D();

        for (var j = 0; j < piece.children.length; j++) {
            newPiece.add(new THREE.Mesh(piece.children[j].geometry, piece.children[j].material));
        }

        newPiece.position.set(i * 100, 0, 0);
        newPiece.scale.set(30, 30, 30);
        scene.add(newPiece);
    }

    renderer.render(scene, camera);
});

因此,我得到了一组网格,而不是单个网格.我对此很陌生,所以我不知道为什么这与我见过的所有其他答案都不同.dae 文件是直接从 Sketchup 导出的.我很想知道是否有更简单/更好的方法来做到这一点.

So instead of getting a single mesh, I got a group of meshes. I'm new to this, so I don't know why this is different from what every other answer I've seen. The dae file was exported directly from Sketchup. I'd be interested in knowing if there is a easier/better was to do this.

这篇关于从 Collada 加载调用克隆 Object3D 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:57