OBJLoader .obj模型不投射阴影



我正在研究一个项目,我希望允许从OBJLoader.js加载的. obj模型从聚光灯投射阴影。灯光会投射其他正常物体的阴影,但. obj似乎不会投射阴影。

该问题的可能症状如下:当这些普通对象在点击地板时被创建时,它们被输入到数组objects[]中,这反过来又使它们可以点击以在其顶部添加对象。obj模型也被添加到这个数组中,但是我不能点击它来在上面添加模型;好像光线投射器没有检测到它。

我将包括所有的代码,因为问题可能出现在不可预见的地方。

这里有一个工作链接

http://www.powertrooper.com/3D/demos/issues/OBJShadows

试着点击地板,看看其他物体如何投射阴影。

有人有什么想法吗?Mr.Doob吗?你在吗?:)

ps:我不知道为什么在我的浏览器中,我留下的链接指向一个名为"4safe.in"的恶意软件网站。试着复制和粘贴链接,我猜…

以防万一——这里有一段代码,包含了可能导致问题的大部分原因。

    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' );

对象的每个子网格必须将castShadow设置为true

newModel.traverse( function ( child ) {
    if ( child instanceof THREE.Mesh ) {
        child.material.map = texture;
        child.castShadow = true;
    }
} );

要使raycaster.intersectObjects()与您的对象一起工作,您需要将递归标志设置为true

var intersects = raycaster.intersectObjects( objects, true );

three.js r.57

最新更新