CopperCube JavaScript reference
(Under Construction)

Note:- This page is currently  being under construction. Information available on this page might not be accurate and complete.


CopperCube provides a very simple interface to manipulate all aspects of a 3D scene. This page lists all available functions.
Most of these functions manipulate so called 'scene nodes'. A scene node is nothing more than a 3d object with a position, rotation, scale, its materials and childrens. The name 'scene node' is there because CopperCube is internally using a scene graph to represent the 3d scene.

Here is the list of JavaScript functions, each function is marked with icons that represent the platform on which that function will work. Functions marked with icon will work in Windows client,  will work in webGL and  will work in CopperCube Editor. If you don't see a specific icon in front of a function then it means that functions doesn't work on that platform.


Scene Node Handling

ccbCloneSceneNode  
ccbGetActiveCamera
ccbSetActiveCamera
ccbGetChildSceneNode
ccbGetRootSceneNode
ccbGetSceneNodeChildCount
ccbGetSceneNodeProperty
ccbSetSceneNodeProperty
ccbGetSceneNodeFromName
ccbGetSceneNodeMaterialCount
ccbGetSceneNodeMaterialProperty
ccbSetSceneNodeMaterialProperty
ccbRemoveSceneNode
ccbSetSceneNodeParent
ccbSetSceneNodePositionWithoutCollision

Events

ccbRegisterKeyDownEvent
ccbRegisterKeyUpEvent
ccbRegisterMouseDownEvent
ccbRegisterMouseUpEvent
ccbRegisterOnFrameEvent
ccbUnregisterOnFrameEvent

Drawing

ccbDrawColoredRectangle
ccbDrawTextureRectangle
ccbDrawTextureRectangleWithAlpha

Collision

ccbGet3DPosFrom2DPos
ccbGet2DPosFrom3DPos
ccbGetCollisionPointOfWorldWithLine
ccbDoesLineCollideWithBoundingBoxOfSceneNode

Various

ccbEndProgram
ccbLoadTexture
ccbGetMousePosX
ccbGetMousePosY
ccbGetScreenWidth
ccbGetScreenHeight
ccbSetCloseOnEscapePressed
ccbSetCursorVisible
ccbSwitchToScene
ccbPlaySound
ccbStopSound
ccbGetCopperCubeVariable
ccbSetCopperCubeVariable
ccbReadFileContent
ccbWriteFileContent
ccbGetPlatform
ccbInvokeAction
ccbGetCurrentNode
ccbCleanMemory
ccbSwitchToFullscreen
ccbDoHTTPRequest
ccbCancelHTTPRequest
ccbCreateMaterial
ccbSetShaderConstant
ccbSetPhysicsVelocity
ccbUpdatePhysicsGeometry
ccbAICommand
ccbSteamSetAchievement
ccbSteamResetAchievements
ccbSaveScreenshot
ccbSaveTexture
ccbSwitchToCCBFile
print
system

Only in the editor

confirm 
alert 
prompt 
editorAddSceneNode 
editorFocusPosition
editorGetFileNameFromDialog
editorGetSelectedSceneNode
editorGetSelectedTexture
editorUpdateAllWindows
editorRegisterMenuEntry
editorSetSelectedSceneNode
editorImportStatic3DMesh
editorImportAnimated3DMesh

Mesh Editing

ccbGetSceneNodeMeshBufferCount
ccbRemoveMeshBuffer
ccbAddMeshBuffer
ccbGetMeshBufferVertexCount
ccbGetMeshBufferIndexCount
ccbAddMeshBufferIndex
ccbGetMeshBufferIndexValue
ccbSetMeshBufferIndexValue
ccbAddMeshBufferVertex
ccbGetMeshBufferVertexPosition
ccbSetMeshBufferVertexPosition
ccbGetMeshBufferVertexTextureCoord
ccbSetMeshBufferVertexTextureCoord
ccbGetMeshBufferVertexNormal
ccbSetMeshBufferVertexNormal
ccbGetMeshBufferVertexColor
ccbSetMeshBufferVertexColor
ccbUpdateSceneNodeBoundingBox

Other:

vector3d - a vector class
Standard Library
(basic functions for math, strings, arrays, regex etc)


ccbCloneSceneNode(node)

Note: This function is not available in the editor.

Creates a new scene node based on an existing scene node. All the behaviors and actions will also be applied to the cloned node .

The parameter 'node' must be an existing scene node. You can get an existing scene node for example with ccbGetSceneNodeFromName()

Returns: The new scene node.

Examples:

var sourceNode = ccbGetSceneNodeFromName("myNode");
var newscenenode = ccbCloneSceneNode(sourceNode);
Above example will create a copy of an existing scene node with the name 'myNode'.

var name_increment = ccbGetCopperCubeVariable("name_increment");
var incremented_value = Number(name_increment + 1);
ccbSetCopperCubeVariable("name_increment", incremented_value);
var MainNode = ccbGetSceneNodeFromName("node_to_be_cloned");
var ClonedNode = ccbCloneSceneNode(MainNode);
ccbSetSceneNodeProperty(ClonedNode, "Name", "new_name_for_clone"+ "" +incremented_value+ "" );
Above example will create a clone of the existing node and will assign a new name to every node that is cloned with a number as suffix.
In order to make the above script work, you need to set a CopperCube Variable "name_increment" with a value of "0".

ccbGetActiveCamera()

Note: This function is not available in the editor.

Returns the currently active camera node of the scene.

Examples:

var Camera = ccbGetActiveCamera();
var CameraName = ccbGetSceneNodeProperty(Camera,"Name");
print(CameraName)
Above example will get the current active camera from the scene and will print the name of the camera in the debug console.


ccbSetActiveCamera(node)

Note: This function is not available in the editor.

Sets a camera node as currently active camera for the scene.

The parameter 'node' must be an existing camera node. You can get an existing camera node for example with ccbGetSceneNodeFromName()

Examples:

var NewCamera = ccbGetSceneNodeFromName("Camera2");
ccbSetActiveCamera(NewCamera);
Above example will get the "Camera2" from the scene and make it the current active camera for the scene.


ccbGetChildSceneNode(parentSceneNode, childIndex)

Returns the child scene node of a parent scene node. ChildIndex must be >= 0 and less than the total childcount of that node that is < ccbGetSceneNodeChildCount

The parameter 'parentnode' must be an existing scene node. You can get an existing scene node for example with ccbGetSceneNodeFromName() and ChildIndex must be an integer lower than the total childCount of parentNode

Examples:

var ParentNode = ccbGetSceneNodeFromName("myNode");
var Child = ccbGetChildSceneNode(parentNode, 0);
var Childname = ccbGetSceneNodeProperty(Child, "Name");
print(Childname);
Above example will get child at index 0 of a node with the name "myNode" and then print the name of the child node in the debug console.

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");
}
Above example will print name of all the children of the root scene node in the debug console.

ccbGetRootSceneNode()

Returns the root scene node. You cannot remove it, but can make changes to its attributes like "Gravity", "Fog" (to enable/disable Fog), "Wind", "FogColor", "Realtime Shadows" (to enable/disable shadow mapping), "AmbientLight", "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" etc.

Examples:

var RootNode = ccbGetRootSceneNode();
var Fog = ccbGetSceneNodeProperty(RootNode,"Fog");
print(Fog);
Above example will get the state of Fog in your scene and then print "true" or "false" in the debug console.


About

Neophyte is a website developed to provide tutorials, assets and source files of CopperCube projects.

Join Us