Three.js - VRML 加载器 [英] Three.js - VRML Loader
问题描述
我正在尝试将 Three.js 与 VRML (WRL) 模型一起使用.我想知道的是模型加载了各种颜色(彩色).如何将纯色模型加载为原始文件?
我的例子是:http://dev.logicarts.com.br/semapro/projeto-3d/teste-1.html
代码:
<a href="http://threejs.org" target="_blank">three.js</a>——vrml 格式加载器测试 -<!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank">VRML 2.0 教程</a>,--><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><脚本>if (!Detector.webgl) Detector.addGetWebGLMessage();var 容器,统计数据;var 相机、控件、场景、渲染器;无功十字架;在里面();动画();函数初始化(){camera = new THREE.PerspectiveCamera( 60, window.innerWidth/window.innerHeight, 0.01, 1e10 );相机.位置.z = 6;控件 = 新的 THREE.OrbitControls( 相机 );control.rotateSpeed = 5.0;control.zoomSpeed = 5;control.noZoom = false;control.noPan = false;场景 = 新的 THREE.Scene();场景添加(相机);//光var dirLight = new THREE.DirectionalLight(0xffffff);dirLight.position.set( 200, 200, 1000 ).normalize();相机.添加( dirLight );相机.添加( dirLight.target );var loader = new THREE.VRMLLoader();loader.addEventListener('加载',函数(事件){场景.添加(事件.内容);});loader.load("3d/conjunto-carcaca.wrl");//渲染器renderer = new THREE.WebGLRenderer( { antialias: false } );renderer.setSize( window.innerWidth, window.innerHeight );container = document.createElement('div');document.body.appendChild(容器);container.appendChild(renderer.domElement);统计=新统计();stats.domElement.style.position = '绝对';stats.domElement.style.top = '0px';container.appendChild(stats.domElement);//window.addEventListener('resize', onWindowResize, false );}函数 onWindowResize() {camera.aspect = window.innerWidth/window.innerHeight;相机.updateProjectionMatrix();renderer.setSize( window.innerWidth, window.innerHeight );control.handleResize();}函数动画(){requestAnimationFrame( 动画 );控制更新();renderer.render(场景,相机);stats.update();}
如果你在 scene.add(event.content);
语句下添加这段代码,你场景中的所有对象都会转动红色.
scene.traverse(函数(对象){如果(对象实例THREE.Mesh){object.material.color.setHex(0xff0000);}});
I'm trying to use the Three.js with VRML (WRL) models. What I am wondering is that the model is loaded with variations of colors (colored). How can I load the model in solid color as the original file?
My example is: http://dev.logicarts.com.br/semapro/projeto-3d/teste-1.html
The code:
<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>
If you add this code under the scene.add(event.content);
statement, all the objects in your scene will turn red.
scene.traverse (function (object)
{
if (object instanceof THREE.Mesh) {
object.material.color.setHex( 0xff0000 );
}
});
这篇关于Three.js - VRML 加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!