Three.js - 使用 MeshFaceMaterial 创建阴影
Three.js - Creating shadows with MeshFaceMaterial
我现在尝试了几种不同的灯光(Directional、Spot、Point),但其中 none 会在 MeshFaceMaterial 对象上产生漂亮的阴影。相反,整个 MeshFaceMaterial 对象将变成黑色。
My Test Website(请持保留意见,不断变化中)
如何使用灯光在 MeshFaceMaterials 上创建阴影? MeshFaceMaterial 是否支持阴影? documentation 表示 "Affects objects using MeshLambertMaterial or MeshPhongMaterial."
这是我如何加载 .json 模型的示例代码。
loader.load('sample-concrete.js', function ( geometry, materials ) {
mesh1 = new THREE.Mesh(
geometry, new THREE.MeshFaceMaterial( materials )
);
mesh1.rotation.x = -Math.PI / 2;
scene.add( mesh1 );
});
这是我的 .json 文件中 material 的示例。
"materials": [
{
"DbgIndex" : 0,
"DbgName" : "Steel",
"colorDiffuse" : [0.3059, 0.0471, 0.0471],
"colorAmbient" : [0.3059, 0.0471, 0.0471],
"colorSpecular" : [1.0000, 1.0000, 1.0000],
"transparency" : 1.0,
"specularCoef" : 25.0,
"vertexColors" : false
}
谢谢。
一个MeshFaceMaterial
只是素材的集合。因此,如果您的 materials
变量包含 MeshLambertMaterial
或 MeshPhongMaterial
,您应该没问题。阴影将从 DirectionalLight
或 SpotLight
生成。
只需确保您的渲染器具有:
renderer.shadowMapEnabled = true;
你的灯有:
light.castShadow = true;
你的每一个网格:
mesh.castShadow = true;
并且您至少有一个对象(例如一架飞机):
plane.receiveShadow = true;
我现在尝试了几种不同的灯光(Directional、Spot、Point),但其中 none 会在 MeshFaceMaterial 对象上产生漂亮的阴影。相反,整个 MeshFaceMaterial 对象将变成黑色。
My Test Website(请持保留意见,不断变化中)
如何使用灯光在 MeshFaceMaterials 上创建阴影? MeshFaceMaterial 是否支持阴影? documentation 表示 "Affects objects using MeshLambertMaterial or MeshPhongMaterial."
这是我如何加载 .json 模型的示例代码。
loader.load('sample-concrete.js', function ( geometry, materials ) {
mesh1 = new THREE.Mesh(
geometry, new THREE.MeshFaceMaterial( materials )
);
mesh1.rotation.x = -Math.PI / 2;
scene.add( mesh1 );
});
这是我的 .json 文件中 material 的示例。
"materials": [
{
"DbgIndex" : 0,
"DbgName" : "Steel",
"colorDiffuse" : [0.3059, 0.0471, 0.0471],
"colorAmbient" : [0.3059, 0.0471, 0.0471],
"colorSpecular" : [1.0000, 1.0000, 1.0000],
"transparency" : 1.0,
"specularCoef" : 25.0,
"vertexColors" : false
}
谢谢。
一个MeshFaceMaterial
只是素材的集合。因此,如果您的 materials
变量包含 MeshLambertMaterial
或 MeshPhongMaterial
,您应该没问题。阴影将从 DirectionalLight
或 SpotLight
生成。
只需确保您的渲染器具有:
renderer.shadowMapEnabled = true;
你的灯有:
light.castShadow = true;
你的每一个网格:
mesh.castShadow = true;
并且您至少有一个对象(例如一架飞机):
plane.receiveShadow = true;