three.js GPU Instantiation with custom mesh and material

Viewed 203

Trying to implement GPU instantiation, following the instances/gpu three.js example.

However, somehow nothing seems to be loading in my attempt: http://designs.playgami.com/webgl_loader_fbx3.html

(here is the non-gpu instantiation version - http://designs.playgami.com/webgl_loader_fbx2.1.html)

Here's specifically where I am trying to load the fbx model just once, and then instantiate. I'm trying to instantiate using var object = new THREE.Mesh( geo );, but somehow that does not work?

  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);
                                }
                            }   
                    }

                });
   }

1 Answers

Apparently FBXLoader does not load just the mesh geometry but actually the entire three.js game object. So, the mesh instantiation needed to reference the geometry of the first child.

geo = geo.children[0].geometry;

Related