Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Mesh selector

Registered User
2013-10-23 15:27:17

Hello again,
I am having problems with something I expected to be very easy...
mesh click events..

I have tried all animators, all selectors and I have read every single post about events...

The most success I had was with this code:
Casa1Out.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
However (I need various objects with similar click behaviour behind this one) when I click on this one object all objects with this behaviour behind it get the click event..

All I would need is for the endLine to actually end the line at the place I clicked in 3D on the canvas but this does not seem to be the case with my code. As this event is pretty important to me (duh!), I will need this to work somehow.. Here is my code:
canvas. = function(event){
var endLine = engine.get3DPositionFrom2DPosition(engine.getMouseDownX(), engine.getMouseDownY());
var startLine = engine.getScene().getActiveCamera().getAbsolutePosition();

var Casa1Out = scene.getSceneNodeFromName('Casa1Fuori');
var Casa1In = scene.getSceneNodeFromName('Casa1Dentro');
var Casa2Out = scene.getSceneNodeFromName('Casa2Fuori');
var Casa2In = scene.getSceneNodeFromName('Casa2Dentro');
var Bagno = scene.getSceneNodeFromName('Bagno');

var Intersect = new Array(null,null,null,null,null);
IIntersect[0] = Casa1Out.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
Intersect[1] = Casa1In.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
Intersect[2] = Casa2Out.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
Intersect[3] = Casa2In.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
Intersect[4] = Bagno.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);

var colorableArr = new Array(Casa1Out,Casa1In,Casa2Out,Casa2In,Bagno);

for (var i=0; i<4; ++i){
if (Intersect[i]){
var SelectionMeshC=colorableArr[i];
var Casa1OutMesh = SelectionMeshC.getMesh();
var buffers = Casa1OutMesh.GetMeshBuffers();

for (var n=0; n<buffers.length; ++n){
var vertices = buffers[n].Vertices;
for (var v=0; v<vertices.length; ++v)
var vtx = vertices[v];
vtx.Color = CL3D.createColor(newColor[0],newColor[1],newColor[2],newColor[3]);
buffers[0].update(false, true);

I could not use getTransformedBoundingBox() as this would always overlap with the other nodes (the nodes are walls)

As you can see I have multiple meshes in my scene and all of them are overimposed (they are walls of a house).

I am on a trial version of CopperCube now, if this is not possible I won't be buying this software and unfortunately I won't be using copperlicht... I am surprised how complicated it is to get an event from one node (with the node name returned)! and I don't seem to be the only one... this problem goes back from the start of CopperLicht...

I suggest you do a tutorial for simple events with copperlicht that give back the object name that has been clicked (in a scene with multiple overlapping meshes, as they usually are)

Thanks in advance for any help you may be able to provide, or even better samples.

Daniel Bowyer
Director at RighTwist

2013-10-23 16:10:30


if you are using CopperCube (the editor), then you can use the most easy way to do this: Add a "when clicked do something" behavior to the object. That's it.

If you prefer to do this in code using the CopperLicht SDK, then this also works, of course. Your code is correct, it only misses a check if there is another object between you and the point on the object you clicked on.

So it should work like this, extending your code:

var endLine = engine.get3DPositionFrom2DPosition(engine.getMouseDownX(), engine.getMouseDownY());
var startLine = engine.getScene().getActiveCamera().getAbsolutePosition();
var collisionPoint = Casa1Out.Selector.getCollisionPointWithLine(startLine, endLine, true, null,true);
var collides = false;

if (collisionPoint != null)
// the click was on the object. We now check if there was something other in between
collides = true;

var collisionPointWithWorld =
engine.getScene().CollisionWorld.getCollisionPointWithLine(startLine, collisionPoint, true, null, true);
if (collisionPointWithWorld)
var distancetoWorld = startLine.getDistanceTo(collisionPointWithWorld );
var distancetoObject = startLine.getDistanceTo(collisionPoint );
if (distancetoWorld + 0.0001 < distancetoObject)
collides = false; // there is something other in between

if (collides)
// the click is on your object
// the click is not on your object or something is between.

Note: this only works with the copperlicht.js from the copperlicht SDK, the one generated by the coppercube editor might for example not have the CollisionWorld variable defined.

Registered User
2013-10-23 16:44:56

Niko you are awesome!!!

By the way, just for reference, there is no mention of
the class CollisionWorld anywhere online or within the documentation attached to the latest SDK.

Thanks so much!

This is was a make or break problem, I am glad it is sorted


Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Inte?national" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



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