Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
createClone() problems - still

csp-games
Guest
Quote
2022-01-07 17:43:40

First of all, I unsuccessfully tried to find the answer in this forum and elsewhere for a few hours, so I dare to ask.

For now the simple goal is to clone a ccbz-loaded mesh, position it somewhere, and have collision working like with the original.

I do this (on a keyhit):

// find entity
var mytree=ccbGetSceneNodeFromName("my_pinetree1");

// entityxyz
var myvec=cam.getAbsolutePosition();
myvec.X+=20;
myvec.Y+=20;
//positionentity
mytree.Pos=myvec;
mytree.updateAbsolutePosition();

//copyentity
var mytree2=mytree.createClone(scene.getRootSceneNode(),mytree.Id,mytree.Id+100);
// scene.getRootSceneNode().addChild(mytree2);// makes no difference, I assume a clone is added to the parent of the original anyway?
mytree2.Name="bubu";
//mytree2.init();// just scales it to 1,1,1
var myvec2=myvec;
myvec2.Y-=40;
mytree2.Pos=myvec2;
mytree2.updateAbsolutePosition();



Now what happens is: I hit space the 1st time, there's a tree at the myvec2 position, but the original tree has disappeared. This new one has working collision. I move the cam and hit space again, there's a new tree, but the other one is still there, so I really cloned it. But the new one has collision, and the old one has not. I move and hit space again, there's a third tree, with collision, but the other 2 old ones have no collision now. This keeps on, and the last one is always the only one that has collision response.

Can somebody point me out in simple code, how to achieve my goal, or if it's not possible, admit it and help me stop wasting time?
I've seen Niko's function to overwrite the createClone function, but AFAIS, as it creates a mesh from scratch, it won't have working collision - at least I never managed to get collision to work with a cusom made mesh node. I actually abandoned a working mesh loader because I couldn't get collision to work.

I add here further questions, that somebody may be capable to answer:

How can I get collision to work with a mesh that is made by code. What's the deal with the whole Selector business.

How can I linepick an animated mesh. I can do it on a static one, based on one of the tutorials. However, shooting targets are usually animated.

Is it possible to use BLOOM etc. with direct copperlicht.js use? I tried those constants, never worked. If this is some kind of limit in the free, open source version, not just because of the apocalypse etc., I would recc to enable it for everybody. Growth is everything, if you want to play the engine game. There's a huge engine graveyard. Don't waste the potential of CL.

I imported a B3D mesh in ccube, with masked textures. This is not alpha, but 1 bit masking (directx, probably webGL too?). In ccube it uses alpha. The z-order of the tris is unsorted. Can this be fixed? I noticed there is sorting for seperate nodes.

The editor supports masked dds textures (tho using alpha blending), when run in the browser, it's solid (may be the browser).

Can dynamic lights put shadows on a lightmapped mesh? Maybe on a clone in some blend mode?

I leave it at that, thanks.


csp-games
Guest
Quote
2022-01-07 18:38:08

As it happens so often, we find a solution right after asking. The cloning thing is solved, my code just sucketh, but the missing collision on the clones is still a game stopper, any ideas?

BTW here's the code that works:

// find entity
var mytree=ccbGetSceneNodeFromName("my_pinetree1");

// entityxyz
var myvec_old=mytree.getAbsolutePosition();
var myvec=cam.getAbsolutePosition();

//copyentity
var mytree2=mytree.createClone(scene.getRootSceneNode(),mytree.Id,mytree.Id+count_trees);// worked
count_trees+=1; // that's a global
myvec.Z-=40;
myvec.Y=myvec_old.Y;
mytree2.Pos=myvec;
mytree2.updateAbsolutePosition();


I added this to the example that allows to shoot a cube at the wall (collision example), so I can walk around and just plant trees, pretty cool, but I really need collision.


csp-games
Guest
Quote
2022-01-07 22:43:01

Okee dokee! Wow today things really work. I just managed to get collision working with a cloned mesh. Thanks to wild-master!

His code at the end of a onL.o.a.d.ingComplete function:


// add a cube to test
var cubenode = new CL3D.CubeSceneNode();
scene.getRootSceneNode().addChild(cubenode);

var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(cubenode.getMesh(), cubenode);
MetaTriangleSelector = new CL3D.MetaTriangleSelector();

