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'
Loads a texture into the texture cache. Returns the texture object if sucessful, which then can be used for example in ccbSetSceneNodeMaterialProperty() calls with the texture parameter. Note that the texture is only loaded once. You can call this multiple times with the same texture file, but CopperCube won't try to load it multiple times if it has been loaded once already.
Parameters:
- filename: Name of the texture to load. Use something like 'example.jpg', this will then load the file 'example.jpg' from the directory where your Windows or Mac OS X app is. On the Flash and WebGL target, the file will be loaded from where your website is on your server. On these targets, it also works to use URLs (like http://www.example.com/foobar.jpg") as parameter, but it depends on the security settings of your browser if the file then is actually loaded.
Example:
var node = ccbGetSceneNodeFromName("cubeMesh1"); var tex = ccbLoadTexture("example.jpg"); ccbSetSceneNodeMaterialProperty(node, 0, "Texture1", tex);Loads a texture and sets it as material onto an object name 'cubeMesh1'.
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.
ccbSetSceneNodeParent(sceneNode, newparentnode)
Sets the parent scene node of a scene node. If this node has already a parent, it will be removed from that parent. Note that by setting a new parent, position, rotation and scale of this node becomes relative to that of the new parent.
ccbSetSceneNodeMaterialProperty(sceneNode, materialIndex, propertyName, value)
Sets the property of the material of a scene node.
Parameters:
Possible material parameters are:
Parameter name Possible values Type "solid", "lightmap", "lightmap_add", "lightmap_m2", "lightmap_m4", "reflection_2layer", "trans_add", "trans_alphach", "trans_reflection_2layer" Texture1 A texture for texture layer 1 Texture2 A texture for texture layer 2 Lighting true or false to enable or disable dynamic lighting Backfaceculling true or false to enable or disable backface culling
Also, if you are writing a plugin for the editor, there are some advanced properties available: "Type", "Ambient", "Diffuse", "Emissive", "Specular", "Shininess", "Param1", "Param2", "Texture1", "Texture2", "Texture3", "Texture4", "Wireframe", "GouraudShading", "Lighting", "ZBuffer", "ZWriteEnable", "BackfaceCulling", "BilinearFilter", "TrilinearFilter", "AnisotropicFilter", "FogEnable", "NormalizeNormals".
Example:
var s = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodeMaterialProperty(s, 0, "Lighting", true);
Makes a node with the name 'cubeMesh1' to use dynamic light. Example 2:
var node = ccbGetSceneNodeFromName("cubeMesh1"); var tex = ccbLoadTexture("example.jpg"); ccbSetSceneNodeMaterialProperty(node, 0, "Texture1", tex);Loads a texture and sets it as material onto an object name 'cubeMesh1'.
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', 'PositionAbs' (absolute position), 'Rotation', 'Scale', 'Visible' are available at least. Please note that the name is case sensitive.
- For animated scene nodes, Properties like 'Animation', 'Looping', 'FramesPerSecond' 'AnimationBlending', and 'BlendTimeMs' are available.
- For camera nodes, Properties like 'Target', 'UpVector', 'AspectRatio' and 'FieldOfView_Degrees' are available.
- For 2D overlay nodes, Properties like the following are available: 'Pos X (percent)', 'Pos Y (percent)', 'Width (percent)', 'Height (percent)', 'Pos X (pixels)', 'Pos Y (pixels)', 'Width (pixels)', 'Height (pixels)', 'Alpha', 'Image', 'Background Color', 'Draw Text', 'TextColor', 'Text'.
- For light nodes, Properties like 'Radius' (for point lights), 'Color', and 'Direction' (for directional lights) are available.
- For the root scene node, you can use "FogColor", "Realtime Shadows" (to enable/disable shadow mapping), "AmbientLight", and "BackgroundColor". PostEffect properties are also supported: "Bloom", "Bloom_BlurIterations", "Bloom_Treshold", "Black and White", "Invert", "Blur", "Blur_Iterations", "Colorize", "Colorize_Color", "Vignette", "Vignette_Intensity", "Vignette_RadiusA", "Vignette_RadiusB".
- You can also use "Type" which then usually returns something like "mesh", "animatedmesh", "billboard", "camera", "light", "mobile2dinput", "2doverlay", "particlesystem", "path", "sky", "sound", or "water".
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)" Also see ccbSetSceneNodeProperty().
ccbSetSceneNodeProperty(sceneNode,
propertyName, value)
ccbSetSceneNodeProperty(sceneNode, propertyName, x, y, z)
ccbSetSceneNodeProperty(sceneNode, propertyName, r, g, b)
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. When setting a vector, you can use x,y,z parameters, or a vector3d object. For colors, you can use a single int or 3 RGB values like 255,128,0.
- For animated scene nodes, Properties like 'Animation', 'Looping', 'FramesPerSecond' 'AnimationBlending', and 'BlendTimeMs' are available.
- For camera nodes, Properties like 'Target', 'UpVector', 'AspectRatio' and 'FieldOfView_Degrees' are available.
- For 2D overlay nodes, Properties like the following are available: 'Pos X (percent)', 'Pos Y (percent)', 'Width (percent)', 'Height (percent)', 'Pos X (pixels)', 'Pos Y (pixels)', 'Width (pixels)', 'Height (pixels)', 'Alpha', 'Image', 'Background Color', 'Draw Text', 'TextColor', 'Text'.
- For light nodes, Properties like 'Radius' (for point lights), 'Color', and 'Direction' (for directional lights) are available.
- For the root scene node, you can use "FogColor", "Realtime Shadows" (to enable/disable shadow mapping), "AmbientLight", and "BackgroundColor". PostEffect properties are also supported: "Bloom", "Bloom_BlurIterations", "Bloom_Treshold", "Black and White", "Invert", "Blur", "Blur_Iterations", "Colorize", "Colorize_Color", "Vignette", "Vignette_Intensity", "Vignette_RadiusA", "Vignette_RadiusB".
Examples:
var s = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodeProperty(s, "Visible", false);Makes a node with the name 'cubeMesh1' invisible.
Also see ccbGetSceneNodeProperty().
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, and only in the Windows and Mac OS X app target. For getting key events, use the behavior functions onKeyEvent().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, and only in the Windows and Mac OS X app target. For getting key events, use the behavior functions onKeyEvent().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, and only in the Windows and Mac OS X app target. For getting mouse events, use the behavior functions onMouseEvent().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, and only in the Windows and Mac OS X app target. For getting mouse events, use the behavior functions onMouseEvent().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(func)
ccbUnregisterOnFrameEvent(func)
Note: These functions are not available in the editor.ccbRegisterOnFrameEvent registers a function for receiving a 'on frame' event, an event which is called every frame the screen drawn. The function registered must take no parameters. Inside this function, it is possible to draw own, custom things like user interfaces.
Examples:
After you no longer need events, call ccbUnregisterOnFrameEvent() to unregister your function.
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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. On Flash and WebGL, this closes the window (if it was opened before as popup by a script).
Note: This function is not available in the editor.Returns the current X position of the mouse cursor in pixels.
Examples:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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. This function is only available in the Windows .exe and macOS .app target.Set new position of the mouse on the screen
Note: This function is not available in the editor.Returns the current Y position of the mouse cursor in pixels.
Examples:
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);
}
ccbRegisterOnFrameEvent(onFrameDrawing);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 with of the screen in pixels.
Note: This function is not available in the editor.Returns the current with of the screen in pixels.
ccbSetCloseOnEscapePressed(bClose)
By default, the application on Windows and Mac OS X will close when the user presses escape in debug mode. By calling ccbSetCloseOnEscapePressed(false) will disable this feature. On other targets, this function has no effect.
Note: This function may not do anything depending on the target it runs on (web apps for example have no access to the cursor).
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 on Windows and Mac OS X: WAV, OGG, MOD, XM, IT, S3M. For the other targets, this depends on the browser and platform. But usually, MP3 and OGG should be fine.
Will stop a sound or music, which has been started either by ccbPlaySound or the "Play Sound" action.
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.
Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).
reads a full (text) file into a string
ccbWriteFileContent(filename, content)
Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).
writes a full (text) file from a string
Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).
tests if a file exists
Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system).
deletes a file from disk
ccbInvokeAction(actionId, currentNode)
Starts a CopperCube action. To be used together with extension script behaviors or actions: If some action was defined in the editor to be executed for this behavior or action, you can run it with this command.
Parameters:
- actionId: The id of the action to be run. Is stored by the coppercube runtime in the property with the type 'action'.
- currentNode: Optional reference to the 'current scene node'. Actions which which are set to use the 'current' scene node will then use this scene node as current one.
Example:
Assume you have a script extension action with the following definition in it:
<property name="ActionWhenFinished" type="action" />
This means that the JavaScript instance of this action will have a property named 'ActionWhenFinished' at runtime then, referencing the action defined by the user in the editor. You can start this action using this call then:
ccbInvokeAction(this.ActionWhenFinished);
Note that most actions assume the 'currentNode' to be set for this action, so set this to a real action which makes sense to be the current node in this context, like this:
ccbInvokeAction(this.ActionWhenFinished, this.TheNodeIamCurrentlyWorkingWith);
Returns the current scene node. When running some JavaScript code via an 'execute JavaScript' action, there is always a "current node" set, usually the node in which the action is being run.
Cleans up the current memory usage. Tries to free up as much memory as possible by freeing up unused textures, vertex and index buffers and similar. This is useful for calling it for example after switching scenes to increase performance of the app. May have different effects on different platforms.
Returns a string identifying the system the CopperCube app is running on. For now, the following return types are possible:
- "windows" - for Windows .exe apps
- "macosx" - for Mac OS X .apps
- "android" - for Android apps
- "webgl" - when running as WebGL app
- "flash" - for flash apps
ccbSwitchToFullscreen(enablePointerLock, elementToSwitchToFullscreen, switchBackToWindowed)
When running as Windows .exe, WebGL or Flash app, switches the app to fullscreen, and also enables pointer lock for Flash or WebGL, if wanted. Note that this function does nothing or doesn't even exist on platforms which are not Windows .exe, WebGL or Flash.
Parameters:
- enablePointerLock: If set to 'true', this enables mouse pointer lock after switching to fullscreen in Flash or WebGL. That way, first person cameras work nicely in the Web. This parameter is ignored on the Windows .exe platform.
- elementToSwitchToFullscreen: In WebGL, this is the HTML element which should be switched to fullscreen. If set to null, the canvas element will be switched. This parameter can be set to null on other platforms.
- switchBackToWindowed: If set to 'true', on the Windows .exe platform, this switches back to windowed mode. This parameter can be set to null on other platforms.
There are a few limitations to this function:
- In Flash and WebGL, this function must be called in reaction to a mouse click or keyboard key press event. Otherwise this won't work. This is a security limitation of the browser, both in Flash AND WebGL.
- When using this in Windows .exe, this only works in dynamic / resizeable window mode.
- When using this in Flash, after switching to fullscreen mode, only cursorkeys and space keys work. This is a security limitation of Flash.
ccbDoHTTPRequest(url, callback)
ccbCancelHTTPRequest(connectionIdToCancel)
Note: This function is not available in the editor.ccbDoHTTPRequest() makes a GET network request via HTTP to any web server, and ccbCancelHTTPRequest can cancel this request while it is running. This allows to communicate with any web/database/multiplayer server with ease. For ccbDoHTTPRequest parameters are:
- url: set it an URL to request, like 'http:://www.example.com' or similar.
- callback: A callback function which will be called with the received data once the request is finished. This will also be called if the request ailed, with an empty string as parameter.
The function returns an unique Id, for identifying this request. You can use this id as parameter for ccbCancelHTTPRequest(), to cancel the running request, if it takes too long for example.
Note: On some targets, like WebGL and Flash, it is not possible to do cross domain requests because of security reasons. Usually you should only do requests to the same server your script is running on.
Examples:
function finishedRequest(dataReceived) { print("finished request! Data size:" + dataReceived.length); } ccbDoHTTPRequest("http://www.ambiera.com/index.html", finishedRequest);Downloads the front page of www.ambiera.com and shows how many bytes the page contains.
ccbCreateMaterial(vertexShader, fragmentShader, baseMaterialType, shaderCallback)
ccbSetShaderConstant(type, name, value1, value2, value3, value4)
Note: This function is not available in the editor.ccbCreateMaterial() creates a new material based on vertex and pixel shaders. See Shader Programming in CopperCube for details.
Paramers for ccbCreateMaterial() are:The function returns an unique material id, which you can use to set the material type of any node to your new material using ccbSetSceneNodeMaterialProperty(). It returns -1 if an error happened.
- vertexShader: code of the vertex shader, or an empty string "".
- fragmentShader: code of the vertex shader, or an empty string "".
- base material type: usually 0 for the solid material. (2 for lightmap, 12 for additive transparency).
- shaderCallback: a function to be called before the material is used. In the function, call ccbSetShaderConstant() to set your shader constants.
ccbSetShaderConstant() may only be called during the material callback. Paramers for ccbSetShaderConstant() are:
- type: type of the shader, either 1 for vertex and 2 for pixel shader. For GLSL, this is ignored.
- name: name of the variable to set
- value1, value2, value3, value4: Content of the variable, 4 floats.
Examples can be found in Shader Programming in CopperCube.
ccbSetPhysicsVelocity(sceneNode, x, y, z)
Note: This function is not available in the editor.Sets the linear velocity of an object simulated by the physics engine. This only works when physics simulation is turned on and available for the current platform.
Paramers are:
- sceneNode: Node where this is applied to. The node needs either a "collide when moved" or a "object moved by physics engine" behavior attached to it, in oder to work.
- x, y, z: Velocity.
Note: This function is not available in the editor.Updates the collision geometry of the physics simulation. Call this when you modified the static geometry of the world and want the physics simulation to respect that. This only works when physics simulation is turned on and available for the current platform.
ccbAICommand(sceneNode, command, param)
Note: This function is not available in the editor.Sends a command to an object with the behavior 'Game Actor with Health'. In this way, it is possible to make the object move somewhere, attack something, or similar.
Paramers are:
- sceneNode: Node where this is applied to. The node has to have a Game Actor with Health behavior attached to it.
- command: String with the command. See below.
- param, Parameter for the command. See below.
Possible commands and parameters for the AI are:
- "cancel" - AI will cancel the current action it is doing (shooting, walking etc) and start doing nothing, or start the next action which makes sense to it in the current situation (like attacking a nearby enemy). The parameter will be ignored and can be null.
- "moveto" - AI will move to a 3d position. The parameter needs to be a vector3d() with the 3d position where to move to.
- "attack" - AI will attack the enemy which is supplied as parameter. The ai will attack the enemy even if it is outside of the range of its weapon.
Examples:
var s = ccbGetSceneNodeFromName("man"); var otherNode = ccbGetSceneNodeFromName("soldier"); ccbAICommand(s, "attack", otherNode);Lets an AI with the name "man" attack another node with the name "soldier".
var s = ccbGetSceneNodeFromName("man"); ccbAICommand(s, "moveto", new vector3d(-16.4, 4.5, -38.7));Lets an AI with the name "man" move to the position -16.4, 4.5, -38.7.
ccbSteamSetAchievement(achievementId)
Note: This function only works in the Windows .exe target.Sets a Steam achievement as achieved. The 'achievementId' is the string you specify in the Steam admin interface when creating the achievement. Will draw the achivement overlay as well if set for the first time. See the Steam support description for details.
Note: This function only works in the Windows .exe target.Resets all Steam achievemts for the current user. See the Steam support description for details.
Note: This function only works in the Windows .exe and Mac OS X .app target.Makes a screenshot: Saves the current content of the screen to a image file on the disk. The only parameter must be a file name, like "test.jpg" or "C:\\test.jpg". Supported file formats are .bmp, .jpg, .tga, .psd, .pcx, .png and .ppm.
ccbSaveTexture(texture, filename)
Note: This function only works in the editor and the Windows .exe and Mac OS X .app target.Saves a texure as file. The first parameter is the texture, the second must be a file name, like "test.jpg" or "C:\\test.jpg". Supported file formats are .bmp, .jpg, .tga, .psd, .pcx, .png and .ppm.
Example:var s = ccbGetSceneNodeFromName("cubeMesh1"); var t = ccbGetSceneNodeMaterialProperty(s, 0, "Texture1"); ccbSaveTexture(t, "testout.jpg");
Note: This function only works in the Windows .exe and Mac OS .app target.If your game uses a lot of data like textures / sounds / scenes etc, you can dynamically load levels and scenes at runtime using this function. When invoked this will wipe the memory and load/start that new file. This makes it possible to split your game up easily into multiple files. Example:
ccbSwitchToCCBFile("otherfile.ccb");
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.
system(commandline)
system(commandline, hideWindow)
Executes the given command line. Can be used to run commands or launch programs.
If the optional parameter 'hideWindow' is set to 'true', then no console window will be shown when running this command.
Examples:
system("type C:\\Windows\\WindowsUpdate.log");On windows, this will print the content of the file WindowsUpdate.log (if available) to the screen. system("type C:\\Windows\\WindowsUpdate.log", true);Same, but without the console window becoming visible.
There is also tutorial available on how to Create 3D geometry using JavaScript.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","overlay2d"
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.
editorImportStatic3DMesh(filename)
Imports a static mesh file into the editor.
Returns the currently selected scene node or 0 if nothing imported.
Example:
var filename = editorGetFileNameFromDialog("please select a mesh file to import"); editorImportStatic3DMesh(filename);Imports a static mesh file which is selected by the user.
editorImportAnimated3DMesh(node)
Imports an animated mesh file into the editor.
Returns the currently selected scene node or 0 if nothing imported.
Example:
var filename = editorGetFileNameFromDialog("please select a mesh file to import"); editorImportAnimated3DMesh(filename);Imports an animated mesh file which is selected by the user.
ccbGetAnimatedJointCount(animatednode)
Note: This function is only available in the editor and the Windows and macOS target.Returns the number of bones(joint) of an animated scenenode
ccbGetAnimatedJointName(animatednode,jointIndex)
Note: This function is only available in the editor and the Windows and macOS target.Returns the name of the bone(joint) of an animated scenenode, joint index is the index of bone it should be less than the AnimatedJointCount
ccbGetCurrentAnimationFrame(animatednode)
Note: This function is only available in the editor and the Windows and macOS target.Returns the current animation frame playing in the scene by the animated scenenode
ccbSetCurrentAnimationFrame(animatednode, framenumber)
Note: This function is only available in the editor and the Windows and macOS target.Set the current animation to be played from a supplied animation framenumber.
ccbSetAnimationFromSceneNode(node1, node2, animationname)
Note: This function is not available in the editor. It is only available in the Windows and macOS target.Set animation of animated scenenode from the animation of another animated scenenode that poses same skeleton(rig). First node is to which the animation will be applied, second node is from which the animation will be used, Animation name is the name of the animation that should be used.
Note: This function is only available in the editor and the Windows and macOS target.Returns the Width of a texture.
Note: This function is only available in the editor and the Windows and macOS target.Returns the Height of a texture.
Note: This function is only available in the editor and the Windows and macOS target.Pause and unpause all sounds node (True means pause, False means unpause).
ccbSetDopplerEffectParameters(DopplerFactor, DistanceFactor)
Note: This function is only available in the editor and the Windows and macOS target.Sets the DopplerEffect parameters to a different value. CC uses (1.0,1.0) as default parameters. The value ranges from 1.0 to 10.0
ccbRenderToTexture(node, camera, material index, Xresolution, Yresolution)
Note: This function is not available in the editor. It is only available in the Windows and macOS target.Captures the screen and apply it as a texture on a scenenode.
ccbSplitScreen(cam1,x1,y1,x2,y2, cam2,x3,y3,x4,y4)
Note: This function is not available in the editor. It is only available in the Windows and macOS target.Splits the Screen into two with 2 camera's rendering at the same time
ccbGetAnimatedJointPosition(animatednode,Jointindex)
Note: This function is only available in the editor and the Windows and macOS target.Returns the Position of a bones(joint) of an animated scenenode
ccbSetGameTimerSpeed(speedFloat)
Note: This function is not available in the editor. It is only available in the Windows and macOS target.Set the speed of the game timer to fast or slow
ccbEmulateKey(keyCode, pressedDown)
Note: This function is not available in the editor. It is only available in the Windows and macOS target.Emulate a keyboard keyevent for the specified Key with the keycode
A class for holding 3 float coordinates - x, y, and z. Also provides helper methods:
Examples:
var v = new vector3d(0,0,0);
print(v);prints (0, 0, 0)
var v1 = new vector3d(10,0,0);
var v2 = new vector3d(0,20,0);
var v3 = v1.add(v2);
v3.normalize();
print(v3 + " Length:" + v3.getLength())prints (0.447214, 0.894427, 0) Length: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.