为什么在不使用任何光源的情况下在Three.js中可以看到3d模型?

时间:2019-02-14 12:27:34

标签: javascript model three.js 3d light

我有什么

如下图所示,我使用Three.js库创建WEBGL画布,并使用GLTFLoader.js在场景中加载.gltf模型。

Demo Image

我使用的代码

//Add THREE Renderer
renderer_Main = new THREE.WebGLRenderer({ antialias: true });
renderer_Main.setSize(canvasWidth, canvasHeight); //Set Renderer Size

//Add THREE Scene
scene_Main = new THREE.Scene();

//Add First THREE Camera
camera_Main = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 10000);
camera_Main.position.set(-2000, 500, 500); //Set camera position

//Add THREE Grid Helper
var size = 1000; //Value of Each Square Size 
var divisions = 60; //Value of Grid Divisions 
gridHelper = new THREE.GridHelper(size, divisions);
gridHelper.material.opacity = 0.045;
gridHelper.material.transparent = false;
scene_Main.add(gridHelper); //Add Grid in the Scene

//Add THREE Orbit Controller for the first camera
//Activate mouse events (L_Click, Scroll, R_Click) for moving around in 3D scene
orbitController_Main = new THREE.OrbitControls(camera_Main, renderer_Main.domElement);
orbitController_Main.maxPolarAngle = Math.PI / 2;  
orbitController_Main.saveState();

//Add Lights
//var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
//scene_Main.add( directionalLight );

//Add a model (.gltf file)
var loader = new THREE.GLTFLoader();
loader.load( 'models/model_environment/scene.gltf', 
    function ( gltf ) {
        //Add 3d model - file types : .gltf, .bin and (.png materials)
        selectedModel = gltf.scene; 
        selectedModel.scale.set(3,3,3);
        selectedModel.position.y = 45;
        scene_Main.add(selectedModel);
    }, 
    ...
);

问题

问题在于,加载对象时可见。请注意,我不使用任何类型的灯(已注释)。同样,当添加灯光时,没有任何变化。我尝试使用THREE.DirectionalLightTHREE.PointLight,但没有运气。如果您想知道我用于此示例的材料是:

1)多维数据集:

camera_RT_Holder = new THREE.Mesh(
   new THREE.BoxGeometry(20, 20, 30),
   new THREE.MeshNormalMaterial()
);

2).gltf模型:

Link of the model

问题 如果您有任何想法,请告诉我。

1 个答案:

答案 0 :(得分:4)

glTF文件中的资料使用KHR_materials_unlit扩展名。使用此扩展名的材料被映射到THREE.MeshBasicMaterial,后者是未照明的材料。这意味着它不会对灯光产生反应,因此即使您的场景中没有任何光源也可以看到它。