BaseObject¶
Overview¶
Provides actions on object.
Name | Description | Returns |
---|---|---|
addGravity | Add a gravity value to a specified object | none |
addScript | Add a script to a specified object,Returns the type of script added to the object | script |
addTail | Add a tail to a specified object. Commonly used with the function movePath | none |
clone | Copy an existing object | BaseObject |
destroy | Remove an existing object | BaseObject |
getPosition | Acquire the position of a specified object | Vector3 |
getScale | Acquire the scale of a specified object,``Vector3`` movePath,Move object by a specified parameter | none |
moveTo | Move object to a position within a given time | none |
pitch | Angel of rotation(in degree) of the object around its pivot point along X axis | none |
removeScript | Remove a script from the specified object | none |
roll | Angel of rotation (in degree) of the object around its pivot point along the Z axis | none |
setAnimSpeed | Set the animation speed of a specified object | none |
setColor | Set the color of a specified object | none |
setColorFlash | Set the flash state, flash color and flash time of a specified object | none |
setPickEnabled | Set the selectable state of the specified object. Commonly used with mouse event functions | none |
setPosition | Set the object’s position | none |
setPositionXZ | Set the object’s horizontal position | none |
setPositionY | Set the object’s position along the Y axis | none |
setScale | Set the scale of the object | none |
setTransparent | Set the transparency of a specified object | none |
stopAnim | Stop a specified object’s animation | none |
stopMoving | Stop the object moving | none |
transformPoint | Change specified coordinates of object from relative coordinates to absolute coordinates | Vector3 |
translate | Move a specified object in a specified direction and distance | Vector3 |
yaw | Angel of rotation (in degree) of the object around its pivot point along the Y axis | none |
BaseObject.addGravity¶
Add gravitational value to a object
Parameters¶
Name | Description |
---|---|
mass | float the weight of the object |
Example¶
1 2 3 | //add gravity to a 3.5 KG weight object
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.addGravity(3.5)
|
BaseObject.addScript¶
Add script to a object
Parameters¶
Name | Description |
---|---|
script | script to associate with the object |
name | string name of the script |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** Create a script named'AutoRtate'used to define the speed of object'objOption'.
A script may include a'Start'and'Update' function which is automatically recognized by the system.
The'Start'function will be called only once while the'Update'function will be called on repeatedly */
AutoRotate = {
speed : 0,
objOption : null,
function Start() {this.speed = util.randomFloat(1, 8);}
function Update() {this.objOption.yaw(this.speed); }
}
//create object
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088", Vector3(2.5, 0, 0));
//add script “rotation” to object
var script = obj.addScript(AutoRtate,"rotation");
//set script's attribute objOption to be object; now function Update can rotate obj by its Y axis in a random speed
script.objOption = obj;
|
BaseObject.addTail¶
Add trail to a specified object. Most Commonly used with the function movePath. Often used to increase the visual effects of an object.
Parameters¶
Name | Description |
---|---|
{json} | json format includes start width, end width ,end color and time |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | //create object
var obj =object.create("AB052B5B646E4A48B9C045096FF9B088");
var path = Vector3List();
//generate 36 vector3 point, add them to a Vector3List, this could be seen as a circle, its radius is 10
for (var degree = 0; degree < 360; degree += 10)
{
path.Add(Vec3(Math.Cos(degree*Math.Deg2Rad)*10,0.5,Math.Sin(degree*Math.Deg2Rad)*10));
}
// move an object along the path in 10 seconds repeatly, whilst moving,
// the object will always look at (0,0,0),
obj.movePath({
"path": path,
"time": 10,
"lookPos": Vector3.zero,
"loopType": "loop"
});
//add a tail, start width 0.6, end width 0, color is red, lasting 5 seconds
obj.addTail({
"startWidth": 0.6,
"endWidth":0,
"color":Color.red,
"time": 5
});
|
BaseObject.clone¶
Clone a object.
Parameters¶
None.
Example¶
1 2 3 4 5 6 7 | //Create an object, copy it and name is'obj2'. Then rotate'obj2'along the Y-Axis at a 45 degree angle
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
var obj2=obj.clone();
obj2.yaw(45)
|
BaseObject.destroy¶
Remove a object.
Parameters¶
None.
Example¶
1 2 3 4 5 6 | //Create an object named 'Obj'. Create a button named'Delete'with the size (10,100,100,20).
//click on this button to remove object'obj'from the scene
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
gui.createButton("Delete",Rect(10,100,100,20),function(){obj.destroy()})
|
BaseObject.getPosition¶
Get position of a object.
Parameters¶
None.
Example¶
1 2 3 4 | //Create an object and print its position
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
print(obj.getPosition())
|
BaseObject.getScale¶
Get scale information of a object.
Parameters¶
None.
Example¶
1 2 3 4 | //Create an object and print its scale
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
print(obj.getScale())
|
BaseObject.movePath¶
Move object along pre-defined path.
Parameters¶
Name | Description |
---|---|
{json} | json format, specify path, time, target point, if loop, etc. |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | //Create object
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
//Generate 36 Vector3 point, add them in a Vector3List, you could see this Vector3List as a circle
var path = Vector3List();
for (var degree = 0; degree < 360; degree += 10)
path.Add(Vec3(Math.Cos(degree*Math.Deg2Rad)*10,0.5,Math.Sin(degree*Math.Deg2Rad)*10));
//Move an object along a path in 10 seconds , whilst moving ,the object will always face the vector (0,0,0) ,
//after the object completes the movement , loop this function
obj.movePath({
"path": path,
"time": 10,
"lookPos": Vector3.zero,
"loopType": "loop"
});
|
BaseObject.moveTo¶
Move object to target position within a certain time
Parameters¶
Name | Description |
---|---|
pos | Vector3 destination position |
time | float moving time |
Example¶
1 2 3 | // Create object, move it to (10,0,0) in 5 seconds
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.moveTo(Vector3(10, 0, 0), 5.0)
|
BaseObject.pitch¶
Rotate object on the X-axis by degree
Parameters¶
Name | Description |
---|---|
degree | float degree of rotation |
Example¶
1 2 3 | //Create an object and rotate the object on the X-axis at a 45 degree angle.
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.pitch(45)
|
BaseObject.playAnim¶
Play object’s animation
Parameters¶
Name | Description |
---|---|
animName | string name of the animation |
Example¶
1 2 3 4 | // Create an object named'obj'. Create a button with size (100,100,100,30).
// Pressing on this button will execute the “Run” animation of the object.
var obj = object.create("0bcba8ca78734b64a3dae3eb699a913c");
gui.createButton("Run", Rect(100, 100, 100, 30), function() {obj.playAnim("Run");});
|
BaseObject.removeScript¶
Move script associate with object
Parameters¶
Name | Description |
---|---|
name | string name of the script |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | AutoRtate = {
speed : 0,
objOption : null,
function Start() {this.speed = util.randomFloat(1, 8);}
function Update() {this.objOption.yaw(this.speed); }}
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088", Vector3(2.5, 0, 0));
var script = obj.addScript(AutoRtate,"rotation");
script.objOption = obj;
//Create a button. Pressing on this button will remove the “rotation” script from the object'obj'.
gui.createButton("Remove Script", Rect(100, 100, 100, 30),function(){obj.removeScript("rotation")})
|
BaseObject.roll¶
Rotate object a specified degree around the Z-axis (clockwise)
Parameters¶
Name | Description |
---|---|
degree | float degree of rotation |
Example¶
1 2 3 | //Create an object and rotate the object on the X-axis at a 45 degree angle.
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.roll(45)
|
BaseObject.setAnimSpeed¶
Set the animation speed of a specified object
Parameters¶
Name | Description |
---|---|
speed | float speed of animation playing |
Example¶
1 2 3 4 5 6 | var obj = object.create("0bcba8ca78734b64a3dae3eb699a913c");
gui.createButton("Run", Rect(100, 100, 100, 30), function() {obj.playAnim("Run");});
//Create a button. Pressing on this button will set the objects animation speed to'4.5'
gui.createButton("Accelerate", Rect(100, 150, 100, 30), function() {obj.setAnimSpeed(4.5)})
|
BaseObject.setColor¶
Set object color
Parameters¶
Name | Description |
---|---|
color | color |
Example¶
1 2 3 4 5 | //Set the object color to blue
var obj = object.create("FF2A3E364B1E4B928891E05A9279C7A7", Vector3(0, 0, 0));
obj.setColor(Color.blue);
|
BaseObject.setColorFlash¶
Set flash state, flash color and flash interval of a specified object
Parameters¶
Name | Description |
---|---|
enable | boolen turn flash ‘On’ or’ Off’ |
color | color flash color |
time | float flash interval |
Example¶
1 2 3 4 5 | // Create object and set flash to'On', flash color to 'Green' and Flash interval to 2.5 seconds.
var obj = object.create("FF2A3E364B1E4B928891E05A9279C7A7", Vector3(4, 0, 0));
obj.setColorFlash(true, Color.green,2.5);
|
BaseObject.setPickEnabled¶
Set selectable state of the specified object. Commonly use with the ‘Mouse event’ functions
Parameters¶
Name | Description |
---|---|
enable | boolen turn pickable ‘On’ or’ Off’ |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
var dragObj = null;
util.addEventListener("dragstart", function(event) {
if (event.obj && event.button == 0) {
dragObj = event.obj;
dragObj.setPickEnabled(false)
camera.enableRot = false; }});
// Add a “dragstart” event to an object named'obj'.
// Left clicking and dragging object'obj'will change the selectable state to false (Prevents object from being repeatedly dragged).
util.addEventListener("drag", function(event) {
if (dragObj && event.button == 0)
dragObj.pos = event.pos;});
util.addEventListener("dragend", function(event) {
if (dragObj && event.button == 0) {
dragObj.setPickEnabled(true);
dragObj = null;
camera.enableRot = true;}});
|
BaseObject.setPosition¶
Set object position
Parameters¶
Name | Description |
---|---|
x | float X-Axis value |
y | float Y-Axis value |
z | float Z-Axis value |
Example¶
1 2 3 4 5 | //Set the object's position to (0,5,0)
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.setPosition(0, 5, 0);
|
BaseObject.setPositionXZ¶
Set object horizontal position
Parameters¶
Name | Description |
---|---|
x | float X-Axis value |
z | float Z-Axis value |
Example¶
1 2 3 4 5 | // Set the object's horizontal position to (1,1)
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.setPositionXZ(1,1);
|
BaseObject.setPositionY¶
Set object Y-Axis coordinate position
Parameters¶
Name | Description |
---|---|
y | float Y-Axis value |
Example¶
1 2 3 4 5 | // Set the Y-Axis coordinate of the object to 5
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.setPositionY(5);
|
BaseObject.setScale¶
Set object scale
Parameters¶
Name | Description |
---|---|
x | float X-Axis value |
y | float Y-Axis value |
z | float Z-Axis value |
Example¶
1 2 3 4 5 | // Set the scale of the object to be (1,2,3)
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.setScale(1,2,3);
|
BaseObject.setTransparent¶
Set object transparency.
Parameters¶
Name | Description |
---|---|
trans | float transparency value range 0~1 |
Example¶
1 2 3 4 5 | // Set the object's transparency to'0.5'
object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.setTransparent(0.5);
|
BaseObject.stopAnim¶
Stop play object animation.
Parameters¶
None
Example¶
1 2 3 4 5 6 7 8 | var obj = object.create("0bcba8ca78734b64a3dae3eb699a913c");
gui.createButton("Run", Rect(100, 100, 100, 30), function() {obj.playAnim("Run");});
// Create a button named 'Stop'and set its size to (100,150,100,30).
// Pressing this button will stop object'obj'from playing the animation'Run'.
gui.createButton("Stop", Rect(100, 150, 100, 30), function() {obj.stopAnim()});
|
BaseObject.stopMoving¶
Stop object moving.
Parameters¶
None
Example¶
1 2 3 4 5 6 7 8 | var obj = = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.moveTo(Vector3(10, 0, 0), 5.0)
// Create a button named 'Stop'and set its size to (100,150,100,30).
// Pressing this button will stop object'obj'from moving.
gui.createButton("Stop", Rect(100, 150, 100, 30), function() {obj.stopMoving()});
|
BaseObject.transformPoint¶
Convert coordinates of object from relative coordinates to absolute coordinates
Parameters¶
Name | Description |
---|---|
pos | Vector3 relative coordinates of the object |
Example¶
1 2 3 4 5 6 7 | // Create object'obj1, set its position (1,2,3)
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088",Vector3(1,2,3));
// Create a second object named'obj2'whose parent is'obj1'
var obj2 = object.create("AB052B5B646E4A48B9C045096FF9B088",obj1,Vector3(4,5,6));
print(obj2.transformPoint(Vector3(7,8,9)));
|
Note
- The relative coordinates of’obj2’is (4,5,6)(Thus the absolute coordinates of’obj2’is
(1,2,3)+(4,5,6)=(5,7,9)
- Printing the transformPoint of Vector3(7,8,9) will show the value (12,15,18) (Converting the relative coordinates of Vector3 to absolute coordinates is
(5,7,9)+(7,8,9)=(12,15,18))
BaseObject.translate¶
Move a specified object to a specified direction and distance .
Parameters¶
Name | Description |
---|---|
pos | Vector3 |
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // Create object'obj1, set its position (1,2,3)
var obj = object.create("81807868C78141BFB2E93275AC3ABB39");
// Create button *Button1*, If press this button, object obj's position add Vector3(1,0,1)
var Button1= gui.createButton("translate", Rect(100, 200, 80, 50), function() {
obj.translate(Vector3(1, 0, 1))});
// Create a button named *Button2* Pressing on this button will move object'obj' position by a vector of (1,0,1)
var Button2= gui.createButton("setPosition", Rect(100, 300, 80, 50), function() {
obj.setPosition(Vector3(1, 0, 1))});
|
BaseObject.yaw¶
Rotate an object a specified degree around the Y-axis (clockwise)
Parameters¶
Name | Description |
---|---|
degree | float rotation degree |
Example¶
1 2 3 4 | //Create an object named'obj'and rotate object'obj'a 45 degree angle around the Y-axis(clockwise).
var obj = object.create("AB052B5B646E4A48B9C045096FF9B088");
obj.yaw(45)
|