我可以从加载的模型细分选定的面

时间:2016-01-13 14:10:03

标签: javascript selected

我创建了此代码以加载现有模型并细分选定的面。

var loader = new THREE.PLYLoader();
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;           
var material = new THREE.MeshPhongMaterial( { color:0xFFFFFF , specular: 0x0, shading: THREE.FlatShading, side: THREE.DoubleSide } );                   
geometry.dynamic=true;
for ( var i = 0; i < geometry.faces.length; i++ ) 
    {
        face = geometry.faces[ i ]; 
        face.color.setRGB( 0, 0, 0.8 * Math.random() + 0.2 );       
    }
    var faceColorMaterial = new THREE.MeshBasicMaterial( 
    { color: 0xffffff, vertexColors: THREE.FaceColors } );
var mesh = new THREE.Mesh( geometry,faceColorMaterial );
                    mesh.position.set( 0, - 0.5, 0 );
                mesh.rotation.set( 0, - Math.PI / 2, 0 );
                    mesh.scale.set( 5, 5, 5 );
                    scene.add( mesh );              targetList.push(mesh);
    projector = new THREE.Projector();
                } );
        loader.load('http://localhost/tessellation/data/Mesh20.ply');

用户点击面部选择所选择的面部。

这项工作的目的是通过其面的细分来细化网格部分。

为此,我们创建了这段代码:

function onDocumentMouseDown( event ) 
{
    console.log("Click.");
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
    var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
    projector.unprojectVector( vector, camera );
    var ray = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
    var intersects = ray.intersectObjects( targetList );
    if ( intersects.length > 0 )
    {

var smooth = THREE.GeometryUtils.clone( intersects[0].object.geometry );

var modifier = new THREE.SubdivisionModifier(1);

modifier.modify( smooth );

intersects[0].object.geometry = smooth;

}

但是网格的整体细分不是选定的面。 你能帮我细分加载模型的选定部分。

the program subdivide the totality of mesh

0 个答案:

没有答案