ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperLicht
Copying one meshes to another.
Author Text

freddy
Registered User
Quote
2014-09-12 19:10:51

I'm trying to work on my morphing algorithm.

How can I copy one buffer into another buffer please ?

say I have two meshes and I want to copy the tempMeshBuffer into the currentMeshBuffer in this example...

currentMeshBuffer.Vertices = tempMeshBuffer.Vertices;


Am I doing that right ? It doesn't seem to be working the way I want it to.

What I want is for currentMeshBuffer to be altered to match tempMeshBuffer.


freddy
Registered User
Quote
2014-09-12 23:38:15

I must add that the once one mesh has been duplicated they have to be totally independent of each other.

I tried the method above and I also tried createClone()... when I do that, if I change one mesh it also changes the other one !

Thanks for any guidance :)


niko
Moderator
Quote
2014-09-13 05:54:35

If you assign the vertices like the one above, then both point to the same array, meaning that if you change one, the other one also changes, because it is actually the same, yes :)

You are right, when calling MeshBuffer::createClone(), a new array is created, but actually the same vertices are used. Will be fixed in the new release (about two weeks away). You can fix this yourself, by adding this code and overwriting the wrong implementation in the meantime:


CL3D.MeshBuffer.prototype.createClone = function()
{
var ret = new CL3D.MeshBuffer();
ret.Box = this.Box.clone();
ret.Mat = this.Mat.clone();

if (this.Vertices)
{
for (var i=0; i<this.Vertices.length; ++i)
{
var v = new CL3D.Vertex3D();
var vold = this.Vertices[i];
v.Pos = vold.Pos.clone();
v.Normal = vold.Normal.clone();
v.Color = vold.Color;
v.TCoords = new CL3D.Vect2d(vold.TCoords.x, vold.TCoords.y);
v.TCoords2 = new CL3D.Vect2d(vold.TCoords2.x, vold.TCoords2.y);
ret.Vertices.push(v);
}
}

if (this.Indices)
{
for (var i=0; i<this.Indices.length; ++i)
ret.Indices.push(this.Indices[i]);
}

if (this.Tangents)
{
for (var i=0; i<this.Tangents.length; ++i)
ret.Tangents.push(this.Tangents[i]);
}

if (this.Binormals)
{
for (var i=0; i<this.Binormals.length; ++i)
ret.Binormals.push(this.Binormals[i]);
}

return ret;
}



freddy
Registered User
Quote
2014-09-13 15:34:03

Great I will try the clone fix for now, thank you very much :)


freddy
Registered User
Quote
2014-09-13 18:18:43

This works well. One bug in it, these lines needs to be capital X and Y or you lose the textures :

v.TCoords = new CL3D.Vect2d(vold.TCoords.x, vold.TCoords.y);
v.TCoords2 = new CL3D.Vect2d(vold.TCoords2.x, vold.TCoords2.y);


Needs to be :

v.TCoords = new CL3D.Vect2d(vold.TCoords.X, vold.TCoords.Y);
v.TCoords2 = new CL3D.Vect2d(vold.TCoords2.X, vold.TCoords2.Y);


Then it works.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (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-2019 Nikolaus Gebhardt, Ambiera e.U.