three.js GPU实例,包含自定义网格和材质

尝试在
instances/gpu three.js example之后实现GPU实例化.

但是,在我的尝试中似乎没有任何东西加载:http://designs.playgami.com/webgl_loader_fbx3.html

(这里是非gpu实例化版本 – http://designs.playgami.com/webgl_loader_fbx2.1.html)

这里特别是我试图加载fbx模型一次,然后实例化.我正在尝试使用var object = new THREE.Mesh(geo);来实例化,但不知怎的,这不起作用?

  function CreateCraneScape(texturearray,squareside,armyside){
                var total = texturearray.length;
                var halfside = Math.floor(squareside*0.5);

                loader.load( '/11272018-crane.fbx', function ( geo ) {
                    var k = 0;
                    // create cranes
                    for(var i=-halfside;i<=halfside;i++){
                        for(var j=-halfside;j<=halfside;j++){
                            var object = new THREE.Mesh( geo );
                            CraneApplyTexture(object,texturearray[k]); 
                            CranePosRot(object,i,j);
                            k++;
                        }   
                    }

                    // create army
                    
                    for(var i=-(halfside+armyside);i<=(halfside+armyside);i++){ 
                            for(var j=-(halfside+armyside);j<=(halfside+armyside);j++){ 
                                if(j<-halfside||j>halfside || (i<-halfside||i>halfside)){ 
                                    var object = new THREE.Mesh( geo );
                                    CraneApplyTexture(object,''); 
                                    CreatePosRot(object,i,j);
                                }
                            }   
                    }

                });
   }

最佳答案 显然FBXLoader不仅仅加载网格几何体,而是实际上只加载整个three.js游戏对象.因此,网格实例化需要引用第一个子节点的几何.

geo = geo.children [0] .geometry;

点赞