Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > CopperCube Open discussion
Manipulating meshes
Author Text

freddy
Registered User
Quote
2014-09-06 19:32:19

Hi everyone,

Just trying out the demo of CC. I come from working on a C-sharp project where I built and animated a head. I animated using my own morph target animation.

My question is this : can I take a mesh and iterate over it changing it's shape per vertex ?

Is there possibly some one who could show me in code an example of doing this ?

I see when I import an OBJ model that the groups seemed to get merged into one mesh - is that correct ? Can the grouping be retained so I have a model made of it's groups, ie individual meshes of the groups ?

If not I figured I could import the groups individually and animate them separately... but 'join' them somehow.

The reason is that for efficiency I would only want to animate parts of the whole model.

Any thoughts ?

Many thanks !


erik
Registered User
Quote
2014-09-06 20:35:28

Yes, you can do this using the Mesh Editing functions (see here: http://www.ambiera.com/coppercub...), like with this example for scaling all vertices by a factor 2:

var meshnode = editorGetSelectedSceneNode();
var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode);
if (bufferCount == 0)
alert('The selected node has no 3D geometry.');
else
{
for (var i=0; i<bufferCount; ++i)
{
var vertexcount = ccbGetMeshBufferVertexCount(meshnode, i);
for (var v=0; v<vertexcount; ++v)
{
var pos = ccbGetMeshBufferVertexPosition(meshnode, i, v);

pos.x *= 2;
pos.y *= 2;
pos.z *= 2;

ccbSetMeshBufferVertexPosition(meshnode, i, v, pos);
}
}
ccbUpdateSceneNodeBoundingBox(meshnode);
}


But this only works in the editor and in the Windows .exe and Mac OS .exe targets. (For the last two, you need to adapt the example of course a bit, because the functions starting with editor won't exist there)

About the groups when importing: Yes, that's how it works in coppercube. If you want multiple meshes, you need to import them from separate files.


freddy
Registered User
Quote
2014-09-06 20:53:47

Thanks for the quick reply.

I was hoping to run this on the web using an HTML document. But from what you say that's not possible.

That's a shame :(


freddy
Registered User
Quote
2014-09-06 21:01:21

Are there any plans to extend this to be included in the WebGL part ?


erik
Registered User
Quote
2014-09-06 21:02:09

If you want to run this one the web with WebGL, this is also possible. You just need to use another API for it, there is something more powerful available for WebGL, named copperlicht, see here: http://www.ambiera.com/copperlic...


freddy
Registered User
Quote
2014-09-06 21:07:05

Ohh nice :) Thanks, I will take a look at the new goodies


freddy
Registered User
Quote
2014-09-06 21:22:21

Just one quick question...

I was using morph targets in my C-sharp program. In other words I had differing models loaded into memory and used them as my reference points for the morphing.

My question is, would I be able to load a mesh but not necessarily display it ? Can a mesh be in memory and not displayed without any overheads ?

IF not, maybe I can write something to load the target morphs into some data structure.

Thanks :)


niko
Moderator
Quote
2014-09-07 07:09:10

Yes, that's no problem. In copperLicht, you can access your data through CL3D.Mesh and CL3D.MeshBuffer. Simply don't display it (make it invisible for example, or remove it from the scene) and no overhead will be done.


freddy
Registered User
Quote
2014-09-07 22:49:20

Hi Niko,

Thanks for the information. I'll have a play with things this week hopefully.

Thanks a lot for the replies you guys :)


freddy
Registered User
Quote
2014-09-10 15:13:57

I can't quite work this out. I'm trying to load a mesh into an array, so that I can traverse the array and work out how the main model should be morphed....

'v3' is a model that is in memory but not visible - this is my morph target.

This is my JS, the trouble is there does not seem to be anything in 'foo'.

Could someone advise please ?



	var engine = startCopperLichtFromFile('3darea', 'copperlichtdata/anima.ccbjs', 'Loading $PROGRESS$...', 'Error: This browser does not support WebGL.');

var morphSceneNode = null;
var foo;

// this is called when loading the 3d scene has finished
engine.ingComplete = function()
{
var scene = engine.getScene();
if (scene)
{
// also, force the 3d engine to update the scene every frame
scene.setRedrawMode(CL3D.Scene.REDRAW_EVERY_FRAME);

foo = CL3D.Mesh('v3');

}
}



freddy
Registered User
Quote
2014-09-10 15:55:59

Above, Niko gave this example for CopperCube....


var meshnode = editorGetSelectedSceneNode();
var bufferCount = ccbGetSceneNodeMeshBufferCount(meshnode);
if (bufferCount == 0)
alert('The selected node has no 3D geometry.');
else
{
for (var i=0; i<bufferCount; ++i)
{
var vertexcount = ccbGetMeshBufferVertexCount(meshnode, i);
for (var v=0; v<vertexcount; ++v)
{
var pos = ccbGetMeshBufferVertexPosition(meshnode, i, v);

pos.x *= 2;
pos.y *= 2;
pos.z *= 2;

ccbSetMeshBufferVertexPosition(meshnode, i, v, pos);
}
}
ccbUpdateSceneNodeBoundingBox(meshnode);
}


This is the kind of thing that I need to do. Is there possibly an example for CopperLicht ? I can't seem to find anything..

Cheers :)


niko
Moderator
Quote
2014-09-10 16:46:59

Hi,
you can use the CopperLicht API as well like this:


var node = engine.getScene().getSceneNodeFromName('NameOfYourNode');

if (node)
{
if (node.getType() == 'mesh')
{
var mesh = node.getMesh();
for (var i=0; i<mesh.GetMeshBuffers().length; ++i)
{
var meshBuffer = mesh.GetMeshBuffers()[i];
for (var v=0; v<meshBuffer.Vertices.length; ++v)
{
meshBuffer.Vertices[v].Pos.X += 1.0;
}

meshBuffer.update(false, false);
}
}
}


I just wrote this without testing it, but it should work.


freddy
Registered User
Quote
2014-09-10 17:04:33

Hey Nico, thanks a lot for you help.

I tried this but Firefox is returning the error :

TypeError: mesh.Vertices is undefined

I'll see if I can find out why, unless you beat me to it ;)


niko
Moderator
Quote
2014-09-10 17:10:01

Oh, it should have been 'meshBuffer', mistyped. I updated the code :)


freddy
Registered User
Quote
2014-09-10 17:12:17

Yeah that works

Thank you !


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internat?onal" (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© 2020 Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact