ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperLicht
I need help detecting collisions with custom scene nodes. I put a custom node in an official tutorial and it's not solid.
Author Text

wild-master
Registered User
Quote
2018-05-19 19:57:11

I followed this official tutorial:
https://ambiera.com/copperlicht/...

The live demo from that page is included with the source code of CopperLicht, so I added the included custom node from the "cubescenenode.js" file of the source to the demo.

I added the Cube node, but the First-Person Camera character walks through it.

I added the cube like this:
var cubenode = new CL3D.CubeSceneNode();
scene.getRootSceneNode().addChild(cubenode);
newposition = new CL3D.Vect3d(-50,100,20);
cubenode.Pos = newposition;

The tutorial linked above says this:
"CopperLicht automatically provides a triangle selector for all geometry where the 'Collision' attribute was checked in the editor via scene.getCollisionGeometry(), so you won't have to build it yourself."

If I plan to always create my own custom nodes without the aid of CopperCube, just for fun, I won't be able to activate the "Collision" attribute because the node won't ever be in CopperCube first. For that situation, the demo says I should use the "MeshTriangleSelector()" and "OctTreeTriangleSelector()" features.

The tutorial above says this:
"We could have also supplied some other collision geometry represented as TriangleSelector. Triangle selectors in CopperLicht simply provide a way to access geometry. If you have a Mesh for example, you can create a new triangle selector using new MeshTriangleSelector(yourMesh, yourSceneNode);. If the mesh is big, you could use new OctTreeTriangleSelector(yourMesh, yourSceneNode) instead to speed up the collision queries a bit."

I tried adding this line at many spots of the code:
new MeshTriangleSelector(cubenode.getMesh(), null, null, cubenode);

That causes all collisions to stop working as a side effect of the whole code being destroyed by that incorrect line, and this error appears in the console of my browser:
ReferenceError: MeshTriangleSelector is not defined

Please tell me how to use "MeshTriangleSelector()" and "OctTreeTriangleSelector()" correctly so I can enable collision detection for nodes that aren't imported from CopperCube. The file "cubescenenode.js" shows that the Cube is a "CL3D.MeshSceneNode" with a MeshBuffer attached, but I don't know how to call the mesh and I don't know how to add it to the collision detection routine of CopperLicht.

I surpassed many barriers by myself while practicing CopperLicht because I don't want to be lazy, but this seems to be beyond my current level and I need a boost.

I know the benefits of importing all models from CopperCube. I just want to practice by detecting the collision with the custom cube that doesn't have an enabled "Collision" marker because it is created fully with CopperLicht.

I know the fear of the employees of Ambiera, but don't worry. Even if I practice for the next five years, and I become so wise that I could switch to CopperLicht exclusively, I will always buy every version of CopperCube to show support and appreciation toward this company, and if I ever become adept with JavaScript, I will graduate by practicing the C++ source that is included with the Professional version, and I will always need to pay you for that, so I'm locked in (willingly!).

If I practice for a decade and I feel like I still cannot sufficiently utilize the power of JavaScript, I will traverse the Earth until I tell every living human that I am too stupid. I will fully admit it. I will write it on my tombstone. I will write it on my bones.


wild-master
Registered User
Quote
2018-05-20 02:51:22

I fixed one problem.

I wrote "new TriangleMeshSelector", but the correct way to write it is: "new CL3D.TriangleMeshSelector".

Now, I found a new problem.

I searched the forum and tried to decipher Niko's old posts for clues, and the culmination of information led to the creation of this code:
var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(cubenode.Mesh, null, null, cubenode);

var colanimator = new CL3D.AnimatorCollisionResponse(
new CL3D.Vect3d(20,40,20), // size of the player ellipsoid
new CL3D.Vect3d(0,30,0), // position of the eye in the ellipsoid
scene.getCollisionGeometry());

cam.addAnimator(colanimator);

colanimator.setWorld(TriangleSelectorOfCubeNode);

With that code, I see this error in the console of my Firefox browser:
TypeError: this.Node is undefined
triangleselector.js:239:6

I wish I could pay a professional for private lessons of CopperLicht. I want to know if I am dumb or if I just need all of the information displayed with super-clear instructions before I fully understand them, meaning I would be only halfway dumb.

I don't yet know if I am dumb, but until a perfect piece of evidence arises, I shall continue to search for answers.

Before I die, I may be crushed by what I find,
because the answers I obtain, are not the answers that are kind.
The answers that are kind, may not be able to be real,
because the limits of my mind, I may wish to soon conceal.



wild-master
Registered User
Quote
2018-05-20 19:44:35

I uncovered the answer!

So many hours!

Countless hours!

Beyond sleep and time!

This is the answer:
var TriangleSelectorOfCubeNode = new CL3D.MeshTriangleSelector(cubenode.getMesh(), cubenode);

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
scene.getCollisionGeometry());

colanimator.AffectedByGravity = false;

cam.addAnimator(colanimator);

colanimator.setWorld(TriangleSelectorOfCubeNode);

I will now try to discover why that solution doesn't work for scene nodes that are imported with the OBJ Loader from the other thread in this forum.


wild-master
Registered User
Quote
2018-05-20 21:15:37

Here's the thread about the OBJ Loader:
https://ambiera.com/forum.php?t=...

The first post says this:

Since the loader doesn't stop the execution of the rest of the program, I had difficulty implementing collisions for the object.