var colanimator = new CL3D.AnimatorCollisionResponse(
new CL3D.Vect3d(6,12,6), // size of the player ellipsoid
new CL3D.Vect3d(0,0,0), // position of the eye in the ellipsoid
MetaTriangleSelector);

colanimator.AffectedByGravity = false;

cam.addAnimator(colanimator);

var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(cubenode.getMesh(), cubenode);
MetaTriangleSelector.addSelector(TriangleSelectorOfCubeNode);

worked right out of the box (didn't read it carefully enough the first time). Furthermore, by adding:
cubenode.Visible=false;
I can have an invisible collision cube and position it around an object with high polycount, which is preferable, performence-wise. However, the code also works with a cloned mesh, so here's the whole tree planting code:

var cam = scene.getActiveCamera();
var mytree=ccbGetSceneNodeFromName("my_pinetree1");

var myvec_old=mytree.getAbsolutePosition();
var myvec=cam.getAbsolutePosition();

var mytree2=mytree.createClone(scene.getRootSceneNode(),mytree.Id,mytree.Id+count_trees);// worked
count_trees+=1; // that's a global, declared outside of any functions as "var count_trees=0";
myvec.Z-=40;
myvec.Y=myvec_old.Y;
mytree2.Pos=myvec;
mytree2.updateAbsolutePosition();
//------- add collision handler for cloned mesh
var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(mytree2.getMesh(), mytree2);
MetaTriangleSelector = new CL3D.MetaTriangleSelector();

var colanimator = new CL3D.AnimatorCollisionResponse(
new CL3D.Vect3d(6,12,6), // size of the player ellipsoid
new CL3D.Vect3d(0,12,0), // position of the eye in the ellipsoid
MetaTriangleSelector);

colanimator.AffectedByGravity = false;

cam.addAnimator(colanimator);

var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(mytree2.getMesh(), mytree2);
MetaTriangleSelector.addSelector(TriangleSelectorOfCubeNode);
//----------

What used to confuse me was that I had to set player ellipsoid. It appears the cam has an individual coll ellipsoid for each coll animator. I also had to set eyeheight to ellipsoid height to make it work.
But as I said, I will rather use an invisible box for collision around the trees' stems - collision for all the leaf triangles seems silly (1000 rtis per tree, yet, no noticeable impact with about 10 trees with full mesh collision).
Using mesh collision with a clone or a custom made mesh node is esp. interesting for the ground and walls.
Horray!


csp-games
Guest
Quote
2022-01-07 23:32:43

🔎︎

trees are still bad, but that's a matter of ccube settings.
So now I can load a ccbz file containing all potential assets, ten clone them and reconstruct a game level from my win32 fps engine easily. Next: linepick on animated meshes.


csp-games
Guest
Quote
2022-01-07 23:35:03

sorry, image link was wrong... hopefully now:
🔎︎



csp-games
Guest
Quote
2022-01-08 16:38:44

Ok, but Line Picks on clones still don't work. I can't find anything about :
scene.getCollisionGeometry().getCollisionPointWithLine(...
other than in one example. It does not work with the clones described above (even tho cam2clone collision works), and I also can't see a way to figure out WHAT node has been picked, as getCollisionPointWithLine(. returns a 3D vector position only.

I even can't find "getCollisionPointWithLine" as a string inside copperlicht.js, which indicates that the ccbz file contains additional features in code. However the file appears to be encrypted.

Also, picks on animated meshes don't work. However I plan to use surrounding lowpoly meshes, like the cube mentioned above. But I want to clone npcs, which works, except for line picks, which didn'tt work for the original animated npc anyway.

Any ideas?


csp-games
Guest
Quote
2022-01-08 18:12:34

Ok I was wrong, not sure what copperlicht.js I was looking at, but in the one that's running I find it, and also in the Docs, but that's what I mean by unintuitive: how am I supposed to know that I have to look up this:
scene.getCollisionGeometry().getCollisionPointWithLine(

under:
Class CL3D.TriangleSelector

Anyway, so I find getRelatedSceneNode(), supposed to "Returns the scenenode this selector is for", ok. I try it this way:

alert(scene.getCollisionGeometry().getRelatedSceneNode() );

but it always returns Null. So how am I supposed to get the Node the line hit?


csp-games
Guest
Quote
2022-01-08 18:21:29

BTW. problem of unsorted Z-order of alpha leaves on trees solved, by using the "for plants and grass" feature under advanced settings of the texture of the material in coppercube.
🔎︎



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

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


   






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