This is an old revision of the document!
Shape
A Shape in the code
Following notes are only a draft and work in progress! — Sit Melai 2016/12/05 19:37
How a shape is optimally created
To fill a shape, you have to fill the CMesh::CMeshBuild (structure explained below). Then you can call build on a CMesh object with your CMesh::CMeshBuild object as parameter. The CMesh object generated from this can be written into a file by opening a COFile stream and calling the serial method on the CMesh with your stream as paremeter.
How it is serialized in the code (using serial())
Click to display ⇲
Click to hide ⇱
CShapeStream::serial(NLMISC::IStream &f) // called by NLMISC::IStream.serial(CShapeStream)
f.serialCheck( NELID( "PAHS" ) ) // NELID converts the string to a uint32
f.serialPolyPtr( _Shape ) // _Shape is a property of the CShapeStream object
// both functions above can be found in stream.h
serialCheck(const T &value) // in stream.h
read and compare to value
or
write value
serialPolyPtr(T* &ptr) // in stream.h
create IStreamable pointer p from ptr
serialIStreamable(p) // in stream.h
static_cast p back to type T and assign to ptr
IStream::serialIStreamable(IStreamable* &ptr) // in stream.cpp
if reading
serial a uint64
result is 0 -> set ptr to NULL and end
else
Check if object already created or read
if not
serial a string className
set ptr to CClassRegistry::create(className) dynamic_cast to IStreamable*
if ptr is null
throw error
else
check ptr is valid object with CClassREgistry::checkObject
Insert into the _IdMap
ptr->serial(*this) // Should call IStreamable::serial which is equal to class of this::serial(IStream &f)
How CMeshBuild struct looks like
Click to display ⇲
Click to hide ⇱
CMesh::CMeshBuild structure (mesh.h) sint32 VertexFlags uint8 NumCoords[CVertexBuffer::MaxStage] // how many coordinates each uvw uses (2 or 3) uint8 UVRouting[CVertexBuffer::MaxStage] // uv routing table, each uv channel can be routed to any vertex uv std::vector<NLMISC::CVector> Vertices std::vector<CMesh::CSkinWeight> SkinWeights // same size as Vertices, NULL if no skinning (Palette Skinning Vertices array?) std::vector<std::string> BonesNames // each matrix id in SkinWeights must have a corresponding entry in bone name entry std::vector<CMesh::CFace> Faces std::vector<CMesh::CBlendShape> BlendShapes std::vector<CMesh::CVertLink> VertLink // Link between VB and max vertex index, will be filled by build NLMISC::CSmartPtr<IMeshVertexProgram> MeshVertexProgram // MeshVertexProgram to be copied to meshGeom std::vector<CMesh::CInterface> Interfaces // Mesh Interface System for MRM building std::vector<CMesh::CInterfaceLink> InterfaceLinks // Same size as Vertices, or Mesh Interface system disabled NLMISC::CBitSet InterfaceVertexFlag // each bit indicates if vertex belongs to an interface CMeshBuild() // build a CMesh NLMISC::CVector (vector.h) float x float y float z CVector(x, y, z) // all mathematic standard operations and more NL3D_MESH_SKINNING_MAX_MATRIX = 4 (mesh.h) CMesh::CSkinWeight (mesh.h) // if you don't use all matrix set 0 on weights you don't use uint32 MatrixId[NL3D_MESH_SKINNING_MAX_MATRIX] // which matrix of skeleton shape this vertexuses float Weights[NL3D_MESH_SKINNING_MAX_MATRIX] // sum of all entries should be 1 CMesh::CFace (mesh.h) NLMISC::CCorner Corner[3] sint32 MaterialId sint32 SmoothGroup CMesh::CCorner (mesh.h) sint32 Vertex // id of the vertex NLMISC::CVector Normal NLMISC::CUVW Uvws[CVertexBuffer::MaxStage] NLMISC::CRGBA Color NLMISC::CRGBA Specular NLMISC::CUVW (uv.h) float u float v float w CUVW(u, v, w) // all mathematic standard operations and more NLMISC::CRGBA (rgba.h) uint8 R uint8 G uint8 B uint8 A CRGBA(R, G, B, A = 255) NL3D::CBlendShape (mesh_morpher.h) std::string Name std::vector<NLMISC::CVector> deltaPos std::vector<NLMISC::CVector> deltaNorm std::vector<NLMISC::CVector> deltaTgSpace std::vector<NLMISC::CUV> deltaUV std::vector<NLMISC::CRGBAF> deltaCol std::vector<uint32> VertRefs // Array of vertices references NLMISC::CUV NLMISC::RGBAF CMesh::CVertLink (mesh.h) uint32 nFace uint32 nCorner uint32 VertVB CVertLink(nFace, nCorner, VertVB) CMesh::CInterface (mesh.h) std::vector<CInterfaceVertex> Vertices // polygon of interface between 2 meshs CMesh::CInterfaceVertex (mesh.h) CVector Pos CVector Normal CMesh::CInterfaceLink (mesh.h) sint InterfaceId // id of the interface this vertex is welded to uint InterfaceVertexId // id of the vertex this vertex is welded to
The .shape format
You want to make your own importer/exporter for .shape files? Take a look at the structure of the .shape format:
Not finished yet, missing some parts that can be parsed as PolyPtr! WIP! — Sit Melai 2016/12/11 16:48
Click to display ⇲
Click to hide ⇱
Version
- 1 byte number, ver
if ver = 0xFF
- 4 bytes number, ver
Double
- 8 bytes number
Float
- 4 bytes number
Bool
- 1 byte number
String (Length encoded)
- 4 bytes number, len
- len bytes string
RGBA
- 1 byte number r (0 - 255)
- 1 byte number g (0 - 255)
- 1 byte nubmer b (0 - 255)
- 1 byte number a (0 - 255)
2DVector
- Float x
- Float y
3DVector
- Float x
- Float y
- Float z
4DVector
- Float a
- Float b
- Float c
- Float d
PolyPtr
- 8 bytes number, an id
- if id not in file yet
- String, classname
- classname
Shape
- 4 bytes that are "SHAP"
- PolyPtr
CMesh
- Version
- CMeshBase
- CMeshGeom
CMeshBase
- Version, ver
- ver greater/equal to 2
- 4 bytes number, Number Animated Morphs
0 to Number Animated Morphs
- String, Material Name
- ver bigger than 1
- Version
- 3DVector, Default Position
- Version
- 3DVector, Default Pivot
- Version
- 3DVector, Default Rotation Euler
- Version
- 4DVector, Default Rotation Quat
- Version
- 3DVector, Default Scale
- 4 bytes number, Number Materials
0 to Number Materials
- CMaterial
- 4 bytes number, Number Elements
0 to Number Elements
- 4 bytes number, key
- CMaterialBase, value
- map key to value
- ver bigger/equal to 8 // Map m maps light name to map p
// Map p maps index to matnumber and stage number
- 4 bytes number, Number Lights
0 to Number Lights
- CLightMapInfoList
- ver smaller than 8 // Map m maps light name to map p
// Map p maps index to matnumber and stage number
- 4 bytes number, Number Lights
0 to Number Lights
- String, key
- 4 bytes number, num
0 to num, i
- 1 byte number, value[i]["MatNumber"]
- 1 byte number, value[i]["StageNumber"]
- ver bigger/equal to 3
- Bool, Lightable
- ver bigger/equal to 4
- Bool, Use Lighting Local Attenuation
- ver bigger/equal to 5
- Bool, Auto Anim
- ver bigger/equal to 6
- Float, Max Distance
- ver bigger/equal to 7
- 8 bytes number, id
- if id not read yet
- CLodCharacterTexture
- ver bigger/equal to 9
- 4 bytes number, index
index value
- case 0
- Auto Camera Collision
- case 1
- No Camera Collision
- case 2
- Force Camera Collision
CMeshGeom
- Version, ver
- ver bigger/equal to 4
- 4 bytes number, Number Bone Names
0 to Number Bone Names
- String, Bone Name
- ver bigger/equal to 3
- PolyPtr, Mesh Vertex Program
- ver bigger/equal to 1
- CMeshMorpher, Mesh Morpher
- CVertexBuffer, VBuffer
- 4 bytes number, Number Matrix Blocks
0 to Number Matrix Blocks
- CMatrixBlock
- CAABBox, BBox
- Bool, Skinned
CMaterial
- Version
- 4 bytes number, index
index in Shaders:
"Normal", "Bump", "UserColor", "LightMap", "Specular", "Caustics", "PerPixelLighting", "PerPixelLightingNoSpec", "Cloud", "Water"
- 4 bytes number, flags
- 4 bytes number, index
index in Source Blenders
"one", "zero", "srcalpha", "invsrcalpha", "srccolor", "invsrccolor", "blendConstantColor", "blendConstantInvColor", "blendConstantAlpha", "blendConstantInvAlpha"
- 4 bytes number, index
index in Destination Blenders
"one", "zero", "srcalpha", "invsrcalpha", "srccolor", "invsrccolor", "blendConstantColor", "blendConstantInvColor", "blendConstantAlpha", "blendConstantInvAlpha"
- 4 bytes number, index
index in ZFunctions
"always", "never", "equal", "notequal", "less", "lessequal", "greater", "greaterequal"
- Float, ZBias
- RGBA, Color
- RGBA, Emissive
- RGBA, Ambient
- RGBA, Diffuse
- RGBA, Specular
- ver greater/equal to 2
- Float, Shininess
- ver greater/equal to 5
- Float, AlphaTestThreshold
- ver greater/equal to 8
- 2 bytes number, Texture Coordinate Generation Mode
0 to IDRV_MAT_MAXTEXTURES (0 to 4)
- PolyPtr, Texture
- ver greater/equal to 1
- TexEnv (ver greater/equal 9)
- ver greater/equal to 3
- ver greater/equal to 7
- 4 bytes number, Number of Light Maps
0 to Number of Light Maps
- CLightMap_2
- Bool
- ver smaller 7
- 4 bytes number, Number of Light Maps
0 to Number of Light Maps
- CLightMap
- ver greater/equal to 4
- flags greater 0
0 to Max Textures (4)
- 1 byte number, Texture Address Mode
- ver greater/equal to 6
0 to Max Textures (4), i
- flags greater 0
- i smaller than 3
- CMatrix, Texture User Mat
CMaterialBase
- Version, ver
- String, Name
- Version
- RGBA, Default Ambient
- Version
- RGBA, Default Diffuse
- Version
- RGBA, Default Specular
- Version
- Float, Shininess
- Version
- RGBA, Default Emissive
- Version
- Float, Default Opacity
- Version
- 4 bytes number, Default Texture
- 4 bytes number, Number Elements
0 to Number Elements
- 4 bytes number, key
- CAnimatedTexture, mat
- map key to mat
- ver greater 0
0 to Max Textures (4)
- CTexAnimTracks
CLightMapInfoList
- Version
- 4 bytes number, Light Group
- String, Animated Light
- 4 bytes number, Number Mat Stages
0 to Number Mat Stages
- Version
- 1 byte number, Material Id
- 1 byte number, Stage Id
CLodCharacterTexture
- Version
- 4 bytes number, Width
- 4 bytes number, Height
- 4 bytes number, Number Points
0 to Number Points
- 1 byte number, T
- 1 byte number, U
- 1 byte number, V
- 1 byte number, Q
CMeshMorpher
- Version
- 4 bytes number, Number Blend Shapes
0 to Number Blend Shapes
- CBlendShape
CVertexBuffer
- Version, ver
- ver smaller 2
- 4 bytes number, Flags
bit 1 = XYZ
bit 2 = Weight0, WeightCount = 1 // if multiple, highest WeightCount
bit 3 = Weight1, WeightCount = 2
bit 4 = Weight2, WeightCount = 3
bit 5 = Weight3, WeightCount = 4
bit 6 = Normal
bit 7 = PrimaryColor
bit 8 = SecondaryColor
bit 9 = TexCoord0
bit 10 = TexCoord1
bit 11 = TexCoord2
bit 12 = TexCoord3
bit 13 = TexCoord4
bit 14 = TexCoord5
bit 15 = TexCoord6
bit 16 = TexCoord7
bits 17 & 2 & 3 & 4 & 5 = PaletteSkin
- 4 bytes number, Number Vertices
0 to Number Vertices
- XYZ_Flag
- 3DVector, XYZ
- Normal_Flag
- 3DVector, Normal
0 to MaxStage (8), i
- UVi_Flag
- CUV
- PrimaryColor_Flag
- RGBA, Color
- SecondaryColor_Flag
- RGBA, Specular
0 to WeightCount
- Float, Weight
- PaletteSkin_Flag
- CPaletteSkin
- ver greater/equal to 2
- Version, hver
- hver smaller 1
- 4 bytes number, Flags
bit 1 = XYZ
bit 2 = Weight0, WeightCount = 1 // if multiple, highest WeightCount
bit 3 = Weight1, WeightCount = 2
bit 4 = Weight2, WeightCount = 3
bit 5 = Weight3, WeightCount = 4
bit 6 = Normal
bit 7 = PrimaryColor
bit 8 = SecondaryColor
bit 9 = TexCoord0
bit 10 = TexCoord1
bit 11 = TexCoord2
bit 12 = TexCoord3
bit 13 = TexCoord4
bit 14 = TexCoord5
bit 15 = TexCoord6
bit 16 = TexCoord7
bits 17 & 2 & 3 & 4 & 5 = PaletteSkin
- hver greater/equal to 1
- 2 bytes number, Flags
bit 1 = Position
bit 2 = Normal
bit 3 = TexCoord0
bit 4 = TexCoord1
bit 5 = TexCoord2
bit 6 = TexCoord3
bit 7 = TexCoord4
bit 8 = TexCoord5
bit 9 = TexCoord6
bit 10 = TexCoord7
bit 11 = PrimaryColor (Color?)
bit 12 = SecondaryColor (Specular?)
bit 13 = Weight
bit 14 = PaletteSkin
bit 15 = Fog
bit 16 = Empty
0 to NumValue (16), i
- 1 byte number, Type[i]
- 4 bytes number, Number Vertices
- hver greater/equal to 2
- 1 byte number, Vertex Color Format
- hver greater/equal to 3
- 4 bytes number, index
index in PreferredMemory:
"RAMPreferred", // A block of driver RAM memory is allocated for this buffer. The buffer is read/write.
"AGPPreferred", // A block of driver AGP memory is allocated for this buffer. The buffer is writeonly.
"StaticPreferred", // The buffer will not be modified. A block of driver AGP or VRAM memory is allocated for this buffer. The buffer is writeonly.
"RAMVolatile", // A block of temporary driver RAM memory will be returned by lock(). The buffer must be entirely filled after each swapBuffers(). The buffer is writeonly.
"AGPVolatile" // A block of temporary driver AGP memory will be returned by lock(). The buffer must be entirely filled after each swapBuffers(). The buffer is writeonly.
- String, Name
- Version, sver
0 to Number Vertices
0 to NumValue (16), i
- Flags bit i set
- Type[i] equal 0
- Double
- Type[i] equal 1
- Float
- Type[i] equal 2
- 2 bytes number
- Type[i] equal 3
- Double
- Double
- Type[i] equal 4
- Float
- Float
- Type[i] equal 5
- 2 bytes number
- 2 bytes number
- Type[i] equal 6
- Double
- Double
- Double
- Type[i] equal 7
- Float
- Float
- Float
- Type[i] equal 8
- 2 bytes number
- 2 bytes number
- 2 bytes number
- Type[i] equal 9
- Double
- Double
- Double
- Double
- Type[i] equal 10
- Float
- Float
- Float
- Float
- Type[i] equal 11
- 2 bytes number
- 2 bytes number
- 2 bytes number
- 2 bytes number
- Type[i] equal 12
- 1 byte number
- 1 byte number
- 1 byte number
- 1 byte number
- sver greater/equal to 2
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
- 1 byte number, UVRouting
CMatrixBlock
- Version
0 to 16
- 4 bytes number, Matrix Id
- 4 bytes number, Number Matrix
- 4 bytes number, num
0 to num
- CRdrPass
CAABBox
- Version
- 3DVector, Center
- 3DVector, Half Size
TexEnv (ver)
- 1 byte number, Color Operand
- 1 byte number, Color Argument 0
- 1 byte number, Color Operand 0
- 1 byte number, Color Argument 1
- 1 byte number, Color Operand 1
- ver greater 0
- 1 byte number, Color Argument 2
- 1 byte number, Color Operand 2
- 1 byte number, Alpha Operand
- 1 byte number, Alpha Argument 0
- 1 byte number, Alpha Operand 0
- 1 byte number, Alpha Argument 1
- 1 byte number, Alpha Operand 1
- ver greater 0
- 1 byte number, Alpha Argument 2
- 1 byte number, Alpha Operand 2
- RGBA, Constant Color
CLightMap_2
- Version, ver
- RGBA, Factor
- RGBA, LMCDiffuse
- ver greater/equal to 1
- RGBA, LMCAmbient
- PolyPtr, Texture
CLightMap
- RGBA, Factor
- PolyPtr, Texture
CMatrix
- Version, ver
- 4 bytes number, StateBit
- Float, Scale 33
- StateBit bit for value 2, 4 or 8 set
- Float, Matrix [0][0]
- Float, Matrix [0][1]
- Float, Matrix [0][2]
- Float, Matrix [1][0]
- Float, Matrix [1][1]
- Float, Matrix [1][2]
- Float, Matrix [2][0]
- Float, Matrix [2][1]
- Float, Matrix [2][2]
- StateBit bit for value 1 set
- Float, Matrix [0][3]
- Float, Matrix [1][3]
- Float, Matrix [2][3]
- StateBit bit for value 16 set
- Float, Matrix [3][0]
- Float, Matrix [3][1]
- Float, Matrix [3][2]
- Float, Matrix [3][3]
CAnimatedTexture
- PolyPtr, Texture
CTexAnimTracks
- Version, ver
- Float, Default U Translation
- Float, Default V Translation
- Float, Default U Scale
- Float, Default V Scale
CBlendShape
- Version, ver
- String, Name
- 4 bytes number, Number deltaPos
0 to Number deltaPos
- 3DVector
- 4 bytes number, Number deltaNorm
0 to Number deltaNorm
- 3DVector
- 4 bytes number, Number deltaUV
0 to Number deltaUV
- CUV
- 4 bytes number, Number deltaCol
0 to Number deltaCol
- CRGBAF
- ver greater/equal to 1
- 4 bytes number, Number deltaTgSpace
0 to Number deltaTgSpace
- 3DVector
- 4 bytes number, Number Vertex References
0 to Number Vertex References
- 4 bytes number, Vertex Reference
CUV
- Float, u
- Float, v
CPaletteSkin
- 1 byte number, MatrixId 0
- 1 byte number, MatrixId 1
- 1 byte number, MatrixId 2
- 1 byte number, MatrixId 3
CRdrPass
- Version
- 4 bytes number, MaterialId
- CIndexBuffer
CRGBAF
- Float, R (0 - 1)
- Float, G (0 - 1)
- Float, B (0 - 1)
- Float, A (0 - 1)
CIndexBuffer
- Version, ver
- ver smaller 1 // Primitive block
- 4 bytes number, Number
- 4 bytes number, Capacity
- 4 bytes number, Number Indexes
0 to Number Indexes
- 4 bytes number, Index
- 4 bytes number, Number
- 4 bytes number, Capacity
- 4 bytes number, Number nonResidentIndexes
0 to Number nonResidentIndexes
- 4 bytes number, nonResidentIndex
- 4 bytes number, Number
- 4 bytes number, Capacity
- 4 bytes number, Number Indexes
0 to Number Indexes
- 4 bytes number, Index
- ver greater/equal 1 // Index buffer
- 4 bytes number, Number Indexes
- 4 bytes number, Capacity
- 4 bytes number, Number nonResidentIndexes
0 to Number nonResidentIndexes
- 4 bytes number, nonResidentIndex
- 4 bytes number, index
index in PreferredMemory:
"RAMPreferred", // A block of driver RAM memory is allocated for this buffer. The buffer is read/write.
"AGPPreferred", // A block of driver AGP memory is allocated for this buffer. The buffer is writeonly.
"StaticPreferred", // The buffer will not be modified. A block of driver AGP or VRAM memory is allocated for this buffer. The buffer is writeonly.
"RAMVolatile", // A block of temporary driver RAM memory will be returned by lock(). The buffer must be entirely filled after each swapBuffers(). The buffer is writeonly.
"AGPVolatile" // A block of temporary driver AGP memory will be returned by lock(). The buffer must be entirely filled after each swapBuffers(). The buffer is writeonly.
- ver equal to 1
0 to PreferredCount (5)
- Bool, old Format Memory Preference





