Other:
vector3d - a vector class
Standard Library (basic functions for math, strings, arrays, regex etc)
Note: This function is not available in the editor.Creates a new scene node based on an existing scene node.
The parameter 'node' must be an exiting scene node. You can get an existing scene node forexample with ccbGetSceneNodeFromName()
Returns: The new scene node.
Examples:
var sourceNode = ccbGetSceneNodeFromName("myNode");
var newscenenode = ccbCloneSceneNode(sourceNode);
This example will create a copy of an existing scene node with the name 'myNode'.
Note: This function is not available in the editor.Returns the currently active camera of the scene.
Note: This function is not available in the editor.Sets the currently active camera to the scene. The parameter 'node' must be a camera scene node.
ccbGetChildSceneNode(parentSceneNode, childIndex)
Returns the child scene node of a parent scene node. ChildIndex must be >= 0 and < ccbGetSceneNodeChildCount.
Example:
var root = ccbGetRootSceneNode();
var count = ccbGetSceneNodeChildCount(root);
for(var i=0; i<count; ++i)
{
var child = ccbGetChildSceneNode(root, i);
print("node:" + ccbGetSceneNodeProperty(child, "Name") + "\n");
}This example prints the name of all child scene nodes of the root.
Returns the root scene node. You cannot remove it and it does not make a lot of sense to change its attributes, but you can use it as starting point to iterate the whole scene graph. Take a look at ccbGetSceneNodeChildCount for an example.
Returns: The root scene node.
ccbGetSceneNodeChildCount(sceneNode)
Returns the amount of children of a scene node.
Example:
var root = ccbGetRootSceneNode();
var count = ccbGetSceneNodeChildCount(root);
print("Scene nodes in the top level of the scene graph:" + count);This example will return '2' if there are two scene nodes in your scene.
Searches the whole scene graph for a scene node with this name. Please note that the name is case sensitive. If it is found, it is returned, otherwise null is returned.
Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
if (s) print("found node.\n");
else
print("not found the node.\n")Searches for a scene node with name 'cubeMesh1' and prints some text.
ccbGetSceneNodeMaterialCount(sceneNode)
Returns the amount of materials of the scene node.
Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
var n = ccbGetSceneNodeMaterialCount(s);
print("the scene node has " + n + " materials");Prints the amount of materials in a scene node named 'cubeMesh1'
ccbGetSceneNodeMaterialProperty(sceneNode, materialIndex, propertyName)
Returns the property of the material of a scene node.
Parameters:
Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
var t = ccbGetSceneNodeMaterialProperty(s, 0, "Texture1");
print("texture of the cube is: " + t);Prints the name of the texture set in an existing scene node named 'cubeMesh1'. Prints something like 'texture of the new cube is: textures/editor_defaults/default_texture.png'
ccbGetSceneNodeProperty(sceneNode, propertyName)
Gets the property value of a scene node. The propertyName is also the name displayed in the property window of the editor in the left column. Possible names depend on the scene node type, but usually names like 'Name', 'Position', 'Rotation', 'Scale', 'Visible' are available at least. Please note that the name is case sensitive.
For animated scene nodes, Properties like 'Animation', 'Looping' and 'FramesPerSecond' are available.Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
var position = ccbGetSceneNodeProperty(s, "Position");
print("The cube is at " + position);If the scene contains a scene node with the name 'cubeMesh1', this example prints something like "The cube is at (-2.15537, -0.751433, -15.6934)"
Loads a texture into the texture cache. Returns true if sucessful and false if not.
Example:
if (ccbLoadTexture("textures/walls/smallmetalpipe_1-1.jpg"))
print("yipee, it worked.");
editorUpdateAllWindows(); // show changes in texture manager windowLoads a texture.
Removes the scene node from the scene, deleting it. Doesn't work for the root scene node.
Example:
ccbRemoveSceneNode( ccbGetSceneNodeFromName("cubeMesh1") );Deletes a scene node with the name 'cubeMesh1' if it exists.
ccbSetSceneNodeMaterialProperty(sceneNode, materialIndex, propertyName, value)
Sets the property of the material of a scene node.
Parameters:
Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
var t = ccbSetSceneNodeMaterialProperty(s, 0, "Wireframe", "true");
Makes a node with the name 'cubeMesh1' to be displayed in wireframe mode.
ccbSetSceneNodeProperty(sceneNode,
propertyName, value)
ccbSetSceneNodeProperty(sceneNode, propertyName,
x, y, z)
Sets the property value of a scene node. The propertyName is also the name displayed in the property window of the editor in the left column. Possible names depend on the scene node type, but usually names like 'Name', 'Position', 'Rotation', 'Scale', and 'Visible' are available at least. Please note that the name is case sensitive.
For animated scene nodes, Properties like 'Animation', 'Looping' and 'FramesPerSecond' are available.Examples:
var s = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodeProperty(s, "Visible", false);Makes a node with the name 'cubeMesh1' invisible.
var s = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodeProperty(s, "Rotation", 20, 90, 0);
Changes the rotation of a node with the name 'cubeMesh1' to (20, 90, 0)
ccbSetSceneNodePositionWithoutCollision(sceneNode, x, y, z)
Sets a new position of a scene node, even if the scene node has a 'collide with walls' behavior attached to it. So it it possible to move such a scene node through walls. Note that you have to ensure that the new position of the scene node is not inside a wall, otherwise the node will be stuck.
Examples:
var s = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodePositionWithoutCollision(s, -22.097015, 9.848448, -40.738777);Makes a scene node change its position, independent of its collision behavior.
ccbRegisterKeyDownEvent(funcstr)
Note: This function is not available in the editor.Registers a function for receiving a key down event. The function registered must take one parameter which will be the key code.
Examples:
ccbRegisterKeyDownEvent("keyPressedDown()");
function keyPressedDown(keyCode)
{
print("A key was pressed down:" + keyCode);
}Prints which key was pressed when it is pressed.
ccbRegisterKeyUpEvent(funcstr)
Note: This function is not available in the editor.Registers a function for receiving a key down event. The function registered must take one parameter which will be the key code.
Examples:
ccbRegisterKeyUpEvent("keyPressedUp()");
function keyPressedUp(keyCode)
{
print("A key was left up:" + keyCode);
}Prints which key was left up when it is left up.
ccbRegisterMouseDownEvent(funcstr)
Note: This function is not available in the editor.Registers a function for receiving a key down event. The function registered must take one parameter which will be the mouse button pressed (1 for left button, 2 for right button, 3 for middle button).
Examples:
ccbRegisterMouseDownEvent("mousePressedDown()");
function mousePressedDown(button)
{
print("A mouse button was presssed down:" + button);
}Prints which mouse button was pressed when it is pressed
ccbRegisterMouseUpEvent(funcstr)
Note: This function is not available in the editor.Registers a function for receiving a key down event. The function registered must take one parameter which will be the mouse button left up (1 for left button, 2 for right button, 3 for middle button)
Examples:
ccbRegisterMouseUpEvent("mouseLeftUp()");
function mouseLeftUp(button)
{
print("A mouse button was left up:" + button);
}Prints which mouse button was left up when it is left up.
ccbRegisterOnFrameEvent(funcstr)
Note: This function is not available in the editor.Registers a function for receiving a on frame event, an event which is called every frame drawn. The function registered must take no parameters. Inside this function, it is possible to draw own, custom things like user interfaces.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing()");
function onFrameDrawing()
{
// draw a red, transparent rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}Draws a red rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
ccbDrawColoredRectangle(color, x1, y1, x2, y2)
Note: This function is not available in the editor.Draws a colored rectangle. This function can only be used inside a frame event function which must have been registered with ccbRegisterOnFrameEvent().
The color is a 32 bit value with alpha, red, green and blue components (0xaarrggbb, like the color values known from HTML but with an alpha channel value added in front, for the transarency). 0x77ff0000 is for example a transparent red, 0xff0000ff is a not-transparent blue.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing()");
function onFrameDrawing()
{
// draw a red, transparent rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}Draws a red rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
ccbDrawTextureRectangle(file, x1, y1, x2, y2)
Note: This function is not available in the editor.Draws a textured rectangle. This function can only be used inside a frame event function which must have been registered with ccbRegisterOnFrameEvent().
This function will ignore the alpha channel of the texture. Use ccbDrawTextureRectangleWithAlpha if you want the alpha channel to be taken into account as well.Examples:
ccbRegisterOnFrameEvent("onFrameDrawing");
function onFrameDrawing()
{
// draw a red, textured rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawTextureRectangle("someFile.png", mouseX-100, mouseY-100, mouseX+100, mouseY+100);
}Draws a textured rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
ccbDrawTextureRectangleWithAlpha(file, x1, y1, x2, y2)
Note: This function is not available in the editor.Draws a textured rectangle with alpha channel. This function can only be used inside a frame event function which must have been registered with ccbRegisterOnFrameEvent().
This function will take the alpha channel of the texture into account, use ccbDrawTextureRectangleWithAlpha the texture does not have an alpha channel.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing");
function onFrameDrawing()
{
// draw a red, textured rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawTextureRectangleWithAlpha("someFile.png", mouseX-100, mouseY-100, mouseX+100, mouseY+100);
}Draws a textured rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
Returns the 3d position of a 2d position on the screen. Note: A 2d position on the screen does not represent one single 3d point, but a actually a 3d line. So in order to get this line, use the 3d point returned by this function and the position of the current camera to form this line.
Examples:
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
var anode = ccbGetSceneNodeFromName("somenode");
var pos3d = ccbGet3DPosFrom2DPos(mouseX, mouseY);
ccbSetSceneNodeProperty(anode, "Position", pos3d);Sets the position of a scene node with the name 'somenode' to the 3d position behind the mouse cursor.
Returns the 2D position of a 3D position or nothing if the position would not be on the screen (for example behind the camera).
Examples:
var pos = ccbGet2DPosFrom3DPos(20, 30, 30);
print("Position on screen: " + pos);Prints the position of a 3d coordinate in 2D.
ccbGetCollisionPointOfWorldWithLine(startX, startY, startZ, endX, endY, endZ)
Returns the collision point with a line and the world. Returns null if there is no collision.
ccbDoesLineCollideWithBoundingBoxOfSceneNode(node, startX, startY, startZ, endX, endY, endZ)
Returns if the bounding box of the given scene node collides with the line between two given points.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing");
function onFrameDrawing()
{
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
// test collision
var cube = ccbGetSceneNodeFromName("cubeMesh");
var endPoint3d = ccbGet3DPosFrom2DPos(mouseX, mouseY);
var startPos3D = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position");
if (ccbDoesLineCollideWithBoundingBoxOfSceneNode(cube, startPos3D.x, startPos3D.y,
startPos3D.z, endPoint3d.x, endPoint3d.y, endPoint3d.z))
{
ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}
else
ccbDrawColoredRectangle(0x770000ff, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}Draws a red rectangle at the position of the mouse cursor (or the center of the screen if controlled by a FPS style camera controller) if the mouse cursor is over a scene node named 'cubeMesh', and draws a blue rectangle if not.
Note: This function is not available in the editor.Ends the application
Note: This function is not available in the editor.Returns the current X position of the mouse cursor in pixels.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing");
function onFrameDrawing()
{
// draw a red, transparent rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}Draws a red rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
Note: This function is not available in the editor.Returns the current Y position of the mouse cursor in pixels.
Examples:
ccbRegisterOnFrameEvent("onFrameDrawing");
function onFrameDrawing()
{
// draw a red, transparent rectangle at the position of the mouse
var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();
ccbDrawColoredRectangle(0x77ff0000, mouseX-10, mouseY-10, mouseX+10, mouseY+10);
}Draws a red rectangle at the position of the mouse cursor (or at the center if the mouse cursor is controlling a FPS style camera)
ccbSetCloseOnEscapePressed(bClose)
By default, the application will close when the user presses escape. By calling ccbSetCloseOnEscapePressed(false) will disable this feature.
Sets if the mouse cursor is visible or not. Call ccbSetCursorVisible(false) to make it invisible, call ccbSetCursorVisible(true) to make visible again.
Note: This function is not available in the editor.Switch to the scene with the specified name. ccbSwitchToScene("my scene") will switch to a scene named "my scene" if there is one. Note: The name is case sensitive.
Will play a sound or music file. The following file formats are supported: WAV, OGG, MOD, XM, IT, S3M.
ccbSetCopperCubeVariable(varname, value)
Will set a CopperCube variable to a certain value. CopperCube variables can be set and changed using the Variable Actions in the editor.
ccbGetCopperCubeVariable(varname)
Will get the value of a CopperCube variable. CopperCube variables can be set and changed using the Variable Actions in the editor.
reads a full (text) file into a string
cccWriteFileContent(filename, content)
writes a full (text) file from a string
Prints a string into the output window of the editor or into the debug console window of the app.
This function is only available in the CopperCube editor
Shows a string in a modal message box.
Examples:
alert("Hello World");Shows the text Hello World! in a modal message box
This function is only available in the CopperCube editor
Shows a string in a modal message box and asks to press either OK or CANCEL.
Examples:
if (confirm("Continue?")) print("User pressed OK!"); else print("User pressed Cancel.");Shows the text Continue? in a modal message box and prints a text depending on what button the user pressed.
This function is only available in the CopperCube editor
Shows an edit box in a modal message box and asks to press either OK or CANCEL.
Examples:
var ret = prompt("Please enter a text", "some text"); if (ret) print("User entered this:" + ret); else print("User pressed cancel");Shows the text Please enter a text? in a modal message box and an additional edit box.
Executes the given command line. Can be used to run commands or launch programs.
Examples:
system("type C:\\Windows\\WindowsUpdate.log");On windows, this will print the content of the file WindowsUpdate.log (if available) to the screen.
The functions listed above give access to all static 3D geometry in the editor, and make it possible to change it. It works like this: Every node which has 3D geometry in copperCube has a 3D mesh, representing this 3D geometry. A 3D mesh consists of several mesh buffers, one for each material. In each mesh buffer, there are several vertices, defining the 3D position of each point of the 3D geometry, and several indices, connecting theses points to form triangles. There is always a multiple of three indices, like for example 0, 2, 1 forming a triangle of the first three indices.
Examples:
Polygon and Material counting: var meshnode = editorGetSelectedSceneNode(); var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode); if (bufferCount == 0) alert('The selected node has no 3D geometry.'); else { var totalVertexCount = 0; var totalIndexCount = 0; for (var i=0; i<bufferCount; ++i) { totalVertexCount += ccbGetMeshBufferVertexCount(meshnode, i); totalIndexCount += ccbGetMeshBufferIndexCount(meshnode, i); } alert('The selected node has ' + (totalIndexCount/3) + ' polygons ' + totalVertexCount + ' vertices, and ' + bufferCount + ' materials.' ); }This will print the total amount of polygons, vertices and materials of the selected node in the editor, like this: The selected node has 12 polygons 36 vertices, and 1 materials. .
Modifying a 3D mesh: var meshnode = editorGetSelectedSceneNode(); var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode); if (bufferCount == 0) alert('The selected node has no 3D geometry.'); else { for (var i=0; i<bufferCount; ++i) { var vertexcount = ccbGetMeshBufferVertexCount(meshnode, i); for (var v=0; v<vertexcount; ++v) { var pos = ccbGetMeshBufferVertexPosition(meshnode, i, v); pos.x *= 2; pos.y *= 2; pos.z *= 2; ccbSetMeshBufferVertexPosition(meshnode, i, v, pos); } } ccbUpdateSceneNodeBoundingBox(meshnode); }This will scale all vertices of the currently selected node in the editor by the factor 2. Note this is different from setting the scale value of the node, it actually will move all vertex positions.
editorAddSceneNode(type)
editorAddSceneNode(type, x, y, z)
editorAddSceneNode(type, x, y, z, size)
Creates a new scene node of type (must be a string) at position x, y, z, applies the default editor settings to it, selects it and updates all editor views. This is just like if the user used the 'edit->insert' command from the editor menu.
The parameter 'type' must be one of these strings:
"cube", "sphere", "cylinder", "cone", "plane", "light", "camera", "billboard", "skybox", "hotspot", "3dsound"
x,y,z is the position where the scene node will be created. If not used, the position will be the default editor position.
The parameter 'size' is optional, and specifies a default size for the object, like 10 as widht and height of the cube.
Returns: The new scene node.
Examples:
var count = 3; var size = 12;
for (var x=0; x<count; ++x) for (var y=0; y<count; ++y) for (var z=0; z<count; ++z) editorAddSceneNode("cube", x*size, y*size, z*size);This example will create 27 cubes placed in a hypercube.
editorAddSceneNode("billboard");This example will create a billBoard placed directly on front of the 3d camera in the main view.
Lets the cameras of all view ports focus the given position.
Example:
editorFocusPosition(vector3d(0,10,20));Lets all cameras focus the position (0,10,20)
Returns the currently selected scene node or 0 if nothing selected.
Example:
var s = editorGetSelectedSceneNode();
if (s) alert("Name of the selected node is: '" + ccbGetSceneNodeProperty(s, "Name") + "'"); else alert("nothing selected");This example prints the name of the currently selected scene node.
Returns the currently selected texture from the texture manager window.
Example:
var t = editorGetSelectedTexture();
var s = editorAddSceneNode("cube");
ccbSetSceneNodeMaterialProperty(s, 0, "Texture1", t);
if (t == "") print("added no texture"); else print("set texture to: " + t );
editorUpdateAllWindows();Creates a new cube and applies the currently selected texture to it.
editorGetFileNameFromDialog()
editorGetFileNameFromDialog(message)
editorGetFileNameFromDialog(message, fileExtensions)
editorGetFileNameFromDialog(message, fileExtensions,
isOpenDialog)
Shows a file selection dialog prompting the user to select a file and returns the selected filename or an empty string if the user cancelled.
Parameters:
Example:
var s = editorGetFileNameFromDialog("please select something");
if (s != "")
alert ("user selected " + s);
else
alert("user cancelled selection");This example prompts the user to select a filename and prints which file was selected when finished.
Updates all windows of the editor. Same as selecting the command Edit->UpdateAllWindows or pressing F5 in the editor.
Example:
editorAddSceneNode("cube"); editorUpdateAllWindows();This example creates a new cube without default settings and updates the editor windows to show the new scene node in all windows.
editorRegisterMenuEntry(function, text)
Note: This function is only available in the editor.Registers a new entry in the menu under 'Plugins' using the text provided in the 'text' parameter. When the menu command is selected by the user, the global function provided in the 'function' parameter will be executed.
Please note that editorRegisterMenuEntry only works when executed by a script run in the autostart mode, which means a script placed in the \Documents\CopperCube\plugins directory and with the extension '.js'.Example:
function printHello()
{
print("Hello\n");
}
editorRegisterMenuEntry("printHello();", "Print Hello into the log");Putting this script in a file named for example 'CopperCube\plugins\autostart_printhello.js' and starting the editor will add a new menu entry into the Tool menu which will print 'Hello'
editorSetSelectedSceneNode(node)
Sets a selected scene node. Set node to 0 to select nothing.
Example:
var s = editorAddSceneNode("sphere");
editorSetSelectedSceneNode(s);Adds a scene node and selects it in the editor.
A class for holding 3 float coordinates - x, y, and z. Also provides helper methods:
Examples:
local v = vector3d();
print(v);prints (0, 0, 0)
local v1 = vector3d(10,0,0);
local v2 = vector3d(0,20,0);
local v3 = v1 + v2;
v3.normalize();
print(v3 + " Lenght:" + v3.getLength())prints (0.447214, 0.894427, 0) Lenght:1
Other routines available (for details please see the JavaScript Standard):
Math: Math.abs(x); Math.acos(x); Math.asin(x); Math.atan(x); Math.atan2(x, y); Math.ceil(x); Math.cos(x); Math.exp(x); Math.floor(x); Math.log(x); Math.pow(x, y); Math.random(); Math.round(), Math.sin(x); Math.sqrt(x); Math.tan(x);
Others All the JavaScript core functionality, like date, regexp, strings, arrays, etc.