How to create a custom square in a-frame

后端 未结 1 1548
难免孤独
难免孤独 2021-01-28 13:21

How can I create a custom square registering a new component in a-frame?

I am trying to update the example found here https://github.com/aframevr/aframe/blob/master/docs

1条回答
  •  迷失自我
    2021-01-28 14:06

    This seems to work;

    AFRAME.registerGeometry('example', {
          schema: {
            vertices: {
              default: ['-10 10 0', '-10 -10 0', '10 -10 0', '10 -10 0'],
            }
          },
    
          init: function (data) {
            var geometry = new THREE.Geometry();
            geometry.vertices = data.vertices.map(function (vertex) {
                var points = vertex.split(' ').map(function(x){return parseInt(x);});
                return new THREE.Vector3(points[0], points[1], points[2]);
            });
            geometry.computeBoundingBox();
            geometry.faces.push(new THREE.Face3(0, 1, 2));
            geometry.faces.push(new THREE.Face3(0, 2, 3));
            geometry.mergeVertices();
            geometry.computeFaceNormals();
            geometry.computeVertexNormals();
            this.geometry = geometry;
          }
        });
    

    again followed by this in the html

    
    

    0 讨论(0)
提交回复
热议问题