A帧中的设计模式以重用几何

时间:2017-09-10 02:44:15

标签: d3.js three.js aframe

以下代码笔说明了直接在three.js和A-Frame中生成的50个立方体:https://codepen.io/ubermario/pen/XavVxY

复制直接引用three.js时实现的几何重用算法的A-Frame设计模式是什么?

代码段:

//Re-use geometry if it was already instantiated;   
try {
    cubeGeom = uniqueGeom.filter(function(obj) { return obj.intDim == d.intDim})[0].geometry;
}
catch(err) {
    cubeGeom = new THREE.CubeGeometry(d.intDim,d.intDim,d.intDim); 
    uniqueGeom.push({intDim:d.intDim, geometry:cubeGeom})
}

1 个答案:

答案 0 :(得分:0)

A-Frame将几何属性哈希到字符串并将其放在地图中。

如,

{
  'primitive:box;width:5': THREE.BoxBufferGeometry(),
  'primitive:sphere;radius:2' THREE.SphereBufferGeometry()
}

然后在创建新几何体时,使用相同的函数创建一个哈希,并检查地图。