ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Create Scene Node Object in Javascript or CPP
person icon
gazzauk
Registered User
Quote
2026-06-26 22:39:23

I'm having an issue with creating a skyBox scene node using the c++ win32player source code.

I have partial success but the skybox textures have a "whitewash" effect or over exposed to almost white.
I can see the skybox is created and the textures are loading.

Using the following code below within the CPlayer.cpp constructor method:


irr::video::IVideoDriver* driver = Device->getVideoDriver();
if (Document) {
CFlaceScene* scene = Document->getCurrentScene();
if (scene) {
scene::ISceneManager* smgr = scene->getSceneManager();
//smgr->addSphereSceneNode(5, 16, 0);
scene::ISceneNode* skyboxNode = smgr->addSkyBoxSceneNode(
driver->getTexture("./media/skybox/sky_up.png"),
driver->getTexture("./media/skybox/sky_dn.png"),
driver->getTexture("./media/skybox/sky_lf.png"),
driver->getTexture("./media/skybox/sky_rt.png"),
driver->getTexture("./media/skybox/sky_ft.png"),
driver->getTexture("./media/skybox/sky_bk.png"));
}
}


Also, why is it not possible to create scene nodes in javascript instead of the editor, to create say cubes and spheres or even watersurfaces and skybox etc..
Is it for any reason ?

The above code works without any problems when using the Irrlicht sdk directly but an almost white sky texture when compiled with Coppercube sdk.

Any ideas or solutions anyone ?? Thanks!

person icon
Guest2
Guest
Quote
2026-07-14 20:39:28

