我有的
如下图所示,我使用Three.js库创建一个WEBGL画布,并使用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和THREE.PointLight,但没有运气。如果你想知道我在这个例子中使用的材料是:
1)立方体:
camera_RT_Holder = new THREE.Mesh(
new THREE.BoxGeometry(20, 20, 30),
new THREE.MeshNormalMaterial()
);
2).gltf型号:
问题如果你知道发生了什么,请告诉我。
glTF
文件中的材料使用KHR_materials_unlit扩展名。使用此扩展的材质被映射到THREE.MeshBasicMaterial,这是一种未点亮的材料。这意味着它不会对灯光作出反应,因此即使场景中没有任何光源也可以看到它。