Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js 3D模型看起来不太干净_Javascript_Three.js - Fatal编程技术网

Javascript Three.js 3D模型看起来不太干净

Javascript Three.js 3D模型看起来不太干净,javascript,three.js,Javascript,Three.js,我正在使用Thrre.js进行三维建模,在阅读.DAE文件后必须显示整洁的产品,但我的产品显示不太干净。有人能帮我吗?我也提供了光源,但展示的产品仍然很单调 我正在尝试以下代码: <script> var renderer, scene, camera, controls, light; var geometry, material, mesh; init(); animate(); function init() { document.body.style.cssT

我正在使用Thrre.js进行三维建模,在阅读.DAE文件后必须显示整洁的产品,但我的产品显示不太干净。有人能帮我吗?我也提供了光源,但展示的产品仍然很单调

我正在尝试以下代码:

<script>
var renderer, scene, camera, controls, light;
var geometry, material, mesh;

init();
animate();

function init() {

    document.body.style.cssText = 'margin: 0; overflow: hidden' ;
    renderer = new THREE.WebGLRenderer( { alpha: 1, antialias: true, clearColor: 0xffffff }  );
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 50000 );
    camera.position.set( 100, 100, 100 );
    //camera.position.set(-15, 10, 15);
    controls = new THREE.TrackballControls( camera, renderer.domElement );
    scene.add(camera);

    light = new THREE.AmbientLight(0xffffff, 10);
    light.position.set(100,100, 100).normalize();
    scene.add(light);

    light = new THREE.DirectionalLight(0xffffff, 1);
    light.position.set(10, 10, 10).normalize();
    scene.add(light);

    var pointlight = new THREE.PointLight(0xffffff, 1, 0);
    pointlight.position.set(50, 100, 50)
    camera.add(pointlight);
    scene.add(pointlight);
    var spotLight = new THREE.SpotLight(0xffffff);
    spotLight.position.set(10,10,10);
    scene.add(spotLight);

    var pointHelper = new THREE.PointLightHelper(pointlight, 0.1);
    scene.add(pointHelper);
    this.renderer.render(this.scene, this.camera);
    geometry = new THREE.BoxGeometry( 10, 10, 10 );
    material = new THREE.MeshLambertMaterial( { ambient: 0x333333, color: 0x888888, opacity: 0.000001, transparent: true } );
   // material = new THREE.MeshLambertMaterial({ color: 0xffffff, vertexColors: THREE.FaceColors });
    mesh = new THREE.Mesh( geometry, material );
    mesh.name = 'basic template mesh';
    mesh.visible = false;
    scene.add( mesh );

}

function animate() {
    requestAnimationFrame( animate );
    renderer.render( scene, camera );
    controls.update();
}``

var渲染器、场景、摄影机、控件、灯光;
变量几何、材质、网格;
init();
制作动画();
函数init(){
document.body.style.cssText='边距:0;溢出:隐藏';
renderer=new THREE.WebGLRenderer({alpha:1,antialas:true,clearColor:0xffffff});
renderer.setSize(window.innerWidth、window.innerHeight);
document.body.appendChild(renderer.doElement);
场景=新的三个。场景();
摄像头=新的三个透视摄像头(40,window.innerWidth/window.innerHeight,150000);
摄像机位置设置(100100100);
//相机。位置。设置(-15,10,15);
控件=新的三个轨迹球控件(camera、renderer.DoElement);
场景。添加(摄影机);
光=新的三个环境光(0xffffff,10);
light.position.set(100100100.normalize();
场景。添加(灯光);
灯光=新的三个方向灯光(0xffffff,1);
light.position.set(10,10,10).normalize();
场景。添加(灯光);
var pointlight=新的三个点光源(0xffffff,1,0);
点光源。位置。设置(50,100,50)
添加(点光源);
场景。添加(点光源);
var spotLight=新的三个聚光灯(0xffffff);
聚光灯位置设置(10,10,10);
场景。添加(聚光灯);
var pointHelper=新的三个.PointLightHelper(pointlight,0.1);
添加(pointHelper);
this.renderer.render(this.scene,this.camera);
几何体=新的三个长方体几何体(10,10,10);
material=new THREE.MeshLambertMaterial({环境光:0x333333,颜色:0x88888,不透明度:0.000001,透明:true});
//材质=新的三个.MeshLambertMaterial({color:0xffffff,vertexColors:THREE.FaceColors});
网格=新的三个网格(几何体、材质);
mesh.name='基本模板网格';
mesh.visible=false;
场景。添加(网格);
}
函数animate(){
请求动画帧(动画);
渲染器。渲染(场景、摄影机);
控件更新();
}``

通过这个代码,我得到了非常乏味的产品。
谁能帮我解决这个问题吗?

你用错了材料。Meshlambert材质用于漫反射曲面,即没有镜面反射高光的曲面(纸张、原木、布料)。您需要使用MeshPhongMaterial,它允许椅子中的镜面反射高光(白点)


在模型中,有两种类型的曲面:皮革和木材。尽管它们都有镜面反射高光,但它们的光泽度是不同的。必须为两个曲面定义单独的材质。但是,因为我看到你只有一个物体,这可能很困难。您可以为两个曲面定义一个MeshPhongMaterial,但必须尝试参数中的多个值才能获得所需的效果。

感谢sosegon的回复,我将按照您的建议进行操作,并与您联系。无论如何谢谢你!!嗨,sosegen,我已经按照你的建议应用了MeshPhongMaterial,并尝试了不同的模式,但仍然不起作用。材质=新的3.MeshPhongMaterial({环境光:0x333333,颜色:0x888888,镜面反射:0x555555,光泽度:30,不透明度:0.000001,透明:真});你能建议并输入相关代码吗。