Constructor
new Scene()
Properties:
Name | Type | Description |
---|---|---|
name |
string | The name of the scene. |
modules |
Object.<string, ModuleDef> | The definitions of modules used in the scene. |
objs |
Array.<BaseSceneObj> | The objects (optical elements and/or decorations created by the user with "Tools") in the scene. |
mode |
string | The mode of the scene. Possible values: 'rays' (Rays), 'extended' (Extended Rays), 'images' (All Images), 'observer' (Seen by Observer). |
rayModeDensity |
number | The density of rays in 'rays' and 'extended' modes. |
imageModeDensity |
number | The density of rays in 'images' and 'observer' modes. |
showGrid |
boolean | The "Grid" option indicating if the grid is visible. |
snapToGrid |
boolean | The "Snap to Grid" option indicating if mouse actions are snapped to the grid. |
lockObjs |
boolean | The "Lock Objects" option indicating if the objects are locked. |
gridSize |
number | The size of the grid. |
observer |
Circle | null | The observer of the scene, null if not set. |
lengthScale |
number | The length scale used in line width, default font size, etc in the scene. |
origin |
Point | The origin of the scene in the viewport. |
scale |
number | The scale factor (the viewport CSS pixel per internal length unit) of the scene. |
width |
number | The width (in CSS pixels) of the viewport. |
height |
number | The height (in CSS pixels) of the viewport. |
simulateColors |
boolean | The "Simulate Color" option indicating if the color (wavelength) of the rays is simulated (also affecting whether the options of color filtering or Cauchy coefficients of some objects are shown.) |
colorMode |
string | The mode of rendering the color of rays (color mapping functions, etc, including the brightness behavior when |
showRayArrows |
boolean | The "Show Ray Arrows" option indicating if the arrows are shown on the rays indicating its direction. |
symbolicBodyMerging |
boolean | The "Symbolic body-merging" option in the gradient-index glass objects (which is a global option), indicating if the symbolic math is used to calculate the effective refractive index resulting from the "body-merging" of several gradient-index glass objects. |
randomSeed |
string | null | The seed for the random number generator used in the simulation, null if using randomly generated seed. Using a seed allows the simulation to be deterministic for the same version of this app when randomness is used. However, reproducibility is only guaranteed if the scene is just loaded (that is, no other editing has been done on the scene). Also, reproducibility is not guaranteed across different versions of the app. |
rng |
function | The random number generator. |
backgroundImage |
Object | null | The background image of the scene, null if not set. |
- Source:
Members
opticalObjs
Properties:
Name | Type | Description |
---|---|---|
opticalObjs |
Array.<BaseSceneObj> | The objects in the scene which are optical. Module objects are expanded recursively. If the user edits only the non-optical part of the scene, then the content of this array will not change. |
- Source:
rayDensity
Properties:
Name | Type | Description |
---|---|---|
rayDensity |
number | The mode-dependent ray density. |
- Source:
Methods
addModule(moduleName, moduleDef) → {boolean}
Add a module definition.
Parameters:
Name | Type | Description |
---|---|---|
moduleName |
string | |
moduleDef |
ModuleDef |
- Source:
Returns:
Whether the module is successfully added.
- Type
- boolean
cloneObj(index) → {BaseSceneObj}
Clone the object at an index.
Parameters:
Name | Type | Description |
---|---|---|
index |
number |
- Source:
Returns:
The cloned object
- Type
- BaseSceneObj
cloneObjsByHandle(index)
Clone the objects bound to the handle at an index.
Parameters:
Name | Type | Description |
---|---|---|
index |
number |
- Source:
loadJSON(json, callback)
Load the scene from JSON.
Parameters:
Name | Type | Description |
---|---|---|
json |
string | |
callback |
loadJSONCallback | The callback function when the entire scene or a resource (e.g. image) is loaded. |
- Source:
pushObj(obj)
Add an object to the scene.
Parameters:
Name | Type | Description |
---|---|---|
obj |
BaseSceneObj |
- Source:
removeModule(moduleName)
Remove a given module and demodulize all corresponding module objects.
Parameters:
Name | Type | Description |
---|---|---|
moduleName |
string |
- Source:
removeObj(index)
Remove the object at an index.
Parameters:
Name | Type | Description |
---|---|---|
index |
number |
- Source:
setScaleWithCenter(value, centerX, centerY)
Set the scale of the scene while keeping a given center point fixed.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | The new scale factor. |
centerX |
number | The x-coordinate of the center point. |
centerY |
number | The y-coordinate of the center point. |
- Source:
unshiftObj(obj)
Add an object to the scene at the beginning of the list.
Parameters:
Name | Type | Description |
---|---|---|
obj |
BaseSceneObj |
- Source:
validateDelayed()
Perform an delayed validation on the scene and generate warnings if necessary. This method should not be called when the editing is in progress.
- Source: