非常感谢您的回答。
我正在学习 A-Frame、Three.js、Javascript 和 html。
你用 A-Frame 做的事情真是太棒了。
完成以下操作,它并不完美,但现在它可以工作:
在 registerComponent init:function()
在网格中投射阴影:
el.getObject3D('mesh').castShadow = data.shadow; //data.shadow = true
在网格中接收阴影:
el.getObject3D('mesh').receiveShadow = data.shadow; //data.shadow = true
在聚光灯下:
this.spotlight = new THREE.SpotLight(data.colorm);
el.setObject3D('spotlight', this.spotlight);
el.getObject3D('spotlight').castShadow = data.shadow;
el.getObject3D('spotlight').shadow.camera.near = data.shadowcameranear;
el.getObject3D('spotlight').shadow.camera.far = data.shadowcamerafar;
el.sceneEl.systems.light.registerLight(el);
然后使用场景加载事件:
function setShadows()
{
aframeRenderer.shadowMap.enabled = true;
aframeRenderer.shadowMap.type = THREE.PCFSoftShadowMap;
aframeRenderer.setClearColor(0x000000, 1.0);
aframeRenderer.setSize(window.innerWidth, window.innerHeight);
aframeRenderer.shadowMap.enabled = true;
threeSpotLight.shadowCameraNear = 0.01;
threeSpotLight.castShadow = true;
threeCube.castShadow = true;
threeCube.receiveShadow = false;
threePlane.castShadow = false;
threePlane.receiveShadow = true;
threeSpotLight.visible = true;
}