A plugin for using the ThreeJS 3D-graphics library inside krpano.
With this plugin it is possible to use 3D Models (glb, gltf, obj+mtl files) as krpano Hotspots.
These hotspots can interact and intersect with the krpano content and automatically support all krpano hotspot controls and events.
Additionally this plugin supports many helper functions for using 3D-content:
Special Light Hotspots for creating light and shadow effects.
It provides optionally using color temperatures for setting the lights colors.
A Shadow Floor plane to see shadows also on the pano-background.
Automatic Environment Mapping for lighting and reflections using the preview pano.
Getting the untransformed Bounding Box informations.
The plugin has the ThreeJS library and some of its addons modules directly integrated and embedded.
This integration allows much faster loading and provides better browser compatibility.
Beside the functions provided by this plugin, it is also possible to access
the ThreeJS library directly via Javascript and perform custom tasks with it.
For even more customization and to help understanding how the integration works,
there is an Open Source version of the plugin available.
Use the ThreeJS library that is embedded inside the krpano ThreeJS plugin.
When disabling this setting, the ThreeJS library and its add-ons need to be included manually in the html file.
And an import map must exist to map the ThreeJS library files to their typical import names.
Example for a minimum importmap in the html file when useembeddedthreejs is disabled:
Use 'integrated' rendering - that means rendering the krpano content and the ThreeJS content into the same WebGL context - same framebuffer, same depthbuffer, same WebGL states.
With this the 3D-contents of krpano and ThreeJS can intersect each other.
When disabled, ThreeJS will use its own separate WebGL context and render on top of the krpano WebGL content.
Enable or disable the usage of Javascript ES6 modules.
By default the krpano ThreeJS plugin uses its own module loader.
This one works also without importmap-support by the browser
and additionally also should be faster.
When disabled, the plugin getmodule() function would need to be used instead of the
Javascript import()
function to get a module object.
krpano and ThreeJS are using different units and
generally this is no problem as the positions can be easily adjusted accordingly,
but the physically-based lighting in ThreeJS has the light falloff decaying hard-coded in the
Shader code
and is based on the ThreeJS units.
Therefore without adjusting the lights would fall off much too quickly with distance.
When this setting is enabled (the default), the ThreeJS Shaders will be patched
to use the krpano units for the light falloff.
This setting need to be set at startup and can't be changed at runtime.
This can improve the display quality of downscaled and mip-mapped images / textures.
But therefore increase the memory-need and reduce rendering-performance.
Note - this setting would need to be set or changed before loading textures!
Any later setting change will only affect textures that will be loaded after the change.
Sets an environment map to illuminate the scene by a given image and to have a mirror image for reflecting materials.
Here either an url to a spherical pano image (360x180) could be set,
or the special value preview be used. In this case the current
krpano pano <preview> image will be automatically used.
Sphere and Cubestrip images are supported in this case.
The hotspots use the same positioning system as normal krpano hotspots.
This means that the resulting position in 3D space is a combination of the spherical position
given by ath/atv/depth and the translation given by
tx/ty/tz.
For using only the 3D XYZ position, set depth to 0.0.
The unit for the 3D positions is: 1.0 ^= 1.0 cm.
The XML syntax with all supported settings and their default values:
When using .obj and .mtl files, ThreeJS doesn't automatically take the .mtl file specified in the .obj file.
That means the path and filename of the .mtl file would need to be set manually.
The krpano ThreeJS plugin adds a little helper here - when mtlurl is not set,
it automatically uses the same path and filename as the .obj file and tries loading that one.
For many cases this automatic help should work, but if the filenames are different, it would be necessary
to set the mtlurl filename manually.
Get the current ThreeJS position, rotation, scale settings and convert them
to the related krpano hotspot settings (tx,ty,tz, rx,ry,rz, scalex,scaley,scalez).
Here the light source position is defined by a spherical ath/atv position and the light target
and so also the shadow-map is always automatically at the camera / view position.
A light from a single point into all directions, with a certain range with a decreasing intenstiy.
Note - shadows from this light require the most processing power!
That's because here a cubemap (six sides/images) needs to be rendered to have shadows into all directions.
A light from a single point into a specific direction, in the shape of a cone.
Notes about Performance and Implementation
Lights and shadows can be very performance intensive, each light and shadow counts.
For best performance try to use a few lights and shadows as possible!
Try to avoid dynamically adding and removing lights (this requires an internal recompilation of the WebGL shader).
Instead toggle the hotspot visible setting.
The light-positioning, ranges and some settings and helpers are not directly mapped to their ThreeJS equivalents and
use an own implementation for a better krpano integration.
This light will behave as though it is infinitely far away and the rays produced from it are all parallel.
The common use case for this is to simulate daylight.
The sun is far enough away that its position can be considered to be infinite, and all light rays coming from it are parallel.
The light direction is calculated as pointing from the light's position to the target's position.
Different to a normal directional light, which has a source and target position, the sun light is always automatically positioned
around the current camera/view position.
The shadowmap therefore also is automatically always around the current camera/view position.
The Point Light light gets emitted from the tx, ty, tz position
and shines in all directions.
Note - shadows from this light require the most processing power!
That's because here a cubemap (six sides/images) needs to be rendered to have shadows into all directions.
Only for Sun lights: the sun itself is basically infinity far away and has only a direction (ath/atv) and no position,
but the shadowmap (an area where shadows can be rendered) can only at/around a certain position.
If true (default): the center of the shadowmap will be always at the view position.
If false: the center of the shadowmap will be at the tx, ty, tz position.
When distance is set to 0.0, the decay setting will be used to calculate the light intensity falloff.
When distance is set to a value greater than 0.0, then the light intensity will falloff
according to Inverse Square Law until near the distance cutoff,
where it will then attenuate quickly and smoothly to 0.
Inherently, cutoffs are not physically correct.
This affects the quality of the shadows, but also the memory need and the rendering performance!
The default is 256 for point lights (because point-lights use a cubemap where six maps with that size are used) and
512 for all other lights (there only one map).
The Open Source version is a simplified and stripped down version of the krpano ThreeJS Plugin.
It shows how the renderer and hittest integration works and how to use 3D Models as hotspots.