realbasic-games
[Top] [All Lists]

Re: Tearing in trimesh morphs

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Tearing in trimesh morphs
From: "Joseph J. Strout" <joe at strout dot net>
Date: Mon, 13 Feb 2006 22:01:06 -0700
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <AD2720A3-FE2D-43AB-A346-B11C9EAF0B19 at mindspring dot com> <a0620073bc0115bf6e836 at [10 dot 0 dot 1 dot 13]> <CB9FFBC4-8741-461E-B76C-D8BE4980D5E8 at chaoticbox dot com> <a0620073fc011766b1b83 at [10 dot 0 dot 1 dot 13]> <B78BCBE3-2AE6-4BFE-8415-3730A760860A at chaoticbox dot com> <C31343CF-851B-46FA-804F-16593F025A78 at mindspring dot com>
I finally took some time to look at Jeff's example, and I think I've found the problem. The models Jeff is loading have triangle normals. These are an optional attribute of a trimesh, though they're usually a good idea since they save the renderer the trouble of calculating them on the fly. But in the case of morphing meshes, they're a hindrance; they don't get updated just because you've changed the triangle positions, and because they're NOT calculated on the fly, they remain in effect, causing triangles to be culled inappropriately. (And if you don't have vertex normals, then it causes them to be shaded inappropriately too.)

Fortunately, there is a pretty easy fix: don't use triangle normals with models you're going to morph! Then Quesa/QD3D will recalculate them on each frame, and they'll always be correct even as your model morphs.

Meshwork doesn't have an option for this, but it does comment its 3DMF output, so it's easy to find the "triangle normals" section and cut it out. An automated post-processor could of course be made to do this if you need it a lot.

Another way around it is to copy the original TriMesh into one you have more control over, like so:

Protected Function CopyTrimesh(tm As Trimesh) As Trimesh
  // Make a new Trimesh with the same geometry as the given one.
  // But this way, we make sure we don't have any extra attributes
  // we don't want (like triangle normals!).

  Dim out As New Trimesh

  out.VertexCount = tm.VertexCount
  out.VertexPositions.Copy tm.VertexPositions

  out.TriangleCount = tm.TriangleCount
  out.Triangles.Copy tm.Triangles

  return out

End Function

Jeff, in your demo, simply adding the above method and loading your poses with:

  mPoses.Append CopyTrimesh( Obj.Trimesh(0) )

in the Box constructor seems to fix it. Note that I haven't copied the material here -- in a real app, you'd almost certainly want to copy that too.

As a side note, Jeff, I notice in your demo that you're looping over the vertices and interpolating for each one. That's OK, but not as fast (nor as easy!) as it could be; the VectorList class has methods to operate on the entire list at once. I'd demonstrate, but I have to run; let me know if you want any help figuring that out.

Best,
- Joe

--

Joseph J. Strout
joe at strout dot net
_______________________________________________
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>