0
votes

I'm hoping to get some help using geometry instancing with A-Frame. I was trying to figure out the bottleneck for my web app and after implementing pooling for physics objects being created in the scene, saw that the number of draw calls was increasing with each new object -- I had thought that by utilizing the asset management system in A-Frame my models were automatically cached, but I think I was mistaken.

I was wondering, if I register the geometry of the model using AFRAME.registerGeometry, would I be able to utilize geometry instancing? I saw that creating from a pool of object using the A-Frame geometry primitives did not increase the geometry count of the scene on a per-entity basis. I took a shot at loading my GLTF and registering the geometry from the mesh, but I'm getting an error from a-node that I don't understand:

<script>
AFRAME.registerGeometry('ramshorn', {
  schema: {
    depth: {default: 1, min: 0},
    height: {default: 1, min: 0},
    width: {default: 1, min: 0},
  },

  init: function(data) {
    var model = null;
    var geometry = null;

    var manager = new THREE.LoadingManager();
    manager.onLoad = function () {
      console.log(geometry);
      this.geometry = geometry;
      console.log(this.geometry);
    }
    var gltfLoader = new THREE.GLTFLoader(manager);
    gltfLoader.setCrossOrigin('anonymous');
    const src = "./assets/ramsHorn/Ram's Horn 2.gltf";
    gltfLoader.load(src, function ( gltf ) {
      console.log("Gltf: " + gltf);
      model = gltf.scene;
      console.log("Model: " + model)
      model.children.forEach((child) => {
        console.log(child);
      });
      gltf.scene.traverse(function (o) {
        if (o.isMesh) {
          geometry = o.geometry;
            //console.log(geometry);
            //tried assigning "this.geometry" here
          }
        });

      }, undefined, function ( error ) {
        console.error(error);
      });
     //tried assigning "this.geometry" here
  }
});
</script>

Error:

core:a-node:error Failure loading node:   TypeError: "t is undefined"
aframe-master.min.js:19:658

Any help with this would be appreciated! Thanks

1

1 Answers

1
votes

The code at 19:658 in aframe-master.min.js is trying to run something with a variable t but it has not been declared.

By using aframe-master.js it would be possible to get a more meaningful error.