Jump to content

Three.js subdivision surfaces


Pekele
 Share

Recommended Posts

Hi there !

I'm trying to add a subdivision surface on a loaded json file with Three.js and SubdivisionModifier.js or BufferSubdivisionModifier.js without any result.

I searched and found various code and topic but none of them worked. That's why I'm looking for help here.

my code with the BufferSubdivisionModifier.js :

function initMesh() {
    var loader = new THREE.JSONLoader();
    loader.load('js/cube.json', function(cubeGeometry, materials) {
        
        cubegeometryClone = cubeGeometry.clone();
    cubegeometryClone.mergeVertices();
    cubegeometryClone.computeFaceNormals();
    cubegeometryClone.computeVertexNormals();

    var modifier = new THREE.BufferSubdivisionModifier(1);
    smoothCube = modifier.modify( cubegeometryClone );
        mesh = new THREE.Mesh(smoothCube, new THREE.MultiMaterial(materials)); // of course cube appears if you replace smoothCube by cubeGeometry
        mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.95;
        mesh.translation = cubegeometryClone.center(cubeGeometry);
         scene.add(mesh);
});
}

no errors in console

my code with the SubdivisionModifier.js  which is the example I found mostly :

function initMesh() {
    var loader = new THREE.JSONLoader();
    loader.load('js/cube.json', function(cubeGeometry, materials) {
        
        smooth = cubeGeometry.clone();
    smooth.mergeVertices();
    smooth.computeFaceNormals();
    smooth.computeVertexNormals();

    var modifier = new THREE.SubdivisionModifier(1);
    modifier.modify(smooth); // if I comment this line, cube show but, of course, with no surface smoothing

        mesh = new THREE.Mesh(smooth, new THREE.MultiMaterial(materials));
        mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.95;
        mesh.translation = cubeGeometry.center(cubeGeometry);
         scene.add(mesh);
});
}

console show : TypeError: undefined is not an object (evaluating 'v.x')

any help will be apreciated, I'm getting mad after 2 days of tries

thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...