aalavandhaann / blueprint-js

The Javascript es6 version of the original furnishup/blueprint3d. Need some royalty free low poly models for the inventory. Can someone help me with this?
MIT License
504 stars 158 forks source link

Shadows from Walls #7

Closed CanKavaloglu closed 5 years ago

CanKavaloglu commented 5 years ago

I tried to have shadows in the models and the items cast shadow but not the walls. Can it be related with Mesh objects? I see that items are meshes whereas the walls are not.

I have added the "castShadow" property to the newWall object in forEach in "loadFloorplan" method and also the Wall class itself, but no luck so far. I just could not get them casting the shadow.

Is there a parameter or something like that preventing the walls to cast the shadow ?

aalavandhaann commented 5 years ago

Since this is an editor it's better to avoid any effects like shadows. But the shadows are highly useful in the final rendering.

Anyways, you can find that the shadows can be added to the meshes in the new wall. You are correct. But also you need to enable the shadows from the lights? Refer to lights.js inside three folder. And try playing with lights to get there shadows.

Regards,

0K

CanKavaloglu commented 5 years ago

Well, I have already enabled the shadows from the light source (point light). For this very same reason, I am able to get the shadows from all the items (windows, floor items, etc...) but I can not get only the walls to cast the shadow.

In the Main class, I have just added the following lines for the light source:

        scope.pointLigth = new PointLight(0xffffff, 0.8, 9000);
        scope.pointLigth.position.set(10, 200, 20);
        scope.pointLigth.castShadow = true;
        scope.pointLigth.shadow.camera.near = 0.1;
        scope.pointLigth.shadow.camera.far = 2500;
        scope.scene.add(scope.pointLigth);`

Then, I commented the line:

// scope.lights = new Lights(scope.scene, scope.model.floorplan);

With these changes and enabling the castShadow on the items, I got it working. In this very point, what more should I do for the walls. Currently, the loop in "loadFloorPlan" method is like this:

                floorplan.walls.forEach(function (wall) {
                var newWall = scope.newWall(corners[wall.corner1], corners[wall.corner2]);
                if (wall.frontTexture) {
                    newWall.frontTexture = wall.frontTexture;
                }
                if (wall.backTexture) {
                    newWall.backTexture = wall.backTexture;
                }
                newWall.castShadow = true;    <------ CHANGE
                newWall.receiveShadow = true;      <------ CHANGE
            });

Despite of these two lines of changes, walls still do not cast the shadow.

aalavandhaann commented 5 years ago

I can think of only thing that would be the problem. The walls are using baked textures. But I am not sure. Maybe try to put a spotlight on one of the walls and check if you still don't get the shadows.

I don't have access to the machine now. Will check it once I am there. But as I said earlier there are no plans of supporting shadows in the editor. That would be a huge load on the frontend. Rather it's better to have it on there rendered output using Blender.

Regards,

0K

CanKavaloglu commented 5 years ago

I tried the spot light and it is still the same, I have shadows from doors, items, etc... but not from the walls. Can it be related with the issue ? The first comment of mrdoob:

Shadows currently need objects to be solid and, ideally, without back side surfaces and front side surfaces in the same position.

Or is it because of the baked textures ?

I will be waiting for your when you have access to your machine. I'll keep digging and let you know if I figure it out.

Cheers !

aalavandhaann commented 5 years ago

Hey,

Any luck on this? I am planning to work on this in the next two days. Do you have any updates? Would be glad to do a PR from you.

Regards,

0K

aalavandhaann commented 5 years ago

I have decided that the lighting and baking should be separated from the threejs rendering layer. Rather it can move to the final rendering phase of a floorplan. This rendering layer can then be made using the export GLTF option and bringing it inside a regular 3D renderer. So shadows and lighting will not be supported in the editor. I believe this is necessary to keep the framework in the perspective of an editor.

Regards,

0K