68#define DISABLE_CLIPPING 0
98 Verts.Delete_All(
false);
112 if (
Verts.Count() <= 2)
return;
116 int iprev =
Verts.Count() - 1;
117 bool cur_point_in_front;
118 bool prev_point_in_front;
127 prev_point_in_front =
true;
130 for (
int j=0; j<
Verts.Count(); j++) {
134 cur_point_in_front =
true;
137 if (prev_point_in_front) {
139 if (cur_point_in_front) {
158 if (cur_point_in_front) {
172 prev_point_in_front = cur_point_in_front;
174 i = (i+1)%(
Verts.Count());
264 for (i=0; i<
Decals.Count(); i++) {
270 for (i=0; i<
Polys.Count(); i++) {
274 for (i=0; i<
Verts.Count(); i++) {
311 for (
int i=0; i<
Verts.Count(); i++) {
340 for (
int i=0; i <
Polys.Count(); i++)
342 indices[i*3 + 0] = (
unsigned short)
Polys[i].
I;
343 indices[i*3 + 1] = (
unsigned short)
Polys[i].J;
344 indices[i*3 + 2] = (
unsigned short)
Polys[i].K;
351 int cur_poly_index = 0;
352 int next_poly_index = 0;
354 while (next_poly_index <
Polys.Count()) {
360 (next_poly_index - cur_poly_index),
362 1 +
Polys[next_poly_index-1].K -
Polys[cur_poly_index].
I);
363 cur_poly_index = next_poly_index;
390 int next_index = start_index;
391 while ( (next_index <
Polys.Count()) &&
425 Vector3 zbias_offset(0.0f,0.0f,0.0f);
428 const float ZBIAS_DISTANCE = 0.01f;
431 Parent->Get_Transform().Get_Orthogonal_Inverse(invtm);
433 zbias_offset *= ZBIAS_DISTANCE;
445 if (apt.
Count() == 0) {
483 planes[0].
Set(-direction,localbox.
Center + extent);
484 planes[1].
Set(direction,localbox.
Center - extent);
489 planes[2].
Set(-direction,localbox.
Center + extent);
490 planes[3].
Set(direction,localbox.
Center - extent);
495 bool added_polys =
false;
498 for (i=0; i<apt.
Count(); i++) {
512 const TriIndex & poly = src_polys[apt[i]];
513 for (j=0; j<3; j++) {
514 _DecalPoly0.Add_Vertex(src_verts[poly[j]] + zbias_offset,src_vnorms[poly[j]]);
520 _DecalPoly0.Clip(planes[0],_DecalPoly1);
521 _DecalPoly1.Clip(planes[1],_DecalPoly0);
522 _DecalPoly0.Clip(planes[2],_DecalPoly1);
523 _DecalPoly1.Clip(planes[3],_DecalPoly0);
528 if (_DecalPoly0.Verts.Count() >= 3) {
533 int first_vert =
Verts.Count();
535 for (j=1; j<_DecalPoly0.Verts.Count()-1; j++) {
546 Polys.Add(
TriIndex(first_vert,first_vert + j,first_vert + j + 1));
554 for (j=0; j<_DecalPoly0.Verts.Count(); j++) {
556 Verts.Add(_DecalPoly0.Verts[j]);
557 _DecalPoly0.VertNorms[j].Normalize();
589 int poly_count =
Polys.Count();
590 int vert_count =
Verts.Count();
591 for (
int poly_idx = 0; poly_idx < poly_count; poly_idx++) {
625 int decal_index = -1;
626 for (
int i = 0;i <
Decals.Count(); i++) {
627 if (
Decals[i].DecalID ==
id) {
633 if (decal_index == -1) {
650 for (
int poly_index = 0; poly_index <
Polys.Count(); poly_index++) {
672 for (
int di=decal_index+1; di<
Decals.Count(); di++) {
676 Decals.Delete(decal_index);
682 int poly_count =
Polys.Count();
683 int vert_count =
Verts.Count();
684 for (
int poly_idx = 0; poly_idx < poly_count; poly_idx++) {
747 for (i=0; i<
Decals.Count(); i++) {
753 for (i=0; i<
Polys.Count(); i++) {
784 WWDEBUG_SAY((
"ERROR: decals applied to a sorted mesh!\n"));
799 Parent->Get_Deformed_Vertices(&(_TempVertexBuffer[0]),&(_TempNormalBuffer[0]));
811 vertex->
x = _TempVertexBuffer[src_i].X;
812 vertex->
y = _TempVertexBuffer[src_i].Y;
813 vertex->
z = _TempVertexBuffer[src_i].Z;
815 vertex->
nx = _TempNormalBuffer[src_i].X;
816 vertex->
ny = _TempNormalBuffer[src_i].Y;
817 vertex->
nz = _TempNormalBuffer[src_i].Z;
838 for (
int i=0; i <
Polys.Count(); i++)
840 indices[i*3 + 0] = (
unsigned short)
Polys[i].
I;
841 indices[i*3 + 1] = (
unsigned short)
Polys[i].J;
842 indices[i*3 + 2] = (
unsigned short)
Polys[i].K;
849 int cur_poly_index = 0;
850 int next_poly_index = 0;
852 while (next_poly_index <
Polys.Count()) {
858 (next_poly_index - cur_poly_index),
860 1 +
Polys[next_poly_index-1].K -
Polys[cur_poly_index].
I);
862 cur_poly_index = next_poly_index;
888 int next_index = start_index;
889 while ( (next_index <
Polys.Count()) &&
926 if (apt.
Count() == 0) {
957 int face_size_hint =
Polys.Count() + apt.
Count();
959 for (i = 0; i < apt.
Count(); i++) {
960 int offset = first_vert + i * 3;
961 Polys.Add(
TriIndex(offset, offset + 1, offset + 2), face_size_hint);
973 for (i = 0; i < apt.
Count(); i++) {
974 int face_index = apt[i];
975 for (
int vi = 0; vi < 3; vi++) {
1008 int poly_count =
Polys.Count();
1010 for (
int poly_idx = 0; poly_idx < poly_count; poly_idx++) {
1042 int decal_index = -1;
1043 for (
int i = 0;i <
Decals.Count(); i++) {
1044 if (
Decals[i].DecalID ==
id) {
1050 if (decal_index == -1) {
1066 for (
int poly_index = 0; poly_index <
Polys.Count(); poly_index++) {
1075 for (
int fi = decal->
FaceStartIndex; fi < decal->FaceCount; fi++) {
1088 for (
int di=decal_index+1; di<
Decals.Count(); di++) {
1092 Decals.Delete(decal_index);
1098 int poly_count =
Polys.Count();
1100 for (
int poly_idx = 0; poly_idx < poly_count; poly_idx++) {
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static const DX8Caps * Get_Current_Caps()
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static void Set_Material(const VertexMaterialClass *material)
static void Set_Shader(const ShaderClass &shader)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
void Add_Mesh(RenderObjClass *mesh)
void Set_Mesh_Transform(const Matrix3D &tm)
DecalSystemClass * Peek_Decal_System(void)
MaterialPassClass * Get_Material(void)
uint32 Get_Decal_ID(void)
float Get_Backface_Threshhold(void)
DecalSystemClass * DecalSystem
virtual ~DecalMeshClass(void)
DecalMeshClass(MeshClass *parent, DecalSystemClass *system)
SimpleDynVecClass< Vector3 > Verts
SimpleDynVecClass< Vector3 > VertNorms
void Clip(const PlaneClass &plane, DecalPolyClass &dest) const
void Add_Vertex(const Vector3 &point, const Vector3 &normal)
unsigned short * Get_Index_Array()
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
ShaderClass Peek_Shader(void) const
VertexMaterialClass * Get_Material(void) const
TextureClass * Get_Texture(int stage=0) const
static const Matrix3D Identity
Vector3 Rotate_Vector(const Vector3 &vect) const
WWINLINE Vector3 Get_Z_Vector() const
WWINLINE Vector3 Get_Y_Vector(void) const
WWINLINE Vector3 Get_Z_Vector(void) const
static WWINLINE void Rotate_Vector(const Matrix3x3 &tm, const Vector3 &in, Vector3 *out)
WWINLINE Vector3 Get_X_Vector(void) const
const Vector3 * Get_Vertex_Normal_Array(void)
int Get_Vertex_Count(void) const
void Compute_Plane(int pidx, PlaneClass *set_plane) const
const TriIndex * Get_Polygon_Array(void)
Vector3 * Get_Vertex_Array(void)
int Get_Flag(FlagsType flag)
bool Compute_Intersection(const Vector3 &p0, const Vector3 &p1, float *set_t) const
bool In_Front(const Vector3 &point) const
void Set(float a, float b, float c, float d)
void Compute_Texture_Coordinate(const Vector3 &point, Vector3 *set_stq)
virtual const Matrix3D & Get_Transform(void) const
WWINLINE void Release_Ref(void) const
virtual ~RigidDecalMeshClass(void)
SimpleDynVecClass< Vector3 > Verts
virtual bool Create_Decal(DecalGeneratorClass *generator, const OBBoxClass &localbox, SimpleDynVecClass< uint32 > &apt, const DynamicVectorClass< Vector3 > *world_vertex_locs=0)
virtual void Render(void)
SimpleDynVecClass< ShaderClass > Shaders
SimpleDynVecClass< VertexMaterialClass * > VertexMaterials
SimpleDynVecClass< TriIndex > Polys
RigidDecalMeshClass(MeshClass *parent, DecalSystemClass *system)
SimpleDynVecClass< DecalStruct > Decals
SimpleDynVecClass< Vector2 > TexCoords
SimpleDynVecClass< Vector3 > VertNorms
virtual bool Delete_Decal(uint32 id)
int Process_Material_Run(int start_index)
SimpleDynVecClass< TextureClass * > Textures
virtual ~SkinDecalMeshClass(void)
SimpleDynVecClass< VertexMaterialClass * > VertexMaterials
SimpleDynVecClass< ShaderClass > Shaders
virtual bool Delete_Decal(uint32 id)
SimpleDynVecClass< uint32 > ParentVertexIndices
SimpleDynVecClass< DecalStruct > Decals
virtual void Render(void)
SimpleDynVecClass< TextureClass * > Textures
virtual bool Create_Decal(DecalGeneratorClass *generator, const OBBoxClass &localbox, SimpleDynVecClass< uint32 > &apt, const DynamicVectorClass< Vector3 > *world_vertex_locs)
SimpleDynVecClass< Vector2 > TexCoords
int Process_Material_Run(int start_index)
SkinDecalMeshClass(MeshClass *parent, DecalSystemClass *system)
SimpleDynVecClass< TriIndex > Polys
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
WWINLINE void Set(float x, float y, float z)
static void Lerp(const Vector3 &a, const Vector3 &b, float alpha, Vector3 *set_result)
static bool Are_Decals_Enabled(void)
const unsigned dynamic_fvf_type
@ BUFFER_TYPE_DYNAMIC_DX8
#define REF_PTR_RELEASE(x)