为什么 3d 模型在 Three.js 中可见而不使用任何光源?
Why 3d models are visible in Three.js without using any light sources?
我有什么
如下图所示,我使用Three.js库创建了一个WEBGL canvas并使用GLTFLoader.js在场景中加载了一个.gltf模型。
我使用的代码
//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.DirectionalLight and THREE.PointLight,但没有成功。如果您想知道我在此示例中使用的材料是:
1) 立方体:
camera_RT_Holder = new THREE.Mesh(
new THREE.BoxGeometry(20, 20, 30),
new THREE.MeshNormalMaterial()
);
2).gltf 模型:
问题
如果您知道发生了什么,请告诉我。
您的 glTF
文件中的 material 使用 KHR_materials_unlit extension. Materials using this extensions are mapped to THREE.MeshBasicMaterial,它是未点亮的 material。这意味着它不会对灯光做出反应,因此即使场景中没有任何光源,它也可见。
我有什么
如下图所示,我使用Three.js库创建了一个WEBGL canvas并使用GLTFLoader.js在场景中加载了一个.gltf模型。
我使用的代码
//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.DirectionalLight and THREE.PointLight,但没有成功。如果您想知道我在此示例中使用的材料是:
1) 立方体:
camera_RT_Holder = new THREE.Mesh(
new THREE.BoxGeometry(20, 20, 30),
new THREE.MeshNormalMaterial()
);
2).gltf 模型:
问题 如果您知道发生了什么,请告诉我。
您的 glTF
文件中的 material 使用 KHR_materials_unlit extension. Materials using this extensions are mapped to THREE.MeshBasicMaterial,它是未点亮的 material。这意味着它不会对灯光做出反应,因此即使场景中没有任何光源,它也可见。