Maybe you've already solved the problem.
Nevertheless, I am throwing in some questions & ideas (since I don't have access to the CopperCube game-client C++ code):

- Could the "raw" Irrlicht SceneNode creation be bypassing some setup in the CopperCube framework?
- Can you check if there is a class named "CFlaceSkyBoxSceneNode" that can be used to create the skybox?
- Another clue: check the C++ CopperCube code base for references to "EFSNT_FLACE_SKY_BOX"

- In Irrlicht there was a class named "CDefaultSceneNodeFactory" that contained valuable info on how to spawn SceneNodes.
Try to find a similar class (probably starting with or containing the string "CFlace") for the CopperCube framework and use it as inspiration.

- Is the initialization phase of the engine already completely finished when your code gets executed?
Is it possible that follow-up init code from the CopperCube SDK runs right after this and overwrites your material or scene settings or introduces unwanted changes to your setup?
Is it possible that the CopperCube SDK spawns a default light or skybox or modifies the fog and global light settings without your knowledge?

Note: In Irrlicht & CopperLicht, skybox materials appear to be initialized with specific material settings and in both systems, skyboxes also use a special rendering path.

- Is it possible that the compiled custom exe loads a default scene without your knowledge?

- Is an unintended light source overexposing the skybox?
An effect matching your description can be recreated in vanilla CopperCube by enabling "Dynamic Lighting" on a default skybox and dropping a point light with a large radius (> 6000) into the scene.

- Does the issue persist across DirectX & OpenGL rendering drivers?

person icon
gazzauk
Registered User
Quote
2026-07-15 16:29:05

Guest2 wrote:
Maybe you've already solved the problem.
Nevertheless, I am throwing in some questions & ideas (since I don't have access to the CopperCube game-client C++ code):


That's quite a few possible reasons and I will go through each of them and see if any of them help. I would not be doing this in C++source code if it was possible to do using javascript.

Thanks for your input on this and you appear to have to great knowledge of the engine and source code. How do you know all this without having the C++ client engine code ??

person icon
gazzauk
Registered User
Quote
2026-07-15 20:01:38

Ok, I've made some progress with this but the results are still not what expected (skybox texture is still overexposed white washed)

The client C++ sourcecode file CSpidermonkeyScriptEngine.cpp contains the following line that was commented out from use in javascript:

addGlobalFunction(ccbLibAddSceneNode, "ccbAddSceneNode" );


I've uncommented this line and other places in code where it was commented out and I can now successfully call this function from Javascript to create most of the default node types.

So to create a cube I use:

ccbAddSceneNode("cube",0,0,0);


To create a water surface I use:

ccbAddSceneNode("waterSurface",0,0,0);


And to create a skybox I use:

ccbAddSceneNode("skyBox",0,0,0);


I still work out a way to add the textures to these node objects though. But it makes me wonder why the developer (Niko) left out this very useful script function ???

person icon
gazzauk
Registered User
Quote
2026-07-15 20:08:32

Forgot to mention that the numbers (0,0,0) in those function calls above are the x,y,z position values.

I don't think the issue is with lighting as I have a default skybox already in the scene that I can disable and enable perfectly fine without the whitewashed textures.

Appears to be with the colors as the skybox textures are visible and loading.

person icon
gazzauk
Registered User
Quote
2026-07-15 20:28:34

A single line of code has fixed the problem by changing the material type as follows:


skyboxNode->setMaterialType(irr::video::EMT_SOLID_2_LAYER);


The code comments for this function explain this:

//! Solid material with 2 texture layers. The second is blended
//! onto the first using the alpha value of the vertex colors.
//! This material is currently not implemented in OpenGL.


I still don't understand why this material type works but EMT_SOLID does not ??

person icon
Guest2
Guest
Quote
2026-07-15 22:40:03

Excellent write-up, gazzauk!

It seems strange that you need to manually adjust material settings.
One would expect that everything should work out-of-the-box, like it did in your Irrlicht tests.

Keep in mind that the default skybox may use specific material flags!
Leverage ccbAddSceneNode() and check how it works internally when creating the skybox.
This will hopefully reveal the exact configuration steps expected by CopperCube.

If you really want to go further with the manual material setup approach:
Try something like this with material type EMT_SOLID (the code below is untested and based on Irrlicht 1.7.3):


//Worth a try:
skyboxNode->setMaterialFlag(irr::video::EMF_LIGHTING, false);

//Could there be an issue with the material colors?

//Worth a try:
skyboxNode->setMaterialFlag(irr::video::EMF_COLOR_MATERIAL, false);

//Alternatively, if EMF_COLOR_MATERIAL doesn't work in CopperCube:
skyboxNode->getMaterial(0).ColorMaterial = irr::video::ECM_NONE;
skyboxNode->getMaterial(1).ColorMaterial = irr::video::ECM_NONE;
skyboxNode->getMaterial(2).ColorMaterial = irr::video::ECM_NONE;
skyboxNode->getMaterial(3).ColorMaterial = irr::video::ECM_NONE;
skyboxNode->getMaterial(4).ColorMaterial = irr::video::ECM_NONE;
skyboxNode->getMaterial(5).ColorMaterial = irr::video::ECM_NONE;

//Alternatively, try to set the material colors directly via SColor (u32 alpha, u32 red, u32 green, u32 blue)
for (irr::u32 i = 0; i < skyboxNode->getMaterialCount(); ++i) {
skyboxNode->getMaterial(i).AmbientColor = irr::video::SColor(255, 255, 255, 255);
skyboxNode->getMaterial(i).DiffuseColor = irr::video::SColor(255, 255, 255, 255);
}


For context, here is how the original Irrlicht 1.7.3 source sets some important default CSkyBoxSceneNode material settings:

mat.Lighting = false;
mat.ZBuffer = video::ECFN_NEVER;
mat.ZWriteEnable = false;


person icon
gazzauk
Registered User
Quote
2026-07-16 00:03:40

Guest2 wrote:
Excellent write-up, gazzauk!

It seems strange that you need to manually adjust material settings.
One would expect that everything should work out-of-the-box, like it did in your Irrlicht tests.

Keep in mind that the default skybox may use specific material flags!


Hey, thanks for the code snippets but none of your suggested code methods worked at setting the texture correctly. The only material types that have worked so far are:


skyboxNode->setMaterialType(irr::video::EMT_LIGHTMAP);

and

skyboxNode->setMaterialType(irr::video::EMT_SOLID_2_LAYER);


I've tried every possible one of them in many different orders and places. Including your suggestions above.
I've no idea how the editor adds a skybox to the scene or what initialization materials and flags are used.
If I use the same skybox code in pure Irilict SDK it works out of the box like you say, without changing any materials or flags.

person icon
Guest2
Guest
Quote
2026-07-16 18:14:41

At this point, the idea with using the EMT_SOLID_2_LAYER and EMT_LIGHTMAP seems to be the right course of action.
You have discovered a solid workaround and narrowed down the cause of this issue.

Notes on the material types:
EMT_SOLID: Modulates the texture with lighting, material & vertex colors.
Leads to the over-exposure effect on the skybox. Modifying material settings doesn't seem to have any effect.

EMT_SOLID_2_LAYER: Uses the vertex alpha channel to blend 2 textures.
EMT_LIGHTMAP: Blends 2 textures (color texture, lightmap).
Both material types focus strictly on texture blending.
No influence from material colors, lighting, vertex RGB colors.
Without a second texture, both material types should cleanly draw the first texture.

Note: Contrary to the code comment about EMT_SOLID_2_LAYER not being implemented in OpenGL,
it appears to be fully implemented in Irrlicht 1.7.3.

Since you have uncovered the ccbLibAddSceneNode() function in "CSpidermonkeyScriptEngine.cpp",
examine the function body in the C++ source code to see how the engine handles the node creation.
At each of the following steps, check if the skybox SceneNode is modified by the framework.

1. ccbLibAddSceneNode() - Check how it parses the javascript arguments and extracts the "skyBox" string via attr->getAttributeAsString(argument_index) (useful for receiving filepath strings in your own script-functions).
Check the code section handling the "skyBox" string.
Does ccbLibAddSceneNode call a special SceneNodeFactory or the SceneManager (smgr)?
2. SceneNodeFactory->addSceneNode("skyBox") - this will likely only call the SceneManager (smgr) next
3. SceneManager->addSkyBoxSceneNode() - Check if the framework calls the standard Irrlicht constructor or a custom one:
Irrlicht: new CSkyBoxSceneNode(...)
CopperCube: new CFlaceSkyBoxSceneNode(...)
4. Also, check what is happening inside the SkyboxSceneNode constructor method.

This call path must contain a clue on how the framework handles the skybox initialization.
Compare it to your initial code.
If there is nothing handled differently, the framework appears to bypass / break the standard Irrlicht pipeline
without hinting this to the C++ user via clarifying comments.
The game-client may rely on ccb-files & the editor to provide readily configured SceneNodes - and your workaround remains to be the only viable option when dynamically creating skybox nodes.
This would also indicate that one would need to find the correct base config for each SceneNode type, which seems a bit off.

person icon
gazzauk
Registered User
Quote
2026-07-16 23:57:25

Guest2 wrote:
At this point, the idea with using the EMT_SOLID_2_LAYER and EMT_LIGHTMAP seems to be the right course of action.
You have discovered a solid workaround and narrowed down the cause of this issue.

the framework appears to bypass / break the standard Irrlicht pipeline
without hinting this to the C++ user via clarifying comments.
The game-client may rely on ccb-files & the editor to provide readily configured SceneNodes - and your workaround remains to be the only viable option when dynamically creating skybox nodes.
This would also indicate that one would need to find the correct base config for each SceneNode type, which seems a bit off.


Yes, you are correct to see that the framework is not using the standard Irrlicht pipeline in some cases.


Since you have uncovered the ccbLibAddSceneNode() function in "CSpidermonkeyScriptEngine.cpp"


Yes, I discovered this in the source code but it was commented out and not fully implemented. I added all those extra node string functions. They are boiler plate code at the moment.

person icon
Guest2
Guest
Quote
2026-07-17 22:06:36

One more idea.
Build a minimal custom C++ "myAddSceneNodeCube" function and expose it to the javascript engine.
The code snippets below are untested, may contain improper syntax and will probably not compile as-is. They are meant as inspiration and to give you a starting point.

Sources: YouTube tutorials by Saturn7/Robbo & Glitched Velocity/JIC/just_in_case, and forum posts by "Any Guy" (highly recommended!)

Warning: Without access to the CopperCube C++ game-client code I was unable to properly test & validate any of this. Scope & namespaces may be problematic. Expect compiler warnings & errors. Also, the sources I used may have demonstrated heavily modified codebases, so some things in the snippets below may simply not exist in the vanilla CopperCube framework.
Make sure to add proper safety- & pointer-checks everywhere.

General info:
Executing javascript-snippets from C++:
With access to a valid Scripting-object, it seems like you should be able to run javascript from the C++ side. Looks like a powerful tool, but I don't know if this is safe to use in the scope of a C++ scripting function.

Scripting->executeCode("var a = 1 + 1;");


Building the skeleton "myAddSceneNodeCube"-function:
The goal is to expose the following scripting-function in javascript:

myAddSceneNodeCube(custom_name, size, x, y, z, parentnode_name, texture_path);


//Function call example:
var mycube = myAddSceneNodeCube("cubexyz1", 10.0, 0, 5, 0, "", "cube_tex.png");


Open up the "CSpidermonkeyScriptEngine.cpp" file.

Function registration:
Add this to the list where the other registration-calls are in "CSpidermonkeyScriptEngine".

addGlobalFunction(myAddSceneNodeCube, "myAddSceneNodeCube");


Add the C++ function declaration to the header-file ("CSpidermonkeyScriptEngine.h").
Check if the following declaration is correct. If not, adjust the follow-up code accordingly.

static long myAddSceneNodeCube(ScriptFunctionParameterObject obj);


Start of the function:

long CSpidermonkeyScriptEngine::myAddSceneNodeCube(ScriptFunctionParameterObject obj)
{
CSpidermonkeyScriptEngine* scriptEngine = CSpidermonkeyScriptEngine::getEngineFromScriptFunctionObject(obj);
if (!scriptEngine) return 0;

irr::io::IAttributes* attr = scriptEngine->createParameterListFromScriptObject(obj);
if (!attr) return 0;


person icon
Guest2
Guest
Quote
2026-07-17 22:09:05

Part2.

Get the parameters from javascript:


if (attr->getAttributeCount() < 7) //check the parameter count
{
attr->drop();
return 0;
}

const irr::core::stringc nodename = attr->getAttributeAsString(0);
float base_size = attr->getAttributeAsFloat(1);
float px = attr->getAttributeAsFloat(2);
float py = attr->getAttributeAsFloat(3);
float pz = attr->getAttributeAsFloat(4);
const irr::core::stringc parentname = attr->getAttributeAsString(5);
const irr::core::stringc texture = attr->getAttributeAsString(6);




Get SceneManager and video driver:

ISceneManager* smgr = scriptEngine->getSceneManager();
if (!smgr) {
attr->drop();
return 0;
}

IVideoDriver* driver = smgr->getVideoDriver();
if (!driver) {
attr->drop();
return 0;
}


Create the node & adjust it.
This probably creates an "unmanaged" loose Irrlicht SceneNode, not properly registered in CopperCube. Physics & properties may or may not work.
Possible clues for proper implementations (probably needs deep digging into the functions): ccbCloneSceneNode(), ccbRemoveSceneNode(), ccbLibAddSceneNode()


//get the parent node
irr::scene::ISceneNode* parentnode = nullptr;
if (parentname.size() == 0)
{
parentnode = smgr->getRootSceneNode();
}
else
{
parentnode = smgr->getSceneNodeFromName(parentname.c_str());
if (!parentnode) parentnode = smgr->getRootSceneNode(); //fallback
}

//create the new node
ISceneNode* node = smgr->addCubeSceneNode(base_size, parentnode);

//Alternatively, a call into the SceneNode-"factory" could also work and may spawn a default size 10 cube:
//ISceneNode* node = smgr->addSceneNode("cube", parentnode);
//ISceneNode* node = smgr->addSceneNode("cube", 0); //or this
//Would be interesting to know if any of this ultimately builds on a CFlace* class or a "raw" Irrlicht class
//Assumption: The CopperCube framework extends the Irrlicht nodes or wraps them inside its own classes to track properties, physics, behaviors. A raw Irrlicht cube will probably lack collision, properties and may have rendering glitches.


if (!node) {
attr->drop();
return 0;
}

//apply position, rotation, scale
node->setPosition(irr::core::vector3df(px, py, pz));
node->setRotation(irr::core::vector3df(0.0f, 0.0f, 0.0f));
node->setScale(irr::core::vector3df(1.0f, 1.0f, 1.0f));

//enable lighting on the node
//node->setMaterialFlag(irr::video::EMF_LIGHTING, true);

//the following can be seen in a code snippet by "Any Guy"
setUniqueNameForSceneNode(node, nodename.c_str(), smgr);
//if the above doesn't work in the current scope, try this:
//scriptEngine->setUniqueNameForSceneNode(node, nodename.c_str(), smgr);


person icon
Guest2
Guest
Quote
2026-07-17 22:11:11

Part3.

Texture loading.
This uses a relative file-path and probably creates an "unmanaged" texture.
- A better way to resolve local assets must exist.
- Proper implementations can probably be found in the C++ implementations of the js-functions ccbLoadTexture() and ccbSetSceneNodeMaterialProperty()

if (texture.size() > 0)
{
irr::video::ITexture* tex = driver->getTexture(texture.c_str());
if (tex)
{
node->setMaterialTexture(0, tex);
}
}


End of the function:


attr->drop(); //properly remove the IAttributes parameter-list

//Pass the node reference back to javascript
//May not work properly, be careful:
//- You may need to explicitly create a SpiderMonkey js wrapper object and return that instead
//- As mentioned, the "node" could be just a loose raw Irrlicht SceneNode without proper hooks into the CopperCube system
//if (node) {scriptEngine->setReturnValue(node);}

return 1;
}


Well, that's all.

person icon
Guest2
Guest
Quote
2026-07-17 22:25:55

One thing:
I commented out the following line in Part 3:

//if (node) {scriptEngine->setReturnValue(node);}


This will prevent the following snippet from working as expected:

var mycube = myAddSceneNodeCube("cubexyz1", 10.0, 0, 5, 0, "", "cube_tex.png");


Why did I do this?
Because I think it may be safer to not use the setReturnValue() until one can be sure that the node is created correctly. Instead, while debugging it may be better to rely on
ccbGetSceneNodeFromName() in javascript to get a reference to the node.

person icon
gazzauk
Registered User
Quote
2026-07-18 02:08:41

I like it, not tried any of what you suggested yet but as an initial idea I can't see why the code wouldn't work.

I will look into what other coppercube functions return for nodes given your suggestion about the return value from scriptEngine->setReturnValue(node);

I'm having a little coding break at the moment and working on some model designing, it's much less frustrating.

Thanks for the advice.


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |