59 for (
int i=0; i<
Count; i++) {
68 for (
int i=0; i<
Count; i++) {
81 Array[index]->Add_Ref();
103 for (
int i=0; i<
Count; i++) {
112 for (
int i=0;i<
Count;i++) {
125 Array[index]->Add_Ref();
152 return (CRC == that.CRC);
158 return (CRC == that.CRC);
303 Texture[pass][stage]->Add_Ref();
363 for (
int pass = 0; pass <
MAX_PASSES; pass++) {
369 if (alternate_materials.
UVSource[pass][stage] == -1) {
370 if (default_materials.
UVSource[pass][stage] != -1) {
373 int default_uv_source = default_materials.
UVSource[pass][stage];
375 int found_index = -1;
379 if (uvarray->
Get_CRC() ==
UV[i]->Get_CRC()) {
387 if (found_index != -1) {
388 UVSource[pass][stage] = found_index;
427 if (default_materials.
Material[pass]) {
431 WWDEBUG_SAY((
"Unimplemented case: mesh has more than one default vertex material but no alternate vertex materials have been defined.\r\n"));
446 if (
UV[uvarray] !=
NULL)
return false;
488 shaders[pidx] = shader;
528 Texture[pass][stage]->Add_Ref();
581 int uvindex =
UVSource[pass][stage];
582 if (
UV[uvindex]->Num_Refs() > 1) {
584 UV[uvindex]->Release_Ref();
585 UV[uvindex] = unique_uv;
611 if (
UV[i]->Get_CRC() == crc) {
621 if (found ==
false) {
635 memcpy(
UV[new_index]->Get_Array(),uvs,count *
sizeof(
Vector2));
636 UV[new_index]->Update_CRC();
649 bool set_lighting_to_false=
true;
650 for (
int pass=0; pass<
PassCount; pass++) {
673 if ((mtl != prev_mtl) && (mtl !=
NULL)) {
684 Vector3 single_diffuse(0.0f,0.0f,0.0f);
685 Vector3 single_ambient(0.0f,0.0f,0.0f);
686 Vector3 single_emissive(0.0f,0.0f,0.0f);
687 float single_opacity=1.0f;
688 bool single_diffuse_used=
true;
689 bool single_ambient_used=
true;
690 bool single_emissive_used=
true;
691 bool single_opacity_used=
true;
692 bool diffuse_used=
false;
693 bool ambient_used=
false;
694 bool emissive_used=
false;
695 bool opacity_used=
false;
700 float mtl_opacity = 1.0f;
710 if (single_diffuse.
X || single_diffuse.
Y || single_diffuse.
Z) diffuse_used=
true;
711 if (single_ambient.
X || single_ambient.
Y || single_ambient.
Z) ambient_used=
true;
712 if (single_emissive.
X || single_emissive.
Y || single_emissive.
Z) emissive_used=
true;
713 if (single_opacity!=1.0f) opacity_used=
true;
718 if (mtl != prev_mtl) {
726 if (mtl_diffuse.
X!=single_diffuse.
X || mtl_diffuse.
Y!=single_diffuse.
Y || mtl_diffuse.
Z!=single_diffuse.
Z) {
727 single_diffuse_used=
false;
729 if (mtl_ambient.
X!=single_ambient.
X || mtl_ambient.
Y!=single_ambient.
Y || mtl_ambient.
Z!=single_ambient.
Z) {
730 single_ambient_used=
false;
732 if (mtl_emissive.
X!=single_emissive.
X || mtl_emissive.
Y!=single_emissive.
Y || mtl_emissive.
Z!=single_emissive.
Z) {
733 single_emissive_used=
false;
735 if (mtl_opacity!=single_opacity) {
736 single_opacity_used=
false;
739 if (mtl_diffuse.
X || mtl_diffuse.
Y || mtl_diffuse.
Z) diffuse_used=
true;
740 if (mtl_ambient.
X || mtl_ambient.
Y || mtl_ambient.
Z) ambient_used=
true;
741 if (mtl_emissive.
X || mtl_emissive.
Y || mtl_emissive.
Z) emissive_used=
true;
742 if (mtl_opacity!=1.0f) opacity_used=
true;
749 unsigned * diffuse_array =
ColorArray[0]->Get_Array();
750 unsigned * emissive_array =
ColorArray[1]->Get_Array();
755 diffuse.
X *= emissive.
X;
756 diffuse.
Y *= emissive.
Y;
757 diffuse.
Z *= emissive.
Z;
764 unsigned * diffuse_array =
ColorArray[0]->Get_Array();
766 float mtl_opacity = 1.0f;
774 if (mtl != prev_mtl) {
781 if (diffuse_used && !ambient_used && !emissive_used) {
783 diffuse.
X *= mtl_diffuse.
X;
784 diffuse.
Y *= mtl_diffuse.
Y;
785 diffuse.
Z *= mtl_diffuse.
Z;
786 diffuse.
W *= mtl_opacity;
798 if (diffuse_used && ambient_used && !emissive_used) {
800 diffuse.
X *= mtl_diffuse.
X;
801 diffuse.
Y *= mtl_diffuse.
Y;
802 diffuse.
Z *= mtl_diffuse.
Z;
803 diffuse.
W *= mtl_opacity;
812 if (!diffuse_used && ambient_used && !emissive_used) {
814 diffuse.
X *= mtl_ambient.
X;
815 diffuse.
Y *= mtl_ambient.
Y;
816 diffuse.
Z *= mtl_ambient.
Z;
817 diffuse.
W *= mtl_opacity;
826 if (!diffuse_used && !ambient_used && emissive_used) {
828 diffuse.
X *= mtl_emissive.
X;
829 diffuse.
Y *= mtl_emissive.
Y;
830 diffuse.
Z *= mtl_emissive.
Z;
831 diffuse.
W *= mtl_opacity;
841 set_lighting_to_false=
false;
854 bool kill_pass =
false;
876 Material[pass]->Set_Emissive(0,0,0);
877 Material[pass]->Set_Specular(0,0,0);
885 else if (set_lighting_to_false) {
886 Vector3 single_diffuse(0.0f,0.0f,0.0f);
887 Vector3 single_ambient(0.0f,0.0f,0.0f);
888 Vector3 single_emissive(0.0f,0.0f,0.0f);
889 bool diffuse_used=
false;
890 bool ambient_used=
false;
891 bool emissive_used=
false;
904 if (single_diffuse.
X || single_diffuse.
Y || single_diffuse.
Z) diffuse_used=
true;
905 if (single_ambient.
X || single_ambient.
Y || single_ambient.
Z) ambient_used=
true;
906 if (single_emissive.
X || single_emissive.
Y || single_emissive.
Z) emissive_used=
true;
911 if (mtl != prev_mtl) {
918 if (mtl_diffuse.
X || mtl_diffuse.
Y || mtl_diffuse.
Z) diffuse_used=
true;
919 if (mtl_ambient.
X || mtl_ambient.
Y || mtl_ambient.
Z) ambient_used=
true;
920 if (mtl_emissive.
X || mtl_emissive.
Y || mtl_emissive.
Z) emissive_used=
true;
928 if (mtl != prev_mtl) {
931 if (!diffuse_used && !ambient_used && emissive_used) {
961 for (
int pass=0; pass<
PassCount; pass++) {
976 if ((mtl != prev_mtl) && (mtl !=
NULL)) {
unsigned long CRC_Memory(const unsigned char *data, unsigned long length, unsigned long crc)
static bool Is_Initted(void)
static const DX8Caps * Get_Current_Caps()
static Vector4 Convert_Color(unsigned color)
VertexMaterialClass * Peek_Element(int index)
VertexMaterialClass * Get_Element(int index)
void Set_Element(int index, VertexMaterialClass *mat)
MatBufferClass(int count, const char *msg)
TextureClass * Texture[MAX_PASSES][MAX_TEX_STAGES]
VertexMaterialClass * Peek_Material(int vidx, int pass=0) const
friend class MeshModelClass
void Install_UV_Array(int pass, int stage, Vector2 *uvs, int count)
TexBufferClass * TextureArray[MAX_PASSES][MAX_TEX_STAGES]
VertexMaterialClass * Material[MAX_PASSES]
MatBufferClass * Get_Material_Array(int pass, bool create=true)
void Set_Texture(int pidx, TextureClass *tex, int pass=0, int stage=0)
ShareBufferClass< ShaderClass > * ShaderArray[MAX_PASSES]
ShaderClass Shader[MAX_PASSES]
TextureClass * Get_Single_Texture(int pass=0, int stage=0) const
void Reset(int polycount, int vertcount, int passcount)
void Set_Single_Texture(TextureClass *tex, int pass=0, int stage=0)
void Set_Shader(int pidx, ShaderClass shader, int pass=0)
VertexMaterialClass::ColorSourceType DCGSource[MAX_PASSES]
TextureClass * Get_Texture(int pidx, int pass=0, int stage=0) const
void Configure_Material(VertexMaterialClass *mtl, int pass, bool lighting_enabled)
ShaderClass Get_Shader(int pidx, int pass=0) const
static ShaderClass NullShader
TexBufferClass * Get_Texture_Array(int pass, int stage, bool create=true)
ShaderClass * Get_Shader_Array(int pass, bool create=true)
int Get_UV_Array_Count(void)
void Post_Load_Process(bool enable_lighting=true, MeshModelClass *parent=NULL)
UVBufferClass * UV[MAX_UV_ARRAYS]
MeshMatDescClass & operator=(const MeshMatDescClass &that)
void Make_Color_Array_Unique(int index)
void Set_UV_Source(int pass, int stage, int sourceindex)
MatBufferClass * MaterialArray[MAX_PASSES]
VertexMaterialClass * Get_Material(int vidx, int pass=0) const
bool Do_Mappers_Need_Normals(void)
void Set_Material(int vidx, VertexMaterialClass *vmat, int pass=0)
void Init_Alternate(MeshMatDescClass &def_mat_desc, MeshMatDescClass &alternate_desc)
void Make_UV_Array_Unique(int pass, int stage)
void Set_Single_Material(VertexMaterialClass *vmat, int pass=0)
TextureClass * Peek_Texture(int pidx, int pass=0, int stage=0) const
void Set_Single_Shader(ShaderClass shader, int pass=0)
VertexMaterialClass::ColorSourceType DIGSource[MAX_PASSES]
ShareBufferClass< unsigned > * ColorArray[2]
int UVSource[MAX_PASSES][MAX_TEX_STAGES]
ShareBufferClass(int count, const char *msg)
Vector2 * Get_Array(void)
VertexMaterialClass ** Array
TextureClass * Get_Element(int index)
TexBufferClass(int count, const char *msg)
void Set_Element(int index, TextureClass *mat)
TextureClass * Peek_Element(int index)
unsigned int Get_CRC(void)
UVBufferClass(int count, const char *msg)
bool operator==(const UVBufferClass &that)
bool Is_Equal_To(const UVBufferClass &that)
void Set_Lighting(bool lighting)
bool Do_Mappers_Need_Normals(void) const
void Get_Diffuse(Vector3 *set_color) const
void Set_Ambient_Color_Source(ColorSourceType src)
void Get_Emissive(Vector3 *set_color) const
void Get_Ambient(Vector3 *set_color) const
void Set_Emissive_Color_Source(ColorSourceType src)
float Get_Opacity(void) const
void Set_Diffuse_Color_Source(ColorSourceType src)
void Set_UV_Source(int stage, int array_index)
static unsigned Get_NPatches_Level()
#define REF_PTR_RELEASE(x)
#define REF_PTR_SET(dst, src)