Add subdivision to a geometry

穿精又带淫゛_ 提交于 2020-01-03 16:48:24

问题


I'm trying add subdivisions to a sphere like this:

http://stemkoski.github.com/Three.js/Subdivision-Cube.html

Here's my code: http://jsfiddle.net/mdrorum/HvFLw/

        <script src="http://mrdoob.github.com/three.js/build/three.js"></script>

            <script type="text/javascript">

            var camera, scene, renderer;
            var geometry, material, mesh;
            var smooth, subdiv, modifier;

            init();
            animate();

            function init() {

                camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
                camera.position.z = 1000;

                scene = new THREE.Scene();

                renderer = new THREE.CanvasRenderer();
                renderer.setSize( window.innerWidth, window.innerHeight );

                document.body.appendChild( renderer.domElement );

                geometry = new THREE.SphereGeometry( 200 );
                material = new THREE.MeshBasicMaterial( { color: 0x00ff00, wireframe: true } );

                mesh = new THREE.Mesh( geometry, material );
                scene.add( mesh );

                var smooth = mesh.clone();
                var subdiv = 3;
                var modifier = new THREE.SubdivisionModifier( subdiv );
                //modifier.modify( smooth );


            }

            function animate() {

                requestAnimationFrame( animate );

                mesh.rotation.x += 0.01;
                mesh.rotation.y += 0.02;

                renderer.render( scene, camera );

            }

        </script>

This works fine, but uncomment: //modifier.modify( smooth );

Nothing happens. :(

How I can add subdivisions?


回答1:


You are trying to modify a mesh. You need to modify a geometry.

modifier.modify( geometry );



回答2:


Here you can find a good tutorial with a working demo. Citing the author:

// First we want to clone our original geometry.
// Just in case we want to get the low poly version back.
var smooth = THREE.GeometryUtils.clone( geometry );

// Next, we need to merge vertices to clean up any unwanted vertex. 
smooth.mergeVertices();

// Create a new instance of the modifier and pass the number of divisions.
var divisions = 3;
var modifier = new THREE.SubdivisionModifier(divisions);

// Apply the modifier to our cloned geometry.
modifier.modify( smooth );

// Finally, add our new detailed geometry to a mesh object and add it to our scene.
var mesh = new THREE.Mesh( smooth, new THREE.MeshPhongMaterial( { color: 0x222222 } ) );
scene.add( mesh );


来源:https://stackoverflow.com/questions/13880497/add-subdivision-to-a-geometry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!