Scripting languages are linked to Realsoft 3D through a small set of low level functions corresponding to those used in the Realsoft 3D SDK 'C' API.
![]() |
Note |
|---|---|
| The API described here is not indended for end users but for class implementators and other advanced users who need to get full control over Realsoft 3D. |
Scrips can access Realsoft 3D through two variables:
r3MainWindow - root of the user interface (main window)
r3Model - root of the model (functionality).
include - include a JavaScript file
include(filename);
filename - JavaScript file to be included
-
Loads in given JavaScript file, if not already loaded. This function corresponds to #include directive of 'C/C++' and can be used for loading JavaScript files defining "proto type" objects (in Java or C++, these would be called 'classes').
include("oops/r3button.js");
load - load a file
load(filename);
filename - the name of JavaScript file to be loaded
-
Loads in given JavaScript file. Unlike include(), this function doesn't detect whether the file was already loaded. A file can be loaded any number of times.
load("myclasses/toolbars/mycreationtools.js");
MakeID - Create an IFF identifier
id = MakeID(a,b,c,d);
a,b,c,d - four ascii values
32 bit IFF identifier
Creates a 32 bit IFF identifier from the given four 8 bit values.
var myid = MakeID('I','a','g','e');
R3New - create a new Realsoft 3D object
obj = new R3New(classid, taglist);
classid - class identifier
obj - realsoft 3d object
Class id, methods and attributes for the object are defined in the object's class header file. All class header files can be found in 'scripts' folder.
// Create a sphere object
include("real/objects/r3sphere.js");
sphere = R3New(R3CLID_SPHERE,
[R3RA_Name, "my sphere",
R3SPHA_Center, new r3Vect(0.0, 0.1, 0.0),
R3SPHA_Radius, 0.1]);
R3Dispose - delete object
R3Dispose(obj);
obj - realsoft 3d object to be disposed
-
Deletes the given Realsoft 3D object
// create a sphere sphere = R3New(R3CLID_SPHERE, ...); ... // delete the sphere R3Dispose(sphere);
R3Set - set object attribute
R3Set(obj, id, value, type, flags);
obj - address of Realsoft 3D object
-
Set attribute. This function corresponds to 'R3SetAttrs()' function of 'C' API. The parameter 'object' refers to Realsoft 3D object. The 'id' is a unique identifier specifying the attribute to be set. The type of the 'value' parameter must match the type of the attribute to be set. There is no run time type conversion and the type of the attribute must be correct or program may crash.
// move the main window to x=10, y=20 R3Set(r3MainWindow, R3WGA_Left, 10, R3TID_INTEGER, 0); R3Set(r3MainWindow, R3WGA_Top, 20, R3TID_INTEGER, 0);
R3Get - fetch object attribute
R3Get(obj, id, value, typeid, flags);
obj - Realsoft 3D object
value - fetched attribute.
Fetch object attribute. This function corresponds to R3GetAttrs() function of 'C' API. Typeid parameter specifies the type of the attribute to be fetched. Supported types are defined in 'oops/r3typids.js'. The 'byvalue' attribute indicates whether the attribute is fetched 'by value' or 'by reference'. This is needed to tell R3Get() whether it should allocate temporary buffer or not.
name = R3Get(r3MainWindow, R3WA_Title, R3TID_STRING, R3TNS_COPYSTRING);
print("Current window title is " + name);
R3Do - call a method
rc = R3Do(obj, mth, taglist) - call a method
obj - address of Realsoft 3D object
rc - method specific return value
Send a method to Realsoft 3D object. There are six different functions which corresponds to those used by SDK/'C' API. Because JavaScript keeps track of number of passed parameters, there is no need to terminate the tag list by 'R3TAG_END'.
// Ask the Realsoft 3D to find out its native size R3DoA(r3MainWindow, R3WGM_FIT, R3WFP_BESTFIT);
R3ProcessEvents - start event processing
R3ProcessEvents(obj);
obj - main window
-
Start event processing for the given window. There can only be one event loop per application. If there is already an event processing loop running on the application in question, the function returns immediately. Otherwise the function returns when the event loop is terminated.
R3ProcessEvents(window);
R3Exit - stop event processing
R3Exit();
-
-
Terminates event processing loop, which most likely causes the program to exit.
R3Exit();
R3ClassFind - find class
obj = R3ClassFind(classid);
classid - class identifier
obj - class object
Find class by given id. If the class is not registered, returns NULL.
In Realsoft Graphics Oy's object oriented programming system, constructor is a class method. Creating a sphere means we call R3RM_CREATE method of the sphere class.
include("real/objects/r3sphere.js");
// find sphere class
class = R3ClassFind(R3CLID_SPHERE);
if(class) {
// ask sphere class to create sphere instance
sphere = R3Do(class, R3RM_CREATE,
[R3SPHA_Radius, 0.1]);
}
Class - show class info
Class(name);
name - name of the object
-
Show class specific info.
Class("CurrentProject.Geometrics.Root");
Attrs - list public attributes
Attrs(name);
name - hierarchical name specifying the object
-
This function attemps to find the given object and enumerate its attributes. The name is a hierarchical name which identifies an object in the application in question.
// Ask a sphere to enumerate its attributes
Attrs("CurrentProject.Geometrics.Root.mylevel.mysphere");
Get - fetch attribute by name
value = Get(name);
name - hierarchical name specifying a Realsoft 3D attribute to be fetched
obj - attribute
Fetches an attribute by symbolic name.
// fetch the addres of the project list object in Realsoft 3D
aProjectList = Get("");
// fetch the current project object
aCurrPrj = Get("CurrentProject");
// fetch the name of the current project
sName = Get("CurrentProject.Geometrics.Name");
// fetch the name of the Root level
sName = Get("CurrentProject.Geometrics.Root.Name");
Set - set public attribute
rc = Set(name, value);
name = symbolic name identifying the object/attribute
-
Set public attribute.
// rename the root level
Set("CurrentProject.Geometrics.Root.Name", "my new root");
// set the radius and center of 'mysphere'
Set("CurrentProject.Geometrics.Root.mysphere.Radius", 0.2);
Set("CurrentProject.Geometrics.Root.mysphere.Center", new r3Vect(0.2, 0.1, 0));
// set current animation frame
Set("CurrentProject.Animator.Frame", 30);
Co - set Current Object
ok = Co(name);
name - symblic name
ok - true if succeeded
Make the given object the current working object. Names passed to Get(), Set() and Attrs() functions are relative to the current object.
// make the 'root' level the current working object
Co("CurrentProject.Geometrics.Root");
// change the root's name
Set("Name", "my root level");
Up - make the parent object the current object
Up();
-
-
Make the parent object the current working object. Returns false if there is no parent object.
// make the 'root' level the current working object
Co("CurrentProject.Geometrics.Root");
// change the root's Translate attribute
Set("Translate", new r3Vect(0, 0, 0));
// pop up one level
Up();
// set root object's name
Set("Root.Name", "my root level");