2012-08-07 69 views
1

我需要添加到相同的場景幾何體中多個體素(立方體等於),但每個都具有不同的紋理。具有不同紋理的多個體素。性能

我有超過500體素的性能嚴重錯誤。

這是我的代碼:

texture = crearTextura(voxel.text,color,voxelSize); 
material = new THREE.MeshBasicMaterial({ map: texture });  
mesh = new THREE.Mesh(new THREE.CubeGeometry(voxelSize, voxelSize, voxelSize, 1, 1, 1,material),faceMaterial); 
scene.add(mesh); 

回答

0

最後我創建了一個geoemtry與所有多維數據集合並。

在此更改之前,我曾在多維數據集中用鼠標點擊相交。

我tryed解決這個問題,但沒有奏效:

代碼添加幾何合併和陣列的所有網:

var geometry = new THREE.Geometry(); 
for(var i = 0; i < voxels.length; i++){ 
    var voxel = voxels[i]; 
    color = voxel.color; 
    texture = textPlaneTexture(voxel.text,color,voxelSize); 
    material = new THREE.MeshBasicMaterial({ map: texture });    
    mesh = new THREE.Mesh(new THREE.CubeGeometry(voxelSize, voxelSize, voxelSize, 1, 1, 1, material)); 

    mesh.name = voxel.name; 
    mesh.position.x = voxel.x * voxelSize + offset_x; 
    mesh.position.y = voxel.y * voxelSize + offset_y; 
    mesh.position.z = voxel.z * voxelSize + offset_z; 

    // 
    objects.push(mesh); 

    THREE.GeometryUtils.merge(geometry, mesh); 
} 

//Add geometry to scene 
mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial()); 
scene.add(mesh);  
... 

鼠標雙擊事件

function onDocumentMouseDoubleClick(event) { 
    if (event.target instanceof HTMLCanvasElement) { 
    event.preventDefault(); 

    mouse2D.x = (event.clientX/widthChart) * 2 - 1; 
    mouse2D.y = - ((parseInt(event.clientY) - offset_mouse_y)/heightChart) * 2 + 1;  

    mouse3D = projector.unprojectVector(mouse2D.clone(), camera); 
      ray.direction = mouse3D.subSelf(camera.position).normalize(); 
    var intersects = ray.intersectObjects(objects); 

    if (intersects.length > 0) { 
     if ((intersects[ 0 ].object.name != 'undefined') && (intersects[ 0 ].object.name != '')) { 
     //Object clicked 
     }; 
    };  
    }; 
}; 
相關問題