NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer Class Reference

#include <mesh_mrm_skinned.h>


Detailed Description

The packed vertex buffer.

Definition at line 423 of file mesh_mrm_skinned.h.

Public Member Functions

void build (const CVertexBuffer &buffer, const std::vector< CMesh::CSkinWeight > &skinWeight)
void clear ()
void contReset ()
uint getNumVertices () const
CPackedVertexgetPackedVertices ()
const CPackedVertexgetPackedVertices () const
void getPos (CVector &dest, const CPackedVertex &src) const
void serial (NLMISC::IStream &f)

Private Attributes

float _DecompactScale
 Decompact position values.

std::vector< CPackedVertex_PackedBuffer


Member Function Documentation

void NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::build const CVertexBuffer buffer,
const std::vector< CMesh::CSkinWeight > &  skinWeight
 

Definition at line 2018 of file mesh_mrm_skinned.cpp.

References _DecompactScale, _PackedBuffer, buffer, NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::Matrices, NLMISC::CVector::maxof(), NLMISC::CVector::minof(), NL3D_MESH_MRM_SKINNED_DEFAULT_POS_SCALE, NL3D_MESH_MRM_SKINNED_MAX_MATRIX, nlassert, NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::setNormal(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::setPos(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::setUV(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::setWeight(), sint, uint, uint8, NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::Weights, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by NL3D::CMeshMRMSkinnedGeom::build().

02019 {
02020         const uint numVertices = buffer.getNumVertices();
02021         nlassert (numVertices == skinWeight.size());
02022         nlassert (buffer.getVertexFormat() & (CVertexBuffer::PositionFlag|CVertexBuffer::NormalFlag|CVertexBuffer::TexCoord0Flag) == (CVertexBuffer::PositionFlag|CVertexBuffer::NormalFlag|CVertexBuffer::TexCoord0Flag));
02023 
02024         _PackedBuffer.resize (numVertices);
02025 
02026         // default scale
02027         _DecompactScale = NL3D_MESH_MRM_SKINNED_DEFAULT_POS_SCALE;
02028 
02029         if (numVertices)
02030         {
02031                 // Get the min max of the bbox
02032                 CVector _min = *(const CVector*)buffer.getVertexCoordPointer(0);
02033                 CVector _max = _min;
02034 
02035                 // For each vertex
02036                 uint i;
02037                 for (i=1; i<numVertices; i++)
02038                 {
02039                         // Update min max
02040                         const CVector &vect = *(const CVector*)buffer.getVertexCoordPointer(i);
02041                         _min.minof(_min, vect);
02042                         _max.maxof(_max, vect);
02043                 }
02044 
02045                 // Scale enough ?
02046                 float max_width = std::max((float)fabs(_min.x), std::max((float)fabs(_min.y), (float)fabs(_min.z)));
02047                 max_width = std::max(max_width, std::max((float)fabs(_max.x), std::max((float)fabs(_max.y), (float)fabs(_max.z))));
02048                 _DecompactScale = std::max(_DecompactScale, max_width / 32767.f);
02049 
02050                 // Pack
02051                 for (i=0; i<numVertices; i++)
02052                 {
02053                         CPackedVertex &vertex = _PackedBuffer[i];
02054 
02055                         // Position
02056                         vertex.setPos (*(const CVector*)buffer.getVertexCoordPointer(i), _DecompactScale);
02057 
02058                         // Normal
02059                         vertex.setNormal (*(const CVector*)buffer.getNormalCoordPointer(i));
02060 
02061                         // UV
02062                         const float *uv = (const float*)buffer.getTexCoordPointer(i, 0);
02063                         vertex.setUV (uv[0], uv[1]);
02064 
02065                         // Matrices
02066                         uint j;
02067                         sint weightSum = 0;
02068                         for (j=0; j<NL3D_MESH_MRM_SKINNED_MAX_MATRIX; j++)
02069                         {
02070                                 vertex.Matrices[j] = (uint8)skinWeight[i].MatrixId[j];
02071                                 vertex.setWeight (j, skinWeight[i].Weights[j]);
02072                                 weightSum += (sint)vertex.Weights[j];
02073                         }
02074 
02075                         // Weight error
02076                         weightSum = 255 - weightSum;
02077 
02078                         // Add error to the first weight
02079                         nlassert ((sint)vertex.Weights[0] + weightSum <= 255);
02080                         nlassert ((sint)vertex.Weights[0] + weightSum > 0);
02081                         vertex.Weights[0] += weightSum;
02082                 }
02083         }
02084 }

void NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::clear  )  [inline]
 

Definition at line 475 of file mesh_mrm_skinned.h.

References _PackedBuffer.

Referenced by NL3D::CMeshMRMSkinnedGeom::build().

00476                 {
00477                         _PackedBuffer.clear();
00478                 }

void NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::contReset  )  [inline]
 

Definition at line 481 of file mesh_mrm_skinned.h.

References _PackedBuffer, and NLMISC::contReset().

Referenced by NL3D::CMeshMRMSkinnedGeom::serial().

00482                 {
00483                         NLMISC::contReset (_PackedBuffer);
00484                 }

uint NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::getNumVertices  )  const [inline]
 

