[英]Three.js OBJLoader .obj model not casting shadows
I'm working on a project where I wish to allow a .OBJ model loaded from OBJLoader.js to cast a shadow from a spotlight. 我正在一个项目中,我希望允许从OBJLoader.js加载的.OBJ模型从聚光灯下投射阴影。 The light will cast shadows from other normal objects, but the .OBJ will not seem to cast shadows.
光线会从其他正常对象投射阴影,但是.OBJ似乎不会投射阴影。
A possible symptom to the problem is as follows: When these normal objects are created when clicking on the floor, they are entered into the array Objects[], which in turn makes them clickable to add objects on top of themselves. 问题的可能征兆如下:单击地板时创建这些普通对象时,会将它们输入到数组Objects []中,这又使它们可单击以将对象添加到自身之上。 The .OBJ model is also added to this array, however I cannot click it to add models on top of it;
.OBJ模型也已添加到此数组,但是我无法单击它以在其顶部添加模型。 as if the raycaster is not detecting it.
就像光线投射器没有检测到它一样。
I'll include all of the code, as the problem may lie somewhere unforeseen. 我将包括所有代码,因为问题可能出在无法预料的地方。
A working link is available HERE 这里有可用的链接
http://www.powertrooper.com/3D/demos/issues/OBJShadows http://www.powertrooper.com/3D/demos/issues/OBJShadows
Try Clicking on the floor to see how other objects do cast shadows. 尝试单击地板以查看其他对象如何投射阴影。
Anyone have any ideas? 有人有想法么? Mr.Doob?
杜布先生? Are you out there?
你在外面吗 :)
:)
ps: I have no idea why in my browser, the link I have left is directing to a malware site called "4safe.in". ps:我不知道为什么在我的浏览器中,我留下的链接指向一个名为“ 4safe.in”的恶意软件网站。 Try copying and pasting the link I guess...
尝试复制和粘贴链接,我猜...
Just in case- here's a snippet of code that includes most of what is likely causing the problem. 以防万一-这是一段代码片段,其中包括可能导致问题的大部分内容。
renderer.shadowMapEnabled = true;///////////////////////////////////////////// RENDERER /// <------------Renderer and lights set up to cast shadows
light.castShadow = true;
light.shadowDarkness = 1;
renderer.shadowMapSoft = true;
floor.receiveShadow = true;
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader();
loader.addEventListener( 'load', function ( event ) {
texture.image = event.content;
texture.needsUpdate = true;
} );
loader.load( 'modeltest/ash_uvgrid01.jpg' );
// model
var loader = new THREE.OBJLoader();
loader.addEventListener( 'load', function ( event ) {
var newModel = event.content;
newModel.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = texture;
}
} );
newModel.position.set (200,30,0);
newModel.castShadow = true;///////////////////////////// <------ This doesn't seem to be working.
scene.add( newModel );
objects.push( newModel );/////////////////////////////// <------ The other HINT: because of this, the raycaster SHOULD allow us to click the model and create a new block. But we can't.
});
loader.load( 'modeltest/male02.obj' );
Each child mesh of your object must have castShadow
set to true
. 对象的每个子网格必须将
castShadow
设置为true
。
newModel.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = texture;
child.castShadow = true;
}
} );
To get raycaster.intersectObjects()
to work with your object, you need to set the recursive flag to true
. 为了使
raycaster.intersectObjects()
与您的对象一起使用,您需要将递归标志设置为true
。
var intersects = raycaster.intersectObjects( objects, true );
three.js r.57 three.js r.57
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.