To resolve this issue, I had to add the TriangleSelector after the mesh was loaded. Before loading the mesh, create a MetaSelector and apply it to the camera. Then, in the pastebin code, at line 113, create a TriangleSelector and add that to the allready existing MetaSelector.

I followed his instructions by creating a "CL3D.MetaTriangleSelector" before I imported the object, and then I injected the "CL3D.MeshTriangleSelector" for the imported object into the "MetaTriangleSelector" by using this code, but I can still walk through it like it's not solid:
MetaTriangleSelector.addSelector(MeshTriangleSelectorOfImportedObject);
I know I created the MetaTriangleSelector correctly because I injected the MeshTriangleSelector of the Cube Scene Node from the "cubescenenode.js" file that's included with CopperLicht into the MetaTriangleSelector and the collision system works for it.

I may not be capturing the Mesh from the OBJ Loader script correctly. If someone wants to help, please remember that I am using the script from the second pastebin link in that thread (in the second post from warner).


wild-master
Registered User
Quote
2018-05-21 01:11:12

OOOOOHHH WOOOOWW!!!!

OOOOOOOHHHHH WWWWOOOOOWWWW!!!!!

After hours of debugging, I found the answer!

The old usage of "setWorld()" was interfering with the "MetaTriangleSelector"! I removed that part, and the imported objects are detected by the collision-detection system now!

I did this to solve it:
// 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);

Then, I imported the external ".OBJ" file:
sampleobject = new ObjLoaderNode();
sampleobject.load(engine, "sampleobject.obj", 1); //filename + scale
scene.getRootSceneNode().addChild(sampleobject);
NewPositionOfSampleObject = new CL3D.Vect3d(0, 0, 50);
sampleobject.Pos = NewPositionOfSampleObject;
sampleobject.updateAbsolutePosition();

Then, I added these lines near the end of the OBJ Loader script:
var TriangleSelectorOfLoadedObject = new CL3D.MeshTriangleSelector(loaderNode.getMesh(), loaderNode);
MetaTriangleSelector.addSelector(TriangleSelectorOfLoadedObject);

I copied the whole OBJ Loader script here with those lines already attached:
https://pastebin.com/raw/CwpiM7U...

Edit 1:
I changed the pastebin link above because I added many comments, to help people understand parts of the script.


wild-master
Registered User
Quote
2018-05-21 20:46:42

I discovered how to create a great collision system that causes all objects to collide realistically! Mesh-to-Mesh collisions!

I created a separate "CL3D.MetaTriangleSelector()" for each node!

(I first created a separate "CL3D.AnimatorCollisionResponse()" for each node, and then I put its personal "CL3D.MetaTriangleSelector()" inside of it.)

The reason each node has its own "MetaTriangleSelector" is that an object cannot move if it is a part of the MetaTriangleSelector for its own self! It will be stuck, because the engine will think it is touching a physical object! So, I created a separate MetaTriangleSelector for each node that includes the MeshTriangleSelector of every object EXCEPT for the one for ITSELF! A node's own Mesh won't count as a collision, so it can move!

The objects collide like real pieces of matter now! They don't move through each other!
The whole shape of each object is detected, instead of a general collision-shape around it! Like the collisions of reality!
I imported an object with many crevices and bumps, and the other objects seemed to move along all of those areas, like rough terrain, so it's very realistic!

I also created an invisible cube attached to my camera, so the camera won't go through physical objects, either!

I saved my progress on multiple hard drives, although losing the progress will not be catastrophic, because I believe I can recreate all of it quite quickly. So quickly, in fact, that some cultures believe I have reached a new intelligence.

I feel so wise now.

Wise beyond time.

I feel like a master.

A master of the Earth.


niko
Moderator
Quote
2018-05-22 08:57:04

Hm, great. :)


just_in_case
Registered User
Quote
2018-06-11 07:40:02

Ca you please export this script to Coppercube behaviour or extension... it can be really helpful....


wild-master
Registered User
Quote
2018-06-11 11:51:57

Hello.

Perfect collisions that detect the exact physical shapes of objects don't seem possible with CopperCube. The scripting manual doesn't show a way to manipulate Triangle Selectors.

The closest idea I found is the example in my CCB file here:
https://ambiera.com/forum.php?t=...

I don't know whether the perfect collisions that are possible with CopperLicht have long term-term negative effects for games with many objects, like speed problems. Perhaps the method possible with CopperCube is better overall because of speed considerations. I am not qualified to say which method is faster and better for release-worthy games.

I've noticed that many professional games that involve people, like RPGs, seem to use the method shown in my CCB file above. Many professional games show hands not being detected by the collision boxes of other characters, while the overall shapes of the characters are still detected because they're unable to walk through other characters. I've seen Super Mario's 3D hands and hat go through walls while his overall body cannot walk through them.

All other engines I've tried also used the same idea. They used overall collision boxes and I didn't notice options for perfectly-realistic collisions.


just_in_case
Registered User
Quote
2018-06-11 20:17:10

I was using the same idea since i started using coppercube... I was expecting perfect collisions.... To be developed for coppercube and saw your post today... And i thought if you can develop something for coppercube too...But sadly there is no perfect collision sysytem...

Problem i generally got into while using static mesh is that... If there are more than one static mesh attached to my object... Then there more chances of internal collision... And the object doesn't move at all...

I use the term dummy mesh for the collision detectors created using static mesh around the object..


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Forum 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


   





Software: Ambiera Light Forum. © 2008-2018 Nikolaus Gebhardt, Ambiera e.U.