DtScript
From delta3d-extras
!!!DTSCRIPT IS NO LONGER MAINTAINED!!!
DtScript is a JavaScript language binding for Delta3D. It uses the V8 JavaScript engine.
DtScript is not a one-to-one binding of the Delta3D C++ API. Instead, it offers a simplified API.
Contents |
Features
- Create actors
- Read and modify Actor Properties
- Define actor classes and types
- Add actor properties that can be used in STAGE
- Send messages
- React to messages
- React to mouse and key events - create motion models with a few lines of code
- Create and modify CEGUI widgets, add callbacks to buttons and other events
- Load maps
- Other stuff
Getting the source
Check it out from SVN: https://delta3d-extras.svn.sourceforge.net/svnroot/delta3d-extras/dtScript
Run CMake. Build.
There is an example ProjectAssets folder included in the source tree. Please check that the context folder is correctly set in testDtScript/gameentrypoint.cpp or in the config.xml.
Game Actor Scripts
A game actor class can be added by adding a .js file to a subfolder of the Scripts folder. A file MyActor.js stored in ProjectAssets/Scripts/MyActors will add an actor type with name MyActor and category MyActors. This actor can now be instantiated from STAGE. To make the actor useful, add stuff to the .js file. The variable "actor" can be used to access the actor. Example actor.js:
actor.setName("MyActor");
actor.setClassName("MyActorClass");
// will show up in STAGE as a double property
actor.addProperty(new FloatActorProperty("ExampleNum", 3.1415, "MyGroup", "MyDescription"));
// will show up in STAGE as a string property
actor.addProperty(new StringActorProperty("ExampleString", "Hello Actor"));
// will show up in STAGE as a vec3 property
actor.addProperty(new Vec3ActorProperty("Velocity", new Vec3()));
// will show up in STAGE as an ActorID property, actors with given ClassName can be selected
actor.addProperty(new ActorActorProperty("ClassName", "CameraConnection", null);
// will be executed when actor is instantiated in game
actor.onEnteredWorld = function()
{
println(this.ExampleString);
// print some actor properties
print("Translation " + this.Translation);
print("Are collisions enabled: " + this["Enable Collision"]);
}
Example Script
The source includes a simple example project that demonstrates the capabilities of dtScript. The user can use the arrow keys to steer a ball around a plane. The camera follows the ball. On the plane, there are a number of boxes that the ball can collide with. The ball and the boxes are created from JavaScript. The camera connection of the ball can be set from STAGE.
Using the Google Chrome Developer Tools to debug JavaScript
There is an Eclipse plugin that you can use to edit and debug your JavaScript. It connects to DtScript over a network port and lets you define break points, step through functions and explore variable values. You can grab the eclipse plugin here: [[1]] To open a remote debugging port at adress 8888, execute this:
std::string flags = "--debugger-agent";
v8::V8::SetFlagsFromString(flags.c_str(), flags.length());
v8::Debug::EnableAgent("DtScript", 8888);
Please see testDtScript/gameentrypoint.cpp for an example. You can now connect eclipse to V8 by creating a new debug configuration of type "standalone V8 VM" and starting it.
JavaScript API
Global Functions
/*
* print string to console
*/
function print(string);
/*
* print string to console. Append newline.
*/
function println(string);
/*
* Read and execute a JavaScript file.
* Uses osgdb paths.
* Example: <pre>include("Scripts/myscript.js");
*/
function include(string);
/*
* Read and execute a JavaScript file.
* The path is checked against a list to make sure
* it is only included once.
* Uses osgdb paths.
* Example: <pre>include_once("Scripts/myscript.js");
*/
function include_once(string);
/*
* Reads text file from path
* @return the context of the text file or exception if file was not found
*/
function loadTextFile(string);
Actor
DtScript does not separate into actors and actor proxies. Only the properties exposed by the proxy are accessible. Also, the actor can send and receive messages.
Example:
// js code
// get a static mesh actor with name "MyStaticMeshActor"
meshactor = GameManager.findActorByName("MyStaticMeshActor");
// access property "name"
println(meshactor.name);
// access actor property "Translation"
println(meshactor.Translation);
// set property Translation
meshactor.Translation = new Vec3(10,0,0);
// set property on translation property. This also updates the wrapped property!
meshactor.Rotation.x = 30;
Actor methods:
/* Add a game actor component to actor. Actor has to be a game actor, otherwise an exception is thrown. @param component An actor component @returns Undefined */ function addActorComponent(ActorComponent component); /* @param child add this as child to actor @return undefined */ function addChild(child); /* Add an actor property to actor. After adding a property, it can be accessed via actor["propertyname"] or actor.propertyname. Actor has to be a script actor, otherwise an exception is thrown. @param property Add this property. Has to be a valid actor property! @return Undefined */ function addProperty(property); /* @return vec3 with absolute rotation of actor */ function getAbsoluteRotation(); /* @return vec3 with absolute translation of actor */ function getAbsoluteTranslation(); /* directly get absolute translation and rotation of actor @return an array [x,y,z,h,p,r] */ function getAbsoluteTranslationAndRotation(x,y,z,h,p,r); /* @return true if actor is active, else false */ function getActive(); /* @returns Actor type of this actor */ function getActorType(); /* @returns Classname string of actor. */ function getClassName(); /* @returns Description of this actor */ function getDescription(); /* @returns Name of this actor */ function getName(); /* @return parent of actor if it is a child */ function getParent(); /* @return vec3 with relative rotation of actor */ function getRotation(); /* @return vec3 with relative translation of actor */ function getTranslation(); /* directly get relative translation and rotation of actor @return an array [x,y,z,h,p,r] */ function getTranslationAndRotation(x,y,z,h,p,r); /* @param child remove this child from actor @return undefined */ function removeChild(child); /* @param vec3 Rotate actor to this HPR @return undefined */ function setAbsoluteRotation(vec3); /* @param vec3 Move actor to this absolute position @return undefined */ function setAbsoluteTranslation(vec3); /* directly set absolute translation and rotation of actor */ function setAbsoluteTranslationAndRotation(x,y,z,h,p,r); /* @param active boolean Actor is set to visible if active is true, else invisible @return undefined */ function setActive(active); /* Sets Delta3D class name string of this actor. Only works on Script actors! @param name new class name @returns Undefined */ function setClassName(string name); /* @param description New description for this actor @returns Undefined */ function setDescription(string description); @param name New name for this actor @returns Undefined */ function setName(string name); /* @param vec3 Move actor to this relative rotation @return undefined */ function setRotation(vec3); /* Set transform of actor by position, lookat and up @param position Vec3 that sets new position of actor @param lookat Vec3, point that actor will face @param up Vec3, gives up direction of actor */ function setTransformByLookat(position, lookat, up); /* @param vec3 Move actor to this relative position @return undefined */ function setTranslation(vec3); /* directly set relative translation and rotation of actor */ function setTranslationAndRotation(x,y,z,h,p,r); /* takes a point in actor local coordinates and transforms it to global coordinate space. */ function transformPointToGlobal(vec3); /* takes a point in global coordinate space and transforms it to actor local coordinates. */ function transformPointToLocal(vec3); /* takes a vector in actor local coordinates and transforms it to global coordinate space. Translation is ignored, only rotation is applied */ function transformVecToGlobal(vec3); /* takes a vector in global coordinate space and transforms it to actor local coordinates. Translation is ignored, only rotation is applied */ function transformVecToLocal(vec3);
Actor Property
Can be added to actors.
/* @param classname Only actors with this class name can be set as value @param name name of this property @param value initial actor id value @param groupname Group name string of this property @param description Description string of this property @returns a new ActorActorProperty */ function ActorActorProperty(classname, name, value, groupname, description); /* @param name name of this property @param value initial value (boolean) @param groupname Group name string of this property @param description Description string of this property @returns a new BooleanActorProperty */ function BooleanActorProperty(name, value, groupname, description); /* @param name name of this property @param value initial value (double) @param groupname Group name string of this property @param description Description string of this property @returns a new DoubleActorProperty */ function DoubleActorProperty(name, value, groupname, description); /* @param name name of this property @param value initial value (float) @param groupname Group name string of this property @param description Description string of this property @returns a new FloatActorProperty */ function FloatActorProperty(name, value, groupname, description); /* @param name name of this property @param value initial value (int) @param groupname Group name string of this property @param description Description string of this property @returns a new IntActorProperty */ function IntActorProperty(name, value, groupname, description); /* @param actor The actor that this resource will be attached to @param name name of this property @param value initial value (int) @param groupname Group name string of this property @param description Description string of this property @returns a new ResourceActorProperty */ function ResourceActorProperty(actor, name, value, groupname, description); /* @param name name of this property @param value initial value (string) @param groupname Group name string of this property @param description Description string of this property @returns a new StringActorProperty */ function StringActorProperty(name, value, groupname, description); /* where X is [2-4] @param name name of this property @param value initial value (VecX) @param groupname Group name string of this property @param description Description string of this property @returns a new VecXActorProperty */ function VecXActorProperty(name, value, groupname, description); /* * @return current value of property */ function valueOf(); /* * Set value of property */ function setValue(value); /* @return true if readonly, else false */ function isReadOnly() /* * @param b set readonly if true, read-write if false */ function setReadOnly(bool b);
Actor Type
/* @returns name of actor type. */ function getName();
Actor Component
no methods wrapped. Component Properties are accessible through named parameters:
actor.myComponent.componentProperty = value; actor.myComponent["componentProperty"] = value;
To create a new component, do this:
myComponent = new ActorComponent("DebugViewComponent");
Here, "DebugViewComponent" is the type string that identifies the actor component.
Before you can instantiate a component you have to register it with the actor component factory:
//c++ code: dtScript::ActorComponentFactory::GetInstance().Register<DebugViewComponent>(DebugViewComponent::TYPE);
GameManager
/*
Add an actor to game. (actors created with createActor are immediately added if
not told otherwise)
@param actor A valid actor, not yet added to game
@return Undefined
*/
function addActor(actortype type);
/*
Add a path to the OSG path list
@param path An absolute or relative path string
@return Undefined
*/
function addDataFilePath(path);
/*
Load the given maps
@param map1 name of map
@param map2 name of map
@return Undefined
*/
function changeMapSet(string map1 [, string map2, ...]);
/*
Cause a timer message to be cleared
@param name name of timer
@return Undefined
*/
function clearTimer(string name);
/*
creates an actor from given type
@param actortype must be a valid actor type
@param addToScene Optional, default is true. If true, add actor to scene immediately.
@return An actor
*/
function createActor(actortype type, [bool addToScene]);
/*
creates an actor from prototype
@param prototype Either the unique id or name string of a prototype
@return An actor
*/
function createActorFromPrototype(prototype);
/*
Delete actor from scene
@param actor a valid actor
@return Undefined
*/
function deleteActor(actor);
/*
returns an actor with the given ID or Null
when no actor with that ID was found
@param id must be a unique id
@return an actor or null
*/
function findActorById(id);
/*
returns an actor with the given name or Null
when no actor of that name was found
@param actorname must be a string
@return an actor or null
*/
function findActorByName(actorname);
/*
returns an actor with the given type or Null
when no actor with that type was found
@param category Category of type
@param name name of type
@return an actor or null
*/
function findActorByType(category, name);
/* @return message type with given name or null if not found
function FindMessageTypeByName(name);
/*
returns an actor type with the given category and name or undefined
when no actor type was found
@param category must be a string
@param name must be a string
@return an actor type
*/
function getActorType(category, name);
/*
@return The path to the Project assets folder
*/
function getContext();
/*
@return Name of currently loaded map
*/
function getCurrentMap();
/**
Return a property entry from the config.xml file
@param name Name of the property
@param default Return this if property is not set
*/
function getConfigPropertyValue(name, default);
/*
@return An array with the names of all loaded maps
*/
function getCurrentMapSet();
/*
returns a message type with the given name or null
when no message type of that name was found
@param typename must be a string
@return a message type or null
*/
function getMessageType(typename);
/*
@return simulation time in microseconds
*/
function getSimulationClockTime();
/*
Returns a view
@param view If empty, returns default view. If Int32: return view with this index. If string: return view with this name.
@return a view object or Null
function getView([view]);
/*
@return The default window of the delta3d app
*/
function getWindow();
/*
@param actor publish this actor to the world
@return undefined
*/
function publishActor(actor);
/*
Shut down Delta3D
@return Undefined
*/
function quit();
/*
register a callback function to be executed when a message of given type is received
Usage example:
actor = GameManager.findActorByName("MyActor");
GameManager.registerForMessages(actor, "Tick Local", function(msg) { print("Tick!"); });
@param actor The game actor which owns the function
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function registerForMessages(Actor actor, MessageType type, Function cbfunction);
/*
register a callback function to be executed when a message of given type is received
and its AboutActorID is the ID of actor
Usage example:
actor = GameManager.findActorByName("MyActor");
GameManager.registerForMessages(actor, "Tick Local", function(msg) { print("Tick!"); });
@param actor The game actor which owns the function
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function registerForMessagesAboutActor(Actor actor, MessageType type, Function cbfunction);
/*
register a callback function to be executed when a message of given type is received.
This is not dependent on an actor. The callback will not be cleared when the current map is unloaded.
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function registerPersistent(MessageType type, Function cbfunction);
/*
reloads all currently loaded maps from disk. Good if you changed something
in STAGE and don't want to restart the application
*/
function reloadCurrentMaps();
/**
@param name Unset this property in the config.xml file
@return Undefined
*/
function removeConfigPropertyValue(name);
/*
send the message
Usage example:
GameManager.sendMessage(new Message("Tick Local"));
@param message A valid message object
@return undefined
*/
function sendMessage(message);
/*
send the message to the network
@param message A valid message object
@return undefined
*/
function sendNetworkMessage(message);
/**
Set this property in the config.xml file
@param name Name of property
@param value Value for property
@return Undefined
*/
function setConfigPropertyValue(name, value);
/*
Display OSG statistics
@return Undefined
*/
function setNextStatisticsType();
/*
sets simulation time in microseconds
@param microseconds The new clock value
@return Undefined
*/
function setSimulationClockTime(int32 microseconds);
/*
Cause a timer message to be sent in the future
@param name name of timer
@param about Timer message will have this actor's ID as AboutActorId
@param time Send message time seconds in the future
@param repeat Send this message periodically?
@param realtime Send msg in real time?
@return Undefined
*/
function setTimer(string name, Actor about, number time [, bool repeat, bool realtime]);
/*
unregister a callback function to no longer be executed when a message of given type is received
@param actor The game actor which owns the function
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function unregisterForMessages(Actor actor, MessageType type, Function cbfunction);
/*
unregister a callback function to no longer be executed when a message of given type is received
for the given actor
@param actor The game actor which owns the function
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function unregisterForMessagesAboutActor(Actor actor, MessageType type, Function cbfunction);
/*
unregister a callback function previously registered.
@param type can be a message type object OR a string containing the name
of a message type
@param cbfunction A function that expects one argument (the message)
@return Undefined
*/
function unregisterPersistent(MessageType type, Function cbfunction);
GUI
Wraps CEGui functionality.
Example:
var gui = new GUI(GameManager.getView().getCamera(), GameManager.getView().getKeyboard(), GameManager.getView().getMouse());
gui.loadScheme("WindowsLook.scheme");
gui.loadLayout("mainHud.layout");
gui.getWidget("QuitButton").onClicked = function() { GameManager.quit(); }
Methods:
/* Constructor. Only call once per camera! @param camera A camera object @param keyboard A keyboard object. Can be null if you don't want to handle keyboard events in GUI @param mouse A mouse object. Can be null if you don't want to handle mouse events in GUI */ function GUI(camera, [keyboard, mouse]); /* Load CEGUI scheme. @param name name of scheme @return Undefined */ function loadScheme(string name); /* Set image as mouse cursor @param imageset The image set containing the cursor image @param image The image to use @return Undefined */ function setMouseCursor(string imageset, string image); /* Load a CEGUI layout @param name The layout to load @return Undefined */ function loadLayout(string name); /* Get GUI widget with given name @param name name of the widget @return GUI widget */ function getWidget(string name); /* Create GUI widget @param parent The parent under which to create the new image @param typename the CEGUI type name (example: "WindowsLook/Button") @param name name of the new widget @return GUI widget */ function createWidget(GUIWidget parent, string typename[, string name]); /* Destroy GUI widget with given name @param name name of the widget @return GUI widget */ function destroyWidget(string name); /* @param name name of the image set @return True if present, else False */ function isImagesetPresent(string name); /* @param name name of the image set to create @return Undefined */ function createImageset(string name); /* @param name name of the image set to destroy @return Undefined */ function destroyImageset(string name); /* Load an image from osgDB path into imageset @param imageset name of the image set @param path Path to image relative to ProjectAssets dir @return Undefined */ function loadImageIntoImageset(string imageset, string path);
GUI Widget
A CEGUI window.
Methods:
/* @param visible Make invisible if false, visible if true @return Undefined */ function setVisible(bool visible); /* Set alpha value of widget @param alpha Number between 0 and 1 @return Undefined */ function setAlpha(Number alpha); /* Set CEGUI property @param name Name of property @param value New value for property @return Undefined */ function setProperty(string name, string value); /* Get CEGUI property @param name Name of property @return Value of property */ function getProperty(string name); /* Add a child widget to widget @param widget New child @return Undefined */ function addChildWidget(GUIWidget widget);
Log
Prints messages to log. File name and line number are passed to log.
function Log.always(string); function Log.debug(string); function Log.error(string); function Log.info(string); function Log.warning(string);
Input
Offers methods to query input devices
Methods:
/* Return current value of keyboard key with given name
example: var spacePressed = Input.getKey("Space");
@return true if pressed, else false
*/
function getKey(name);
/* Return current value of mouse button with given name
example: var mousePressed = Input.getMouseButtonPressed("LeftButton");
Valid names: LeftButton, MiddleButton, RightButton
@return true if pressed, else false
*/
function getMouseButtonPressed(name);
/*
@return a Vec2 with the mouse position on screen (0 - 1)
*/
function getMousePosition();
/*
register the callback function to be called when the mouse button is clicked.
The previously registered callback is unregistered.
@param button one of "left", "right", "middle"
@param cbfunction A function expecting no arguments
@return Undefined
*/
function setButtonClickedCallback(string button, Function cbfunction);
/*
register the callback function to be called when the mouse button is pressed.
The previously registered callback is unregistered.
@param button one of "left", "right", "middle"
@param cbfunction A function expecting no arguments
@return Undefined
*/
function setButtonPressedCallback(string button, Function cbfunction);
/*
register the callback function to be called when the mouse button is released.
The previously registered callback is unregistered.
@param button one of "left", "right", "middle"
@param cbfunction A function expecting no arguments
@return Undefined
*/
function setButtonReleasedCallback(string button, Function cbfunction);
/*
register the callback function to be called when a given key is pressed.
The previously registered callback is unregistered.
@param cbfunction A function with no arguments
@return Undefined
*/
function setKeyPressedCallback(string key, Function cbfunction);
/*
register the callback function to be called when a given key is released.
The previously registered callback is unregistered.
@param cbfunction A function with no arguments
@return Undefined
*/
function setKeyReleasedCallback(string key, Function cbfunction);
/*
register the callback function to be called when a given key is typed.
The previously registered callback is unregistered.
@param cbfunction A function with no arguments
@return Undefined
*/
function setKeyTypedCallback(string key, Function cbfunction);
/*
register the callback function to be called when the mouse is dragged.
The previously registered callback is unregistered.
@param cbfunction A function expecting two arguments (x and y)
@return Undefined
*/
function setMouseDraggedCallback(Function cbfunction);
/*
register the callback function to be called when the mouse is moved.
The previously registered callback is unregistered.
@param cbfunction A function expecting two arguments (x and y)
@return Undefined
*/
function setMouseMovedCallback(Function cbfunction);
/*
register the callback function to be called when the mouse is dragged.
The previously registered callback is unregistered.
@param cbfunction A function expecting one argument (delta)
@return Undefined
*/
function setMouseScrolledCallback(Function cbfunction);
Message
Messages of an existing type can be created:
msg = new Message("Tick Local");
GameManager.sendMessage(msg);
or:
msgtype = GameManager.getMessageType("Tick Local");
msg = new Message(msgtype);
GameManager.sendMessage(msg);
The message constructor can take an object as a second argument:
msg = new Message("Tick Local", {DeltaSimTime: 0.3, DeltaRealTime: 9.9});
This sets the DeltaSimTime and DeltaRealTime named properties of the tick local message to the given values. It could also be written as:
msg = new Message("Tick Local");
msg.DeltaSimTime = 0.3;
msg["DeltaRealTime"] = 9.9;
DtScript also defines a new message type that can be used to assemble messages from JavaScript.
msg = new JSMessage("Steer", [new FloatMessageParameter("Direction", 0.1)]);
GameManager.sendMessage(msg);
"Steer" is not the name of a message type registered with the game manager. It is an ad-hoc name for this message. The command creates a new message of type dtScript::JavaScriptMessage, sets its "name" property to "Steer" and adds a NamedFloatParameter with name "Direction" and value 0.1 to it.
MessageType
Actor type identifier
/* @return name of type */ function getName();
NamedParameter
A message parameter.
/* Constructs a new DoubleMessageParameter. Use with new! @param value initial value @return a new DoubleMessageParameter */ function DoubleMessageParameter(value); /* Constructs a new FloatMessageParameter. Use with new! @param value initial string value @return a new FloatMessageParameter */ function FloatMessageParameter(value); /* Constructs a new GroupMessageParameter. Use with new! @param value Array of sub-parameters @return a new GroupMessageParameter */ function GroupMessageParameter(value); /* Constructs a new IntMessageParameter. Use with new! @param value initial string value @return a new IntMessageParameter */ function IntMessageParameter(value); /* Constructs a new StringMessageParameter. Use with new! @param value initial string value @return a new StringMessageParameter */ function StringMessageParameter(value); /* Constructs a new VecXMessageParameter where X = 2-4. Use with new! @param value initial vector value @return a new VecXMessageParameter */ function VecXMessageParameter(value); /* * return value of parameter. Use this if you want to assign value to something else! */ function valueOf(); /* * set value of parameter. */ function setValue(v);
UniqueId
Wraps a unique actor ID. Warning: Equality test of IDs does not work! Compare like this: actor1.id.stringVal() == myId.stringVal()
Vec2, Vec3, Vec4
Properties: 0, 1, 2, 3 (of course dependent on type)
Example: var vec1 = new Vec3(1,2,3); var vec2 = new Vec3(3,4,5); var vec3 = vec2.clone(); vec3.add(vec1);
Methods:
/*
Add.
@param arg If number: Add arg to each vector component.
If vector: Add arg to this
*/
function add(arg);
/*
return an exact copy of this
*/
function clone();
/*
return euclidean length of vector
*/
function length();
/*
Multiply.
@param arg If number: Scale all vector components by val.
If vector: Scale each vector component by the
corresponding value in the other vector
*/
function mult(arg);
/*
Keep direction, but change length to 1.
Throws exception when called on a null-vector
*/
function normalize();
/*
Set all vector properties at once.
@param arg1 - n numbers
*/
function set(arg1, arg2, ... ,argn);
/*
Subtract a vector from this
@param vec Subtract this vec from vector components of this
*/
function subtract(vec);
/*
Constructor. Creates a null vector.
*/
function VecX();
/*
Copy Constructor.
*/
function VecX(VecX);
/*
Constructor. Set vector components from arguments.
*/
function VecX(arg1, .., argX);
View
Methods:
/* @return The camera assigned to this view */ function getCamera(); /* Shoots a ray from screenPos into scene and returns a list of intersecting game actors. Note: non-game actors (dtDAL::ActorProxy) are not intersected! @param screenPos Vec2 Position in screen coordinates @param nodemask Node mask to use for picking. Defaults to #FFFFFFFF @return An array containing intersetion hits. Each hit is an object with members "normal", "position", "actor" and "nodeName". */ function getIntersectingActors(screenPos[, nodemask]); /* @return The keyboard assigned to this view */ function getKeyboard(); /* @return The mouse assigned to this view */ function getMouse(); /* @param screenPos Vec2 Position in screen coordinates. Defaults to (0, 0) @param nodemask Node mask to use for picking. Defaults to #FFFFFFFF @return A vec3 with the pick position - (0,0,0) when no hit recorded */ function getPickPosition([screenPos, nodemask]);
Window
Methods:
/* Convert screen coordinates to pixel coordinates @param in A vec2 with screen coords from -1 to 1 @param out A vec2 that receives the pixel coordinates @return Undefined */ function calcPixelCoords(in, out);
Actor Components
The DtScript library provides a number of actor components with corresponding wrappers.
AnimActorComponent
Adds an animated mesh to a game actor.
Usage:
var animcomp = new AnimActorComponent();
actor.addActorComponent(animcomp);
animcomp.setMesh("SkeletalMeshes/marine.xml");
animcomp.playAnimation("Run");
API:
/* Constructor. No args. */ function AnimActorComponent(); /* Clears animation with given name @param name String with animation name as defined in anim xml file @return Undefined */ function clearAnimation(name); /* Play this animation @param name String with animation name as defined in anim xml file @param callback Optional: A function without args that gets called when animation ends or is cleared @return Undefined */ function playAnimation(name[, callback]); /* Sets the weight of an animation used for animation blending. @param name String with animation name as defined in anim xml file @param weight New weight for animation @return Undefined */ function setAnimationWeight(name, weight); /* Load animation from this path @param path Load this mesh file @return Undefined */ function setMesh(path); /* @param factor Scale animation speed by this factor. 1 = normal speed, 0 = frozen */ function setTimeFactor(factor); /* Propagate the animation playback. @param dt Time since last call in seconds @return Undefined */ function update(dt);
MeshActorComponent
Adds a static mesh to a game actor. Usage:
actor.addActorComponent(new ActorComponent("MeshActorComponent"));
actor.MeshActorComponent["Mesh File"] = "StaticMeshes/physics_crate.ive";
API: No methods for now. Watch out: The mesh is not scalable! (for performance reasons)