Definition at line 505 of file mesh_mrm_skinned.h.

References _PackedBuffer, and uint.

Referenced by NL3D::CMeshMRMSkinnedGeom::build(), NL3D::CMeshMRMSkinnedGeom::compileRunTime(), NL3D::CMeshMRMSkinnedGeom::computeBonesId(), NL3D::CMeshMRMSkinnedGeom::getSkinWeights(), NL3D::CMeshMRMSkinnedGeom::getVertexBuffer(), and NL3D::CMeshMRMSkinnedGeom::updateRawSkinNormal().

00506                 {
00507                         return _PackedBuffer.size();
00508                 }

CPackedVertex* NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::getPackedVertices  )  [inline]
 

Definition at line 496 of file mesh_mrm_skinned.h.

References _PackedBuffer.

00497                 {
00498                         if (_PackedBuffer.empty())
00499                                 return NULL;
00500                         else
00501                                 return &(_PackedBuffer[0]);
00502                 }

const CPackedVertex* NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::getPackedVertices  )  const [inline]
 

Definition at line 487 of file mesh_mrm_skinned.h.

References _PackedBuffer.

Referenced by NL3D::CMeshMRMSkinnedGeom::applyGeomorphWithVBHardPtr(), NL3D::CMeshMRMSkinnedGeom::build(), NL3D::CMeshMRMSkinnedGeom::computeBonesId(), NL3D::CMeshMRMSkinnedGeom::getSkinWeights(), NL3D::CMeshMRMSkinnedGeom::getVertexBuffer(), and NL3D::CMeshMRMSkinnedGeom::updateRawSkinNormal().

00488                 {
00489                         if (_PackedBuffer.empty())
00490                                 return NULL;
00491                         else
00492                                 return &(_PackedBuffer[0]);
00493                 }

void NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::getPos CVector dest,
const CPackedVertex src
const [inline]
 

Definition at line 511 of file mesh_mrm_skinned.h.

References _DecompactScale, and src.

Referenced by NL3D::CMeshMRMSkinnedGeom::computeBonesId(), NL3D::CMeshMRMSkinnedGeom::getVertexBuffer(), and NL3D::CMeshMRMSkinnedGeom::updateRawSkinNormal().

00512                 {
00513                         src.getPos (dest, _DecompactScale);
00514                 }

void NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::serial NLMISC::IStream f  ) 
 

Definition at line 1926 of file mesh_mrm_skinned.cpp.

References _DecompactScale, _PackedBuffer, NLMISC::IStream::serial(), NLMISC::IStream::serialCont(), NLMISC::IStream::serialVersion(), and sint.

Referenced by NL3D::CMeshMRMSkinnedGeom::serial().

01927 {
01928         // Version
01929         sint ver = f.serialVersion(0);
01930 
01931         f.serialCont (_PackedBuffer);
01932         f.serial (_DecompactScale);
01933 }


Field Documentation

float NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::_DecompactScale [private]
 

Decompact position values.

Definition at line 521 of file mesh_mrm_skinned.h.

Referenced by build(), getPos(), and serial().

std::vector<CPackedVertex> NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::_PackedBuffer [private]
 

Definition at line 524 of file mesh_mrm_skinned.h.

Referenced by build(), clear(), contReset(), getNumVertices(), getPackedVertices(), and serial().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:54:30 2004 for NeL by doxygen 1.3.6