【问题标题】:three.js - Adding to scene from array of mesh - t is undefined in three.js - what am i missing?three.js - 从网格数组添加到场景 - t 在three.js 中未定义 - 我错过了什么?
【发布时间】:2021-11-15 22:53:57
【问题描述】:

为了做这个例子,我摆脱了所有的毛茸茸,希望它能让你更容易帮助我。

https://decadent3d.s3.amazonaws.com/help1.html

https://decadent3d.s3.amazonaws.com/help2.html

两者的唯一区别是,scene.add()被注释掉了。

我创建几何、材质和网格的数组。一切看起来都很好,网格是网格。但是添加到场景中是不行的。希望有人能指出我正确的方向。

screencap_of_inspect

最好, 新b

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: javascript arrays three.js webgl


【解决方案1】:

感谢 -Sammy 对这篇文章的回复... THREE.JS loading an array of STL Meshes

我的解决方案是一个更小的代码块,添加每个网格和材质,按顺序分配一个名称,然后推送到网格和材质数组。
谢谢-萨米


const loader = new THREE.STLLoader();   
const meshArray = [];
const matArray = [];
const fileList = ["https://decadentlab.s3.amazonaws.com/cases/001/Upper.stl", "https://decadentlab.s3.amazonaws.com/cases/001/Lower.stl", "https://decadentlab.s3.amazonaws.com/cases/001/Mockup.stl", "https://decadentlab.s3.amazonaws.com/cases/001/Ideal.stl" ];

var callback = function ( geometry ) { 
    const matColors = ["0xE2D4B7", "0xAF9164", "0x437C90", "0x9EBC9E", "0xFCAB64", "0xAE8799", "0x496DDB", "0x717EC3", "0xC95D63", "0xF2AF29"];
    var mats = new THREE.MeshPhongMaterial({
    color: matColors[i],
    specular: 0x555555,
    shininess: 10
    });
    mats.side = THREE.DoubleSide;
    mats.transparent = true;
    mats.opacity = 1;
    mats.name = "material" + i;
    matArray.push( mats );
    console.log( mats );
    var mesh = new THREE.Mesh( geometry, mats );
    mesh.position.set(0, 0, 0);
    mesh.rotation.set(5.5, 0, 0);
    mesh.name = "mesh" + i;
    meshArray.push(mesh);
    console.log( mesh );
    scene.add( mesh );
    i++;
    if (i < fileList.length)  // put the next load in the callback
        loader.load( fileList[i], callback ) ;
};

i = 0;
loader.load( fileList[i], callback ); 

【讨论】:

    猜你喜欢
    • 2014-08-18
    • 1970-01-01
    • 2015-03-20
    • 2012-06-21
    • 2018-08-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多