Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
1.0.0:custommesh [2023/03/23 13:42] – [Create A Mesh (CustomMesh)] admin | 1.0.0:custommesh [2023/03/23 13:59] – [Add a Skin-Animation] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Create A Mesh (CustomMesh) ====== | ====== Create A Mesh (CustomMesh) ====== | ||
- | Developers need to create meshes and models themselves at runtime. Our 3D format loaders already use those ways to setup their model data. So it is possible for users to build their own import format too. | + | Developers need to create meshes and models themselves at runtime. Our 3D format loaders already use those ways to setup their model data. So it is possible for users to build their own import-format |
===== The Fast Way ===== | ===== The Fast Way ===== | ||
Line 98: | Line 98: | ||
|TextureSource[Index : Integer]|Buffer for multiple texture coordinates| | |TextureSource[Index : Integer]|Buffer for multiple texture coordinates| | ||
|ColorSource[Index : Integer]|Buffer for multiple color values| | |ColorSource[Index : Integer]|Buffer for multiple color values| | ||
- | |IndexMap|Some formats need mapping between vertices by index value| | + | |IndexMap|Some formats need mapping between vertices by index value. Also it is getting filled during auto-triangulation.| |
|Vertices|List of combined vertex data into a single structure (TVertexData): | |Vertices|List of combined vertex data into a single structure (TVertexData): | ||
|Indices|List of arrays with 3 ordinal values representing triangles: TList< | |Indices|List of arrays with 3 ordinal values representing triangles: TList< | ||
Line 137: | Line 137: | ||
|function AddTriangle(const AIndexOffset : Integer; const ATriangle : TTriangleID; | |function AddTriangle(const AIndexOffset : Integer; const ATriangle : TTriangleID; | ||
|function AddPolygon(const AIndexOffset : Integer; const APolygon : TPolygonID; const AVertices : TList< | |function AddPolygon(const AIndexOffset : Integer; const APolygon : TPolygonID; const AVertices : TList< | ||
- | === Example === | + | |
+ | ==== Example | ||
+ | |||
+ | In this detailed example, let's create a mesh the same like in the " | ||
+ | |||
+ | But here we're going further by adding normals, colors, materials, armature+bones and a skin-animation. | ||
+ | |||
+ | In the first step we're going to show the usage of TVertexCache to setup mesh data. | ||
+ | |||
+ | === Adding MeshData | ||
<file pascal> | <file pascal> | ||
Line 277: | Line 286: | ||
</ | </ | ||
- | ==== Add Hierarchy | + | === Add Hierarchy === |
Since v1.0 most objects in DefTypes are inherited from TTransformDef. | Since v1.0 most objects in DefTypes are inherited from TTransformDef. | ||
Line 319: | Line 328: | ||
- | ==== Vertex Groups | + | === How To Use Vertex Groups === |
VertexGroups are helper structures referring to an owner mesh, which holds original vertex data and complete indices list, while this structure only holds a separated index source for partially rendering a mesh. | VertexGroups are helper structures referring to an owner mesh, which holds original vertex data and complete indices list, while this structure only holds a separated index source for partially rendering a mesh. | ||
Line 343: | Line 352: | ||
end; | end; | ||
</ | </ | ||
- | ==== Add Material | + | === Add A Material === |
To expand the dynamic model setup, let's add a material to our sub-mesh. | To expand the dynamic model setup, let's add a material to our sub-mesh. | ||
Line 372: | Line 381: | ||
</ | </ | ||
- | ==== Add Animation | + | === Add A Simple |
Adding animations can become a very challenging part due to complexity. | Adding animations can become a very challenging part due to complexity. | ||
Line 424: | Line 433: | ||
- | ==== Add Armature & SkinController | + | === Add Armature & SkinController === |
To make skin- or skeleton-animations possible you will need an armature with a hierarchy of joints representing the internal skeleton of a body. | To make skin- or skeleton-animations possible you will need an armature with a hierarchy of joints representing the internal skeleton of a body. | ||
Line 481: | Line 490: | ||
LCtrl.Skin.Skeletons.Add(LJtRef); | LCtrl.Skin.Skeletons.Add(LJtRef); | ||
- | // We have to link all relevant joint to the skin and add weights and joint-indices | + | // We have to link all relevant joint to the skin and add weights and vertex-indices |
+ | // " | ||
+ | // The sum of all weights (over all joints) for a specific vertex has to be 1.0! | ||
LJtRef := LCtrl.Skin.LinkJoint(Result.Root); | LJtRef := LCtrl.Skin.LinkJoint(Result.Root); | ||
LJtRef.Weights := [0.75, 0.75, 0.75, 0.75, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0]; | LJtRef.Weights := [0.75, 0.75, 0.75, 0.75, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0]; | ||
Line 509: | Line 520: | ||
</ | </ | ||
- | To animate the armature | + | === Add a Skin-Animation === |
+ | |||
+ | To animate the armature it's necessary to have compatible animation stages and interpolators. | ||
- | Regarding | + | Related to our armature and bones (joints) before, the code could look something like this: |
<file pascal> | <file pascal> | ||
Line 595: | Line 608: | ||
__NOTICE:__ You will need a stage for each joint to be modified during the animation. | __NOTICE:__ You will need a stage for each joint to be modified during the animation. | ||
- | ==== Create FMX Components from Definition | + | === Create FMX Components from Definition === |
<file pascal> | <file pascal> |