0

我正在尝试将 Three.js 与 VRML (WRL) 模型一起使用。我想知道的是该模型加载了各种颜色(彩色)。如何将纯色模型加载为原始文件?

我的例子是:http ://dev.logicarts.com.br/semapro/projeto-3d/teste-1.html

编码:

<div id="info">
    <a href="http://threejs.org" target="_blank">three.js</a> -
    vrml format loader test -
    <!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank">VRML 2.0 Tutorial</a>,-->
    </div>

    <script src="js/three.min.js"></script>

    <script src="js/OrbitControls.js"></script>

    <script src="js/VRMLLoader.js"></script>

    <script src="js/Detector.js"></script>
    <script src="js/stats.min.js"></script>

    <script>

        if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

        var container, stats;

        var camera, controls, scene, renderer;

        var cross;

        init();
        animate();

        function init() {

            camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
            camera.position.z = 6;

            controls = new THREE.OrbitControls( camera );

            controls.rotateSpeed = 5.0;
            controls.zoomSpeed = 5;

            controls.noZoom = false;
            controls.noPan = false;

            scene = new THREE.Scene();
            scene.add( camera );

            // light

            var dirLight = new THREE.DirectionalLight( 0xffffff );
            dirLight.position.set( 200, 200, 1000 ).normalize();

            camera.add( dirLight );
            camera.add( dirLight.target );

            var loader = new THREE.VRMLLoader();
            loader.addEventListener( 'load', function ( event ) {

                scene.add(event.content);

            } );
            loader.load( "3d/conjunto-carcaca.wrl" );

            // renderer

            renderer = new THREE.WebGLRenderer( { antialias: false } );
            renderer.setSize( window.innerWidth, window.innerHeight );

            container = document.createElement( 'div' );
            document.body.appendChild( container );
            container.appendChild( renderer.domElement );

            stats = new Stats();
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.top = '0px';
            container.appendChild( stats.domElement );

            //

            window.addEventListener( 'resize', onWindowResize, false );

        }

        function onWindowResize() {

            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();

            renderer.setSize( window.innerWidth, window.innerHeight );

            controls.handleResize();

        }

        function animate() {

            requestAnimationFrame( animate );

            controls.update();
            renderer.render( scene, camera );

            stats.update();

        }

    </script>
4

1 回答 1

2

如果你在scene.add(event.content);语句下面添加这段代码,你场景中的所有物体都会变成红色。

scene.traverse (function (object)
{
    if (object instanceof THREE.Mesh) {
        object.material.color.setHex( 0xff0000 );
    }
});
于 2014-10-29T17:24:03.017 回答