Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js SubdivisionModifier null error

I'm using the Three.js library and attempting to apply a Subdivision Modifier to a model. I am able to load a model successfully, and I am able to apply a subdivision modifier to a CubeGeometry (for example) successfully as well. The code below works when the line commented below is removed, but then of course there will be no "subdivisioning". When the code is run as is, the JavaScript console gives the error "Uncaught TypeError: Cannot read property 'u' of null". My best guess is that the clone() method was not yet complete and so the modify() method threw a null exception.

Any ideas on how to fix this problem?

var loader = new THREE.JSONLoader();
loader.load( "models/parrot.js", function( geometry ) 
{
    var material = new THREE.MeshFaceMaterial();
    var mesh = new THREE.Mesh( geometry, material );
    mesh.position.set(-50,25,0);
    scene.add( mesh );

    var smooth = THREE.GeometryUtils.clone( geometry );
    smooth.mergeVertices();
    var divisions = 2;
    var modifier = new THREE.SubdivisionModifier( divisions );
    modifier.modify( smooth );   // This is the line causing the error
    var mesh2 = new THREE.Mesh( smooth, material );
    mesh2.position.set(50,25,0);
    scene.add( mesh2 ); 
});
like image 233
Stemkoski Avatar asked Mar 26 '26 02:03

Stemkoski


1 Answers

you could try doing modifier.supportUVs = false to suppress UV errors.

like image 68
zz85 Avatar answered Mar 28 '26 16:03

zz85



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!