environment3dplugin
The lights and the floor of a 3D scene.
Putting it in a scene
List it before render3d. Each light and the floor are made only if the settings include them.
"plugins": ["loader", "scenemanager", "player", "environment3d", "render3d"],
"prefabs": {
"environment3d": {
"sun": {
"at": [30, 60, 20], "color": "#fff1d6", "power": 3,
"shadow": { "map": 2048, "half": 40, "near": 1, "far": 200, "distance": 100, "bias": 0.0005, "normalBias": 0.02 }
},
"sky": { "color": "#bcd4ff", "ground": "#3a3a2e", "power": 0.6 },
"ambient": { "color": "#ffffff", "power": 0.15 },
"lights": [{ "at": [-30, 20, -10], "color": "#6a7bb8", "power": 0.4 }],
"floor": { "size": 400, "color": "#5a6b4a" }
}
}
Properties
Read from prefabs.environment3d, once, when the scene starts. Colours are any three.js colour, such as "#fff1d6". power is the light's intensity.
.sun : { at, color, power, shadow? }
A directional light shining from the point at toward the origin. With shadow it casts shadows.
.sun.shadow : { map, half, near, far, distance, bias, normalBias }
A shadow map of map texels a side, covering a box half metres each way across the light and from near to far metres along it. The box follows the camera, and its light stands distance metres sunward of the box's centre. bias and normalBias stop surfaces shadowing themselves. Shadows also need render3d's shadows on, and meshes that cast and receive.
.sky : { color, ground, power }
A hemisphere light: color from above and ground from below.
.ambient : { color, power }
Light that reaches every surface equally.
.lights : { at, color, power }[]
More directional lights, each shining from its at toward the origin. None of them casts shadows. Use them for a moon, or light bounced off a wall.
.floor : { size, color }
A flat square, size metres across, at y = 0. It takes no shadows and no rain or snow. For ground that does, use terrain3d.