A scene in script is directly related to a scene in a DX Studio document.
Properties
script |
Provides access to all of the functions and variables in the scene. |
Controls the media player for the scene. |
|
objects |
Access objects in the scene. |
sounds |
Access sounds in the scene. |
textures |
Access texture maps in the scene. |
meshes |
Access meshes in the scene. |
timer |
A floating point timer for the scene. |
ambientLightColor |
A Color value for the ambient light in a 3D scene. |
backgroundColor |
A Color value representing a solid background. |
backgroundImage |
The name of the resource to be used as a background image. |
backgroundEnvironment |
The name of the environment map to be used as a background in a 3D scene. |
fogType |
The type of fog used in a 3D scene. Can be none, linear, exponential or exponential2. |
fogColor |
The color of the fog in a 3D scene. This will override any other background. |
fogStart |
The distance at which the fog starts having an effect (linear fog). |
fogEnd |
The distance at which the fog becomes solid (linear fog). |
fogDensity |
The factor by which fog becomes more dense (exponential fog). |
wireframe |
Boolean value that if true draws the scene in wireframe mode (default is false). |
lighting |
Boolean value that if false disables any lighting in the scene (default is true). |
mouseX |
Scene coordinates of the current mouse X position. |
mouseY |
Scene coordinates of the current mouse Y position. |
lastHitInfo |
Collection of properties of the last ray cast (either by mouse or function). Full details here. |
zNear |
Sets the near Z clip plane (float) - this should be as high as possible without losing any near to camera objects. |
zFar |
Sets the far Z clip plane (float) - this should be as close to the near plane as possible without losing any distant objects. |
alphaRef |
An integer value between 0 and 255 that determines the cutoff value used as a reference alpha testing. A low value will cause very transparent edges to be drawn which might block the z-buffer, a higher value will be smoother but may lose some texture around the edge. |
physics |
Controls the physics engine for the scene. |
updateWhenInvisible |
If set to true this scene will keep processing onUpdate functionality even if it is not being displayed in any layer. |
selectionMask |
An integer with 31 bit resolution determining the selection mask. Bit 0 is the selectable value for mouse pick, but you can use the other bits as you choose. Combine with object.selectionMask and scene.getObjectFromRay(). |
maxUpdateCamDist |
A float that determines the maximum distance an object cam be from the camera before it's update is skipped to speed things up. |
update |
A boolean value that if set to false will disable updates for the scene. |
xmlString |
A string containing all of the properties of the scene and their values that can be stored in XML. Read this value to store the scene, and set this value to rebuild the scene. |
Methods
objectAdd(id,type) |
Adds an object called 'id' and sets the 'type' to be the identifier of the mesh/bitmap/object used as a definition. e.g. var myobj = scene.ObjectAdd("clock_1","clock"); |
objectRemove(id) |
Removes the object with the given id from the world. |
objectGetArray() |
Returns an Array of Object types representing all of the objects in the world for this scene. |
objectsCollide(id1,id2,[tolerancefactor],[checkfaces]) |
Returns true if the object with identifier id1 collides with the object with identifier id2. You can also optionally set a floating point tolerancefactor (which defaults to 1.0), such that if you set it to 0.9, the objects could be 10% closer before the collision was triggered. A final optional boolean can be used to actually check the faces for intersection if the first basic test is passed - set to true to enable this. |
mouseOverPlane(planepoint, planenormal) |
Returns true if the mouse is over the given 3D plane. The plane is defined by 2 Vectors, a point on the plane and the normal to the plane. |
mousePlanePos(planepoint, planenormal) |
Returns a Vector giving the current 3D position of the mouse over the given 3D plane. The plane is defined by 2 Vectors, a point on the plane and the normal to the plane. |
rotationDeltaFromScreenDelta(screendx,screendy,factor) |
Returns a Rotation that represents the change in rotation represented by a movement in screen coordinates given the current scene's camera. Combine this with the current rotation of an object, and feed in the change in x,y mouse coordinates to get interactive object manipulation. |
getObjectFromRay(rayfrom,raydir,range) |
Returns an object class of the nearest world object hit by a ray from Vector 'rayfrom' in the direction of Vector 'raydir' with an optional maximum range. Returns null if no object found. Uses the scene and object selectionMask property to determines which objects to check. |
meshAdd(objectdefid, [filename], [inBackground]) |
Adds a new Mesh definition to the scene. (Use objectAdd to create an object and pass the objectdefid as the type). The filename can be a disk file or URL, or not supplied to create a new mesh from scratch. The inBackground property is a boolean value that when true will not interrupt the playback and instead load the mesh during idle time (defaults to false). You can check on the load progress with system.getLoadProgress(filename). |
meshRemove(objectdefid) |
Removes the Mesh definition from the scene. |
backgroundAdd(backgroundid, backgroundtype) |
Adds a background of the given type "solid", "environment", or "image" and id. |
backgroundRemove(backgroundid) |
Removes the background of the given id. |
backgroundRemoveAll() |
Removes all backgrounds from the scene. |
soundGetArray() |
Returns an Array of Sound types representing all of the sounds in this scene. Note these are not string ids - if you want the string id, just read the id property of each sound object in the array. |
waypointLink(objid1, objid2, [linkForward], [linkBack]) |
Links waypoint objects with string ids objid1 and objid2. If only 2 params are supplied it will link forward and back by default, otherwise the linkForward and linkBack boolean values determine the directions supported. |
environmentAdd(id, filename) |
Adds an environment to the scene from either a disk file or a URL. |
environmentRemove(id) |
Removes the given environment from the scene. |
getTextureDifference(texFile1, textFile2, [maskFile]) |
A utility function to compare texture maps and return the pixel difference between them as a float. e.g. If all pixels are different it returns 0, if half are the same 0.5, if all the same 1.0. If you supply a mask file, then it will ignore any pixels at black locations in the mask. All textures must be the same size. |
Accessing script functions/variables
You can also call functions defined in scene script, or read/write variables. Just prefix the function/variable with 'script.' to access...
script.<variable>
script.<function>
e.g.
print(scene.script.power); // print the variable 'power' defined in the script of the current scene.
scenes.scene_2.script.runAway(); // call the function runAway() defined in the scene scene_2's script.
You can also change the whole script on a scene at runtime by setting the scene.script.sourceCode value. Note that when you change the script all variables defined in the script will be reset. onInit will not be called automatically, but you can call it manually if you need to set up your variables in that function with the call to object.script.onInit().
Examples
scene.media.track=2; // goes to track 2 in the media player list for the current scene.
scenes.myscene1.script.openDoor(); // calls the 'openDoor' function in the scene 'myscene1'.
scenes.scene_2.objects.ship.script.Explode(); // calls the 'Explode' function of the 'ship' object in 'scene_2'.
function onInit()
{
var objs=scene.objectGetArray(); // get an Array of all the objects in the world for this scene.
print(objs.length+" objects in the scene.");
for(var i=0;i<objs.length;i++)
{
print(objs[i].id+" ("+objs[i].type+")"); // Prints out all the object ids along with their type.
}
}
Remarks
See Also


