realbasic-games
[Top] [All Lists]

Re: Cloning Trimesh

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Cloning Trimesh
From: Joseph Nastasi <joe at pyramiddesign dot us>
Date: Tue, 8 Nov 2005 13:43:38 -0500
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <14e78666b84e09bd1739f7ef5e4a01b6 at pyramiddesign dot us> <a0620070bbf967cab0ba4 at [10 dot 0 dot 1 dot 4]>

On Nov 8, 2005, at 11:06 AM, Joseph J. Strout wrote:

Yes, though it takes a few steps. Each of the group accessor classes (VectorList, TriangleList, and so on) has a Copy method. So, to clone a TriMesh, you would make a new TriMesh, set its number of vertices and triangles and such to the same as your original, and then call Copy on the VertexPositions, VertexNormals, Triangles, VertexColors (if applicable), and VertexUVs (ditto).

Here's what I did and it worked, but I did not get any noticeable speed increase. In this case, I am loading 200 trimeshes, each a plane created with two triangles. The same 5k image is used as a texture. It takes a real long time to load this. Not to run it, but just to load. I'm obviously overlooking something here:

Private Function CloneTrimesh(original As Trimesh) As Trimesh
  Dim clone As New Trimesh

  clone.VertexCount = original.VertexCount
  clone.TriangleCount = original.TriangleCount
  clone.VertexPositions.Copy(original.VertexPositions)
  clone.Triangles.Copy(original.Triangles)
  clone.HasVertexUVs = True
  clone.VertexUVs.Copy(original.VertexUVs)
  clone.Material.Texture = original.Material.Texture
  clone.Scale = original.Scale
  Return(clone)
End Function

I call this using:

  lastcolumn = 0
  lastrow = lastrow - yoffset
  For r = 1 To Self.Rows
    For c = 1 To Self.Columns
      dclone = Self.CloneTrimesh(dcl)
      dclone.Position.X =  lastcolumn
      dclone.Position.Y = lastrow
      lastcolumn = lastcolumn + xoffset
      Self.Entities.Append dclone
    Next
    lastcolumn = 0
    lastrow = lastrow - yoffset
  Next

Where dcl is the original trimesh and dclone is a placeholder for new ones.

Any ideas?
--
Joseph Nastasi
Pyramid Design - a software development firm
http://www.pyramiddesign.us
Voice 609 601-0814      Fax 609 601-0815
Products:
A-OK! Spacecraft Simulation System - http://aok.pyramiddesign.us
A-OK! The Wings of Mercury http://www.aokwom.com
FTP Suite for REALbasic - http://ftpsuite.pyramiddesign.us
Columnist for REALbasic Developer Magazine
Proud Sponsors of REALbasic Olympics 2005




_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>