diff --git a/src/plugins/Max/Export/BoneDef.cpp b/src/plugins/Max/Export/BoneDef.cpp index d8d31111cc2..4e6e4f9b7ff 100644 --- a/src/plugins/Max/Export/BoneDef.cpp +++ b/src/plugins/Max/Export/BoneDef.cpp @@ -1,46 +1,48 @@ -#include "stdafx.h" #include "plugins/Shared/BoneDef.h" #include "Exporter.h" #include "MeshExpUtility.h" +#include "stdafx.h" -CBoneDef::CBoneDef(INode* pNode) +CBoneDef::CBoneDef(INode* pNode) { - parent = 0; - pBone = pNode; - name = Helper::ConvertSpace(string(pBone->GetName())); + parent = 0; + pBone = pNode; + name = Helper::ConvertSpace(string(pBone->GetName())); - matInit.identity(); - matOffset.identity(); + matInit.identity(); + matOffset.identity(); } LPCSTR CBoneDef::GetParentName() { - INode* node=pBone->GetParentNode(); - if (Helper::IsBone(node,U.m_SkinAllowDummy)) return node->GetName(); - return 0; + INode* node = pBone->GetParentNode(); + if (Helper::IsBone(node, U.m_SkinAllowDummy)) return node->GetName(); + return 0; } BOOL CBoneDef::SetInitTM(IPhysiqueExport* pExport, const Matrix3& matMesh) { - BOOL bErr = false; - R_ASSERT(pBone); - R_ASSERT(Helper::IsBone(pBone,U.m_SkinAllowDummy)); - Matrix3 tmp; - //Log("SetInitTM:",pBone->GetName()); - if(Helper::IsBipedBone(pBone)) { - Helper::SetBipedUniform(pBone, TRUE, TRUE); - bErr = CGINTM(pBone,pExport->GetInitNodeTM(pBone, tmp)); - if (bErr) tmp.IdentityMatrix(); - Helper::SetBipedUniform(pBone, FALSE, FALSE); - } else { - bErr = CGINTM(pBone,pExport->GetInitNodeTM(pBone, tmp)); - if (bErr) tmp.IdentityMatrix(); - } + BOOL bErr = false; + R_ASSERT(pBone); + R_ASSERT(Helper::IsBone(pBone, U.m_SkinAllowDummy)); + Matrix3 tmp; + // Log("SetInitTM:",pBone->GetName()); + if (Helper::IsBipedBone(pBone)) { + Helper::SetBipedUniform(pBone, TRUE, TRUE); + bErr = CGINTM(pBone, pExport->GetInitNodeTM(pBone, tmp)); + if (bErr) tmp.IdentityMatrix(); + Helper::SetBipedUniform(pBone, FALSE, FALSE); + } + else + { + bErr = CGINTM(pBone, pExport->GetInitNodeTM(pBone, tmp)); + if (bErr) tmp.IdentityMatrix(); + } - if (1){//!bErr){ - Helper::ConvertMatrix(tmp,matInit); - matOffset.invert(matInit); - //S matMesh -// pBone->matOffset = matMesh * Inverse(pBone->matInit); - } + if (1) { //! bErr){ + Helper::ConvertMatrix(tmp, matInit); + matOffset.invert(matInit); + // S matMesh + // pBone->matOffset = matMesh * Inverse(pBone->matInit); + } - return 1;//!bErr; + return 1; //! bErr; } diff --git a/src/plugins/Max/Export/EditMeshExportMAX.cpp b/src/plugins/Max/Export/EditMeshExportMAX.cpp index 56fd1ae6932..adb49108539 100644 --- a/src/plugins/Max/Export/EditMeshExportMAX.cpp +++ b/src/plugins/Max/Export/EditMeshExportMAX.cpp @@ -4,262 +4,261 @@ #include "stdafx.h" #pragma hdrstop - - - +#include "Exporter.h" +#include "MeshExpUtility.h" #include "editors/ECore/Editor/EditMesh.h" #include "editors/ECore/Editor/EditObject.h" -#include "MeshExpUtility.h" -#include "Exporter.h" #include "plugins/Shared/GameMaterial.h" //---------------------------------------------------- -void CEditableMesh::FlipFaces(){ - VERIFY(m_Faces); - for(u32 f = 0; fEvalWorldState(0).obj; - if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) { - TriObject *tri = (TriObject *) obj->ConvertToType(0, - Class_ID(TRIOBJ_CLASS_ID, 0)); - // Note that the TriObject should only be deleted - // if the pointer to it is not equal to the object - // pointer that called ConvertToType() - if (obj != tri) deleteIt = TRUE; - return tri; - }else{ - return NULL; - } + deleteIt = FALSE; + Object* obj = node->EvalWorldState(0).obj; + if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) { + TriObject* tri = (TriObject*)obj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0)); + // Note that the TriObject should only be deleted + // if the pointer to it is not equal to the object + // pointer that called ConvertToType() + if (obj != tri) deleteIt = TRUE; + return tri; + } + else + { + return NULL; + } } //---------------------------------------------------------------------------- -bool CEditableMesh::Convert( INode *node ) +bool CEditableMesh::Convert(INode* node) { - // prepares & checks - BOOL bDeleteObj; - bool bResult = true; - TriObject *obj = ExtractTriObject( node, bDeleteObj ); + // prepares & checks + BOOL bDeleteObj; + bool bResult = true; + TriObject* obj = ExtractTriObject(node, bDeleteObj); - if( !obj ){ - ELog.Msg(mtError,"%s -> Can't convert to TriObject", node->GetName() ); - return false; } + if (!obj) { + ELog.Msg(mtError, "%s -> Can't convert to TriObject", node->GetName()); + return false; + } - if( obj->mesh.getNumFaces() <=0 ){ - ELog.Msg(mtError,"%s -> There are no faces ?", node->GetName() ); - if (bDeleteObj) delete (obj); - return false; } + if (obj->mesh.getNumFaces() <= 0) { + ELog.Msg(mtError, "%s -> There are no faces ?", node->GetName()); + if (bDeleteObj) delete (obj); + return false; + } - Mtl *pMtlMain = node->GetMtl(); - DWORD cSubMaterials=0; + Mtl* pMtlMain = node->GetMtl(); + DWORD cSubMaterials = 0; - if (pMtlMain){ - // There is at least one material. We're in case 1) or 2) - cSubMaterials = pMtlMain->NumSubMtls(); - if (cSubMaterials < 1){ - // Count the material itself as a submaterial. - cSubMaterials = 1; - } - } + if (pMtlMain) { + // There is at least one material. We're in case 1) or 2) + cSubMaterials = pMtlMain->NumSubMtls(); + if (cSubMaterials < 1) { + // Count the material itself as a submaterial. + cSubMaterials = 1; + } + } - // build normals - obj->mesh.buildRenderNormals(); + // build normals + obj->mesh.buildRenderNormals(); - // vertices - m_VertCount = obj->mesh.getNumVerts(); - m_Vertices = xr_alloc(m_VertCount); - for (int v_i=0; v_imesh.verts+v_i; - m_Vertices[v_i].set(p->x,p->y,p->z); - } + // vertices + m_VertCount = obj->mesh.getNumVerts(); + m_Vertices = xr_alloc(m_VertCount); + for (int v_i = 0; v_i < m_VertCount; v_i++) + { + Point3* p = obj->mesh.verts + v_i; + m_Vertices[v_i].set(p->x, p->y, p->z); + } - // set smooth group MAX type - m_Flags.set(flSGMask,TRUE); + // set smooth group MAX type + m_Flags.set(flSGMask, TRUE); - // faces - m_FaceCount = obj->mesh.getNumFaces(); - m_Faces = xr_alloc (m_FaceCount); - m_SmoothGroups = xr_alloc (m_FaceCount); + // faces + m_FaceCount = obj->mesh.getNumFaces(); + m_Faces = xr_alloc(m_FaceCount); + m_SmoothGroups = xr_alloc(m_FaceCount); - m_VMRefs.reserve(m_FaceCount*3); - if (0==obj->mesh.mapFaces(1)) - { - bResult = false; - ELog.Msg(mtError,"'%s' hasn't UV mapping!", node->GetName()); - } - if (bResult) - { - CSurface* surf=0; - for (int f_i=0; f_imesh.faces+f_i; - TVFace* tf = obj->mesh.mapFaces(1) + f_i; - if (!tf) - { - bResult = false; - ELog.Msg(mtError,"'%s' hasn't UV mapping!", node->GetName()); - break; - } - m_SmoothGroups[f_i] = vf->getSmGroup(); - for (int k=0; k<3; ++k) - { - m_Faces[f_i].pv[k].pindex = vf->v[k]; - m_VMRefs.push_back(st_VMapPtLst()); - st_VMapPtLst& vm_lst = m_VMRefs.back(); - vm_lst.count = 1; - vm_lst.pts = xr_alloc(vm_lst.count); - for (DWORD vm_i=0; vm_it[k]; - } - m_Faces[f_i].pv[k].vmref = m_VMRefs.size()-1; - if (!bResult) break; - } - if (pMtlMain) - { - int m_id = obj->mesh.getFaceMtlIndex(f_i); - if (cSubMaterials == 1) - { - m_id = 0; - }else - { - // SDK recommends mod'ing the material ID by the valid # of materials, - // as sometimes a material number that's too high is returned. - m_id %= cSubMaterials; - } - surf = m_Parent->CreateSurface(pMtlMain,m_id); - if (!surf) bResult = false; - } - if (!bResult) break; - m_SurfFaces[surf].push_back(f_i); - } - } + m_VMRefs.reserve(m_FaceCount * 3); + if (0 == obj->mesh.mapFaces(1)) { + bResult = false; + ELog.Msg(mtError, "'%s' hasn't UV mapping!", node->GetName()); + } + if (bResult) { + CSurface* surf = 0; + for (int f_i = 0; f_i < m_FaceCount; ++f_i) + { + Face* vf = obj->mesh.faces + f_i; + TVFace* tf = obj->mesh.mapFaces(1) + f_i; + if (!tf) { + bResult = false; + ELog.Msg(mtError, "'%s' hasn't UV mapping!", node->GetName()); + break; + } + m_SmoothGroups[f_i] = vf->getSmGroup(); + for (int k = 0; k < 3; ++k) + { + m_Faces[f_i].pv[k].pindex = vf->v[k]; + m_VMRefs.push_back(st_VMapPtLst()); + st_VMapPtLst& vm_lst = m_VMRefs.back(); + vm_lst.count = 1; + vm_lst.pts = xr_alloc(vm_lst.count); + for (DWORD vm_i = 0; vm_i < vm_lst.count; ++vm_i) + { + vm_lst.pts[vm_i].vmap_index = 0; + vm_lst.pts[vm_i].index = tf->t[k]; + } + m_Faces[f_i].pv[k].vmref = m_VMRefs.size() - 1; + if (!bResult) break; + } + if (pMtlMain) { + int m_id = obj->mesh.getFaceMtlIndex(f_i); + if (cSubMaterials == 1) { + m_id = 0; + } + else + { + // SDK recommends mod'ing the material ID by the valid # of materials, + // as sometimes a material number that's too high is returned. + m_id %= cSubMaterials; + } + surf = m_Parent->CreateSurface(pMtlMain, m_id); + if (!surf) bResult = false; + } + if (!bResult) break; + m_SurfFaces[surf].push_back(f_i); + } + } - // vmaps - if( bResult ){ - int vm_cnt = obj->mesh.getNumTVerts(); - m_VMaps.resize(1); - st_VMap*& VM = m_VMaps.back(); - VM = new st_VMap("Texture",vmtUV,false); - for (int tx_i=0; tx_imesh.tVerts + tx_i; - VM->appendUV(tv->x,1-tv->y); - } - } + // vmaps + if (bResult) { + int vm_cnt = obj->mesh.getNumTVerts(); + m_VMaps.resize(1); + st_VMap*& VM = m_VMaps.back(); + VM = new st_VMap("Texture", vmtUV, false); + for (int tx_i = 0; tx_i < vm_cnt; tx_i++) + { + UVVert* tv = obj->mesh.tVerts + tx_i; + VM->appendUV(tv->x, 1 - tv->y); + } + } - if ((GetVertexCount()<4)||(GetFaceCount()<2)) - { - ELog.Msg(mtError,"Invalid mesh: '%s'. Faces<2 or Verts<4"); - bResult = false; - } + if ((GetVertexCount() < 4) || (GetFaceCount() < 2)) { + ELog.Msg(mtError, "Invalid mesh: '%s'. Faces<2 or Verts<4"); + bResult = false; + } - if (bResult ){ - ELog.Msg(mtInformation,"Model '%s' contains: %d points, %d faces", - node->GetName(), m_VertCount, m_FaceCount); - } + if (bResult) { + ELog.Msg(mtInformation, "Model '%s' contains: %d points, %d faces", node->GetName(), m_VertCount, m_FaceCount); + } - if (bResult) - { - RecomputeBBox (); - OptimizeMesh (false); - RebuildVMaps (); - ELog.Msg(mtInformation,"Model '%s' converted: %d points, %d faces", - node->GetName(), GetVertexCount(), GetFaceCount()); - } + if (bResult) { + RecomputeBBox(); + OptimizeMesh(false); + RebuildVMaps(); + ELog.Msg(mtInformation, "Model '%s' converted: %d points, %d faces", node->GetName(), GetVertexCount(), + GetFaceCount()); + } - if (bDeleteObj) delete (obj); - return bResult; + if (bDeleteObj) delete (obj); + return bResult; } //---------------------------------------------------------------------------- bool CEditableMesh::Convert(CExporter* E) { - bool bResult = true; + bool bResult = true; - m_Name = E->m_MeshNode->GetName(); + m_Name = E->m_MeshNode->GetName(); - // maps - // Weight maps - m_VMaps.resize(E->m_Bones.size()+1); - for (DWORD b_i=0; b_im_Bones.size(); b_i++) - m_VMaps[b_i] = new st_VMap(E->m_Bones[b_i]->name.c_str(),vmtWeight,false);; - // UV map - int VM_UV_idx = m_VMaps.size()-1; - st_VMap*& VM_UV = m_VMaps[VM_UV_idx]; - VM_UV = new st_VMap("texture",vmtUV,false); + // maps + // Weight maps + m_VMaps.resize(E->m_Bones.size() + 1); + for (DWORD b_i = 0; b_i < E->m_Bones.size(); b_i++) + m_VMaps[b_i] = new st_VMap(E->m_Bones[b_i]->name.c_str(), vmtWeight, false); + ; + // UV map + int VM_UV_idx = m_VMaps.size() - 1; + st_VMap*& VM_UV = m_VMaps[VM_UV_idx]; + VM_UV = new st_VMap("texture", vmtUV, false); - // points - { - m_VertCount = E->m_ExpVertices.size(); - m_Vertices = xr_alloc(m_VertCount); - Fvector* p_it = m_Vertices; + // points + { + m_VertCount = E->m_ExpVertices.size(); + m_Vertices = xr_alloc(m_VertCount); + Fvector* p_it = m_Vertices; - for (ExpVertIt ev_it=E->m_ExpVertices.begin(); ev_it!=E->m_ExpVertices.end(); ev_it++,p_it++){ - p_it->set ((*ev_it)->P); - VM_UV->appendUV ((*ev_it)->uv.x,(*ev_it)->uv.y); - } - } - // faces - { - // set smooth group MAX type - m_Flags.set(flSGMask,TRUE); - // reserve space for faces and references - m_FaceCount = E->m_ExpFaces.size(); - m_Faces = xr_alloc (m_FaceCount); - m_SmoothGroups = xr_alloc (m_FaceCount); - m_VMRefs.resize (m_VertCount); + for (ExpVertIt ev_it = E->m_ExpVertices.begin(); ev_it != E->m_ExpVertices.end(); ev_it++, p_it++) + { + p_it->set((*ev_it)->P); + VM_UV->appendUV((*ev_it)->uv.x, (*ev_it)->uv.y); + } + } + // faces + { + // set smooth group MAX type + m_Flags.set(flSGMask, TRUE); + // reserve space for faces and references + m_FaceCount = E->m_ExpFaces.size(); + m_Faces = xr_alloc(m_FaceCount); + m_SmoothGroups = xr_alloc(m_FaceCount); + m_VMRefs.resize(m_VertCount); - int f_id=0; - for (ExpFaceIt ef_it=E->m_ExpFaces.begin(); ef_it!=E->m_ExpFaces.end(); ef_it++,f_id++){ - // FACES - m_SmoothGroups[f_id] = (*ef_it)->sm_group; - st_Face& F = m_Faces[f_id]; - for (int k=0; k<3; ++k) - { - int v_idx = (*ef_it)->v[k]; - st_FaceVert& vt = F.pv[k]; - st_VERT* V = E->m_ExpVertices[v_idx]; - vt.pindex = v_idx; - st_VMapPtLst& vm_lst= m_VMRefs[vt.pindex]; - vm_lst.count = V->data.size()+1; - vm_lst.pts = xr_alloc(vm_lst.count); - vm_lst.pts[0].vmap_index= VM_UV_idx; - vm_lst.pts[0].index = vt.pindex; - for (VDIt vd_it=V->data.begin(); vd_it!=V->data.end(); vd_it++){ - DWORD idx = vd_it-V->data.begin()+1; - st_VMap* vm = m_VMaps[vd_it->bone]; - vm->appendW (vd_it->weight); - vm_lst.pts[idx].vmap_index = vd_it->bone; - vm_lst.pts[idx].index = vm->size()-1; - } - vt.vmref = vt.pindex; - } - CSurface* surf = m_Parent->CreateSurface(E->m_MtlMain,(*ef_it)->m_id); - if (!surf){ - bResult = FALSE; - break; - } - m_SurfFaces[surf].push_back(f_id); - } - } - if ((GetVertexCount()<4)||(GetFaceCount()<2)) - { - Log("!Invalid mesh: '%s'. Faces<2 or Verts<4",*Name()); - bResult = false; - } - if (bResult) - { - RecomputeBBox (); - OptimizeMesh (true);//false); - RebuildVMaps (); - } - return bResult; + int f_id = 0; + for (ExpFaceIt ef_it = E->m_ExpFaces.begin(); ef_it != E->m_ExpFaces.end(); ef_it++, f_id++) + { + // FACES + m_SmoothGroups[f_id] = (*ef_it)->sm_group; + st_Face& F = m_Faces[f_id]; + for (int k = 0; k < 3; ++k) + { + int v_idx = (*ef_it)->v[k]; + st_FaceVert& vt = F.pv[k]; + st_VERT* V = E->m_ExpVertices[v_idx]; + vt.pindex = v_idx; + st_VMapPtLst& vm_lst = m_VMRefs[vt.pindex]; + vm_lst.count = V->data.size() + 1; + vm_lst.pts = xr_alloc(vm_lst.count); + vm_lst.pts[0].vmap_index = VM_UV_idx; + vm_lst.pts[0].index = vt.pindex; + for (VDIt vd_it = V->data.begin(); vd_it != V->data.end(); vd_it++) + { + DWORD idx = vd_it - V->data.begin() + 1; + st_VMap* vm = m_VMaps[vd_it->bone]; + vm->appendW(vd_it->weight); + vm_lst.pts[idx].vmap_index = vd_it->bone; + vm_lst.pts[idx].index = vm->size() - 1; + } + vt.vmref = vt.pindex; + } + CSurface* surf = m_Parent->CreateSurface(E->m_MtlMain, (*ef_it)->m_id); + if (!surf) { + bResult = FALSE; + break; + } + m_SurfFaces[surf].push_back(f_id); + } + } + if ((GetVertexCount() < 4) || (GetFaceCount() < 2)) { + Log("!Invalid mesh: '%s'. Faces<2 or Verts<4", *Name()); + bResult = false; + } + if (bResult) { + RecomputeBBox(); + OptimizeMesh(true); // false); + RebuildVMaps(); + } + return bResult; } diff --git a/src/plugins/Max/Export/EditObjectExportLWO.cpp b/src/plugins/Max/Export/EditObjectExportLWO.cpp index f155a0c1025..c40dbcbfa2e 100644 --- a/src/plugins/Max/Export/EditObjectExportLWO.cpp +++ b/src/plugins/Max/Export/EditObjectExportLWO.cpp @@ -1,92 +1,106 @@ #include "stdafx.h" #pragma hdrstop -#include "editors/ECore/Editor/EditObject.h" -#include "editors/ECore/Editor/EditMesh.h" #include "FS2.h" +#include "editors/ECore/Editor/EditMesh.h" +#include "editors/ECore/Editor/EditObject.h" -int FindLPCSTR(LPCSTRVec& vec, LPCSTR key){ - for (LPCSTRIt it=vec.begin(); it!=vec.end(); it++) - if (0==xr_strcmp(*it,key)) return it-vec.begin(); - return -1; +int FindLPCSTR(LPCSTRVec& vec, LPCSTR key) +{ + for (LPCSTRIt it = vec.begin(); it != vec.end(); it++) + if (0 == xr_strcmp(*it, key)) return it - vec.begin(); + return -1; } bool CEditableObject::ExportLWO(LPCSTR fname) { - CLWMemoryStream* F = new CLWMemoryStream(); + CLWMemoryStream* F = new CLWMemoryStream(); - LPCSTRVec images; + LPCSTRVec images; - F->begin_save(); - // tags - F->open_chunk(ID_TAGS); - for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ - CSurface* S=*s_it; - F->w_stringZ(S->_Name()); - S->tag = s_it-m_Surfaces.begin(); - if (FindLPCSTR(images,S->_Texture())<0) images.push_back(S->_Texture()); - } - F->close_chunk(); - // images - for (LPCSTRIt im_it=images.begin(); im_it!=images.end(); im_it++){ - F->open_chunk(ID_CLIP); - F->w_u32(im_it-images.begin()); - F->open_subchunk(ID_STIL); - F->w_stringZ(*im_it); - F->close_subchunk(); - F->close_chunk (); - } - // surfaces - for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ - CSurface* S=*s_it; - int im_idx=FindLPCSTR(images,S->_Texture()); - R_ASSERT(im_idx>=0); - LPCSTR vm_name=S->_VMap(); - F->Wsurface(S->_Name(),S->m_Flags.is(CSurface::sf2Sided),(u16)im_idx,(vm_name&&vm_name[0])?vm_name:"Texture",S->_ShaderName(),S->_ShaderXRLCName()); - } - // meshes/layers - for (EditMeshIt mesh_it=FirstMesh(); mesh_it!=LastMesh(); mesh_it++){ - CEditableMesh* MESH=*mesh_it; - F->w_layer(u16(mesh_it-FirstMesh()),MESH->Name().c_str()); - // bounding box - F->open_chunk(ID_BBOX); - F->w_vector(MESH->m_Box.min); - F->w_vector(MESH->m_Box.max); - F->close_chunk(); - // points - F->open_chunk(ID_PNTS); - for (u32 point_id=0; point_idGetVCount(); point_id++) - F->w_vector(MESH->GetVertices()[point_id]); - F->close_chunk(); - // polygons - F->open_chunk(ID_POLS); - F->w_u32(ID_FACE); - for (u32 f_id=0; f_idGetFCount(); f_id++) - F->w_face3(MESH->GetFaces()[f_id].pv[0].pindex,MESH->GetFaces()[f_id].pv[1].pindex,MESH->GetFaces()[f_id].pv[2].pindex); - F->close_chunk(); - // surf<->face - F->open_chunk(ID_PTAG); - F->w_u32(ID_SURF); - for (SurfFacesPairIt sf_it=MESH->m_SurfFaces.begin(); sf_it!=MESH->m_SurfFaces.end(); sf_it++){ - IntVec& lst = sf_it->second; - for (IntIt i_it=lst.begin(); i_it!=lst.end(); i_it++){ - F->w_vx (*i_it); - F->w_u16(WORD(sf_it->first->tag)); - } - } - F->close_chunk(); - // vmap&vmad - for (VMapIt vm_it=MESH->m_VMaps.begin(); vm_it!=MESH->m_VMaps.end(); vm_it++){ - st_VMap* vmap = *vm_it; - F->begin_vmap(vmap->polymap, (vmap->type==vmtUV)?ID_TXUV:ID_WGHT, vmap->dim, vmap->name.c_str()); - if (vmap->polymap) for (int k=0; ksize(); k++) F->w_vmad(vmap->vindices[k],vmap->pindices[k],vmap->dim,vmap->getVMdata(k)); - else for (int k=0; ksize(); k++) F->w_vmap(vmap->vindices[k],vmap->dim,vmap->getVMdata(k)); - F->end_vmap(); - } - } - F->end_save(fname); + F->begin_save(); + // tags + F->open_chunk(ID_TAGS); + for (SurfaceIt s_it = m_Surfaces.begin(); s_it != m_Surfaces.end(); s_it++) + { + CSurface* S = *s_it; + F->w_stringZ(S->_Name()); + S->tag = s_it - m_Surfaces.begin(); + if (FindLPCSTR(images, S->_Texture()) < 0) images.push_back(S->_Texture()); + } + F->close_chunk(); + // images + for (LPCSTRIt im_it = images.begin(); im_it != images.end(); im_it++) + { + F->open_chunk(ID_CLIP); + F->w_u32(im_it - images.begin()); + F->open_subchunk(ID_STIL); + F->w_stringZ(*im_it); + F->close_subchunk(); + F->close_chunk(); + } + // surfaces + for (SurfaceIt s_it = m_Surfaces.begin(); s_it != m_Surfaces.end(); s_it++) + { + CSurface* S = *s_it; + int im_idx = FindLPCSTR(images, S->_Texture()); + R_ASSERT(im_idx >= 0); + LPCSTR vm_name = S->_VMap(); + F->Wsurface(S->_Name(), S->m_Flags.is(CSurface::sf2Sided), (u16)im_idx, + (vm_name && vm_name[0]) ? vm_name : "Texture", S->_ShaderName(), S->_ShaderXRLCName()); + } + // meshes/layers + for (EditMeshIt mesh_it = FirstMesh(); mesh_it != LastMesh(); mesh_it++) + { + CEditableMesh* MESH = *mesh_it; + F->w_layer(u16(mesh_it - FirstMesh()), MESH->Name().c_str()); + // bounding box + F->open_chunk(ID_BBOX); + F->w_vector(MESH->m_Box.min); + F->w_vector(MESH->m_Box.max); + F->close_chunk(); + // points + F->open_chunk(ID_PNTS); + for (u32 point_id = 0; point_id < MESH->GetVCount(); point_id++) + F->w_vector(MESH->GetVertices()[point_id]); + F->close_chunk(); + // polygons + F->open_chunk(ID_POLS); + F->w_u32(ID_FACE); + for (u32 f_id = 0; f_id < MESH->GetFCount(); f_id++) + F->w_face3(MESH->GetFaces()[f_id].pv[0].pindex, MESH->GetFaces()[f_id].pv[1].pindex, + MESH->GetFaces()[f_id].pv[2].pindex); + F->close_chunk(); + // surf<->face + F->open_chunk(ID_PTAG); + F->w_u32(ID_SURF); + for (SurfFacesPairIt sf_it = MESH->m_SurfFaces.begin(); sf_it != MESH->m_SurfFaces.end(); sf_it++) + { + IntVec& lst = sf_it->second; + for (IntIt i_it = lst.begin(); i_it != lst.end(); i_it++) + { + F->w_vx(*i_it); + F->w_u16(WORD(sf_it->first->tag)); + } + } + F->close_chunk(); + // vmap&vmad + for (VMapIt vm_it = MESH->m_VMaps.begin(); vm_it != MESH->m_VMaps.end(); vm_it++) + { + st_VMap* vmap = *vm_it; + F->begin_vmap(vmap->polymap, (vmap->type == vmtUV) ? ID_TXUV : ID_WGHT, vmap->dim, vmap->name.c_str()); + if (vmap->polymap) + for (int k = 0; k < vmap->size(); k++) + F->w_vmad(vmap->vindices[k], vmap->pindices[k], vmap->dim, vmap->getVMdata(k)); + else + for (int k = 0; k < vmap->size(); k++) + F->w_vmap(vmap->vindices[k], vmap->dim, vmap->getVMdata(k)); + F->end_vmap(); + } + } + F->end_save(fname); - xr_delete(F); + xr_delete(F); - return true; + return true; } diff --git a/src/plugins/Max/Export/EditObjectExportMAX.cpp b/src/plugins/Max/Export/EditObjectExportMAX.cpp index 63934476f13..443a8a72d14 100644 --- a/src/plugins/Max/Export/EditObjectExportMAX.cpp +++ b/src/plugins/Max/Export/EditObjectExportMAX.cpp @@ -5,184 +5,211 @@ #include "stdafx.h" #pragma hdrstop -#include "editors/ECore/Editor/EditObject.h" -#include "editors/ECore/Editor/EditMesh.h" -#include "xrCore/Animation/Bone.hpp" #include "Exporter.h" +#include "editors/ECore/Editor/EditMesh.h" +#include "editors/ECore/Editor/EditObject.h" #include "plugins/Shared/GameMaterial.h" +#include "xrCore/Animation/Bone.hpp" //---------------------------------------------------------------------------- // Material parsing //---------------------------------------------------------------------------- -BOOL CEditableObject::ExtractTexName(Texmap *src, LPSTR dest) +BOOL CEditableObject::ExtractTexName(Texmap* src, LPSTR dest) { - if( src->ClassID() != Class_ID(BMTEX_CLASS_ID,0) ) - return FALSE; - BitmapTex *bmap = (BitmapTex*)src; - _splitpath( bmap->GetMapName(), 0, 0, dest, 0 ); + if (src->ClassID() != Class_ID(BMTEX_CLASS_ID, 0)) return FALSE; + BitmapTex* bmap = (BitmapTex*)src; + _splitpath(bmap->GetMapName(), 0, 0, dest, 0); EFS.AppendFolderToName(dest, 1024, 1, TRUE); - return TRUE; + return TRUE; } //---------------------------------------------------------------------------- BOOL CEditableObject::ParseStdMaterial(StdMat* src, CSurface* dest) { - R_ASSERT(src); - R_ASSERT((src->ClassID()==Class_ID(DMTL_CLASS_ID,0))||(src->ClassID()==XRAYMTL_CLASS_ID)); - Msg("- Processing material '%s' ...", src->GetName() ); - // ------- texture (if exist) - string1024 tname; - if( src->MapEnabled( ID_AM ) ){ - if( src->GetSubTexmap( ID_AM ) ){ - if (!ExtractTexName( src->GetSubTexmap( ID_AM ), tname )) return FALSE; - dest->SetTexture(tname); - }else{ - return FALSE; - } - }else if( src->MapEnabled( ID_DI ) ){ - if( src->GetSubTexmap( ID_DI ) ){ - if (!ExtractTexName( src->GetSubTexmap( ID_DI ), tname )) return FALSE; - dest->SetTexture(tname); - }else{ - return FALSE; - } - }else{ - return FALSE; - } - dest->m_Flags.set(CSurface::sf2Sided,!!src->GetTwoSided()); - if (src->GetTwoSided()) ELog.Msg(mtInformation," - material 2-sided"); - dest->SetName(GenerateSurfaceName(src->GetName())); - dest->SetFVF(D3DFVF_XYZ|D3DFVF_NORMAL|(1<SetVMap("Texture"); - dest->SetShader("default"); - dest->SetShaderXRLC("default"); - return TRUE; + R_ASSERT(src); + R_ASSERT((src->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) || (src->ClassID() == XRAYMTL_CLASS_ID)); + Msg("- Processing material '%s' ...", src->GetName()); + // ------- texture (if exist) + string1024 tname; + if (src->MapEnabled(ID_AM)) { + if (src->GetSubTexmap(ID_AM)) { + if (!ExtractTexName(src->GetSubTexmap(ID_AM), tname)) return FALSE; + dest->SetTexture(tname); + } + else + { + return FALSE; + } + } + else if (src->MapEnabled(ID_DI)) + { + if (src->GetSubTexmap(ID_DI)) { + if (!ExtractTexName(src->GetSubTexmap(ID_DI), tname)) return FALSE; + dest->SetTexture(tname); + } + else + { + return FALSE; + } + } + else + { + return FALSE; + } + dest->m_Flags.set(CSurface::sf2Sided, !!src->GetTwoSided()); + if (src->GetTwoSided()) ELog.Msg(mtInformation, " - material 2-sided"); + dest->SetName(GenerateSurfaceName(src->GetName())); + dest->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | (1 << D3DFVF_TEXCOUNT_SHIFT)); + dest->SetVMap("Texture"); + dest->SetShader("default"); + dest->SetShaderXRLC("default"); + return TRUE; } BOOL CEditableObject::ParseMultiMaterial(MultiMtl* src, u32 mid, CSurface* dest) { - R_ASSERT(src); - R_ASSERT(src->ClassID()==Class_ID(MULTI_CLASS_ID,0)); - Mtl* M = src->GetSubMtl(mid); - if (M){ - if (M->ClassID()==Class_ID(DMTL_CLASS_ID,0)){ - StdMat *smtl = (StdMat*)src->GetSubMtl(mid); - if (!ParseStdMaterial(smtl,dest)){ - ELog.Msg(mtError,"'%s' -> bad submaterial",src->GetName()); - return FALSE; - } - return TRUE; - }else if (M->ClassID()==XRAYMTL_CLASS_ID){ - XRayMtl *smtl = (XRayMtl*)src->GetSubMtl(mid); - if (!ParseXRayMaterial(smtl,mid,dest)){ - ELog.Msg(mtError,"'%s' -> bad submaterial",src->GetName()); - return FALSE; - } - } - return TRUE; - }else{ - ELog.Msg(mtError,"'%s' -> can't extract multi-material items.",src->GetName()); - return FALSE; - } + R_ASSERT(src); + R_ASSERT(src->ClassID() == Class_ID(MULTI_CLASS_ID, 0)); + Mtl* M = src->GetSubMtl(mid); + if (M) { + if (M->ClassID() == Class_ID(DMTL_CLASS_ID, 0)) { + StdMat* smtl = (StdMat*)src->GetSubMtl(mid); + if (!ParseStdMaterial(smtl, dest)) { + ELog.Msg(mtError, "'%s' -> bad submaterial", src->GetName()); + return FALSE; + } + return TRUE; + } + else if (M->ClassID() == XRAYMTL_CLASS_ID) + { + XRayMtl* smtl = (XRayMtl*)src->GetSubMtl(mid); + if (!ParseXRayMaterial(smtl, mid, dest)) { + ELog.Msg(mtError, "'%s' -> bad submaterial", src->GetName()); + return FALSE; + } + } + return TRUE; + } + else + { + ELog.Msg(mtError, "'%s' -> can't extract multi-material items.", src->GetName()); + return FALSE; + } } BOOL CEditableObject::ParseXRayMaterial(XRayMtl* src, u32 mid, CSurface* dest) { - R_ASSERT(src); - R_ASSERT(src->ClassID()==XRAYMTL_CLASS_ID); - if (!ParseStdMaterial((StdMat*)src,dest)){ - ELog.Msg(mtError,"'%s' -> bad material",src->GetName()); - return FALSE; - } - LPCSTR e_shader = src->GetEShaderName(); - LPCSTR c_shader = src->GetCShaderName(); - LPCSTR g_mtl = src->GetGameMtlName(); - dest->SetShader (e_shader?e_shader:"default"); - dest->SetShaderXRLC (c_shader?c_shader:"default"); - dest->SetGameMtl (g_mtl?g_mtl:"default"); - if (e_shader&&c_shader&&g_mtl){ - ELog.Msg(mtInformation," -Found S.T.A.L.K.E.R. shaders [E:'%s', C:'%s', M:'%s']", dest->_ShaderName(), dest->_ShaderXRLCName(), dest->_GameMtlName() ); - }else{ - if (!e_shader) ELog.Msg(mtError," *Empty engine shader! Set 'DEFAULT'."); - if (!c_shader) ELog.Msg(mtError," *Empty compiler shader! Set 'DEFAULT'."); - if (!g_mtl) ELog.Msg(mtError," *Empty game material! Set 'DEFAULT'."); - } - return TRUE; + R_ASSERT(src); + R_ASSERT(src->ClassID() == XRAYMTL_CLASS_ID); + if (!ParseStdMaterial((StdMat*)src, dest)) { + ELog.Msg(mtError, "'%s' -> bad material", src->GetName()); + return FALSE; + } + LPCSTR e_shader = src->GetEShaderName(); + LPCSTR c_shader = src->GetCShaderName(); + LPCSTR g_mtl = src->GetGameMtlName(); + dest->SetShader(e_shader ? e_shader : "default"); + dest->SetShaderXRLC(c_shader ? c_shader : "default"); + dest->SetGameMtl(g_mtl ? g_mtl : "default"); + if (e_shader && c_shader && g_mtl) { + ELog.Msg(mtInformation, " -Found S.T.A.L.K.E.R. shaders [E:'%s', C:'%s', M:'%s']", dest->_ShaderName(), + dest->_ShaderXRLCName(), dest->_GameMtlName()); + } + else + { + if (!e_shader) ELog.Msg(mtError, " *Empty engine shader! Set 'DEFAULT'."); + if (!c_shader) ELog.Msg(mtError, " *Empty compiler shader! Set 'DEFAULT'."); + if (!g_mtl) ELog.Msg(mtError, " *Empty game material! Set 'DEFAULT'."); + } + return TRUE; } CSurface* CEditableObject::CreateSurface(Mtl* mtl, u32 mid) { - if (!mtl){ ELog.Msg(mtError,"Empty material..."); return 0; } - for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) - if (((*s_it)->mid==mid)&&((*s_it)->mtl==mtl)) return *s_it; - CSurface* S = new CSurface(); - S->mid = mid; - S->mtl = mtl; - Class_ID cls_id = mtl->ClassID(); - BOOL bRes = FALSE; - if (cls_id==Class_ID(MULTI_CLASS_ID,0)) bRes=ParseMultiMaterial ((MultiMtl*)mtl,mid,S); - else if (cls_id==Class_ID(DMTL_CLASS_ID,0)) bRes=ParseStdMaterial ((StdMat*)mtl,S); - else if (cls_id==XRAYMTL_CLASS_ID) bRes=ParseXRayMaterial ((XRayMtl*)mtl,mid,S); - else{ - ELog.Msg (mtError,"'%s' -> unsuported material class...",mtl->GetName()); - xr_delete (S); - return 0; - } - if (!bRes){ - ELog.Msg (mtError,"'%s' -> can't parse material",mtl->GetName()); - return 0; - } - m_Surfaces.push_back(S); - return S; + if (!mtl) { + ELog.Msg(mtError, "Empty material..."); + return 0; + } + for (SurfaceIt s_it = m_Surfaces.begin(); s_it != m_Surfaces.end(); s_it++) + if (((*s_it)->mid == mid) && ((*s_it)->mtl == mtl)) return *s_it; + CSurface* S = new CSurface(); + S->mid = mid; + S->mtl = mtl; + Class_ID cls_id = mtl->ClassID(); + BOOL bRes = FALSE; + if (cls_id == Class_ID(MULTI_CLASS_ID, 0)) + bRes = ParseMultiMaterial((MultiMtl*)mtl, mid, S); + else if (cls_id == Class_ID(DMTL_CLASS_ID, 0)) + bRes = ParseStdMaterial((StdMat*)mtl, S); + else if (cls_id == XRAYMTL_CLASS_ID) + bRes = ParseXRayMaterial((XRayMtl*)mtl, mid, S); + else + { + ELog.Msg(mtError, "'%s' -> unsuported material class...", mtl->GetName()); + xr_delete(S); + return 0; + } + if (!bRes) { + ELog.Msg(mtError, "'%s' -> can't parse material", mtl->GetName()); + return 0; + } + m_Surfaces.push_back(S); + return S; } //---------------------------------------------------------------------------- // Skeleton functions //---------------------------------------------------------------------------- bool CEditableObject::ImportMAXSkeleton(CExporter* E) { - bool bResult = true; - CEditableMesh* MESH = new CEditableMesh(this); - m_Meshes.push_back(MESH); - // import mesh - if (!MESH->Convert(E)) return FALSE; - // BONES - m_Bones.reserve(E->m_Bones.size()); - for (int B=0; B!=E->m_Bones.size(); B++){ - m_Bones.push_back(new CBone()); - CBone* BONE = m_Bones.back(); - CBoneDef* bone = E->m_Bones[B]; - CBoneDef* parent_bone = bone->parent; + bool bResult = true; + CEditableMesh* MESH = new CEditableMesh(this); + m_Meshes.push_back(MESH); + // import mesh + if (!MESH->Convert(E)) return FALSE; + // BONES + m_Bones.reserve(E->m_Bones.size()); + for (int B = 0; B != E->m_Bones.size(); B++) + { + m_Bones.push_back(new CBone()); + CBone* BONE = m_Bones.back(); + CBoneDef* bone = E->m_Bones[B]; + CBoneDef* parent_bone = bone->parent; - Fvector offset,rotate; - float length= 0.1f; + Fvector offset, rotate; + float length = 0.1f; - Fmatrix m; - if (parent_bone) m.mul(parent_bone->matOffset,bone->matInit); - else m.set(bone->matInit); + Fmatrix m; + if (parent_bone) + m.mul(parent_bone->matOffset, bone->matInit); + else + m.set(bone->matInit); - m.getXYZi (rotate); - offset.set (m.c); + m.getXYZi(rotate); + offset.set(m.c); - BONE->SetWMap (bone->name.c_str()); - BONE->SetName (bone->name.c_str()); - BONE->SetParentName (Helper::ConvertSpace(string(bone->pBone->GetParentNode()->GetName())).c_str()); - BONE->SetRestParams (length,offset,rotate); - } + BONE->SetWMap(bone->name.c_str()); + BONE->SetName(bone->name.c_str()); + BONE->SetParentName(Helper::ConvertSpace(string(bone->pBone->GetParentNode()->GetName())).c_str()); + BONE->SetRestParams(length, offset, rotate); + } - // DEFAULT BONE PART - m_BoneParts.push_back(SBonePart()); - SBonePart& BP = m_BoneParts.back(); - BP.alias = "default"; - for (int b_i=0; b_i<(int)m_Bones.size(); b_i++) - BP.bones.push_back(Bones()[b_i]->Name()); + // DEFAULT BONE PART + m_BoneParts.push_back(SBonePart()); + SBonePart& BP = m_BoneParts.back(); + BP.alias = "default"; + for (int b_i = 0; b_i < (int)m_Bones.size(); b_i++) + BP.bones.push_back(Bones()[b_i]->Name()); - m_objectFlags.set(CEditableObject::eoDynamic,TRUE); + m_objectFlags.set(CEditableObject::eoDynamic, TRUE); - if ((0==GetVertexCount())||(0==GetFaceCount())){ - bResult = false; - }else{ - ELog.Msg(mtInformation,"Model '%s' contains: %d points, %d faces, %d bones", E->m_MeshNode->GetName(), GetVertexCount(), GetFaceCount(), Bones().size()); - } + if ((0 == GetVertexCount()) || (0 == GetFaceCount())) { + bResult = false; + } + else + { + ELog.Msg(mtInformation, "Model '%s' contains: %d points, %d faces, %d bones", E->m_MeshNode->GetName(), + GetVertexCount(), GetFaceCount(), Bones().size()); + } - return bResult; + return bResult; } diff --git a/src/plugins/Max/Export/ExportKeys.cpp b/src/plugins/Max/Export/ExportKeys.cpp index 9282d5ed94a..0658d14bffa 100644 --- a/src/plugins/Max/Export/ExportKeys.cpp +++ b/src/plugins/Max/Export/ExportKeys.cpp @@ -4,7 +4,7 @@ #include "MeshExpUtility.h" #include "notetrck.h" -#define BIP_BONE_CLASS_ID 0x00009125 +#define BIP_BONE_CLASS_ID 0x00009125 #define OBTYPE_MESH 0 #define OBTYPE_CAMERA 1 @@ -15,560 +15,596 @@ #define OBTYPE_LTARGET 7 #define OBTYPE_BONE 8 -class SceneEntry { +class SceneEntry +{ public: - TSTR name; - INode *node,*tnode; - Object *obj; - int type; // See above - int id; - SceneEntry *next; - SceneEntry(INode *n, Object *o, int t); - void SetID(int id) { this->id = id; } + TSTR name; + INode *node, *tnode; + Object* obj; + int type; // See above + int id; + SceneEntry* next; + SceneEntry(INode* n, Object* o, int t); + void SetID(int id) { this->id = id; } }; -SceneEntry::SceneEntry(INode *n, Object *o, int t) { - node = n; obj = o; type = t; next = NULL; - tnode = n->GetTarget(); +SceneEntry::SceneEntry(INode* n, Object* o, int t) +{ + node = n; + obj = o; + type = t; + next = NULL; + tnode = n->GetTarget(); } //------------------------------------------------------------------------------- -class SceneEnumProc : public ITreeEnumProc { +class SceneEnumProc : public ITreeEnumProc +{ public: - SceneEntry* head; - SceneEntry* tail; - int count; - TimeValue time; - SceneEnumProc(INode *root_node, TimeValue t, Interface *i); - ~SceneEnumProc(); - int Count() { return count; } - void Append(INode *node, Object *obj, int type); - int callback( INode *node ); - void BuildNames(); + SceneEntry* head; + SceneEntry* tail; + int count; + TimeValue time; + SceneEnumProc(INode* root_node, TimeValue t, Interface* i); + ~SceneEnumProc(); + int Count() { return count; } + void Append(INode* node, Object* obj, int type); + int callback(INode* node); + void BuildNames(); }; -void NodeEnum(SceneEnumProc* se, INode* node){ - // For each child of this node, we recurse into ourselves - // until no more children are found. - for (int c = 0; c < node->NumberOfChildren(); c++){ - se->callback(node->GetChildNode(c)); - NodeEnum(se, node->GetChildNode(c)); - } +void NodeEnum(SceneEnumProc* se, INode* node) +{ + // For each child of this node, we recurse into ourselves + // until no more children are found. + for (int c = 0; c < node->NumberOfChildren(); c++) + { + se->callback(node->GetChildNode(c)); + NodeEnum(se, node->GetChildNode(c)); + } } -SceneEnumProc::SceneEnumProc(INode *root_node, TimeValue t, Interface *ip) { - time = t; - count = 0; - head = tail = NULL; - for (int idx = 0; idx < root_node->NumberOfChildren(); idx++){ - this->callback(root_node->GetChildNode(idx)); - NodeEnum(this, root_node->GetChildNode(idx)); - } +SceneEnumProc::SceneEnumProc(INode* root_node, TimeValue t, Interface* ip) +{ + time = t; + count = 0; + head = tail = NULL; + for (int idx = 0; idx < root_node->NumberOfChildren(); idx++) + { + this->callback(root_node->GetChildNode(idx)); + NodeEnum(this, root_node->GetChildNode(idx)); + } } -SceneEnumProc::~SceneEnumProc() +SceneEnumProc::~SceneEnumProc() { - while(head) { - SceneEntry *next = head->next; - xr_delete(head); - head = next; - } - head = tail = NULL; - count = 0; + while (head) + { + SceneEntry* next = head->next; + xr_delete(head); + head = next; + } + head = tail = NULL; + count = 0; } -int SceneEnumProc::callback(INode *node) +int SceneEnumProc::callback(INode* node) { - char line[1024]; - Object *obj = node->EvalWorldState(time).obj; - - strcpy(line, node->GetName()); - //if(strstr(line, "Bip") != NULL) - { - sprintf(line, "%08X %08X", obj->SuperClassID(), obj->ClassID()); - // MessageBox(NULL, line, node->GetName(), MB_OK); - } - - if( (obj->SuperClassID() == GEOMOBJECT_CLASS_ID) && - (obj->ClassID() == Class_ID(BIP_BONE_CLASS_ID, 0)) ) - { - Append(node, obj, OBTYPE_BONE); - return TREE_CONTINUE; - } - - if (obj->CanConvertToType(triObjectClassID)) - { - Append(node, obj, OBTYPE_MESH); - return TREE_CONTINUE; - } - - if (node->IsTarget()) - { - INode* ln = node->GetLookatNode(); - if (ln) - { - Object *lobj = ln->EvalWorldState(time).obj; - switch(lobj->SuperClassID()) - { - case LIGHT_CLASS_ID: Append(node, obj, OBTYPE_LTARGET); break; - case CAMERA_CLASS_ID: Append(node, obj, OBTYPE_CTARGET); break; - } - } - return TREE_CONTINUE; - } - switch (obj->SuperClassID()) - { - case HELPER_CLASS_ID: - if ( obj->ClassID()==Class_ID(DUMMY_CLASS_ID,0)) - Append(node, obj, OBTYPE_DUMMY); - if(obj->ClassID() == Class_ID(BONE_CLASS_ID,0)) - Append(node, obj, OBTYPE_BONE); - break; - case LIGHT_CLASS_ID: - if (obj->ClassID()==Class_ID(OMNI_LIGHT_CLASS_ID,0)) - Append(node, obj, OBTYPE_OMNILIGHT); - else - if (obj->ClassID()==Class_ID(SPOT_LIGHT_CLASS_ID,0)) - Append(node, obj, OBTYPE_SPOTLIGHT); - //export DIR_LIGHT and FSPOT_LIGHT???? - break; - case CAMERA_CLASS_ID: - if (obj->ClassID()==Class_ID(LOOKAT_CAM_CLASS_ID,0)) - Append(node, obj, OBTYPE_CAMERA); - break; - } - return TREE_CONTINUE; // Keep on enumeratin'! + char line[1024]; + Object* obj = node->EvalWorldState(time).obj; + + strcpy(line, node->GetName()); + // if(strstr(line, "Bip") != NULL) + { + sprintf(line, "%08X %08X", obj->SuperClassID(), obj->ClassID()); + // MessageBox(NULL, line, node->GetName(), MB_OK); + } + + if ((obj->SuperClassID() == GEOMOBJECT_CLASS_ID) && (obj->ClassID() == Class_ID(BIP_BONE_CLASS_ID, 0))) { + Append(node, obj, OBTYPE_BONE); + return TREE_CONTINUE; + } + + if (obj->CanConvertToType(triObjectClassID)) { + Append(node, obj, OBTYPE_MESH); + return TREE_CONTINUE; + } + + if (node->IsTarget()) { + INode* ln = node->GetLookatNode(); + if (ln) { + Object* lobj = ln->EvalWorldState(time).obj; + switch (lobj->SuperClassID()) + { + case LIGHT_CLASS_ID: Append(node, obj, OBTYPE_LTARGET); break; + case CAMERA_CLASS_ID: Append(node, obj, OBTYPE_CTARGET); break; + } + } + return TREE_CONTINUE; + } + switch (obj->SuperClassID()) + { + case HELPER_CLASS_ID: + if (obj->ClassID() == Class_ID(DUMMY_CLASS_ID, 0)) Append(node, obj, OBTYPE_DUMMY); + if (obj->ClassID() == Class_ID(BONE_CLASS_ID, 0)) Append(node, obj, OBTYPE_BONE); + break; + case LIGHT_CLASS_ID: + if (obj->ClassID() == Class_ID(OMNI_LIGHT_CLASS_ID, 0)) + Append(node, obj, OBTYPE_OMNILIGHT); + else if (obj->ClassID() == Class_ID(SPOT_LIGHT_CLASS_ID, 0)) + Append(node, obj, OBTYPE_SPOTLIGHT); + // export DIR_LIGHT and FSPOT_LIGHT???? + break; + case CAMERA_CLASS_ID: + if (obj->ClassID() == Class_ID(LOOKAT_CAM_CLASS_ID, 0)) Append(node, obj, OBTYPE_CAMERA); + break; + } + return TREE_CONTINUE; // Keep on enumeratin'! } +void SceneEnumProc::Append(INode* node, Object* obj, int type) +{ + SceneEntry* entry = new SceneEntry(node, obj, type); -void SceneEnumProc::Append(INode *node, Object *obj, int type) { - SceneEntry *entry = new SceneEntry(node, obj, type); - - if(tail) - tail->next = entry; - tail = entry; - if(!head) - head = entry; - count++; + if (tail) tail->next = entry; + tail = entry; + if (!head) head = entry; + count++; } // We need to maintain a list of the unique objects in the scene -class ObjectEntry { +class ObjectEntry +{ public: - TriObject *tri; - SceneEntry *entry; - ObjectEntry *next; - ObjectEntry(SceneEntry *e) { entry = e; next = NULL; tri = NULL; } + TriObject* tri; + SceneEntry* entry; + ObjectEntry* next; + ObjectEntry(SceneEntry* e) + { + entry = e; + next = NULL; + tri = NULL; + } }; -class ObjectList { +class ObjectList +{ public: - ObjectEntry *head; - ObjectEntry *tail; - int count; - ObjectList(SceneEnumProc &scene); - ~ObjectList(); - int Count() { return count; } - void Append(SceneEntry *e); - ObjectEntry *Contains(Object *obj); - ObjectEntry *Contains(INode *node); - ObjectEntry *FindLookatNode(INode *node); + ObjectEntry* head; + ObjectEntry* tail; + int count; + ObjectList(SceneEnumProc& scene); + ~ObjectList(); + int Count() { return count; } + void Append(SceneEntry* e); + ObjectEntry* Contains(Object* obj); + ObjectEntry* Contains(INode* node); + ObjectEntry* FindLookatNode(INode* node); }; -ObjectList::ObjectList(SceneEnumProc &scene) { - head = tail = NULL; - count = 0; - // Zip thru the object list and record all unique objects (Some may be used by more than one node) - int scount = scene.Count(); - for(SceneEntry *se = scene.head; se!=NULL; se = se->next) { - // can't multiple instance lights and cameras in 3DS - // so make them all unique--DS 4/6/96 - if ( (se->type!=OBTYPE_MESH)|| !Contains(se->obj)) - Append(se); - } +ObjectList::ObjectList(SceneEnumProc& scene) +{ + head = tail = NULL; + count = 0; + // Zip thru the object list and record all unique objects (Some may be used by more than one node) + int scount = scene.Count(); + for (SceneEntry* se = scene.head; se != NULL; se = se->next) + { + // can't multiple instance lights and cameras in 3DS + // so make them all unique--DS 4/6/96 + if ((se->type != OBTYPE_MESH) || !Contains(se->obj)) Append(se); + } } -ObjectList::~ObjectList() +ObjectList::~ObjectList() { - while(head) { - ObjectEntry *next = head->next; - xr_delete(head); - head = next; - } - head = tail = NULL; - count = 0; + while (head) + { + ObjectEntry* next = head->next; + xr_delete(head); + head = next; + } + head = tail = NULL; + count = 0; } -ObjectEntry *ObjectList::Contains(Object *obj) { - ObjectEntry *e; - for (e=head; e!=NULL; e = e->next) { - if(e->entry->obj == obj) - return e; - } - return NULL; +ObjectEntry* ObjectList::Contains(Object* obj) +{ + ObjectEntry* e; + for (e = head; e != NULL; e = e->next) + { + if (e->entry->obj == obj) return e; + } + return NULL; } -class FindDepNodeEnum: public DependentEnumProc { +class FindDepNodeEnum : public DependentEnumProc +{ public: - ReferenceTarget *targ; - INode *depNode; - FindDepNodeEnum() { targ = NULL; depNode = NULL; } - // proc should return 1 when it wants enumeration to halt. - virtual int proc(ReferenceMaker *rmaker); + ReferenceTarget* targ; + INode* depNode; + FindDepNodeEnum() + { + targ = NULL; + depNode = NULL; + } + // proc should return 1 when it wants enumeration to halt. + virtual int proc(ReferenceMaker* rmaker); }; -int FindDepNodeEnum::proc(ReferenceMaker *rmaker) { - if (rmaker->SuperClassID()!=BASENODE_CLASS_ID) return 0; - INode* node = (INode *)rmaker; - if (node->GetTarget()==targ) { - depNode = node; - return 1; - } - return 0; +int FindDepNodeEnum::proc(ReferenceMaker* rmaker) +{ + if (rmaker->SuperClassID() != BASENODE_CLASS_ID) return 0; + INode* node = (INode*)rmaker; + if (node->GetTarget() == targ) { + depNode = node; + return 1; + } + return 0; } -ObjectEntry *ObjectList::FindLookatNode(INode *node) { - FindDepNodeEnum finder; - ObjectEntry *e; - for (e=head; e!=NULL; e = e->next) { - finder.targ = node; - e->entry->node->EnumDependents(&finder); - if (finder.depNode) return e; - } - return NULL; +ObjectEntry* ObjectList::FindLookatNode(INode* node) +{ + FindDepNodeEnum finder; + ObjectEntry* e; + for (e = head; e != NULL; e = e->next) + { + finder.targ = node; + e->entry->node->EnumDependents(&finder); + if (finder.depNode) return e; + } + return NULL; } - -ObjectEntry *ObjectList::Contains(INode *node) { - ObjectEntry *e; - for (e=head; e!=NULL; e = e->next) { - if(e->entry->node == node) - return e; - } - return NULL; +ObjectEntry* ObjectList::Contains(INode* node) +{ + ObjectEntry* e; + for (e = head; e != NULL; e = e->next) + { + if (e->entry->node == node) return e; + } + return NULL; } -void ObjectList::Append(SceneEntry *e) { - ObjectEntry *entry = new ObjectEntry(e); - if(tail) - tail->next = entry; - tail = entry; - if(!head) - head = entry; - count++; +void ObjectList::Append(SceneEntry* e) +{ + ObjectEntry* entry = new ObjectEntry(e); + if (tail) tail->next = entry; + tail = entry; + if (!head) head = entry; + count++; } -ObjectList *theObjects = NULL; +ObjectList* theObjects = NULL; //----------------------------------------------------------------------------------------------------- -class ObjName { +class ObjName +{ public: - TSTR name; - ObjName *next; - ObjName(TSTR n) { name = n; next = NULL; } + TSTR name; + ObjName* next; + ObjName(TSTR n) + { + name = n; + next = NULL; + } }; -class ObjNameList { +class ObjNameList +{ public: - ObjName *head; - ObjName *tail; - int count; - ObjNameList() { head = tail = NULL; count = 0; } - ~ObjNameList(); - int Count() { return count; } - int Contains(TSTR &n); - void Append(TSTR &n); - void MakeUnique(TSTR &n); + ObjName* head; + ObjName* tail; + int count; + ObjNameList() + { + head = tail = NULL; + count = 0; + } + ~ObjNameList(); + int Count() { return count; } + int Contains(TSTR& n); + void Append(TSTR& n); + void MakeUnique(TSTR& n); }; -ObjNameList::~ObjNameList() +ObjNameList::~ObjNameList() { - while(head) { - ObjName *next = head->next; - xr_delete(head); - head = next; - } - head = tail = NULL; - count = 0; + while (head) + { + ObjName* next = head->next; + xr_delete(head); + head = next; + } + head = tail = NULL; + count = 0; } -int ObjNameList::Contains(TSTR &n) { - ObjName *e = head; - int index = 0; - while(e) { - if(e->name == n) - return index; - e = e->next; - index++; - } - return -1; +int ObjNameList::Contains(TSTR& n) +{ + ObjName* e = head; + int index = 0; + while (e) + { + if (e->name == n) return index; + e = e->next; + index++; + } + return -1; } -void ObjNameList::Append(TSTR &n) { - ObjName *entry = new ObjName(n); - if(tail) - tail->next = entry; - tail = entry; - if(!head) - head = entry; - count++; +void ObjNameList::Append(TSTR& n) +{ + ObjName* entry = new ObjName(n); + if (tail) tail->next = entry; + tail = entry; + if (!head) head = entry; + count++; } -void ObjNameList::MakeUnique(TSTR &n) { - // First make it less than 10 chars. - if (n.Length()>10) n.Resize(10); - - if(Contains(n) < 0) { - Append(n); - return; - } - // Make it unique and keep it 10 chars or less - for(int i = 0; i < 100000; ++i) { - char buf[12]; - sprintf(buf,"%d",i); - TSTR num(buf); - TSTR work = n; - int totlen = num.Length() + work.Length(); - if(totlen > 10) - work.Resize(10 - (totlen - 10)); - work = work + num; - if(Contains(work) < 0) { - Append(work); - n = work; - return; - } - } - // Forget it! +void ObjNameList::MakeUnique(TSTR& n) +{ + // First make it less than 10 chars. + if (n.Length() > 10) n.Resize(10); + + if (Contains(n) < 0) { + Append(n); + return; + } + // Make it unique and keep it 10 chars or less + for (int i = 0; i < 100000; ++i) + { + char buf[12]; + sprintf(buf, "%d", i); + TSTR num(buf); + TSTR work = n; + int totlen = num.Length() + work.Length(); + if (totlen > 10) work.Resize(10 - (totlen - 10)); + work = work + num; + if (Contains(work) < 0) { + Append(work); + n = work; + return; + } + } + // Forget it! } ObjNameList theObjNames; //-------------------------------------------------------------------------------------------------- - void SceneEnumProc::BuildNames() { - ObjNameList nameList; - SceneEntry *ptr = head; - - while (ptr) { - // if (ptr->node->IsTarget()) { - // ptr->name = _T(""); - // } - // else { - ptr->name = ptr->node->GetName(); - nameList.MakeUnique(ptr->name); - // } - ptr = ptr->next; - } + ObjNameList nameList; + SceneEntry* ptr = head; + + while (ptr) + { + // if (ptr->node->IsTarget()) { + // ptr->name = _T(""); + // } + // else { + ptr->name = ptr->node->GetName(); + nameList.MakeUnique(ptr->name); + // } + ptr = ptr->next; + } } //-------------------------------------------------------------------------------------------------- - -bool MeshExpUtility::SaveSkinKeys(const char* n){ - CFS_Memory F; - - int FramesPerSecond = GetFrameRate(); - int TicksPerFrame = GetTicksPerFrame(); - int FirstTick = ip->GetAnimRange().Start(); - int LastTick = ip->GetAnimRange().End(); - - Point3 v; - Matrix3 tm; - - // Write signature and version - char S[MAX_PATH]; - sprintf(S, "KEYEXP 3.0"); - F.Wstring(S); - - INode *node; - ObjectEntry *Current; - - //----------------------------------------------------------------------- - // Count bones and report - - int NumBones = 0; - Current = theObjects->head; - while(Current) - { - /* - if(Current->entry->type != OBTYPE_BONE) - { - Current = Current->next; - continue; - } - */ - - NumBones++; - - Current = Current->next; - } - - sprintf(S, "Number of Bones = %d", NumBones); - F.Wstring(S); - ELog.Msg(mtInformation,S); - - //----------------------------------------------------------------------- - // Write out necessary data for motion keys - - sprintf(S, "Key Data"); - F.Wstring(S); - - TimeValue t; - Quat qq; - Point3 tp, sp; - INode* parent; - Matrix3 tmp; - - sprintf(S, "%d %d %d", FirstTick / TicksPerFrame, LastTick / TicksPerFrame, FramesPerSecond); - F.Wstring(S); - - Current = theObjects->head; - while(Current){ - /* - if(Current->entry->type != OBTYPE_BONE) - { - Current = Current->next; - continue; - } - */ - - Matrix3 tm; - - node = Current->entry->node; - - sprintf(S, "Node: %s", node->GetName()); - F.Wstring(S); - ELog.Msg(mtInformation,S); - - // Print notetrack info - { - int NumNT, n, i, j, NumNotes; - NoteTrack* pNT; - DefNoteTrack* pDNT; - NoteKey* pNK; - - NumNT = node->NumNoteTracks(); - - // count all of the notes on all of the notetracks - NumNotes = 0; - for(n=0;nGetNoteTrack(n); - if(pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)){ - pDNT = (DefNoteTrack*)pNT; - j = pDNT->NumKeys(); - for(i=0;ikeys[i]; - if( (pNK->time >= FirstTick) && (pNK->time <= LastTick) ) - NumNotes++; - } - } - } - - sprintf(S, "Number of Notes = %d", NumNotes); - F.Wstring(S); - - for(n=0;nGetNoteTrack(n); - if(pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)){ - pDNT = (DefNoteTrack*)pNT; - j = pDNT->NumKeys(); - for(i=0;ikeys[i]; - if( (pNK->time >= FirstTick) && (pNK->time <= LastTick) ){ - sprintf(S, "%d: %s", (pNK->time - FirstTick) / TicksPerFrame, pNK->note); - F.Wstring(S); - } - } - } - } - } - - for(t=FirstTick;t<=LastTick;t+=TicksPerFrame){ - tm = node->GetNodeTM(t); - DecomposeMatrix(tm, tp, qq, sp); - qq.MakeMatrix (tm); - tm.SetTrans (tp); - - parent = node->GetParentNode(); - if(parent){ - tmp = parent->GetNodeTM(t); - DecomposeMatrix(tmp, tp, qq, sp); - qq.MakeMatrix(tmp); - tmp.SetTrans(tp); - tmp = Inverse(tmp); - tm *= tmp; - } - - DecomposeMatrix(tm, tp, qq, sp); - sprintf(S,"%f %f %f %f",qq.x, qq.y, qq.z, qq.w); - F.Wstring(S); - sprintf(S,"%f %f %f",tp.x,tp.y,tp.z); - F.Wstring(S); - - /* - // Euler angles - Point3 E; - QuatToEuler (Quat(tm), E); - fprintf (f,"%f %f %f",E.x,E.y,E.z); - - // Translate - DecomposeMatrix (tm, tp, qq, sp); - fprintf (f,"%f %f %f",tp.x,tp.y,tp.z); - */ - -// Matrix3fprint(f, tm); - } - Current = Current->next; - } - - sprintf(S, "Key Data Complete"); - F.Wstring(S); - ELog.Msg(mtInformation,S); - - F.SaveTo(n,0); - - return true; +bool MeshExpUtility::SaveSkinKeys(const char* n) +{ + CFS_Memory F; + + int FramesPerSecond = GetFrameRate(); + int TicksPerFrame = GetTicksPerFrame(); + int FirstTick = ip->GetAnimRange().Start(); + int LastTick = ip->GetAnimRange().End(); + + Point3 v; + Matrix3 tm; + + // Write signature and version + char S[MAX_PATH]; + sprintf(S, "KEYEXP 3.0"); + F.Wstring(S); + + INode* node; + ObjectEntry* Current; + + //----------------------------------------------------------------------- + // Count bones and report + + int NumBones = 0; + Current = theObjects->head; + while (Current) + { + /* + if(Current->entry->type != OBTYPE_BONE) + { + Current = Current->next; + continue; + } + */ + + NumBones++; + + Current = Current->next; + } + + sprintf(S, "Number of Bones = %d", NumBones); + F.Wstring(S); + ELog.Msg(mtInformation, S); + + //----------------------------------------------------------------------- + // Write out necessary data for motion keys + + sprintf(S, "Key Data"); + F.Wstring(S); + + TimeValue t; + Quat qq; + Point3 tp, sp; + INode* parent; + Matrix3 tmp; + + sprintf(S, "%d %d %d", FirstTick / TicksPerFrame, LastTick / TicksPerFrame, FramesPerSecond); + F.Wstring(S); + + Current = theObjects->head; + while (Current) + { + /* + if(Current->entry->type != OBTYPE_BONE) + { + Current = Current->next; + continue; + } + */ + + Matrix3 tm; + + node = Current->entry->node; + + sprintf(S, "Node: %s", node->GetName()); + F.Wstring(S); + ELog.Msg(mtInformation, S); + + // Print notetrack info + { + int NumNT, n, i, j, NumNotes; + NoteTrack* pNT; + DefNoteTrack* pDNT; + NoteKey* pNK; + + NumNT = node->NumNoteTracks(); + + // count all of the notes on all of the notetracks + NumNotes = 0; + for (n = 0; n < NumNT; n++) + { + pNT = node->GetNoteTrack(n); + if (pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)) { + pDNT = (DefNoteTrack*)pNT; + j = pDNT->NumKeys(); + for (i = 0; i < j; i++) + { + pNK = pDNT->keys[i]; + if ((pNK->time >= FirstTick) && (pNK->time <= LastTick)) NumNotes++; + } + } + } + + sprintf(S, "Number of Notes = %d", NumNotes); + F.Wstring(S); + + for (n = 0; n < NumNT; n++) + { + pNT = node->GetNoteTrack(n); + if (pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)) { + pDNT = (DefNoteTrack*)pNT; + j = pDNT->NumKeys(); + for (i = 0; i < j; i++) + { + pNK = pDNT->keys[i]; + if ((pNK->time >= FirstTick) && (pNK->time <= LastTick)) { + sprintf(S, "%d: %s", (pNK->time - FirstTick) / TicksPerFrame, pNK->note); + F.Wstring(S); + } + } + } + } + } + + for (t = FirstTick; t <= LastTick; t += TicksPerFrame) + { + tm = node->GetNodeTM(t); + DecomposeMatrix(tm, tp, qq, sp); + qq.MakeMatrix(tm); + tm.SetTrans(tp); + + parent = node->GetParentNode(); + if (parent) { + tmp = parent->GetNodeTM(t); + DecomposeMatrix(tmp, tp, qq, sp); + qq.MakeMatrix(tmp); + tmp.SetTrans(tp); + tmp = Inverse(tmp); + tm *= tmp; + } + + DecomposeMatrix(tm, tp, qq, sp); + sprintf(S, "%f %f %f %f", qq.x, qq.y, qq.z, qq.w); + F.Wstring(S); + sprintf(S, "%f %f %f", tp.x, tp.y, tp.z); + F.Wstring(S); + + /* + // Euler angles + Point3 E; + QuatToEuler (Quat(tm), E); + fprintf (f,"%f %f %f",E.x,E.y,E.z); + + // Translate + DecomposeMatrix (tm, tp, qq, sp); + fprintf (f,"%f %f %f",tp.x,tp.y,tp.z); + */ + + // Matrix3fprint(f, tm); + } + Current = Current->next; + } + + sprintf(S, "Key Data Complete"); + F.Wstring(S); + ELog.Msg(mtInformation, S); + + F.SaveTo(n, 0); + + return true; } -void MeshExpUtility::ExportSkinKeys(){ - bool bResult = true; - - // Make sure there are nodes we're interested in! - // Ask the scene to enumerate all its nodes so we can determine if there are any we can use - INode *root_node = ip->GetRootNode(); - if(!root_node){ - ELog.Msg(mtError,"Scene empty." ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - - SceneEnumProc myScene(root_node, ip->GetTime(), ip); - - // Any useful nodes? - if(!myScene.Count()){ - ELog.Msg(mtError,"Scene has no useful nodes." ); - ELog.Msg(mtError,"-------------------------------------------------------" ); - return; - } - - char m_ExportName[MAX_PATH]; - m_ExportName[0]=0; - if( !Engine.FS.GetSaveName(Engine.FS.m_GameKeys,m_ExportName,MAX_PATH,0) ){ - ELog.Msg(mtInformation,"Export cancelled" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - - // Construct unique names < 10 chars. - myScene.BuildNames(); - - ObjectList myObjects(myScene); - - theObjects = &myObjects; - - bResult = SaveSkinKeys(m_ExportName); - - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - if (bResult) ELog.Msg(mtInformation,"Export completed" ); - else ELog.Msg(mtError,"Export failed***********************" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); +void MeshExpUtility::ExportSkinKeys() +{ + bool bResult = true; + + // Make sure there are nodes we're interested in! + // Ask the scene to enumerate all its nodes so we can determine if there are any we can use + INode* root_node = ip->GetRootNode(); + if (!root_node) { + ELog.Msg(mtError, "Scene empty."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + + SceneEnumProc myScene(root_node, ip->GetTime(), ip); + + // Any useful nodes? + if (!myScene.Count()) { + ELog.Msg(mtError, "Scene has no useful nodes."); + ELog.Msg(mtError, "-------------------------------------------------------"); + return; + } + + char m_ExportName[MAX_PATH]; + m_ExportName[0] = 0; + if (!Engine.FS.GetSaveName(Engine.FS.m_GameKeys, m_ExportName, MAX_PATH, 0)) { + ELog.Msg(mtInformation, "Export cancelled"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + + // Construct unique names < 10 chars. + myScene.BuildNames(); + + ObjectList myObjects(myScene); + + theObjects = &myObjects; + + bResult = SaveSkinKeys(m_ExportName); + + ELog.Msg(mtInformation, "-------------------------------------------------------"); + if (bResult) + ELog.Msg(mtInformation, "Export completed"); + else + ELog.Msg(mtError, "Export failed***********************"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); } - diff --git a/src/plugins/Max/Export/Exporter.cpp b/src/plugins/Max/Export/Exporter.cpp index 29efd049287..f082c4cb1e5 100644 --- a/src/plugins/Max/Export/Exporter.cpp +++ b/src/plugins/Max/Export/Exporter.cpp @@ -7,445 +7,468 @@ // ================================================== FindPhysiqueModifier() // Find if a given node contains a Physique Modifier // DerivedObjectPtr requires you include "modstack.h" from the MAX SDK -Modifier* FindPhysiqueModifier (INode* nodePtr) +Modifier* FindPhysiqueModifier(INode* nodePtr) { - // Get object from node. Abort if no object. - Object* ObjectPtr = nodePtr->GetObjectRef(); - - if ( NULL == ObjectPtr) return NULL; - - // Is derived object ? - if (ObjectPtr->SuperClassID() == GEN_DERIVOB_CLASS_ID){ - // Yes -> Cast. - IDerivedObject* DerivedObjectPtr = static_cast(ObjectPtr); - - // Iterate over all entries of the modifier stack. - int ModStackIndex = 0; - while (ModStackIndex < DerivedObjectPtr->NumModifiers()){ - // Get current modifier. - Modifier* ModifierPtr = DerivedObjectPtr->GetModifier(ModStackIndex); - Class_ID clsid = ModifierPtr->ClassID(); - // Is this Physique ? - if (ModifierPtr->ClassID() == Class_ID(PHYSIQUE_CLASS_ID_A, PHYSIQUE_CLASS_ID_B)) - { - // Yes -> Exit. - return ModifierPtr; - } - - // Next modifier stack entry. - ModStackIndex++; - } - } - - // Not found. - return NULL; + // Get object from node. Abort if no object. + Object* ObjectPtr = nodePtr->GetObjectRef(); + + if (NULL == ObjectPtr) return NULL; + + // Is derived object ? + if (ObjectPtr->SuperClassID() == GEN_DERIVOB_CLASS_ID) { + // Yes -> Cast. + IDerivedObject* DerivedObjectPtr = static_cast(ObjectPtr); + + // Iterate over all entries of the modifier stack. + int ModStackIndex = 0; + while (ModStackIndex < DerivedObjectPtr->NumModifiers()) + { + // Get current modifier. + Modifier* ModifierPtr = DerivedObjectPtr->GetModifier(ModStackIndex); + Class_ID clsid = ModifierPtr->ClassID(); + // Is this Physique ? + if (ModifierPtr->ClassID() == Class_ID(PHYSIQUE_CLASS_ID_A, PHYSIQUE_CLASS_ID_B)) { + // Yes -> Exit. + return ModifierPtr; + } + + // Next modifier stack entry. + ModStackIndex++; + } + } + + // Not found. + return NULL; } // ================================================== GetTriObjectFromObjRef // Return a pointer to a TriObject given an object reference or return NULL // if the node cannot be converted to a TriObject -TriObject *GetTriObjectFromObjRef(Object* pObj, BOOL *pbDeleteIt) +TriObject* GetTriObjectFromObjRef(Object* pObj, BOOL* pbDeleteIt) { - TriObject *pTri; + TriObject* pTri; - R_ASSERT(pObj); - R_ASSERT(pbDeleteIt); + R_ASSERT(pObj); + R_ASSERT(pbDeleteIt); - *pbDeleteIt = FALSE; + *pbDeleteIt = FALSE; - if (pObj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))){ - pTri = (TriObject *) pObj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0)); + if (pObj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) { + pTri = (TriObject*)pObj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0)); - // Note that the TriObject should only be deleted - // if the pointer to it is not equal to the object - // pointer that called ConvertToType() - if (pObj != pTri) - *pbDeleteIt = TRUE; + // Note that the TriObject should only be deleted + // if the pointer to it is not equal to the object + // pointer that called ConvertToType() + if (pObj != pTri) *pbDeleteIt = TRUE; - return pTri; - }else{ - return NULL; - } + return pTri; + } + else + { + return NULL; + } } // ================================================== IsExportableMesh() -BOOL IsExportableMesh(INode* pNode, Object* &pObj) +BOOL IsExportableMesh(INode* pNode, Object*& pObj) { - ULONG superClassID; - - R_ASSERT(pNode); - pObj = pNode->GetObjectRef(); - - if (pObj == NULL) return FALSE; - - superClassID = pObj->SuperClassID(); - //find out if mesh is renderable - - if( !pNode->Renderable() || pNode->IsNodeHidden()) return FALSE; - - BOOL bFoundGeomObject = FALSE; - //find out if mesh is renderable (more) - switch(superClassID){ - case GEN_DERIVOB_CLASS_ID: - do{ - pObj = ((IDerivedObject*)pObj)->GetObjRef(); - superClassID = pObj->SuperClassID(); - } - while( superClassID == GEN_DERIVOB_CLASS_ID ); - switch(superClassID){ - case GEOMOBJECT_CLASS_ID: - bFoundGeomObject = TRUE; - break; - } - break; - case GEOMOBJECT_CLASS_ID: - bFoundGeomObject = TRUE; - break; - default: - break; - } - - return bFoundGeomObject; + ULONG superClassID; + + R_ASSERT(pNode); + pObj = pNode->GetObjectRef(); + + if (pObj == NULL) return FALSE; + + superClassID = pObj->SuperClassID(); + // find out if mesh is renderable + + if (!pNode->Renderable() || pNode->IsNodeHidden()) return FALSE; + + BOOL bFoundGeomObject = FALSE; + // find out if mesh is renderable (more) + switch (superClassID) + { + case GEN_DERIVOB_CLASS_ID: + do + { + pObj = ((IDerivedObject*)pObj)->GetObjRef(); + superClassID = pObj->SuperClassID(); + } while (superClassID == GEN_DERIVOB_CLASS_ID); + switch (superClassID) + { + case GEOMOBJECT_CLASS_ID: bFoundGeomObject = TRUE; break; + } + break; + case GEOMOBJECT_CLASS_ID: bFoundGeomObject = TRUE; break; + default: break; + } + + return bFoundGeomObject; } //----------------------------------------------------------------------------- CExporter::~CExporter() { - for (BoneDefIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ - xr_delete(*b_it); - } - for (VertexDefIt v_it=m_Vertices.begin(); v_it!=m_Vertices.end(); v_it++){ - xr_delete(*v_it); - } - for (ExpVertIt ev_it=m_ExpVertices.begin(); ev_it!=m_ExpVertices.end(); ev_it++){ - xr_delete(*ev_it); - } - for (ExpFaceIt ef_it=m_ExpFaces.begin(); ef_it!=m_ExpFaces.end(); ef_it++){ - xr_delete(*ef_it); - } + for (BoneDefIt b_it = m_Bones.begin(); b_it != m_Bones.end(); b_it++) + { + xr_delete(*b_it); + } + for (VertexDefIt v_it = m_Vertices.begin(); v_it != m_Vertices.end(); v_it++) + { + xr_delete(*v_it); + } + for (ExpVertIt ev_it = m_ExpVertices.begin(); ev_it != m_ExpVertices.end(); ev_it++) + { + xr_delete(*ev_it); + } + for (ExpFaceIt ef_it = m_ExpFaces.begin(); ef_it != m_ExpFaces.end(); ef_it++) + { + xr_delete(*ef_it); + } } //----------------------------------------------------------------------------- -int CExporter::AddBone(INode* pNode, Matrix3 &matMesh, IPhysiqueExport* pExport) +int CExporter::AddBone(INode* pNode, Matrix3& matMesh, IPhysiqueExport* pExport) { - if (!Helper::IsBone(pNode,U.m_SkinAllowDummy)) return BONE_NONE; - - for (BoneDefIt it=m_Bones.begin(); it!=m_Bones.end(); it++) - if ((*it)->isEqual(pNode)) return it-m_Bones.begin(); - - CBoneDef* pBone= new CBoneDef(pNode); - if (pBone->SetInitTM(pExport,matMesh)){ - AddBone(pBone->pBone->GetParentNode(),matMesh,pExport); - m_Bones.push_back (pBone); - return m_Bones.size()-1; - } - return BONE_NONE; + if (!Helper::IsBone(pNode, U.m_SkinAllowDummy)) return BONE_NONE; + + for (BoneDefIt it = m_Bones.begin(); it != m_Bones.end(); it++) + if ((*it)->isEqual(pNode)) return it - m_Bones.begin(); + + CBoneDef* pBone = new CBoneDef(pNode); + if (pBone->SetInitTM(pExport, matMesh)) { + AddBone(pBone->pBone->GetParentNode(), matMesh, pExport); + m_Bones.push_back(pBone); + return m_Bones.size() - 1; + } + return BONE_NONE; } -void CExporter::ScanBones(INode *pNode) +void CExporter::ScanBones(INode* pNode) { - VERIFY (m_Style!=eExportUndef); - R_ASSERT (pNode); - if (Helper::IsBone(pNode,U.m_SkinAllowDummy)) m_AllBones.push_back(pNode); - // process sub-nodes - int cChildren = pNode->NumberOfChildren(); - for (int iChild = 0; iChild < cChildren; iChild++) - ScanBones(pNode->GetChildNode(iChild)); + VERIFY(m_Style != eExportUndef); + R_ASSERT(pNode); + if (Helper::IsBone(pNode, U.m_SkinAllowDummy)) m_AllBones.push_back(pNode); + // process sub-nodes + int cChildren = pNode->NumberOfChildren(); + for (int iChild = 0; iChild < cChildren; iChild++) + ScanBones(pNode->GetChildNode(iChild)); } //----------------------------------------------------------------------------- -void CExporter::ScanMesh(INode *pNode) +void CExporter::ScanMesh(INode* pNode) { - if (m_bHasError) return; - - if (!Helper::IsMesh(pNode)){ -// LPCSTR nm = pNode->GetName(); - int cChildren = pNode->NumberOfChildren(); - for (int iChild = 0; iChild < cChildren; iChild++){ -// LPCSTR nm1 = pNode->GetChildNode(iChild)->GetName(); - ScanMesh (pNode->GetChildNode(iChild)); - } - }else{ -// LPCSTR nm = pNode->GetName(); - if (pNode->Selected()){ - if (m_bFindMesh){ - ERR("Single mesh support only."); - m_bHasError = TRUE; - return; - } - m_MeshNode = pNode; - m_bFindMesh = TRUE; - } - } + if (m_bHasError) return; + + if (!Helper::IsMesh(pNode)) { + // LPCSTR nm = pNode->GetName(); + int cChildren = pNode->NumberOfChildren(); + for (int iChild = 0; iChild < cChildren; iChild++) + { + // LPCSTR nm1 = pNode->GetChildNode(iChild)->GetName(); + ScanMesh(pNode->GetChildNode(iChild)); + } + } + else + { + // LPCSTR nm = pNode->GetName(); + if (pNode->Selected()) { + if (m_bFindMesh) { + ERR("Single mesh support only."); + m_bHasError = TRUE; + return; + } + m_MeshNode = pNode; + m_bFindMesh = TRUE; + } + } } //----------------------------------------------------------------------------- BOOL CExporter::Capture() { - VERIFY (m_Style!=eExportUndef); - Modifier* pPhysique; - IPhysiqueExport* pExport; - IPhyContextExport* pContext; - Object* pObject; - - Matrix3 matMesh; - Matrix3 matZero; - - if (!m_MeshNode){ - ERR("Select mesh and try again."); - m_bHasError=TRUE; - return FALSE; - } - - - pObject = m_MeshNode->GetObjectRef(); - if (!IsExportableMesh(m_MeshNode,pObject)){ - ERR("Can't receive node references."); - m_bHasError=TRUE; - return FALSE; - } - - // Get export interface - pPhysique = FindPhysiqueModifier(m_MeshNode); - if (!pPhysique){ - ERR("Can't find Physique modifier."); - m_bHasError=TRUE; - return FALSE; - } - pExport = (IPhysiqueExport *)pPhysique->GetInterface(I_PHYINTERFACE); - if (!pExport){ - ERR("Can't find Physique interface."); - m_bHasError=TRUE; - return FALSE; - } - - // Get mesh initial transform (used to mult by the bone matrices) - int rval = CGINTM(m_MeshNode,pExport->GetInitNodeTM(m_MeshNode, matMesh)); - matZero.Zero(); - if (rval || matMesh.Equals(matZero, 0.0)){ - ERR("Old CS version. Can't export mesh"); - matMesh.IdentityMatrix(); - } - - // Add hierrarhy parts that has no effect on vertices, - // but required for hierrarhy stability - - if (eExportMotion==m_Style){ - if (m_AllBones.empty()){ - ERR("Invalid skin object. Bone not found."); - return FALSE; - } - - EConsole.ProgressStart((float)m_AllBones.size(),"..Capturing bones"); - for (DWORD i=0; iGetContextInterface(m_MeshNode); - if (!pContext){ - ERR("Can't find Physique context interface."); - return FALSE; - } - - // convert to rigid with blending - pContext->ConvertToRigid(TRUE); - pContext->AllowBlending (TRUE); - - // process vertices - int numVertices = pContext->GetNumberVertices(); - EConsole.ProgressStart(float(numVertices),"..Capturing vertices"); - for (int iVertex = 0; iVertex < numVertices; iVertex++ ){ - IPhyVertexExport *pVertexExport = (IPhyVertexExport *)pContext->GetVertexInterface(iVertex); - R_ASSERT(pVertexExport); - - // What kind of vertices are these? - int iVertexType = pVertexExport->GetVertexType(); - - IPhyRigidVertex* pRigidVertex=(IPhyRigidVertex*)pContext->GetVertexInterface(iVertex); - R_ASSERT (pRigidVertex); - switch (iVertexType){ - case RIGID_TYPE:{ - INode* node = pRigidVertex->GetNode(); - R_ASSERT (node); - LPCSTR nm = node->GetName(); - // get bone and create vertex - CVertexDef* pVertex = AddVertex(); - int boneId = AddBone(node,matMesh,pExport); - if(BONE_NONE==boneId){ - ERR ("Invalid bone: ",node->GetName()); - bRes = FALSE; - }else pVertex->Append (boneId,1.f); - }break; - case RIGID_BLENDED_TYPE:{ - IPhyBlendedRigidVertex* pBlendedRigidVertex=(IPhyBlendedRigidVertex*)pRigidVertex; - int cnt = pBlendedRigidVertex->GetNumberNodes(); - CVertexDef* pVertex = AddVertex(); - for (int i=0; iGetNode(i); - R_ASSERT (node); - LPCSTR nm = node->GetName(); - // get bone and create vertex - int boneId = AddBone(node,matMesh,pExport); - if(BONE_NONE==boneId){ - ERR ("Invalid bone: ",node->GetName()); - bRes = FALSE; - }else pVertex->Append(boneId,pBlendedRigidVertex->GetWeight(i)); - } - }break; - } - - // release vertex - pContext->ReleaseVertexInterface( pRigidVertex ); - - EConsole.ProgressInc(); - - if (!bRes) break; - } - EConsole.ProgressEnd(); - - if (!bRes) return FALSE; - - static int remap[3]; - if (U.m_SkinFlipFaces){ - remap[0] = 0; - remap[1] = 1; - remap[2] = 2; - }else{ - remap[0] = 0; - remap[1] = 2; - remap[2] = 1; - } - - // Process mesh - // Get object from node. Abort if no object. - Log("..Transforming mesh"); - BOOL bDeleteTriObject; - R_ASSERT (pObject); - TriObject * pTriObject = GetTriObjectFromObjRef(pObject, &bDeleteTriObject); - if (!pTriObject){ - ERR("Can't create tri object."); - return FALSE; - } - Mesh& M = pTriObject->mesh; - - // Vertices - { - // check match with - int iNumVert = M.getNumVerts(); - if (!(iNumVert==numVertices && iNumVert==m_Vertices.size())) - { - ERR("Non attached vertices found."); - if (bDeleteTriObject) delete(pTriObject); - return FALSE; - } - - // transform vertices - for (int i=0; iSetPosition(T); - } - } - - Log("..Parsing materials"); - // Parse Materials - m_MtlMain = m_MeshNode->GetMtl(); - R_ASSERT(m_MtlMain); - - DWORD cSubMaterials=m_MtlMain->NumSubMtls(); - if (cSubMaterials < 1) { - // Count the material itself as a submaterial. - cSubMaterials = 1; - } - - // build normals - M.buildRenderNormals(); - - Log("..Converting vertices"); - // our Faces and Vertices - { - for (int i=0; igetMatID(); - if (cSubMaterials == 1){ - m_id = 0; - }else{ - // SDK recommends mod'ing the material ID by the valid # of materials, - // as sometimes a material number that's too high is returned. - m_id %= cSubMaterials; - } - - st_FACE* nF = new st_FACE(); - nF->m_id = m_id; - nF->sm_group = gF->getSmGroup(); - for (int VVV=0; VVV<3; VVV++){ - int vert_id = gF->v[remap[VVV]]; - - CVertexDef &D = *(m_Vertices[vert_id]); - Point3 &UV = M.tVerts[tF->t[remap[VVV]]]; - - st_VERT v; - v.Set (D); - v.P.set (D.P); - v.SetUV (UV.x,1-UV.y); -// v.sm_group = U.m_SkinSuppressSmoothGroup?0:gF->getSmGroup(); // smooth group - nF->v[VVV] = AddVert(v); - } - m_ExpFaces.push_back(nF); - } - } - if (bDeleteTriObject) delete(pTriObject); - } - UpdateParenting(); - - return bRes; + VERIFY(m_Style != eExportUndef); + Modifier* pPhysique; + IPhysiqueExport* pExport; + IPhyContextExport* pContext; + Object* pObject; + + Matrix3 matMesh; + Matrix3 matZero; + + if (!m_MeshNode) { + ERR("Select mesh and try again."); + m_bHasError = TRUE; + return FALSE; + } + + pObject = m_MeshNode->GetObjectRef(); + if (!IsExportableMesh(m_MeshNode, pObject)) { + ERR("Can't receive node references."); + m_bHasError = TRUE; + return FALSE; + } + + // Get export interface + pPhysique = FindPhysiqueModifier(m_MeshNode); + if (!pPhysique) { + ERR("Can't find Physique modifier."); + m_bHasError = TRUE; + return FALSE; + } + pExport = (IPhysiqueExport*)pPhysique->GetInterface(I_PHYINTERFACE); + if (!pExport) { + ERR("Can't find Physique interface."); + m_bHasError = TRUE; + return FALSE; + } + + // Get mesh initial transform (used to mult by the bone matrices) + int rval = CGINTM(m_MeshNode, pExport->GetInitNodeTM(m_MeshNode, matMesh)); + matZero.Zero(); + if (rval || matMesh.Equals(matZero, 0.0)) { + ERR("Old CS version. Can't export mesh"); + matMesh.IdentityMatrix(); + } + + // Add hierrarhy parts that has no effect on vertices, + // but required for hierrarhy stability + + if (eExportMotion == m_Style) { + if (m_AllBones.empty()) { + ERR("Invalid skin object. Bone not found."); + return FALSE; + } + + EConsole.ProgressStart((float)m_AllBones.size(), "..Capturing bones"); + for (DWORD i = 0; i < m_AllBones.size(); i++) + { + AddBone(m_AllBones[i], matMesh, pExport); + EConsole.ProgressInc(); + } + EConsole.ProgressEnd(); + } + + bool bRes = TRUE; + if (eExportSkin == m_Style) { + // For a given Object's INode get a + // ModContext Interface from the Physique Export Interface: + pContext = (IPhyContextExport*)pExport->GetContextInterface(m_MeshNode); + if (!pContext) { + ERR("Can't find Physique context interface."); + return FALSE; + } + + // convert to rigid with blending + pContext->ConvertToRigid(TRUE); + pContext->AllowBlending(TRUE); + + // process vertices + int numVertices = pContext->GetNumberVertices(); + EConsole.ProgressStart(float(numVertices), "..Capturing vertices"); + for (int iVertex = 0; iVertex < numVertices; iVertex++) + { + IPhyVertexExport* pVertexExport = (IPhyVertexExport*)pContext->GetVertexInterface(iVertex); + R_ASSERT(pVertexExport); + + // What kind of vertices are these? + int iVertexType = pVertexExport->GetVertexType(); + + IPhyRigidVertex* pRigidVertex = (IPhyRigidVertex*)pContext->GetVertexInterface(iVertex); + R_ASSERT(pRigidVertex); + switch (iVertexType) + { + case RIGID_TYPE: + { + INode* node = pRigidVertex->GetNode(); + R_ASSERT(node); + LPCSTR nm = node->GetName(); + // get bone and create vertex + CVertexDef* pVertex = AddVertex(); + int boneId = AddBone(node, matMesh, pExport); + if (BONE_NONE == boneId) { + ERR("Invalid bone: ", node->GetName()); + bRes = FALSE; + } + else + pVertex->Append(boneId, 1.f); + } + break; + case RIGID_BLENDED_TYPE: + { + IPhyBlendedRigidVertex* pBlendedRigidVertex = (IPhyBlendedRigidVertex*)pRigidVertex; + int cnt = pBlendedRigidVertex->GetNumberNodes(); + CVertexDef* pVertex = AddVertex(); + for (int i = 0; i < cnt; i++) + { + INode* node = pBlendedRigidVertex->GetNode(i); + R_ASSERT(node); + LPCSTR nm = node->GetName(); + // get bone and create vertex + int boneId = AddBone(node, matMesh, pExport); + if (BONE_NONE == boneId) { + ERR("Invalid bone: ", node->GetName()); + bRes = FALSE; + } + else + pVertex->Append(boneId, pBlendedRigidVertex->GetWeight(i)); + } + } + break; + } + + // release vertex + pContext->ReleaseVertexInterface(pRigidVertex); + + EConsole.ProgressInc(); + + if (!bRes) break; + } + EConsole.ProgressEnd(); + + if (!bRes) return FALSE; + + static int remap[3]; + if (U.m_SkinFlipFaces) { + remap[0] = 0; + remap[1] = 1; + remap[2] = 2; + } + else + { + remap[0] = 0; + remap[1] = 2; + remap[2] = 1; + } + + // Process mesh + // Get object from node. Abort if no object. + Log("..Transforming mesh"); + BOOL bDeleteTriObject; + R_ASSERT(pObject); + TriObject* pTriObject = GetTriObjectFromObjRef(pObject, &bDeleteTriObject); + if (!pTriObject) { + ERR("Can't create tri object."); + return FALSE; + } + Mesh& M = pTriObject->mesh; + + // Vertices + { + // check match with + int iNumVert = M.getNumVerts(); + if (!(iNumVert == numVertices && iNumVert == m_Vertices.size())) { + ERR("Non attached vertices found."); + if (bDeleteTriObject) delete (pTriObject); + return FALSE; + } + + // transform vertices + for (int i = 0; i < iNumVert; i++) + { + Point3 P = M.getVert(i); + Point3 T = matMesh.PointTransform(P); + T *= m_fGlobalScale; + m_Vertices[i]->SetPosition(T); + } + } + + Log("..Parsing materials"); + // Parse Materials + m_MtlMain = m_MeshNode->GetMtl(); + R_ASSERT(m_MtlMain); + + DWORD cSubMaterials = m_MtlMain->NumSubMtls(); + if (cSubMaterials < 1) { + // Count the material itself as a submaterial. + cSubMaterials = 1; + } + + // build normals + M.buildRenderNormals(); + + Log("..Converting vertices"); + // our Faces and Vertices + { + for (int i = 0; i < M.getNumFaces(); i++) + { + Face* gF = M.faces + i; + TVFace* tF = M.tvFace + i; + + int m_id = gF->getMatID(); + if (cSubMaterials == 1) { + m_id = 0; + } + else + { + // SDK recommends mod'ing the material ID by the valid # of materials, + // as sometimes a material number that's too high is returned. + m_id %= cSubMaterials; + } + + st_FACE* nF = new st_FACE(); + nF->m_id = m_id; + nF->sm_group = gF->getSmGroup(); + for (int VVV = 0; VVV < 3; VVV++) + { + int vert_id = gF->v[remap[VVV]]; + + CVertexDef& D = *(m_Vertices[vert_id]); + Point3& UV = M.tVerts[tF->t[remap[VVV]]]; + + st_VERT v; + v.Set(D); + v.P.set(D.P); + v.SetUV(UV.x, 1 - UV.y); + // v.sm_group = U.m_SkinSuppressSmoothGroup?0:gF->getSmGroup(); // smooth group + nF->v[VVV] = AddVert(v); + } + m_ExpFaces.push_back(nF); + } + } + if (bDeleteTriObject) delete (pTriObject); + } + UpdateParenting(); + + return bRes; }; BOOL MeshExpUtility::SaveAsSkin(const char* fname) { - BOOL bRes=true; - if (!(fname&&fname[0])) return false; + BOOL bRes = true; + if (!(fname && fname[0])) return false; - Log ("Exporting..." ); - Log ("-------------------------------------------------------" ); + Log("Exporting..."); + Log("-------------------------------------------------------"); - INode *pRootNode; - pRootNode = ip->GetRootNode(); - R_ASSERT (pRootNode); + INode* pRootNode; + pRootNode = ip->GetRootNode(); + R_ASSERT(pRootNode); - // export - CExporter *E = new CExporter(); - bRes = E->ExportSkin(pRootNode,fname); - xr_delete (E); + // export + CExporter* E = new CExporter(); + bRes = E->ExportSkin(pRootNode, fname); + xr_delete(E); - return bRes; + return bRes; } //------------------------------------------------------------------- -BOOL MeshExpUtility::SaveSkinKeys(LPCSTR fname){ - BOOL bRes=true; - if (!(fname&&fname[0])) return false; +BOOL MeshExpUtility::SaveSkinKeys(LPCSTR fname) +{ + BOOL bRes = true; + if (!(fname && fname[0])) return false; - Log ("Exporting Skin Keys..." ); - Log ("-------------------------------------------------------" ); + Log("Exporting Skin Keys..."); + Log("-------------------------------------------------------"); - INode *pRootNode; - pRootNode = ip->GetRootNode(); - R_ASSERT (pRootNode); + INode* pRootNode; + pRootNode = ip->GetRootNode(); + R_ASSERT(pRootNode); - // export - CExporter *E = new CExporter(); - bRes = E->ExportMotion(pRootNode,fname); - xr_delete(E); + // export + CExporter* E = new CExporter(); + bRes = E->ExportMotion(pRootNode, fname); + xr_delete(E); - return bRes; + return bRes; } //------------------------------------------------------------------- diff --git a/src/plugins/Max/Export/Exporter.h b/src/plugins/Max/Export/Exporter.h index 42a7f98f33d..39c75bd3dce 100644 --- a/src/plugins/Max/Export/Exporter.h +++ b/src/plugins/Max/Export/Exporter.h @@ -1,98 +1,112 @@ #pragma once +#include "plugins/Shared/Face.h" #include "plugins/Shared/Helper.h" #include "plugins/Shared/bonedef.h" -#include "plugins/Shared/Face.h" -DEFINE_VECTOR(INode*,INodeVec,INodeIt); +DEFINE_VECTOR(INode*, INodeVec, INodeIt); //----------------------------------------------------------------------------- -IC void ERR(LPCSTR s, LPCSTR dop="") -{ - Msg("!Error: %s%s",s,dop); +IC void ERR(LPCSTR s, LPCSTR dop = "") +{ + Msg("!Error: %s%s", s, dop); } IC int CGINTM(INode* node, int r) { - char* msg = 0; - switch (r) { - case MATRIX_RETURNED: return r; - case NODE_NOT_FOUND: msg = "NODE_NOT_FOUND"; break; - case NO_MATRIX_SAVED: msg = "NO_MATRIX_SAVED"; break; - case INVALID_MOD_POINTER: msg = "INVALID_MOD_POINTER"; break; - } - if (msg) - Msg("* '%s': GetInitNodeTM failed (%s)",node->GetName(),msg); - return r; + char* msg = 0; + switch (r) + { + case MATRIX_RETURNED: return r; + case NODE_NOT_FOUND: msg = "NODE_NOT_FOUND"; break; + case NO_MATRIX_SAVED: msg = "NO_MATRIX_SAVED"; break; + case INVALID_MOD_POINTER: msg = "INVALID_MOD_POINTER"; break; + } + if (msg) Msg("* '%s': GetInitNodeTM failed (%s)", node->GetName(), msg); + return r; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -class CExporter +class CExporter { - enum EStyle{ - eExportUndef, - eExportSkin, - eExportMotion - }; - EStyle m_Style; - BOOL m_bHasError; + enum EStyle + { + eExportUndef, + eExportSkin, + eExportMotion + }; + EStyle m_Style; + BOOL m_bHasError; + public: - BOOL m_bFindMesh; - INodeVec m_AllBones; - BoneDefVec m_Bones; - VertexDefVec m_Vertices; + BOOL m_bFindMesh; + INodeVec m_AllBones; + BoneDefVec m_Bones; + VertexDefVec m_Vertices; - Mtl* m_MtlMain; - INode* m_MeshNode; + Mtl* m_MtlMain; + INode* m_MeshNode; - // prepared - ExpVertVec m_ExpVertices; - ExpFaceVec m_ExpFaces; + // prepared + ExpVertVec m_ExpVertices; + ExpFaceVec m_ExpFaces; + + // global scale + float m_fGlobalScale; - // global scale - float m_fGlobalScale; private: - void ScanBones (INode *pNode); - void ScanMesh (INode *pNode); - BOOL Capture (); - int AddVert (const st_VERT& pTestV) - { - for (ExpVertIt vI=m_ExpVertices.begin(); vI!=m_ExpVertices.end(); vI++) - if ((*vI)->similar(pTestV)) return vI-m_ExpVertices.begin(); + void ScanBones(INode* pNode); + void ScanMesh(INode* pNode); + BOOL Capture(); + int AddVert(const st_VERT& pTestV) + { + for (ExpVertIt vI = m_ExpVertices.begin(); vI != m_ExpVertices.end(); vI++) + if ((*vI)->similar(pTestV)) return vI - m_ExpVertices.begin(); + + st_VERT* V = new st_VERT(); + *V = pTestV; + m_ExpVertices.push_back(V); + return m_ExpVertices.size() - 1; + } - st_VERT* V = new st_VERT(); - *V = pTestV; - m_ExpVertices.push_back(V); - return m_ExpVertices.size()-1; - } public: - //----------------------------------------------------------------------------- - CVertexDef* AddVertex () - { - CVertexDef* V = new CVertexDef(); - m_Vertices.push_back(V); - return V; - } - //----------------------------------------------------------------------------- - CBoneDef* FindBone (LPCSTR name) - { - if (name&&name[0]){ - string nm = Helper::ConvertSpace(string(name)); - for (BoneDefIt it=m_Bones.begin(); it!=m_Bones.end(); it++) - if ((*it)->name==nm) return *it; - return 0; - }else - return 0; - } - void UpdateParenting() - { - for (BoneDefIt it=m_Bones.begin(); it!=m_Bones.end(); it++) - (*it)->parent = FindBone((*it)->GetParentName()); - } - int AddBone(INode* pNode, Matrix3 &matMesh, IPhysiqueExport* pExport); + //----------------------------------------------------------------------------- + CVertexDef* AddVertex() + { + CVertexDef* V = new CVertexDef(); + m_Vertices.push_back(V); + return V; + } + //----------------------------------------------------------------------------- + CBoneDef* FindBone(LPCSTR name) + { + if (name && name[0]) { + string nm = Helper::ConvertSpace(string(name)); + for (BoneDefIt it = m_Bones.begin(); it != m_Bones.end(); it++) + if ((*it)->name == nm) return *it; + return 0; + } + else + return 0; + } + void UpdateParenting() + { + for (BoneDefIt it = m_Bones.begin(); it != m_Bones.end(); it++) + (*it)->parent = FindBone((*it)->GetParentName()); + } + int AddBone(INode* pNode, Matrix3& matMesh, IPhysiqueExport* pExport); + public: - CExporter (){ m_bHasError=FALSE; m_MtlMain=0; m_Style=eExportUndef; m_bFindMesh = FALSE; m_fGlobalScale=1.f; m_MeshNode=0;}; - virtual ~CExporter (); - BOOL ExportSkin (INode *pNode, LPCSTR fname); - BOOL ExportMotion(INode *pNode, LPCSTR fname); + CExporter() + { + m_bHasError = FALSE; + m_MtlMain = 0; + m_Style = eExportUndef; + m_bFindMesh = FALSE; + m_fGlobalScale = 1.f; + m_MeshNode = 0; + }; + virtual ~CExporter(); + BOOL ExportSkin(INode* pNode, LPCSTR fname); + BOOL ExportMotion(INode* pNode, LPCSTR fname); }; diff --git a/src/plugins/Max/Export/ExporterMotion.cpp b/src/plugins/Max/Export/ExporterMotion.cpp index ac31b0996a8..8ce04f0fe16 100644 --- a/src/plugins/Max/Export/ExporterMotion.cpp +++ b/src/plugins/Max/Export/ExporterMotion.cpp @@ -5,87 +5,118 @@ #include "Exporter.h" #include "MeshExpUtility.h" -#include "editors/ECore/Editor/EditObject.h" #include "editors/ECore/Editor/EditMesh.h" +#include "editors/ECore/Editor/EditObject.h" #include "xrCore/Animation/Bone.hpp" -#include "xrCore/Animation/Motion.hpp" #include "xrCore/Animation/Envelope.hpp" +#include "xrCore/Animation/Motion.hpp" BOOL CExporter::ExportMotion(INode* pNode, LPCSTR fname) { - m_Style = eExportMotion; - ScanBones (pNode); - int i = U.ip->GetSelNodeCount(); - while (i--) ScanMesh(U.ip->GetSelNode(i)); - if (!Capture()) return FALSE; - if (m_bHasError) return FALSE; + m_Style = eExportMotion; + ScanBones(pNode); + int i = U.ip->GetSelNodeCount(); + while (i--) + ScanMesh(U.ip->GetSelNode(i)); + if (!Capture()) return FALSE; + if (m_bHasError) return FALSE; + + int iFPS = GetFrameRate(); + int iTPF = GetTicksPerFrame(); + int iStartTick = U.ip->GetAnimRange().Start(); + int iEndTick = U.ip->GetAnimRange().End(); - int iFPS = GetFrameRate(); - int iTPF = GetTicksPerFrame(); - int iStartTick = U.ip->GetAnimRange().Start(); - int iEndTick = U.ip->GetAnimRange().End(); + // build motion + CSMotion* MOT = new CSMotion(); + MOT->SetParam(iStartTick / iTPF, iEndTick / iTPF, (float)iFPS); + string64 nm; + _splitpath(fname, 0, 0, nm, 0); + MOT->SetName(nm); - // build motion - CSMotion* MOT = new CSMotion(); - MOT->SetParam (iStartTick/iTPF,iEndTick/iTPF,(float)iFPS); - string64 nm; _splitpath(fname,0,0,nm,0); - MOT->SetName (nm); + BoneMotionVec& BMVec = MOT->BoneMotions(); + BMVec.reserve(m_Bones.size()); - BoneMotionVec& BMVec= MOT->BoneMotions(); - BMVec.reserve (m_Bones.size()); + EConsole.ProgressStart((float)m_Bones.size(), "..Exporting per bone motions"); + Fmatrix tmBone; + for (int boneId = 0; boneId < int(m_Bones.size()); boneId++) + { + CBoneDef* bone = m_Bones[boneId]; + // Log("Bone: ",bone->name.c_str()); - EConsole.ProgressStart((float)m_Bones.size(),"..Exporting per bone motions"); - Fmatrix tmBone; - for(int boneId = 0; boneId < int(m_Bones.size()); boneId++){ - CBoneDef* bone = m_Bones[boneId]; - //Log("Bone: ",bone->name.c_str()); + BMVec.push_back(st_BoneMotion()); + st_BoneMotion& BM = BMVec.back(); + BM.SetName(bone->name.c_str()); - BMVec.push_back(st_BoneMotion()); - st_BoneMotion& BM = BMVec.back(); - BM.SetName(bone->name.c_str()); + BM.envs[ctPositionX] = new CEnvelope(); + BM.envs[ctPositionY] = new CEnvelope(); + BM.envs[ctPositionZ] = new CEnvelope(); + BM.envs[ctRotationH] = new CEnvelope(); + BM.envs[ctRotationP] = new CEnvelope(); + BM.envs[ctRotationB] = new CEnvelope(); - BM.envs[ctPositionX] = new CEnvelope(); - BM.envs[ctPositionY] = new CEnvelope(); - BM.envs[ctPositionZ] = new CEnvelope(); - BM.envs[ctRotationH] = new CEnvelope(); - BM.envs[ctRotationP] = new CEnvelope(); - BM.envs[ctRotationB] = new CEnvelope(); + BM.envs[ctPositionX]->behavior[0] = 1; + BM.envs[ctPositionX]->behavior[1] = 1; + BM.envs[ctPositionY]->behavior[0] = 1; + BM.envs[ctPositionY]->behavior[1] = 1; + BM.envs[ctPositionZ]->behavior[0] = 1; + BM.envs[ctPositionZ]->behavior[1] = 1; + BM.envs[ctRotationH]->behavior[0] = 1; + BM.envs[ctRotationH]->behavior[1] = 1; + BM.envs[ctRotationP]->behavior[0] = 1; + BM.envs[ctRotationP]->behavior[1] = 1; + BM.envs[ctRotationB]->behavior[0] = 1; + BM.envs[ctRotationB]->behavior[1] = 1; - BM.envs[ctPositionX]->behavior[0]=1; BM.envs[ctPositionX]->behavior[1]=1; - BM.envs[ctPositionY]->behavior[0]=1; BM.envs[ctPositionY]->behavior[1]=1; - BM.envs[ctPositionZ]->behavior[0]=1; BM.envs[ctPositionZ]->behavior[1]=1; - BM.envs[ctRotationH]->behavior[0]=1; BM.envs[ctRotationH]->behavior[1]=1; - BM.envs[ctRotationP]->behavior[0]=1; BM.envs[ctRotationP]->behavior[1]=1; - BM.envs[ctRotationB]->behavior[0]=1; BM.envs[ctRotationB]->behavior[1]=1; - - TimeValue tick; - st_Key *X,*Y,*Z,*H,*P,*B; - for(tick = iStartTick; tick < iEndTick; tick+=iTPF) - { - X = new st_Key(); Y = new st_Key(); Z = new st_Key(); - H = new st_Key(); P = new st_Key(); B = new st_Key(); - BM.envs[ctPositionX]->keys.push_back(X); BM.envs[ctPositionY]->keys.push_back(Y); BM.envs[ctPositionZ]->keys.push_back(Z); - BM.envs[ctRotationH]->keys.push_back(H); BM.envs[ctRotationP]->keys.push_back(P); BM.envs[ctRotationB]->keys.push_back(B); - // get the bone transformation matrix - bone->CalculateLocalMatrix(tick,tmBone); + TimeValue tick; + st_Key *X, *Y, *Z, *H, *P, *B; + for (tick = iStartTick; tick < iEndTick; tick += iTPF) + { + X = new st_Key(); + Y = new st_Key(); + Z = new st_Key(); + H = new st_Key(); + P = new st_Key(); + B = new st_Key(); + BM.envs[ctPositionX]->keys.push_back(X); + BM.envs[ctPositionY]->keys.push_back(Y); + BM.envs[ctPositionZ]->keys.push_back(Z); + BM.envs[ctRotationH]->keys.push_back(H); + BM.envs[ctRotationP]->keys.push_back(P); + BM.envs[ctRotationB]->keys.push_back(B); + // get the bone transformation matrix + bone->CalculateLocalMatrix(tick, tmBone); - float displacedTime = (float)(tick)/(float)(iTPF*iFPS); + float displacedTime = (float)(tick) / (float)(iTPF * iFPS); - float h,p,b, x,y,z; - tmBone.getHPB(h,p,b); + float h, p, b, x, y, z; + tmBone.getHPB(h, p, b); - x=tmBone.c.x; y=tmBone.c.y; z=tmBone.c.z; - X->time = displacedTime; Y->time = displacedTime; Z->time = displacedTime; - H->time = displacedTime; P->time = displacedTime; B->time = displacedTime; - X->shape = 4; Y->shape = 4; Z->shape = 4; - H->shape = 4; P->shape = 4; B->shape = 4; - X->value = x; Y->value = y; Z->value = z; - H->value =-h; P->value =-p; B->value =-b; - } - EConsole.ProgressInc(); - } - EConsole.ProgressEnd(); - MOT->SaveMotion(fname); - xr_delete(MOT); - return TRUE; + x = tmBone.c.x; + y = tmBone.c.y; + z = tmBone.c.z; + X->time = displacedTime; + Y->time = displacedTime; + Z->time = displacedTime; + H->time = displacedTime; + P->time = displacedTime; + B->time = displacedTime; + X->shape = 4; + Y->shape = 4; + Z->shape = 4; + H->shape = 4; + P->shape = 4; + B->shape = 4; + X->value = x; + Y->value = y; + Z->value = z; + H->value = -h; + P->value = -p; + B->value = -b; + } + EConsole.ProgressInc(); + } + EConsole.ProgressEnd(); + MOT->SaveMotion(fname); + xr_delete(MOT); + return TRUE; } diff --git a/src/plugins/Max/Export/ExporterSkin.cpp b/src/plugins/Max/Export/ExporterSkin.cpp index b946b370918..1d24a1b26ba 100644 --- a/src/plugins/Max/Export/ExporterSkin.cpp +++ b/src/plugins/Max/Export/ExporterSkin.cpp @@ -1,29 +1,30 @@ #include "stdafx.h" #pragma hdrstop -#include "exporter.h" -#include "editors/ECore/Editor/EditObject.h" #include "MeshExpUtility.h" +#include "editors/ECore/Editor/EditObject.h" +#include "exporter.h" //---------------------------------------------------------------------------------------------- BOOL CExporter::ExportSkin(INode* pNode, LPCSTR fname) { - m_Style = eExportSkin; -// ScanBones (pNode); + m_Style = eExportSkin; + // ScanBones (pNode); - int i = U.ip->GetSelNodeCount(); - while (i--) ScanMesh(U.ip->GetSelNode(i)); + int i = U.ip->GetSelNodeCount(); + while (i--) + ScanMesh(U.ip->GetSelNode(i)); - if (!Capture()) return FALSE; - if (m_bHasError) return FALSE; - CEditableObject* OBJECT = new CEditableObject("object"); - OBJECT->SetVersionToCurrent(TRUE,TRUE); - if (!OBJECT->ImportMAXSkeleton(this)){ - xr_delete(OBJECT); - return FALSE; - } - OBJECT->Optimize (); + if (!Capture()) return FALSE; + if (m_bHasError) return FALSE; + CEditableObject* OBJECT = new CEditableObject("object"); + OBJECT->SetVersionToCurrent(TRUE, TRUE); + if (!OBJECT->ImportMAXSkeleton(this)) { + xr_delete(OBJECT); + return FALSE; + } + OBJECT->Optimize(); OBJECT->Save(fname); - xr_delete (OBJECT); - return TRUE; + xr_delete(OBJECT); + return TRUE; }; diff --git a/src/plugins/Max/Export/FS2.CPP b/src/plugins/Max/Export/FS2.CPP index 0302b198089..101beb1945a 100644 --- a/src/plugins/Max/Export/FS2.CPP +++ b/src/plugins/Max/Export/FS2.CPP @@ -6,18 +6,19 @@ // memory CMemoryStream::~CMemoryStream() { - xr_free(data); + xr_free(data); } void CMemoryStream::write(const void* ptr, u32 count) { - if (position+count > mem_size) { - // reallocate - if (mem_size==0) mem_size=128; - while (mem_size <= (position+count)) mem_size*=2; - data = (u8*)xr_realloc(data,mem_size); - } - CopyMemory(data+position,ptr,count); - position+=count; - if (position>file_size) file_size=position; + if (position + count > mem_size) { + // reallocate + if (mem_size == 0) mem_size = 128; + while (mem_size <= (position + count)) + mem_size *= 2; + data = (u8*)xr_realloc(data, mem_size); + } + CopyMemory(data + position, ptr, count); + position += count; + if (position > file_size) file_size = position; } diff --git a/src/plugins/Max/Export/FS2.H b/src/plugins/Max/Export/FS2.H index e8d328ba356..478abc61a65 100644 --- a/src/plugins/Max/Export/FS2.H +++ b/src/plugins/Max/Export/FS2.H @@ -3,258 +3,322 @@ #pragma once -class ENGINE_API IBasicStream { +class ENGINE_API IBasicStream +{ private: - std::stack chunk_pos; - std::stack subchunk_pos; - void revbytes ( void *bp, int elsize, int elcount ) - { - register unsigned char *p, *q; + std::stack chunk_pos; + std::stack subchunk_pos; + void revbytes(void* bp, int elsize, int elcount) + { + register unsigned char *p, *q; + + p = (unsigned char*)bp; - p = ( unsigned char * ) bp; + if (elsize == 2) { + q = p + 1; + while (elcount--) + { + *p ^= *q; + *q ^= *p; + *p ^= *q; + p += 2; + q += 2; + } + return; + } - if ( elsize == 2 ) { - q = p + 1; - while ( elcount-- ) { - *p ^= *q; - *q ^= *p; - *p ^= *q; - p += 2; - q += 2; - } - return; - } + while (elcount--) + { + q = p + elsize - 1; + while (p < q) + { + *p ^= *q; + *q ^= *p; + *p ^= *q; + ++p; + --q; + } + p += elsize >> 1; + } + } - while ( elcount-- ) { - q = p + elsize - 1; - while ( p < q ) { - *p ^= *q; - *q ^= *p; - *p ^= *q; - ++p; - --q; - } - p += elsize >> 1; - } - } public: - virtual ~IBasicStream () - { - R_ASSERT(subchunk_pos.empty()); - while (!chunk_pos.empty()) - close_chunk(); - } + virtual ~IBasicStream() + { + R_ASSERT(subchunk_pos.empty()); + while (!chunk_pos.empty()) + close_chunk(); + } - // kernel - virtual void write (const void* ptr, u32 count) = 0; - virtual void seek (u32 pos) = 0; - virtual u32 tell () = 0; + // kernel + virtual void write(const void* ptr, u32 count) = 0; + virtual void seek(u32 pos) = 0; + virtual u32 tell() = 0; - // generalized writing functions - IC void w_u32 (u32 d) { revbytes(&d,4,1); write(&d,sizeof(u32)); } - IC void w_u16 (u16 d) { revbytes(&d,2,1); write(&d,sizeof(u16)); } - IC void w_float (float d) { revbytes(&d,4,1); write(&d,sizeof(float)); } - IC void w_u8 (u8 d) { write(&d,sizeof(u8)); } - IC void w_string(const char *p) - { - write(p,xr_strlen(p)); - w_u8(13); - w_u8(10); + // generalized writing functions + IC void w_u32(u32 d) + { + revbytes(&d, 4, 1); + write(&d, sizeof(u32)); + } + IC void w_u16(u16 d) + { + revbytes(&d, 2, 1); + write(&d, sizeof(u16)); + } + IC void w_float(float d) + { + revbytes(&d, 4, 1); + write(&d, sizeof(float)); + } + IC void w_u8(u8 d) { write(&d, sizeof(u8)); } + IC void w_string(const char* p) + { + write(p, xr_strlen(p)); + w_u8(13); + w_u8(10); + } + IC void w_stringZ(const char* p) + { + write(p, xr_strlen(p) + 1); + if (!(xr_strlen(p) & 1)) w_u8(0); + } + IC void w_vector(Fvector v) + { + revbytes(&v, 4, 3); + write(&v, 3 * sizeof(float)); + } + IC void w_color(Fcolor c) + { + revbytes(&c, 4, 4); + write(&c, 4 * sizeof(float)); } - IC void w_stringZ(const char *p) { write(p,xr_strlen(p)+1); if (!(xr_strlen(p)&1)) w_u8(0);} - IC void w_vector(Fvector v) { revbytes(&v,4,3); write(&v,3*sizeof(float)); } - IC void w_color (Fcolor c) { revbytes(&c,4,4); write(&c,4*sizeof(float)); } - // generalized chunking - IC void open_chunk (u32 type) - { - w_u32(type); - chunk_pos.push(tell()); - w_u32(0); // the place for 'size' - } - IC void close_chunk () - { - VERIFY(!chunk_pos.empty()); + // generalized chunking + IC void open_chunk(u32 type) + { + w_u32(type); + chunk_pos.push(tell()); + w_u32(0); // the place for 'size' + } + IC void close_chunk() + { + VERIFY(!chunk_pos.empty()); - int pos = tell(); - seek (chunk_pos.top()); - w_u32 (pos-chunk_pos.top()-4); - seek (pos); - chunk_pos.pop(); - } - // generalized chunking - IC void open_subchunk (u32 type) - { - w_u32(type); - subchunk_pos.push((u16)tell()); - w_u16(0); // the place for 'size' - } - IC void close_subchunk () - { - VERIFY(!subchunk_pos.empty()); + int pos = tell(); + seek(chunk_pos.top()); + w_u32(pos - chunk_pos.top() - 4); + seek(pos); + chunk_pos.pop(); + } + // generalized chunking + IC void open_subchunk(u32 type) + { + w_u32(type); + subchunk_pos.push((u16)tell()); + w_u16(0); // the place for 'size' + } + IC void close_subchunk() + { + VERIFY(!subchunk_pos.empty()); - int pos = tell(); - seek (subchunk_pos.top()); - w_u16 (u16(pos-subchunk_pos.top()-2)); - seek (pos); - subchunk_pos.pop(); - } - IC void write_chunk (u32 type, void* data, u32 size) - { - open_chunk (type); - write (data,size); - close_chunk (); - } + int pos = tell(); + seek(subchunk_pos.top()); + w_u16(u16(pos - subchunk_pos.top() - 2)); + seek(pos); + subchunk_pos.pop(); + } + IC void write_chunk(u32 type, void* data, u32 size) + { + open_chunk(type); + write(data, size); + close_chunk(); + } }; class ENGINE_API CMemoryStream : public IBasicStream { - u8* data; - u32 position; - u32 mem_size; - u32 file_size; -public: - CMemoryStream() { - data = 0; - position = 0; - mem_size = 0; - file_size = 0; - } - virtual ~CMemoryStream(); + u8* data; + u32 position; + u32 mem_size; + u32 file_size; - // kernel - virtual void write (const void* ptr, u32 count); +public: + CMemoryStream() + { + data = 0; + position = 0; + mem_size = 0; + file_size = 0; + } + virtual ~CMemoryStream(); - virtual void seek (u32 pos) - { position = pos; } - virtual u32 tell () - { return position; } + // kernel + virtual void write(const void* ptr, u32 count); - // specific - u8* pointer () { return data; } - u32 size () { return file_size; } - void clear () { file_size=0; position=0; } - void SaveTo (const char* fn) - { - #ifdef M_BORLAND - int H = open(fn,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IREAD|S_IWRITE); - #else - int H = _open(fn,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IREAD|S_IWRITE); - #endif - R_ASSERT(H>0); - _write(H,pointer(),size()); + virtual void seek(u32 pos) { position = pos; } + virtual u32 tell() { return position; } + // specific + u8* pointer() { return data; } + u32 size() { return file_size; } + void clear() + { + file_size = 0; + position = 0; + } + void SaveTo(const char* fn) + { +#ifdef M_BORLAND + int H = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); +#else + int H = _open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); +#endif + R_ASSERT(H > 0); + _write(H, pointer(), size()); _close(H); - } + } }; #include "lwchunks.h" -class ENGINE_API CLWMemoryStream: public CMemoryStream{ - IC void make_ord( int nbloks, int index, unsigned char *ord ) - { - int i, d; +class ENGINE_API CLWMemoryStream : public CMemoryStream +{ + IC void make_ord(int nbloks, int index, unsigned char* ord) + { + int i, d; - for ( i = 8, d = 16; i < 128; i *= 2 ){ - if ( i >= nbloks ) break; - d /= 2; - } - ord[ 0 ] = u8(128 + index * d); - ord[ 1 ] = 0; - } + for (i = 8, d = 16; i < 128; i *= 2) + { + if (i >= nbloks) break; + d /= 2; + } + ord[0] = u8(128 + index * d); + ord[1] = 0; + } public: - IC void begin_save () { open_chunk(ID_FORM); w_u32(ID_LWO2);} - IC void end_save (LPCSTR name) { close_chunk(); SaveTo(name);} - IC void w_layer (u16 number, LPCSTR name){ - open_chunk(ID_LAYR); - w_u16 (number); // num - w_u16 (0); - w_float (0); // pivot - w_float (0); - w_float (0); - w_stringZ(name); - close_chunk(); - } - IC void w_vx (int idx) - { - if (idx>=0xFF00){ - idx|=0xff000000; + IC void begin_save() + { + open_chunk(ID_FORM); + w_u32(ID_LWO2); + } + IC void end_save(LPCSTR name) + { + close_chunk(); + SaveTo(name); + } + IC void w_layer(u16 number, LPCSTR name) + { + open_chunk(ID_LAYR); + w_u16(number); // num + w_u16(0); + w_float(0); // pivot + w_float(0); + w_float(0); + w_stringZ(name); + close_chunk(); + } + IC void w_vx(int idx) + { + if (idx >= 0xFF00) { + idx |= 0xff000000; w_u32(idx); - }else - w_u16((u16)idx); + } + else + w_u16((u16)idx); } - IC void w_face3 (int i0, int i1, int i2) - { w_u16(3); w_vx(i0); w_vx(i1); w_vx(i2); } - - IC void begin_vmap (BOOL polymap, u32 type, int dim, LPCSTR name){ - open_chunk(polymap?ID_VMAD:ID_VMAP); - w_u32 (type); - w_u16 ((u16)dim); - R_ASSERT2(name&&name[0],"Empty vmap name!"); - w_stringZ(name); - } - IC void end_vmap () - { close_chunk();} + IC void w_face3(int i0, int i1, int i2) + { + w_u16(3); + w_vx(i0); + w_vx(i1); + w_vx(i2); + } - IC void w_vmap (int v_index, int dim, float* uv) - { w_vx(v_index); w_float(uv[0]); if (dim==2) w_float(1.f-uv[1]); } + IC void begin_vmap(BOOL polymap, u32 type, int dim, LPCSTR name) + { + open_chunk(polymap ? ID_VMAD : ID_VMAP); + w_u32(type); + w_u16((u16)dim); + R_ASSERT2(name && name[0], "Empty vmap name!"); + w_stringZ(name); + } + IC void end_vmap() { close_chunk(); } + IC void w_vmap(int v_index, int dim, float* uv) + { + w_vx(v_index); + w_float(uv[0]); + if (dim == 2) w_float(1.f - uv[1]); + } - IC void w_vmad (int v_index, int f_index, int dim, float* uv) - { w_vx(v_index); w_vx(f_index); w_float(uv[0]); if (dim==2) w_float(1.f-uv[1]); } + IC void w_vmad(int v_index, int f_index, int dim, float* uv) + { + w_vx(v_index); + w_vx(f_index); + w_float(uv[0]); + if (dim == 2) w_float(1.f - uv[1]); + } - IC void Wsurface(LPCSTR name, BOOL b2Sided, u16 image, LPCSTR vmap, LPCSTR sh_eng, LPCSTR sh_comp){ - // surf screen - char ord[2]; - open_chunk(ID_SURF); - w_stringZ(name); - w_stringZ(""); - open_subchunk(ID_COLR); - w_float(1.f);w_float(1.f);w_float(1.f); w_u16(0); - close_subchunk(); - open_subchunk(ID_SIDE); - w_u16(u16(b2Sided?3:1)); - close_subchunk(); - open_subchunk(ID_BLOK); - open_subchunk(ID_IMAP); - make_ord(128,0,(u8*)ord); - w_stringZ(ord); - open_subchunk(ID_CHAN); - w_u32(ID_COLR); - close_subchunk(); - open_subchunk(ID_OPAC); - w_u16(0); - w_float(1.f); - w_u16(0); - close_subchunk(); - open_subchunk(ID_ENAB); - w_u16(1); - close_subchunk(); - close_subchunk(); - open_subchunk(ID_PROJ); - w_u16(5); - close_subchunk(); - open_subchunk(ID_IMAG); - w_u16(image); - close_subchunk(); - open_subchunk(ID_VMAP); - w_stringZ(vmap); - close_subchunk(); - open_subchunk(ID_AAST); - w_u16(1); w_float(1.f); - close_subchunk(); - open_subchunk(ID_PIXB); - w_u16(1); - close_subchunk(); - open_subchunk(ID_STCK); - w_float(0.f); w_u16(0); - close_subchunk(); - open_subchunk(ID_TAMP); - w_float(1.f); w_u16(0); - close_subchunk(); - close_subchunk(); - // plugins -/* open_subchunk(ID_BLOK); + IC void Wsurface(LPCSTR name, BOOL b2Sided, u16 image, LPCSTR vmap, LPCSTR sh_eng, LPCSTR sh_comp) + { + // surf screen + char ord[2]; + open_chunk(ID_SURF); + w_stringZ(name); + w_stringZ(""); + open_subchunk(ID_COLR); + w_float(1.f); + w_float(1.f); + w_float(1.f); + w_u16(0); + close_subchunk(); + open_subchunk(ID_SIDE); + w_u16(u16(b2Sided ? 3 : 1)); + close_subchunk(); + open_subchunk(ID_BLOK); + open_subchunk(ID_IMAP); + make_ord(128, 0, (u8*)ord); + w_stringZ(ord); + open_subchunk(ID_CHAN); + w_u32(ID_COLR); + close_subchunk(); + open_subchunk(ID_OPAC); + w_u16(0); + w_float(1.f); + w_u16(0); + close_subchunk(); + open_subchunk(ID_ENAB); + w_u16(1); + close_subchunk(); + close_subchunk(); + open_subchunk(ID_PROJ); + w_u16(5); + close_subchunk(); + open_subchunk(ID_IMAG); + w_u16(image); + close_subchunk(); + open_subchunk(ID_VMAP); + w_stringZ(vmap); + close_subchunk(); + open_subchunk(ID_AAST); + w_u16(1); + w_float(1.f); + close_subchunk(); + open_subchunk(ID_PIXB); + w_u16(1); + close_subchunk(); + open_subchunk(ID_STCK); + w_float(0.f); + w_u16(0); + close_subchunk(); + open_subchunk(ID_TAMP); + w_float(1.f); + w_u16(0); + close_subchunk(); + close_subchunk(); + // plugins + /* open_subchunk(ID_BLOK); open_subchunk(ID_SHDR); make_ord(128,0,(u8*)ord); w_stringZ(ord); @@ -274,8 +338,8 @@ public: close_subchunk(); close_subchunk(); close_subchunk(); -*/ close_chunk(); - } +*/ close_chunk(); + } }; #endif diff --git a/src/plugins/Max/Export/MeshExpPlugin.cpp b/src/plugins/Max/Export/MeshExpPlugin.cpp index de81929fec0..0f9fe7fc979 100644 --- a/src/plugins/Max/Export/MeshExpPlugin.cpp +++ b/src/plugins/Max/Export/MeshExpPlugin.cpp @@ -5,18 +5,18 @@ #include "MeshExpUtility.h" - //------------------------------------------------------------------- // Class Descriptor -class MeshExpUtilityClassDesc : public ClassDesc { - public: - int IsPublic() { return 1; } - void * Create( BOOL loading ) { return &U; } - const TCHAR * ClassName() { return "S.T.A.L.K.E.R. Export"; } - SClass_ID SuperClassID() { return UTILITY_CLASS_ID; } - Class_ID ClassID() { return Class_ID(EXP_UTILITY_CLASSID,0); } - const TCHAR* Category() { return "S.T.A.L.K.E.R. Export"; } +class MeshExpUtilityClassDesc : public ClassDesc +{ +public: + int IsPublic() { return 1; } + void* Create(BOOL loading) { return &U; } + const TCHAR* ClassName() { return "S.T.A.L.K.E.R. Export"; } + SClass_ID SuperClassID() { return UTILITY_CLASS_ID; } + Class_ID ClassID() { return Class_ID(EXP_UTILITY_CLASSID, 0); } + const TCHAR* Category() { return "S.T.A.L.K.E.R. Export"; } }; MeshExpUtility U; @@ -27,60 +27,52 @@ MeshExpUtilityClassDesc MeshExpUtilityClassDescCD; HINSTANCE hInstance; int controlsInit = FALSE; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, ULONG fdwReason, LPVOID lpvReserved) { - hInstance = hinstDLL; - - if ( !controlsInit ) { - controlsInit = TRUE; - Core._initialize("S.T.A.L.K.E.R.Plugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - FPU::m64r (); // ����� ����� ���� �� ��������� ���������� � 0 - InitCustomControls(hInstance); - InitCommonControls(); - ELog.Msg(mtInformation,"S.T.A.L.K.E.R. Object Export (ver. %d.%02d)",EXPORTER_VERSION,EXPORTER_BUILD); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - } - - switch(fdwReason) { - - case DLL_PROCESS_ATTACH: - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - - case DLL_PROCESS_DETACH: - Core._destroy(); - break; - } - return(TRUE); + hInstance = hinstDLL; + + if (!controlsInit) { + controlsInit = TRUE; + Core._initialize("S.T.A.L.K.E.R.Plugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + FPU::m64r(); // ����� ����� ���� �� ��������� ���������� � 0 + InitCustomControls(hInstance); + InitCommonControls(); + ELog.Msg(mtInformation, "S.T.A.L.K.E.R. Object Export (ver. %d.%02d)", EXPORTER_VERSION, EXPORTER_BUILD); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + } + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: break; + case DLL_THREAD_ATTACH: break; + case DLL_THREAD_DETACH: break; + + case DLL_PROCESS_DETACH: Core._destroy(); break; + } + return (TRUE); } - - -__declspec( dllexport ) const TCHAR * -LibDescription() { return "S.T.A.L.K.E.R. Mesh Export utility"; } - - -__declspec( dllexport ) int LibNumberClasses() { - return 1; +__declspec(dllexport) const TCHAR* LibDescription() +{ + return "S.T.A.L.K.E.R. Mesh Export utility"; } - -__declspec( dllexport ) ClassDesc* LibClassDesc(int i) { - switch(i) { - case 0: return &MeshExpUtilityClassDescCD; - default: return 0; - } +__declspec(dllexport) int LibNumberClasses() +{ + return 1; } - -__declspec( dllexport ) ULONG LibVersion() +__declspec(dllexport) ClassDesc* LibClassDesc(int i) { - return VERSION_3DSMAX; + switch (i) + { + case 0: return &MeshExpUtilityClassDescCD; + default: return 0; + } } - +__declspec(dllexport) ULONG LibVersion() +{ + return VERSION_3DSMAX; +} diff --git a/src/plugins/Max/Export/MeshExpUtility.cpp b/src/plugins/Max/Export/MeshExpUtility.cpp index f42d4271d8a..1dbcbecbb74 100644 --- a/src/plugins/Max/Export/MeshExpUtility.cpp +++ b/src/plugins/Max/Export/MeshExpUtility.cpp @@ -4,52 +4,35 @@ #pragma hdrstop #include "MeshExpUtility.h" -#include "xrCore/FileSystem.h" #include "MeshExpUtility.rh" -#include "editors/ECore/Editor/EditObject.h" #include "editors/ECore/Editor/EditMesh.h" +#include "editors/ECore/Editor/EditObject.h" +#include "xrCore/FileSystem.h" //------------------------------------------------------------------- // Dialog Handler for Utility - -static BOOL CALLBACK DefaultDlgProc( - HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK DefaultDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) { - - case WM_INITDIALOG: - U.Init(hWnd); - break; - - case WM_DESTROY: - U.Destroy(hWnd); - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_CLOSE: - U.iu->CloseUtility(); - break; - case IDC_EXPORT_AS_OBJECT: - U.ExportObject(); - break; - case IDC_EXPORT_AS_LWO: - U.ExportLWO(); - break; - case IDC_SKIN_EXPORT: - U.ExportSkin(); - break; - case IDC_SKIN_KEYS_EXPORT: - U.ExportSkinKeys(); - break; - } - break; - - - default: - return FALSE; - } - return TRUE; + switch (msg) + { + case WM_INITDIALOG: U.Init(hWnd); break; + + case WM_DESTROY: U.Destroy(hWnd); break; + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_CLOSE: U.iu->CloseUtility(); break; + case IDC_EXPORT_AS_OBJECT: U.ExportObject(); break; + case IDC_EXPORT_AS_LWO: U.ExportLWO(); break; + case IDC_SKIN_EXPORT: U.ExportSkin(); break; + case IDC_SKIN_KEYS_EXPORT: U.ExportSkinKeys(); break; + } + break; + + default: return FALSE; + } + return TRUE; } //------------------------------------------------------------------- @@ -57,327 +40,334 @@ static BOOL CALLBACK DefaultDlgProc( MeshExpUtility::MeshExpUtility() { - iu = 0; - ip = 0; - hPanel = 0; + iu = 0; + ip = 0; + hPanel = 0; - m_ObjectFlipFaces = false; - m_SkinFlipFaces = false; - m_SkinAllowDummy = false; + m_ObjectFlipFaces = false; + m_SkinFlipFaces = false; + m_SkinAllowDummy = false; } MeshExpUtility::~MeshExpUtility() { } - -void MeshExpUtility::BeginEditParams(Interface *ip,IUtil *iu) +void MeshExpUtility::BeginEditParams(Interface* ip, IUtil* iu) { - this->iu = iu; - this->ip = ip; - EConsole.Init( hInstance, 0 ); + this->iu = iu; + this->ip = ip; + EConsole.Init(hInstance, 0); - hPanel = ip->AddRollupPage(hInstance, MAKEINTRESOURCE(IDD_MWND), DefaultDlgProc, "S.T.A.L.K.E.R. Export", 0); + hPanel = ip->AddRollupPage(hInstance, MAKEINTRESOURCE(IDD_MWND), DefaultDlgProc, "S.T.A.L.K.E.R. Export", 0); } - -void MeshExpUtility::EndEditParams(Interface *ip,IUtil *iu) + +void MeshExpUtility::EndEditParams(Interface* ip, IUtil* iu) { - m_ObjectFlipFaces = IsDlgButtonChecked( hPanel, IDC_OBJECT_FLIPFACES ); - m_SkinFlipFaces = IsDlgButtonChecked( hPanel, IDC_SKIN_FLIPFACES ); - m_SkinAllowDummy = IsDlgButtonChecked( hPanel, IDC_SKIN_ALLOW_DUMMY ); - - EConsole.Clear(); - - this->iu = 0; - this->ip = 0; - ip->DeleteRollupPage(hPanel); - hPanel = 0; + m_ObjectFlipFaces = IsDlgButtonChecked(hPanel, IDC_OBJECT_FLIPFACES); + m_SkinFlipFaces = IsDlgButtonChecked(hPanel, IDC_SKIN_FLIPFACES); + m_SkinAllowDummy = IsDlgButtonChecked(hPanel, IDC_SKIN_ALLOW_DUMMY); + + EConsole.Clear(); + + this->iu = 0; + this->ip = 0; + ip->DeleteRollupPage(hPanel); + hPanel = 0; } -void MeshExpUtility::SelectionSetChanged(Interface *ip,IUtil *iu) +void MeshExpUtility::SelectionSetChanged(Interface* ip, IUtil* iu) { - RefreshExportList(); - UpdateSelectionListBox(); + RefreshExportList(); + UpdateSelectionListBox(); } void MeshExpUtility::Init(HWND hWnd) { - hPanel = hWnd; + hPanel = hWnd; - hItemList = GetDlgItem(hWnd, IDC_OBJLIST); + hItemList = GetDlgItem(hWnd, IDC_OBJLIST); - CheckDlgButton( hPanel, IDC_OBJECT_FLIPFACES, m_ObjectFlipFaces ); - CheckDlgButton( hPanel, IDC_SKIN_FLIPFACES, m_SkinFlipFaces ); - CheckDlgButton( hPanel, IDC_SKIN_ALLOW_DUMMY, m_SkinAllowDummy ); + CheckDlgButton(hPanel, IDC_OBJECT_FLIPFACES, m_ObjectFlipFaces); + CheckDlgButton(hPanel, IDC_SKIN_FLIPFACES, m_SkinFlipFaces); + CheckDlgButton(hPanel, IDC_SKIN_ALLOW_DUMMY, m_SkinAllowDummy); - RefreshExportList(); - UpdateSelectionListBox(); + RefreshExportList(); + UpdateSelectionListBox(); } void MeshExpUtility::Destroy(HWND hWnd) { } -void MeshExpUtility::RefreshExportList(){ - m_Items.clear(); - ExportItem item; - int i = ip->GetSelNodeCount(); - while( i-- ){ - item.pNode = ip->GetSelNode(i); - m_Items.push_back( item ); - } +void MeshExpUtility::RefreshExportList() +{ + m_Items.clear(); + ExportItem item; + int i = ip->GetSelNodeCount(); + while (i--) + { + item.pNode = ip->GetSelNode(i); + m_Items.push_back(item); + } } void MeshExpUtility::UpdateSelectionListBox() { - SendMessage( hItemList, LB_RESETCONTENT, 0, 0 ); - ExportItemIt it = m_Items.begin(); - for(;it!=m_Items.end();it++) - SendMessage( hItemList, LB_ADDSTRING, - 0,(LPARAM) it->pNode->GetName() ); + SendMessage(hItemList, LB_RESETCONTENT, 0, 0); + ExportItemIt it = m_Items.begin(); + for (; it != m_Items.end(); it++) + SendMessage(hItemList, LB_ADDSTRING, 0, (LPARAM)it->pNode->GetName()); } //------------------------------------------------------------------- BOOL MeshExpUtility::BuildObject(CEditableObject*& exp_obj, LPCSTR m_ExportName) { - bool bResult = true; - - if (m_ExportName[0]==0) return false; - - ELog.Msg(mtInformation,"Building object..." ); - char fname[256]; _splitpath( m_ExportName, 0, 0, fname, 0 ); - exp_obj = new CEditableObject(fname); - exp_obj->SetVersionToCurrent(TRUE,TRUE); - - ExportItemIt it = m_Items.begin(); - for(;it!=m_Items.end();it++){ - CEditableMesh *submesh = new CEditableMesh(exp_obj); - ELog.Msg(mtInformation,"Converting node '%s'...", it->pNode->GetName()); - if( submesh->Convert(it->pNode) ){ - // transform - Matrix3 mMatrix; - mMatrix = it->pNode->GetNodeTM(0)*Inverse(it->pNode->GetParentNode()->GetNodeTM(0)); - - Point3 r1 = mMatrix.GetRow(0); - Point3 r2 = mMatrix.GetRow(1); - Point3 r3 = mMatrix.GetRow(2); - Point3 r4 = mMatrix.GetRow(3); - Fmatrix m; m.identity(); - m.i.set(r1.x, r1.z, r1.y); - m.j.set(r2.x, r2.z, r2.y); - m.k.set(r3.x, r3.z, r3.y); - m.c.set(r4.x, r4.z, r4.y); - - submesh->Transform( m ); - // flip faces - Fvector v; v.crossproduct(m.j, m.k); - if(v.dotproduct(m.i)<0.f) submesh->FlipFaces(); - if(m_ObjectFlipFaces) submesh->FlipFaces(); - submesh->RecomputeBBox(); - // append mesh - submesh->SetName (it->pNode->GetName()); - exp_obj->m_Meshes.push_back (submesh); - }else{ - ELog.Msg(mtError,"! can't convert", it->pNode->GetName()); - xr_delete(submesh); - bResult = false; - break; - } - } - - if (bResult){ - exp_obj->UpdateBox (); - exp_obj->VerifyMeshNames(); - ELog.Msg (mtInformation,"Object '%s' contains: %d points, %d faces", - exp_obj->GetName(), exp_obj->GetVertexCount(), exp_obj->GetFaceCount()); - }else{ - xr_delete(exp_obj); - } -//------------------------------------------------------------------- - return bResult; + bool bResult = true; + + if (m_ExportName[0] == 0) return false; + + ELog.Msg(mtInformation, "Building object..."); + char fname[256]; + _splitpath(m_ExportName, 0, 0, fname, 0); + exp_obj = new CEditableObject(fname); + exp_obj->SetVersionToCurrent(TRUE, TRUE); + + ExportItemIt it = m_Items.begin(); + for (; it != m_Items.end(); it++) + { + CEditableMesh* submesh = new CEditableMesh(exp_obj); + ELog.Msg(mtInformation, "Converting node '%s'...", it->pNode->GetName()); + if (submesh->Convert(it->pNode)) { + // transform + Matrix3 mMatrix; + mMatrix = it->pNode->GetNodeTM(0) * Inverse(it->pNode->GetParentNode()->GetNodeTM(0)); + + Point3 r1 = mMatrix.GetRow(0); + Point3 r2 = mMatrix.GetRow(1); + Point3 r3 = mMatrix.GetRow(2); + Point3 r4 = mMatrix.GetRow(3); + Fmatrix m; + m.identity(); + m.i.set(r1.x, r1.z, r1.y); + m.j.set(r2.x, r2.z, r2.y); + m.k.set(r3.x, r3.z, r3.y); + m.c.set(r4.x, r4.z, r4.y); + + submesh->Transform(m); + // flip faces + Fvector v; + v.crossproduct(m.j, m.k); + if (v.dotproduct(m.i) < 0.f) submesh->FlipFaces(); + if (m_ObjectFlipFaces) submesh->FlipFaces(); + submesh->RecomputeBBox(); + // append mesh + submesh->SetName(it->pNode->GetName()); + exp_obj->m_Meshes.push_back(submesh); + } + else + { + ELog.Msg(mtError, "! can't convert", it->pNode->GetName()); + xr_delete(submesh); + bResult = false; + break; + } + } + + if (bResult) { + exp_obj->UpdateBox(); + exp_obj->VerifyMeshNames(); + ELog.Msg(mtInformation, "Object '%s' contains: %d points, %d faces", exp_obj->GetName(), + exp_obj->GetVertexCount(), exp_obj->GetFaceCount()); + } + else + { + xr_delete(exp_obj); + } + //------------------------------------------------------------------- + return bResult; } //------------------------------------------------------------------- BOOL MeshExpUtility::SaveAsObject(const char* m_ExportName) { - BOOL bResult = TRUE; - - if (m_ExportName[0]==0) return FALSE; - - ELog.Msg(mtInformation,"Exporting..." ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - CEditableObject* exp_obj=0; - if (bResult=BuildObject(exp_obj,m_ExportName)){ - ELog.Msg (mtInformation,"Saving object..."); - for (SurfaceIt s_it=exp_obj->FirstSurface(); s_it!=exp_obj->LastSurface(); s_it++){ - LPSTR t=(LPSTR)(*s_it)->_Texture(); - if (strext(t)) *strext(t)=0; - } - exp_obj->Optimize (); + BOOL bResult = TRUE; + + if (m_ExportName[0] == 0) return FALSE; + + ELog.Msg(mtInformation, "Exporting..."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + CEditableObject* exp_obj = 0; + if (bResult = BuildObject(exp_obj, m_ExportName)) { + ELog.Msg(mtInformation, "Saving object..."); + for (SurfaceIt s_it = exp_obj->FirstSurface(); s_it != exp_obj->LastSurface(); s_it++) + { + LPSTR t = (LPSTR)(*s_it)->_Texture(); + if (strext(t)) *strext(t) = 0; + } + exp_obj->Optimize(); exp_obj->Save(m_ExportName); - } + } - xr_delete(exp_obj); + xr_delete(exp_obj); - return bResult; + return bResult; } //------------------------------------------------------------------- BOOL MeshExpUtility::SaveAsLWO(const char* m_ExportName) { - BOOL bResult = TRUE; + BOOL bResult = TRUE; - if (m_ExportName[0]==0) return FALSE; + if (m_ExportName[0] == 0) return FALSE; - ELog.Msg(mtInformation,"Exporting..." ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - CEditableObject* exp_obj=0; - if (bResult=BuildObject(exp_obj,m_ExportName)){ - ELog.Msg (mtInformation,"Object saved..."); - exp_obj->Optimize (); - exp_obj->ExportLWO (m_ExportName); - } + ELog.Msg(mtInformation, "Exporting..."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + CEditableObject* exp_obj = 0; + if (bResult = BuildObject(exp_obj, m_ExportName)) { + ELog.Msg(mtInformation, "Object saved..."); + exp_obj->Optimize(); + exp_obj->ExportLWO(m_ExportName); + } - xr_delete(exp_obj); + xr_delete(exp_obj); - return bResult; + return bResult; } //------------------------------------------------------------------- //------------------------------------------------------------------- // registry access -const char *g_rOptionsKey = "SOFTWARE\\NerGoSoft\\S.T.A.L.K.E.R. Map Editor\\2.0\\Options"; -const char *g_rPathValue = "MainPath"; -const char *g_rObjFlipFacesVal = "Object Flip Faces"; -const char *g_rObjSuppressSMVal = "Object Suppress SM"; -const char *g_rNoOptimizeVal = "Object No Optimize"; -const char *g_rSkinSuppressSMVal= "Skin Suppress SM"; -const char *g_rSkinProgressive = "Skin Progressive"; +const char* g_rOptionsKey = "SOFTWARE\\NerGoSoft\\S.T.A.L.K.E.R. Map Editor\\2.0\\Options"; +const char* g_rPathValue = "MainPath"; +const char* g_rObjFlipFacesVal = "Object Flip Faces"; +const char* g_rObjSuppressSMVal = "Object Suppress SM"; +const char* g_rNoOptimizeVal = "Object No Optimize"; +const char* g_rSkinSuppressSMVal = "Skin Suppress SM"; +const char* g_rSkinProgressive = "Skin Progressive"; //------------------------------------------------------------------------------------------------- void MeshExpUtility::ExportObject() { - BOOL bResult = FALSE; - - if( m_Items.empty() ){ - ELog.Msg(mtError,"Nothing selected" ); - ELog.Msg(mtError,"-------------------------------------------------------" ); - return; - } - - m_ObjectFlipFaces = IsDlgButtonChecked( hPanel, IDC_OBJECT_FLIPFACES ); - - string_path m_ExportName; - m_ExportName[0]=0; - if( !EFS.GetSaveName("$import$",m_ExportName,0,0) ) - { - ELog.Msg(mtInformation,"Export cancelled" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - EConsole.StayOnTop(TRUE); - if (strext(m_ExportName)) *strext(m_ExportName)=0; - strcat(m_ExportName,".object"); - bResult = SaveAsObject(m_ExportName); - - ELog.Msg (mtInformation,bResult?". Export succesfully completed.":"! Export failed."); - ELog.Msg (mtInformation,"-------------------------------------------------------" ); - EConsole.StayOnTop(FALSE); + BOOL bResult = FALSE; + + if (m_Items.empty()) { + ELog.Msg(mtError, "Nothing selected"); + ELog.Msg(mtError, "-------------------------------------------------------"); + return; + } + + m_ObjectFlipFaces = IsDlgButtonChecked(hPanel, IDC_OBJECT_FLIPFACES); + + string_path m_ExportName; + m_ExportName[0] = 0; + if (!EFS.GetSaveName("$import$", m_ExportName, 0, 0)) { + ELog.Msg(mtInformation, "Export cancelled"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + EConsole.StayOnTop(TRUE); + if (strext(m_ExportName)) *strext(m_ExportName) = 0; + strcat(m_ExportName, ".object"); + bResult = SaveAsObject(m_ExportName); + + ELog.Msg(mtInformation, bResult ? ". Export succesfully completed." : "! Export failed."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + EConsole.StayOnTop(FALSE); } //------------------------------------------------------------------------------------------------- void MeshExpUtility::ExportLWO() { - BOOL bResult = FALSE; - - if( m_Items.empty() ){ - ELog.Msg(mtError,"Nothing selected" ); - ELog.Msg(mtError,"-------------------------------------------------------" ); - return; - } - - m_ObjectFlipFaces = IsDlgButtonChecked( hPanel, IDC_OBJECT_FLIPFACES ); - - string_path m_ExportName; - m_ExportName[0]=0; - if( !EFS.GetSaveName("$import$",m_ExportName,0,1) ){ - ELog.Msg(mtInformation,"Export cancelled" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - if (strext(m_ExportName)) *strext(m_ExportName)=0; - strcat(m_ExportName,".lwo"); - EConsole.StayOnTop(TRUE); - bResult = SaveAsLWO(m_ExportName); - - ELog.Msg (mtInformation,bResult?". Export succesfully completed.":"! Export failed."); - ELog.Msg (mtInformation,"-------------------------------------------------------" ); - EConsole.StayOnTop(FALSE); + BOOL bResult = FALSE; + + if (m_Items.empty()) { + ELog.Msg(mtError, "Nothing selected"); + ELog.Msg(mtError, "-------------------------------------------------------"); + return; + } + + m_ObjectFlipFaces = IsDlgButtonChecked(hPanel, IDC_OBJECT_FLIPFACES); + + string_path m_ExportName; + m_ExportName[0] = 0; + if (!EFS.GetSaveName("$import$", m_ExportName, 0, 1)) { + ELog.Msg(mtInformation, "Export cancelled"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + if (strext(m_ExportName)) *strext(m_ExportName) = 0; + strcat(m_ExportName, ".lwo"); + EConsole.StayOnTop(TRUE); + bResult = SaveAsLWO(m_ExportName); + + ELog.Msg(mtInformation, bResult ? ". Export succesfully completed." : "! Export failed."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + EConsole.StayOnTop(FALSE); } //------------------------------------------------------------------------------------------------- void MeshExpUtility::ExportSkin() { - BOOL bResult = true; - - if( m_Items.empty() ){ - ELog.Msg(mtError,"Nothing selected." ); - ELog.Msg(mtError,"-------------------------------------------------------" ); - return; - } - if( m_Items.size()>1 ){ - ELog.Msg(mtInformation,"More than one object selected." ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - - m_SkinFlipFaces = IsDlgButtonChecked( hPanel, IDC_SKIN_FLIPFACES ); - m_SkinAllowDummy = IsDlgButtonChecked( hPanel, IDC_SKIN_ALLOW_DUMMY ); - - string_path m_ExportName; - m_ExportName[0]=0; - if( !EFS.GetSaveName("$import$",m_ExportName,0,0) ){ - ELog.Msg(mtInformation,"Export cancelled" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - - EConsole.StayOnTop(TRUE); - bResult = SaveAsSkin(m_ExportName); - ELog.Msg (mtInformation,bResult?". Export succesfully completed.":"! Export failed."); - ELog.Msg (mtInformation,"-------------------------------------------------------" ); - EConsole.StayOnTop(FALSE); + BOOL bResult = true; + + if (m_Items.empty()) { + ELog.Msg(mtError, "Nothing selected."); + ELog.Msg(mtError, "-------------------------------------------------------"); + return; + } + if (m_Items.size() > 1) { + ELog.Msg(mtInformation, "More than one object selected."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + + m_SkinFlipFaces = IsDlgButtonChecked(hPanel, IDC_SKIN_FLIPFACES); + m_SkinAllowDummy = IsDlgButtonChecked(hPanel, IDC_SKIN_ALLOW_DUMMY); + + string_path m_ExportName; + m_ExportName[0] = 0; + if (!EFS.GetSaveName("$import$", m_ExportName, 0, 0)) { + ELog.Msg(mtInformation, "Export cancelled"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + + EConsole.StayOnTop(TRUE); + bResult = SaveAsSkin(m_ExportName); + ELog.Msg(mtInformation, bResult ? ". Export succesfully completed." : "! Export failed."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + EConsole.StayOnTop(FALSE); } void MeshExpUtility::ExportSkinKeys() { - BOOL bResult = true; - - if( m_Items.empty() ){ - ELog.Msg(mtError,"Nothing selected." ); - ELog.Msg(mtError,"-------------------------------------------------------" ); - return; - } - if( m_Items.size()>1 ){ - ELog.Msg(mtInformation,"More than one object selected." ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - m_SkinFlipFaces = IsDlgButtonChecked( hPanel, IDC_SKIN_FLIPFACES ); - m_SkinAllowDummy = IsDlgButtonChecked( hPanel, IDC_SKIN_ALLOW_DUMMY ); - - string_path m_ExportName; - m_ExportName[0]=0; - if( !EFS.GetSaveName("$smotion$",m_ExportName,0) ){ - ELog.Msg(mtInformation,"Export cancelled" ); - ELog.Msg(mtInformation,"-------------------------------------------------------" ); - return; - } - - EConsole.StayOnTop(TRUE); - bResult = SaveSkinKeys(m_ExportName); - ELog.Msg (mtInformation,bResult?". Export succesfully completed.":"! Export failed."); - ELog.Msg (mtInformation,"-------------------------------------------------------" ); - EConsole.StayOnTop(FALSE); + BOOL bResult = true; + + if (m_Items.empty()) { + ELog.Msg(mtError, "Nothing selected."); + ELog.Msg(mtError, "-------------------------------------------------------"); + return; + } + if (m_Items.size() > 1) { + ELog.Msg(mtInformation, "More than one object selected."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + m_SkinFlipFaces = IsDlgButtonChecked(hPanel, IDC_SKIN_FLIPFACES); + m_SkinAllowDummy = IsDlgButtonChecked(hPanel, IDC_SKIN_ALLOW_DUMMY); + + string_path m_ExportName; + m_ExportName[0] = 0; + if (!EFS.GetSaveName("$smotion$", m_ExportName, 0)) { + ELog.Msg(mtInformation, "Export cancelled"); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + return; + } + + EConsole.StayOnTop(TRUE); + bResult = SaveSkinKeys(m_ExportName); + ELog.Msg(mtInformation, bResult ? ". Export succesfully completed." : "! Export failed."); + ELog.Msg(mtInformation, "-------------------------------------------------------"); + EConsole.StayOnTop(FALSE); } - diff --git a/src/plugins/Max/Export/MeshExpUtility.h b/src/plugins/Max/Export/MeshExpUtility.h index 1e0bd1ace5f..6466e540c88 100644 --- a/src/plugins/Max/Export/MeshExpUtility.h +++ b/src/plugins/Max/Export/MeshExpUtility.h @@ -1,76 +1,74 @@ // file: MeshExpUtility.h - #ifndef __MeshExpUtility__H__INCLUDED__ #define __MeshExpUtility__H__INCLUDED__ -#include "NetDeviceLog.h" #include "MeshExpUtility.rh" +#include "NetDeviceLog.h" -#define EXPORTER_VERSION 2 -#define EXPORTER_BUILD 03 -//using namespace std; +#define EXPORTER_VERSION 2 +#define EXPORTER_BUILD 03 +// using namespace std; // refs class CEditableObject; -#define EXP_UTILITY_CLASSID 0x507d29c0 +#define EXP_UTILITY_CLASSID 0x507d29c0 -class ExportItem { +class ExportItem +{ public: - INode *pNode; - ExportItem(){ pNode = 0;}; - ExportItem( INode* _pNode ){ pNode = _pNode; }; - ~ExportItem(){}; + INode* pNode; + ExportItem() { pNode = 0; }; + ExportItem(INode* _pNode) { pNode = _pNode; }; + ~ExportItem(){}; }; -DEFINE_VECTOR(ExportItem,ExportItemVec,ExportItemIt); -class MeshExpUtility : public UtilityObj { +DEFINE_VECTOR(ExportItem, ExportItemVec, ExportItemIt); +class MeshExpUtility : public UtilityObj +{ public: + IUtil* iu; + Interface* ip; - IUtil *iu; - Interface *ip; + HWND hPanel; + HWND hItemList; - HWND hPanel; - HWND hItemList; + INode* GetExportNode(); - INode* GetExportNode (); protected: - ExportItemVec m_Items; + ExportItemVec m_Items; - void RefreshExportList(); - void UpdateSelectionListBox(); + void RefreshExportList(); + void UpdateSelectionListBox(); + + BOOL BuildObject(CEditableObject*& obj, LPCSTR m_ExportName); + BOOL SaveAsObject(const char* n); + BOOL SaveAsLWO(const char* n); + BOOL SaveAsSkin(const char* n); + BOOL SaveSkinKeys(const char* n); - BOOL BuildObject (CEditableObject*& obj, LPCSTR m_ExportName); - BOOL SaveAsObject (const char* n); - BOOL SaveAsLWO (const char* n); - BOOL SaveAsSkin (const char* n); - BOOL SaveSkinKeys (const char* n); public: - int m_ObjectFlipFaces; - int m_SkinFlipFaces; - int m_SkinAllowDummy; + int m_ObjectFlipFaces; + int m_SkinFlipFaces; + int m_SkinAllowDummy; + public: - MeshExpUtility (); - virtual ~MeshExpUtility (); - - void BeginEditParams (Interface *ip,IUtil *iu); - void EndEditParams (Interface *ip,IUtil *iu); - void SelectionSetChanged(Interface *ip,IUtil *iu); - void DeleteThis () {} - - void Init (HWND hWnd); - void Destroy (HWND hWnd); - void ExportObject (); - void ExportLWO (); - void ExportSkin (); - void ExportSkinKeys (); + MeshExpUtility(); + virtual ~MeshExpUtility(); + + void BeginEditParams(Interface* ip, IUtil* iu); + void EndEditParams(Interface* ip, IUtil* iu); + void SelectionSetChanged(Interface* ip, IUtil* iu); + void DeleteThis() {} + void Init(HWND hWnd); + void Destroy(HWND hWnd); + void ExportObject(); + void ExportLWO(); + void ExportSkin(); + void ExportSkinKeys(); }; extern MeshExpUtility U; - - #endif /*__MeshExpUtility__H__INCLUDED__*/ - - diff --git a/src/plugins/Max/Export/MeshExpUtility.rc b/src/plugins/Max/Export/MeshExpUtility.rc index 2b84fb79dc1..cb4939c9479 100644 --- a/src/plugins/Max/Export/MeshExpUtility.rc +++ b/src/plugins/Max/Export/MeshExpUtility.rc @@ -19,49 +19,32 @@ #ifdef _WIN32 LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT #pragma code_page(1251) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_MWND DIALOGEX 0, 0, 108, 241 -STYLE DS_SETFONT | WS_CHILD | WS_BORDER -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - PUSHBUTTON "Export Editor Object...",IDC_EXPORT_AS_OBJECT,6,26,95, - 12,BS_FLAT - LISTBOX IDC_OBJLIST,4,134,99,86,LBS_NOINTEGRALHEIGHT | LBS_NOSEL | - WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Export Skin...",IDC_SKIN_EXPORT,6,91,95,12,BS_FLAT - PUSHBUTTON "End",IDC_CLOSE,4,222,99,12,BS_FLAT - PUSHBUTTON "Export Motion...",IDC_SKIN_KEYS_EXPORT,6,105,95,12, - BS_FLAT - GROUPBOX "Object",IDC_STATIC,4,3,99,51,BS_FLAT - CONTROL "Flip faces",IDC_OBJECT_FLIPFACES,"Button", - BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,6,14,92,8 - PUSHBUTTON "Export LWO...",IDC_EXPORT_AS_LWO,6,40,95,12,BS_FLAT - CONTROL "Flip faces",IDC_SKIN_FLIPFACES,"Button",BS_AUTOCHECKBOX | - BS_FLAT | WS_TABSTOP,6,67,92,8 - GROUPBOX "Skeleton ",IDC_STATIC,4,56,99,63,BS_FLAT - CONTROL "Allow Dummy",IDC_SKIN_ALLOW_DUMMY,"Button", - BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,6,79,92,8 - LTEXT "Selected:",IDC_STATIC,4,123,99,8 -END - -IDD_CONSOLE DIALOGEX 500, 0, 311, 175 -STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "X-Ray Export" -FONT 8, "Lucida Console", 0, 0, 0x1 -BEGIN - LISTBOX IDC_MESSAGES,0,0,310,163,NOT LBS_NOTIFY | - LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | - WS_HSCROLL | WS_TABSTOP,WS_EX_STATICEDGE - CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",0x1,0,163, - 310,9 -END - +#endif //_WIN32 + + ///////////////////////////////////////////////////////////////////////////// + // + // Dialog + // + + IDD_MWND DIALOGEX 0, + 0, 108, 241 STYLE DS_SETFONT | WS_CHILD | WS_BORDER FONT 8, "MS Sans Serif", 0, 0, + 0x0 BEGIN PUSHBUTTON "Export Editor Object...", IDC_EXPORT_AS_OBJECT, 6, 26, 95, 12, BS_FLAT LISTBOX IDC_OBJLIST, 4, + 134, 99, 86, LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "Export Skin...", + IDC_SKIN_EXPORT, 6, 91, 95, 12, BS_FLAT PUSHBUTTON "End", IDC_CLOSE, 4, 222, 99, 12, + BS_FLAT PUSHBUTTON "Export Motion...", IDC_SKIN_KEYS_EXPORT, 6, 105, 95, 12, BS_FLAT GROUPBOX "Object", IDC_STATIC, + 4, 3, 99, 51, BS_FLAT CONTROL "Flip faces", IDC_OBJECT_FLIPFACES, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, + 6, 14, 92, 8 PUSHBUTTON "Export LWO...", IDC_EXPORT_AS_LWO, 6, 40, 95, 12, BS_FLAT CONTROL "Flip faces", + IDC_SKIN_FLIPFACES, "Button", BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 6, 67, 92, 8 GROUPBOX "Skeleton ", IDC_STATIC, + 4, 56, 99, 63, BS_FLAT CONTROL "Allow Dummy", IDC_SKIN_ALLOW_DUMMY, "Button", + BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP, 6, 79, 92, 8 LTEXT "Selected:", IDC_STATIC, 4, 123, 99, + 8 END + + IDD_CONSOLE DIALOGEX 500, + 0, 311, 175 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "X-Ray Export" FONT 8, + "Lucida Console", 0, 0, 0x1 BEGIN LISTBOX IDC_MESSAGES, 0, 0, 310, 163, + NOT LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, + WS_EX_STATICEDGE CONTROL "Progress1", IDC_PROGRESS, "msctls_progress32", 0x1, 0, 163, 310, + 9 END ///////////////////////////////////////////////////////////////////////////// // @@ -69,83 +52,56 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_MWND, DIALOG - BEGIN - LEFTMARGIN, 4 - RIGHTMARGIN, 103 - TOPMARGIN, 7 - BOTTOMMARGIN, 235 - END - - IDD_CONSOLE, DIALOG - BEGIN - RIGHTMARGIN, 310 - BOTTOMMARGIN, 163 - END -END -#endif // APSTUDIO_INVOKED + GUIDELINES DESIGNINFO BEGIN IDD_MWND, + DIALOG BEGIN LEFTMARGIN, 4 RIGHTMARGIN, 103 TOPMARGIN, 7 BOTTOMMARGIN, 235 END + IDD_CONSOLE, + DIALOG BEGIN RIGHTMARGIN, 310 BOTTOMMARGIN, 163 END END +#endif // APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// + ///////////////////////////////////////////////////////////////////////////// + // + // TEXTINCLUDE + // -1 TEXTINCLUDE -BEGIN - "MeshExpUtility.rh\0" -END + 1 TEXTINCLUDE BEGIN "MeshExpUtility.rh\0" END -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END + 2 TEXTINCLUDE BEGIN "#include " + "afxres.h" + "\r\n" + "\0" END -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END + 3 TEXTINCLUDE BEGIN "\r\n" + "\0" END -#endif // APSTUDIO_INVOKED +#endif // APSTUDIO_INVOKED -#endif // Russian resources +#endif // Russian resources ///////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////// // Ukrainian resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_UKR) #ifdef _WIN32 -LANGUAGE LANG_UKRAINIAN, SUBLANG_DEFAULT + LANGUAGE LANG_UKRAINIAN, + SUBLANG_DEFAULT #pragma code_page(1251) -#endif //_WIN32 +#endif //_WIN32 -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_SHADERDIALOG DIALOGEX 0, 0, 227, 95 -STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | - WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "Select shader" -FONT 8, "MS Sans Serif", 0, 0, 0x1 -BEGIN - DEFPUSHBUTTON "OK",ID_SHOK,174,15,50,12,BS_FLAT - PUSHBUTTON "Cancel",ID_SHCANCEL,174,31,50,12,BS_FLAT - LISTBOX IDC_SHADERLIST,3,15,164,77,LBS_SORT | - LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP - LTEXT "Texture:",IDC_STATIC,3,4,27,8 - LTEXT "...",IDC_TEXTURE,33,4,191,8 -END + ///////////////////////////////////////////////////////////////////////////// + // + // Dialog + // + IDD_SHADERDIALOG DIALOGEX 0, + 0, 227, 95 STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | + WS_SYSMENU EXSTYLE WS_EX_TOOLWINDOW CAPTION "Select shader" FONT 8, + "MS Sans Serif", 0, 0, 0x1 BEGIN DEFPUSHBUTTON "OK", ID_SHOK, 174, 15, 50, 12, BS_FLAT PUSHBUTTON "Cancel", + ID_SHCANCEL, 174, 31, 50, 12, BS_FLAT LISTBOX IDC_SHADERLIST, 3, 15, 164, 77, + LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP LTEXT "Texture:", IDC_STATIC, 3, 4, 27, 8 LTEXT "...", + IDC_TEXTURE, 33, 4, 191, 8 END ///////////////////////////////////////////////////////////////////////////// // @@ -153,22 +109,12 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_SHADERDIALOG, DIALOG - BEGIN - LEFTMARGIN, 3 - RIGHTMARGIN, 224 - TOPMARGIN, 4 - BOTTOMMARGIN, 92 - END -END -#endif // APSTUDIO_INVOKED - -#endif // Ukrainian resources -///////////////////////////////////////////////////////////////////////////// - + GUIDELINES DESIGNINFO BEGIN IDD_SHADERDIALOG, + DIALOG BEGIN LEFTMARGIN, 3 RIGHTMARGIN, 224 TOPMARGIN, 4 BOTTOMMARGIN, 92 END END +#endif // APSTUDIO_INVOKED +#endif // Ukrainian resources +///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -176,7 +122,5 @@ END // Generated from the TEXTINCLUDE 3 resource. // - ///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +#endif // not APSTUDIO_INVOKED diff --git a/src/plugins/Max/Export/MeshExpUtility.rh b/src/plugins/Max/Export/MeshExpUtility.rh index fee18890a97..1989053c1c0 100644 --- a/src/plugins/Max/Export/MeshExpUtility.rh +++ b/src/plugins/Max/Export/MeshExpUtility.rh @@ -2,32 +2,32 @@ // Microsoft Visual C++ generated include file. // Used by MeshExpUtility.rc // -#define IDD_MWND 101 -#define IDD_CONSOLE 103 -#define IDD_SHADERDIALOG 104 -#define IDC_CLOSE 1000 -#define IDC_EXPORT_AS_OBJECT 1001 -#define IDC_OBJLIST 1002 -#define IDC_SKIN_EXPORT 1003 -#define IDC_SKIN_KEYS_EXPORT 1005 -#define IDC_EXPORT_AS_LWO 1006 -#define IDC_MESSAGES 1015 -#define IDC_OBJECT_FLIPFACES 1023 -#define IDC_SKIN_FLIPFACES 1025 -#define IDC_PROGRESS 1026 -#define ID_SHOK 1028 -#define IDC_SKIN_ALLOW_DUMMY 1028 -#define ID_SHCANCEL 1029 -#define IDC_SHADERLIST 1030 -#define IDC_TEXTURE 1032 +#define IDD_MWND 101 +#define IDD_CONSOLE 103 +#define IDD_SHADERDIALOG 104 +#define IDC_CLOSE 1000 +#define IDC_EXPORT_AS_OBJECT 1001 +#define IDC_OBJLIST 1002 +#define IDC_SKIN_EXPORT 1003 +#define IDC_SKIN_KEYS_EXPORT 1005 +#define IDC_EXPORT_AS_LWO 1006 +#define IDC_MESSAGES 1015 +#define IDC_OBJECT_FLIPFACES 1023 +#define IDC_SKIN_FLIPFACES 1025 +#define IDC_PROGRESS 1026 +#define ID_SHOK 1028 +#define IDC_SKIN_ALLOW_DUMMY 1028 +#define ID_SHCANCEL 1029 +#define IDC_SHADERLIST 1030 +#define IDC_TEXTURE 1032 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 105 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1035 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 105 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1035 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/Max/Export/NetDeviceLog.cpp b/src/plugins/Max/Export/NetDeviceLog.cpp index c5ee9d225c1..4c55e6b7c3a 100644 --- a/src/plugins/Max/Export/NetDeviceLog.cpp +++ b/src/plugins/Max/Export/NetDeviceLog.cpp @@ -5,150 +5,156 @@ #include "stdafx.h" #pragma hdrstop -#include "NetDeviceLog.h" #include "MeshExpUtility.h" #include "MeshExpUtility.rh" +#include "NetDeviceLog.h" //---------------------------------------------------- CExportConsole EConsole; //---------------------------------------------------- -BOOL CALLBACK ConsoleDialogProc( HWND hw, UINT msg, WPARAM wp, LPARAM lp){ - - std::list::iterator _F; - std::list::iterator _E; - - switch( msg ){ - - case WM_INITDIALOG: - SetWindowPos(hw,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE); - EConsole.m_hWindow = hw; - EnterCriticalSection( &EConsole.m_CSection ); - if( !EConsole.m_Messages.empty() ){ - _F = EConsole.m_Messages.begin(); - _E = EConsole.m_Messages.end(); - for(;_F!=_E;_F++){ - int k = SendDlgItemMessage( hw, IDC_MESSAGES, LB_ADDSTRING, 0, (LPARAM)_F->buf ); - SendDlgItemMessage( hw, IDC_MESSAGES, LB_SETCURSEL, k, 0 ); - } - SendDlgItemMessage( hw, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100) ); - SendDlgItemMessage( hw, IDC_PROGRESS, PBM_SETPOS, 0, 0); - } - LeaveCriticalSection( &EConsole.m_CSection ); - break; - case WM_CLOSE: - SendMessage(U.hPanel,WM_COMMAND,IDC_CLOSE,0); - break; - default: - return FALSE; - } - return TRUE; +BOOL CALLBACK ConsoleDialogProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) +{ + std::list::iterator _F; + std::list::iterator _E; + + switch (msg) + { + case WM_INITDIALOG: + SetWindowPos(hw, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + EConsole.m_hWindow = hw; + EnterCriticalSection(&EConsole.m_CSection); + if (!EConsole.m_Messages.empty()) { + _F = EConsole.m_Messages.begin(); + _E = EConsole.m_Messages.end(); + for (; _F != _E; _F++) + { + int k = SendDlgItemMessage(hw, IDC_MESSAGES, LB_ADDSTRING, 0, (LPARAM)_F->buf); + SendDlgItemMessage(hw, IDC_MESSAGES, LB_SETCURSEL, k, 0); + } + SendDlgItemMessage(hw, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); + SendDlgItemMessage(hw, IDC_PROGRESS, PBM_SETPOS, 0, 0); + } + LeaveCriticalSection(&EConsole.m_CSection); + break; + case WM_CLOSE: SendMessage(U.hPanel, WM_COMMAND, IDC_CLOSE, 0); break; + default: return FALSE; + } + return TRUE; } -DWORD WINAPI ConsoleThreadProc( LPVOID ){ - DialogBox( EConsole.m_hInstance, - MAKEINTRESOURCE(IDD_CONSOLE), - 0/*GetForegroundWindow()*/, ConsoleDialogProc ); - return 0; +DWORD WINAPI ConsoleThreadProc(LPVOID) +{ + DialogBox(EConsole.m_hInstance, MAKEINTRESOURCE(IDD_CONSOLE), 0 /*GetForegroundWindow()*/, ConsoleDialogProc); + return 0; } void CExportConsole::StayOnTop(BOOL flag) { - if (flag){ - SetWindowPos(m_hWindow,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE); - }else{ - SetWindowPos(m_hWindow,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE); - SetWindowPos(m_hWindow,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE); - } + if (flag) { + SetWindowPos(m_hWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + } + else + { + SetWindowPos(m_hWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + SetWindowPos(m_hWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + } } -bool CExportConsole::Init( HINSTANCE _Inst, HWND _Window ){ - - if( m_Valid ){ - SetForegroundWindow(m_hWindow); - return true;} - - m_Enter = false; - m_hInstance = _Inst; - m_hParent = _Window; - InitializeCriticalSection( &m_CSection ); - m_hThread = CreateThread( 0, 0, ConsoleThreadProc, 0, 0, &m_ThreadId ); - m_Valid = true; - - return true; +bool CExportConsole::Init(HINSTANCE _Inst, HWND _Window) +{ + if (m_Valid) { + SetForegroundWindow(m_hWindow); + return true; + } + + m_Enter = false; + m_hInstance = _Inst; + m_hParent = _Window; + InitializeCriticalSection(&m_CSection); + m_hThread = CreateThread(0, 0, ConsoleThreadProc, 0, 0, &m_ThreadId); + m_Valid = true; + + return true; } -void CExportConsole::Clear(){ - - if( !m_Valid ) - return; +void CExportConsole::Clear() +{ + if (!m_Valid) return; - m_Valid = false; - TerminateThread( m_hThread, 0 ); - CloseHandle( m_hThread ); - DeleteCriticalSection( &m_CSection ); + m_Valid = false; + TerminateThread(m_hThread, 0); + CloseHandle(m_hThread); + DeleteCriticalSection(&m_CSection); } -void CExportConsole::print(TMsgDlgType mt, const char *buf){ - _ConsoleMsg msg(buf); +void CExportConsole::print(TMsgDlgType mt, const char* buf) +{ + _ConsoleMsg msg(buf); - if( m_Messages.size() > 1000 ) m_Messages.pop_front(); - m_Messages.push_back( buf ); + if (m_Messages.size() > 1000) m_Messages.pop_front(); + m_Messages.push_back(buf); - if( !m_Valid ) - return; + if (!m_Valid) return; - EnterCriticalSection( &m_CSection ); - if( SendDlgItemMessage( m_hWindow, IDC_MESSAGES, LB_GETCOUNT, 0, 0 ) > 1000 ) - SendDlgItemMessage( m_hWindow, IDC_MESSAGES,LB_DELETESTRING, 0, 0 ); - int k = SendDlgItemMessage( m_hWindow, IDC_MESSAGES,LB_ADDSTRING, 0, (LPARAM)buf ); - SendDlgItemMessage( m_hWindow, IDC_MESSAGES,LB_SETCURSEL, k, 0 ); - DWORD dwCnt = SendMessage ( m_hWindow, LB_GETCOUNT, 0, 0); - SendMessage ( m_hWindow, LB_SETTOPINDEX, dwCnt-1, 0); - LeaveCriticalSection( &m_CSection ); + EnterCriticalSection(&m_CSection); + if (SendDlgItemMessage(m_hWindow, IDC_MESSAGES, LB_GETCOUNT, 0, 0) > 1000) + SendDlgItemMessage(m_hWindow, IDC_MESSAGES, LB_DELETESTRING, 0, 0); + int k = SendDlgItemMessage(m_hWindow, IDC_MESSAGES, LB_ADDSTRING, 0, (LPARAM)buf); + SendDlgItemMessage(m_hWindow, IDC_MESSAGES, LB_SETCURSEL, k, 0); + DWORD dwCnt = SendMessage(m_hWindow, LB_GETCOUNT, 0, 0); + SendMessage(m_hWindow, LB_SETTOPINDEX, dwCnt - 1, 0); + LeaveCriticalSection(&m_CSection); } -bool CExportConsole::valid(){ - return m_Valid; +bool CExportConsole::valid() +{ + return m_Valid; } -CExportConsole::CExportConsole(){ - VERIFY( this == &EConsole ); - m_Valid = false; +CExportConsole::CExportConsole() +{ + VERIFY(this == &EConsole); + m_Valid = false; } -CExportConsole::~CExportConsole(){ - VERIFY( m_Valid == false ); - m_Messages.clear(); +CExportConsole::~CExportConsole() +{ + VERIFY(m_Valid == false); + m_Messages.clear(); } //---------------------------------------------------- -void CExportConsole::ProgressStart(float max_val, const char* text){ - fMaxVal=max_val; - fStatusProgress=0; - Msg(text?text:""); - ProgressUpdate(0); +void CExportConsole::ProgressStart(float max_val, const char* text) +{ + fMaxVal = max_val; + fStatusProgress = 0; + Msg(text ? text : ""); + ProgressUpdate(0); } -void CExportConsole::ProgressEnd(){ - ProgressUpdate(0); +void CExportConsole::ProgressEnd() +{ + ProgressUpdate(0); } -void CExportConsole::ProgressInc(){ - ProgressUpdate(fStatusProgress+1); +void CExportConsole::ProgressInc() +{ + ProgressUpdate(fStatusProgress + 1); } -void CExportConsole::ProgressUpdate(float val){ - if (_abs(val-fStatusProgress)<1) return; - fStatusProgress=val; - EnterCriticalSection( &m_CSection ); - if (fMaxVal>0){ - DWORD progress = (DWORD)((fStatusProgress/fMaxVal)*100); - SendDlgItemMessage( m_hWindow, IDC_PROGRESS,PBM_SETPOS, progress, 0 ); - }else{ - DWORD progress = 0; - SendDlgItemMessage( m_hWindow, IDC_PROGRESS,PBM_SETPOS, progress, 0 ); - } - LeaveCriticalSection( &m_CSection ); +void CExportConsole::ProgressUpdate(float val) +{ + if (_abs(val - fStatusProgress) < 1) return; + fStatusProgress = val; + EnterCriticalSection(&m_CSection); + if (fMaxVal > 0) { + DWORD progress = (DWORD)((fStatusProgress / fMaxVal) * 100); + SendDlgItemMessage(m_hWindow, IDC_PROGRESS, PBM_SETPOS, progress, 0); + } + else + { + DWORD progress = 0; + SendDlgItemMessage(m_hWindow, IDC_PROGRESS, PBM_SETPOS, progress, 0); + } + LeaveCriticalSection(&m_CSection); } //---------------------------------------------------- - - diff --git a/src/plugins/Max/Export/NetDeviceLog.h b/src/plugins/Max/Export/NetDeviceLog.h index 8aabef5d825..9169cacc815 100644 --- a/src/plugins/Max/Export/NetDeviceLog.h +++ b/src/plugins/Max/Export/NetDeviceLog.h @@ -9,55 +9,53 @@ #define NLOG_CONSOLE_OUT // ------- -class CExportConsole{ +class CExportConsole +{ protected: - - bool m_Valid; - HANDLE m_hThread; - DWORD m_ThreadId; - + bool m_Valid; + HANDLE m_hThread; + DWORD m_ThreadId; public: + HWND m_hParent; + HWND m_hWindow; + HINSTANCE m_hInstance; - HWND m_hParent; - HWND m_hWindow; - HINSTANCE m_hInstance; + CRITICAL_SECTION m_CSection; - CRITICAL_SECTION m_CSection; + bool m_Enter; + char m_EnterBuffer[256]; - bool m_Enter; - char m_EnterBuffer[256]; + class _ConsoleMsg + { + public: + char buf[1024]; + _ConsoleMsg(LPCSTR b) { strcpy(buf, b); } + }; - class _ConsoleMsg{ - public: - char buf[1024]; - _ConsoleMsg(LPCSTR b){ strcpy(buf,b); } - }; - - std::list<_ConsoleMsg> m_Messages; + std::list<_ConsoleMsg> m_Messages; - float fMaxVal, fStatusProgress; -public: + float fMaxVal, fStatusProgress; - bool Init( HINSTANCE _Inst, HWND _Window ); - void Clear(); +public: + bool Init(HINSTANCE _Inst, HWND _Window); + void Clear(); - void print (TMsgDlgType mt, const char *buf); + void print(TMsgDlgType mt, const char* buf); - bool valid(); + bool valid(); - void ProgressStart(float max_val, const char* text=0); - void ProgressEnd(); - void ProgressInc(); - void ProgressUpdate(float val); + void ProgressStart(float max_val, const char* text = 0); + void ProgressEnd(); + void ProgressInc(); + void ProgressUpdate(float val); - void StayOnTop (BOOL flag); + void StayOnTop(BOOL flag); - CExportConsole(); - ~CExportConsole(); + CExportConsole(); + ~CExportConsole(); }; extern CExportConsole EConsole; #endif /*_INCDEF_NETDEVICELOG_H_*/ - diff --git a/src/plugins/Max/Export/Stdafx.h b/src/plugins/Max/Export/Stdafx.h index ba0c0cf31ed..c2af33e8b0e 100644 --- a/src/plugins/Max/Export/Stdafx.h +++ b/src/plugins/Max/Export/Stdafx.h @@ -6,9 +6,9 @@ #pragma once -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0500 -#pragma warning (disable:4995) +#pragma warning(disable : 4995) #include "Max.h" #include "xrCore/xrCore.h" @@ -17,12 +17,18 @@ #undef _MIN #undef _MAX -#define _MIN(a,b) (a)<(b)?(a):(b) -#define _MAX(a,b) (a)>(b)?(a):(b) +#define _MIN(a, b) (a) < (b) ? (a) : (b) +#define _MAX(a, b) (a) > (b) ? (a) : (b) template -T min(T a, T b) { return _MIN(a,b); } +T min(T a, T b) +{ + return _MIN(a, b); +} template -T max(T a, T b) { return _MAX(a,b); } +T max(T a, T b) +{ + return _MAX(a, b); +} using std::string; #undef _MIN #undef _MAX @@ -35,21 +41,21 @@ using std::string; #define FLT_MIN flt_max +#include #include #include -#include #include -#include "istdplug.h" +#include "UTILAPI.H" #include "iparamb2.h" #include "iparamm2.h" +#include "istdplug.h" #include "stdmat.h" -#include "UTILAPI.H" // CS SDK #ifdef _MAX_EXPORT -# include "phyexp.h" -# include "bipexp.h" +#include "phyexp.h" +#include "bipexp.h" #endif #include @@ -57,38 +63,50 @@ using std::string; #define ENGINE_API #define ECORE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; #include #define AnsiString string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); - - - +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #include "plugins/Shared/ELog.h" #define THROW R_ASSERT(0) #ifdef _MAX_EXPORT - #define _EDITOR_FILE_NAME_ "max_export" +#define _EDITOR_FILE_NAME_ "max_export" #else - #ifdef _MAX_MATERIAL - #define _EDITOR_FILE_NAME_ "max_material" - #endif +#ifdef _MAX_MATERIAL +#define _EDITOR_FILE_NAME_ "max_material" +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" -#pragma warning (default:4995) +#pragma warning(default : 4995) #endif /*_INCDEF_STDAFX_H_*/ - - - - - diff --git a/src/plugins/Max/Export/lwchunks.h b/src/plugins/Max/Export/lwchunks.h index 3b30f53e70e..98aae9da7b8 100644 --- a/src/plugins/Max/Export/lwchunks.h +++ b/src/plugins/Max/Export/lwchunks.h @@ -2,161 +2,161 @@ #define LWCHUNKS_H #ifndef LWID_ -#define LWID_(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d)) +#define LWID_(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) #endif /* chunk and subchunk IDs */ -#define ID_FORM LWID_('F','O','R','M') -#define ID_LWO2 LWID_('L','W','O','2') -#define ID_LWOB LWID_('L','W','O','B') +#define ID_FORM LWID_('F', 'O', 'R', 'M') +#define ID_LWO2 LWID_('L', 'W', 'O', '2') +#define ID_LWOB LWID_('L', 'W', 'O', 'B') /* top-level chunks */ -#define ID_LAYR LWID_('L','A','Y','R') -#define ID_TAGS LWID_('T','A','G','S') -#define ID_PNTS LWID_('P','N','T','S') -#define ID_BBOX LWID_('B','B','O','X') -#define ID_VMAP LWID_('V','M','A','P') -#define ID_VMAD LWID_('V','M','A','D') -#define ID_POLS LWID_('P','O','L','S') -#define ID_PTAG LWID_('P','T','A','G') -#define ID_ENVL LWID_('E','N','V','L') -#define ID_CLIP LWID_('C','L','I','P') -#define ID_SURF LWID_('S','U','R','F') -#define ID_DESC LWID_('D','E','S','C') -#define ID_TEXT LWID_('T','E','X','T') -#define ID_ICON LWID_('I','C','O','N') +#define ID_LAYR LWID_('L', 'A', 'Y', 'R') +#define ID_TAGS LWID_('T', 'A', 'G', 'S') +#define ID_PNTS LWID_('P', 'N', 'T', 'S') +#define ID_BBOX LWID_('B', 'B', 'O', 'X') +#define ID_VMAP LWID_('V', 'M', 'A', 'P') +#define ID_VMAD LWID_('V', 'M', 'A', 'D') +#define ID_POLS LWID_('P', 'O', 'L', 'S') +#define ID_PTAG LWID_('P', 'T', 'A', 'G') +#define ID_ENVL LWID_('E', 'N', 'V', 'L') +#define ID_CLIP LWID_('C', 'L', 'I', 'P') +#define ID_SURF LWID_('S', 'U', 'R', 'F') +#define ID_DESC LWID_('D', 'E', 'S', 'C') +#define ID_TEXT LWID_('T', 'E', 'X', 'T') +#define ID_ICON LWID_('I', 'C', 'O', 'N') /* polygon types */ -#define ID_FACE LWID_('F','A','C','E') -#define ID_CURV LWID_('C','U','R','V') -#define ID_PTCH LWID_('P','T','C','H') -#define ID_MBAL LWID_('M','B','A','L') -#define ID_BONE LWID_('B','O','N','E') +#define ID_FACE LWID_('F', 'A', 'C', 'E') +#define ID_CURV LWID_('C', 'U', 'R', 'V') +#define ID_PTCH LWID_('P', 'T', 'C', 'H') +#define ID_MBAL LWID_('M', 'B', 'A', 'L') +#define ID_BONE LWID_('B', 'O', 'N', 'E') /* polygon tags */ -#define ID_SURF LWID_('S','U','R','F') -#define ID_PART LWID_('P','A','R','T') -#define ID_SMGP LWID_('S','M','G','P') +#define ID_SURF LWID_('S', 'U', 'R', 'F') +#define ID_PART LWID_('P', 'A', 'R', 'T') +#define ID_SMGP LWID_('S', 'M', 'G', 'P') /* envelopes */ -#define ID_PRE LWID_('P','R','E',' ') -#define ID_POST LWID_('P','O','S','T') -#define ID_KEY LWID_('K','E','Y',' ') -#define ID_SPAN LWID_('S','P','A','N') -#define ID_TCB LWID_('T','C','B',' ') -#define ID_HERM LWID_('H','E','R','M') -#define ID_BEZI LWID_('B','E','Z','I') -#define ID_BEZ2 LWID_('B','E','Z','2') -#define ID_LINE LWID_('L','I','N','E') -#define ID_STEP LWID_('S','T','E','P') +#define ID_PRE LWID_('P', 'R', 'E', ' ') +#define ID_POST LWID_('P', 'O', 'S', 'T') +#define ID_KEY LWID_('K', 'E', 'Y', ' ') +#define ID_SPAN LWID_('S', 'P', 'A', 'N') +#define ID_TCB LWID_('T', 'C', 'B', ' ') +#define ID_HERM LWID_('H', 'E', 'R', 'M') +#define ID_BEZI LWID_('B', 'E', 'Z', 'I') +#define ID_BEZ2 LWID_('B', 'E', 'Z', '2') +#define ID_LINE LWID_('L', 'I', 'N', 'E') +#define ID_STEP LWID_('S', 'T', 'E', 'P') /* clips */ -#define ID_STIL LWID_('S','T','I','L') -#define ID_ISEQ LWID_('I','S','E','Q') -#define ID_ANIM LWID_('A','N','I','M') -#define ID_XREF LWID_('X','R','E','F') -#define ID_STCC LWID_('S','T','C','C') -#define ID_TIME LWID_('T','I','M','E') -#define ID_CONT LWID_('C','O','N','T') -#define ID_BRIT LWID_('B','R','I','T') -#define ID_SATR LWID_('S','A','T','R') -#define ID_HUE LWID_('H','U','E',' ') -#define ID_GAMM LWID_('G','A','M','M') -#define ID_NEGA LWID_('N','E','G','A') -#define ID_IFLT LWID_('I','F','L','T') -#define ID_PFLT LWID_('P','F','L','T') +#define ID_STIL LWID_('S', 'T', 'I', 'L') +#define ID_ISEQ LWID_('I', 'S', 'E', 'Q') +#define ID_ANIM LWID_('A', 'N', 'I', 'M') +#define ID_XREF LWID_('X', 'R', 'E', 'F') +#define ID_STCC LWID_('S', 'T', 'C', 'C') +#define ID_TIME LWID_('T', 'I', 'M', 'E') +#define ID_CONT LWID_('C', 'O', 'N', 'T') +#define ID_BRIT LWID_('B', 'R', 'I', 'T') +#define ID_SATR LWID_('S', 'A', 'T', 'R') +#define ID_HUE LWID_('H', 'U', 'E', ' ') +#define ID_GAMM LWID_('G', 'A', 'M', 'M') +#define ID_NEGA LWID_('N', 'E', 'G', 'A') +#define ID_IFLT LWID_('I', 'F', 'L', 'T') +#define ID_PFLT LWID_('P', 'F', 'L', 'T') /* surfaces */ -#define ID_COLR LWID_('C','O','L','R') -#define ID_LUMI LWID_('L','U','M','I') -#define ID_DIFF LWID_('D','I','F','F') -#define ID_SPEC LWID_('S','P','E','C') -#define ID_GLOS LWID_('G','L','O','S') -#define ID_REFL LWID_('R','E','F','L') -#define ID_RFOP LWID_('R','F','O','P') -#define ID_RIMG LWID_('R','I','M','G') -#define ID_RSAN LWID_('R','S','A','N') -#define ID_TRAN LWID_('T','R','A','N') -#define ID_TROP LWID_('T','R','O','P') -#define ID_TIMG LWID_('T','I','M','G') -#define ID_RIND LWID_('R','I','N','D') -#define ID_TRNL LWID_('T','R','N','L') -#define ID_BUMP LWID_('B','U','M','P') -#define ID_SMAN LWID_('S','M','A','N') -#define ID_SIDE LWID_('S','I','D','E') -#define ID_CLRH LWID_('C','L','R','H') -#define ID_CLRF LWID_('C','L','R','F') -#define ID_ADTR LWID_('A','D','T','R') -#define ID_SHRP LWID_('S','H','R','P') -#define ID_LINE LWID_('L','I','N','E') -#define ID_LSIZ LWID_('L','S','I','Z') -#define ID_ALPH LWID_('A','L','P','H') -#define ID_AVAL LWID_('A','V','A','L') -#define ID_GVAL LWID_('G','V','A','L') -#define ID_BLOK LWID_('B','L','O','K') +#define ID_COLR LWID_('C', 'O', 'L', 'R') +#define ID_LUMI LWID_('L', 'U', 'M', 'I') +#define ID_DIFF LWID_('D', 'I', 'F', 'F') +#define ID_SPEC LWID_('S', 'P', 'E', 'C') +#define ID_GLOS LWID_('G', 'L', 'O', 'S') +#define ID_REFL LWID_('R', 'E', 'F', 'L') +#define ID_RFOP LWID_('R', 'F', 'O', 'P') +#define ID_RIMG LWID_('R', 'I', 'M', 'G') +#define ID_RSAN LWID_('R', 'S', 'A', 'N') +#define ID_TRAN LWID_('T', 'R', 'A', 'N') +#define ID_TROP LWID_('T', 'R', 'O', 'P') +#define ID_TIMG LWID_('T', 'I', 'M', 'G') +#define ID_RIND LWID_('R', 'I', 'N', 'D') +#define ID_TRNL LWID_('T', 'R', 'N', 'L') +#define ID_BUMP LWID_('B', 'U', 'M', 'P') +#define ID_SMAN LWID_('S', 'M', 'A', 'N') +#define ID_SIDE LWID_('S', 'I', 'D', 'E') +#define ID_CLRH LWID_('C', 'L', 'R', 'H') +#define ID_CLRF LWID_('C', 'L', 'R', 'F') +#define ID_ADTR LWID_('A', 'D', 'T', 'R') +#define ID_SHRP LWID_('S', 'H', 'R', 'P') +#define ID_LINE LWID_('L', 'I', 'N', 'E') +#define ID_LSIZ LWID_('L', 'S', 'I', 'Z') +#define ID_ALPH LWID_('A', 'L', 'P', 'H') +#define ID_AVAL LWID_('A', 'V', 'A', 'L') +#define ID_GVAL LWID_('G', 'V', 'A', 'L') +#define ID_BLOK LWID_('B', 'L', 'O', 'K') /* texture layer */ -#define ID_TYPE LWID_('T','Y','P','E') -#define ID_CHAN LWID_('C','H','A','N') -#define ID_NAME LWID_('N','A','M','E') -#define ID_ENAB LWID_('E','N','A','B') -#define ID_OPAC LWID_('O','P','A','C') -#define ID_FLAG LWID_('F','L','A','G') -#define ID_PROJ LWID_('P','R','O','J') -#define ID_STCK LWID_('S','T','C','K') -#define ID_TAMP LWID_('T','A','M','P') +#define ID_TYPE LWID_('T', 'Y', 'P', 'E') +#define ID_CHAN LWID_('C', 'H', 'A', 'N') +#define ID_NAME LWID_('N', 'A', 'M', 'E') +#define ID_ENAB LWID_('E', 'N', 'A', 'B') +#define ID_OPAC LWID_('O', 'P', 'A', 'C') +#define ID_FLAG LWID_('F', 'L', 'A', 'G') +#define ID_PROJ LWID_('P', 'R', 'O', 'J') +#define ID_STCK LWID_('S', 'T', 'C', 'K') +#define ID_TAMP LWID_('T', 'A', 'M', 'P') /* texture coordinates */ -#define ID_TMAP LWID_('T','M','A','P') -#define ID_AXIS LWID_('A','X','I','S') -#define ID_CNTR LWID_('C','N','T','R') -#define ID_SIZE LWID_('S','I','Z','E') -#define ID_ROTA LWID_('R','O','T','A') -#define ID_OREF LWID_('O','R','E','F') -#define ID_FALL LWID_('F','A','L','L') -#define ID_CSYS LWID_('C','S','Y','S') +#define ID_TMAP LWID_('T', 'M', 'A', 'P') +#define ID_AXIS LWID_('A', 'X', 'I', 'S') +#define ID_CNTR LWID_('C', 'N', 'T', 'R') +#define ID_SIZE LWID_('S', 'I', 'Z', 'E') +#define ID_ROTA LWID_('R', 'O', 'T', 'A') +#define ID_OREF LWID_('O', 'R', 'E', 'F') +#define ID_FALL LWID_('F', 'A', 'L', 'L') +#define ID_CSYS LWID_('C', 'S', 'Y', 'S') /* image map */ -#define ID_IMAP LWID_('I','M','A','P') -#define ID_IMAG LWID_('I','M','A','G') -#define ID_WRAP LWID_('W','R','A','P') -#define ID_WRPW LWID_('W','R','P','W') -#define ID_WRPH LWID_('W','R','P','H') -#define ID_VMAP LWID_('V','M','A','P') -#define ID_AAST LWID_('A','A','S','T') -#define ID_PIXB LWID_('P','I','X','B') +#define ID_IMAP LWID_('I', 'M', 'A', 'P') +#define ID_IMAG LWID_('I', 'M', 'A', 'G') +#define ID_WRAP LWID_('W', 'R', 'A', 'P') +#define ID_WRPW LWID_('W', 'R', 'P', 'W') +#define ID_WRPH LWID_('W', 'R', 'P', 'H') +#define ID_VMAP LWID_('V', 'M', 'A', 'P') +#define ID_AAST LWID_('A', 'A', 'S', 'T') +#define ID_PIXB LWID_('P', 'I', 'X', 'B') /* procedural */ -#define ID_PROC LWID_('P','R','O','C') -#define ID_COLR LWID_('C','O','L','R') -#define ID_VALU LWID_('V','A','L','U') -#define ID_FUNC LWID_('F','U','N','C') -#define ID_FTPS LWID_('F','T','P','S') -#define ID_ITPS LWID_('I','T','P','S') -#define ID_ETPS LWID_('E','T','P','S') +#define ID_PROC LWID_('P', 'R', 'O', 'C') +#define ID_COLR LWID_('C', 'O', 'L', 'R') +#define ID_VALU LWID_('V', 'A', 'L', 'U') +#define ID_FUNC LWID_('F', 'U', 'N', 'C') +#define ID_FTPS LWID_('F', 'T', 'P', 'S') +#define ID_ITPS LWID_('I', 'T', 'P', 'S') +#define ID_ETPS LWID_('E', 'T', 'P', 'S') /* gradient */ -#define ID_GRAD LWID_('G','R','A','D') -#define ID_GRST LWID_('G','R','S','T') -#define ID_GREN LWID_('G','R','E','N') -#define ID_PNAM LWID_('P','N','A','M') -#define ID_INAM LWID_('I','N','A','M') -#define ID_GRPT LWID_('G','R','P','T') -#define ID_FKEY LWID_('F','K','E','Y') -#define ID_IKEY LWID_('I','K','E','Y') +#define ID_GRAD LWID_('G', 'R', 'A', 'D') +#define ID_GRST LWID_('G', 'R', 'S', 'T') +#define ID_GREN LWID_('G', 'R', 'E', 'N') +#define ID_PNAM LWID_('P', 'N', 'A', 'M') +#define ID_INAM LWID_('I', 'N', 'A', 'M') +#define ID_GRPT LWID_('G', 'R', 'P', 'T') +#define ID_FKEY LWID_('F', 'K', 'E', 'Y') +#define ID_IKEY LWID_('I', 'K', 'E', 'Y') /* shader */ -#define ID_SHDR LWID_('S','H','D','R') -#define ID_DATA LWID_('D','A','T','A') +#define ID_SHDR LWID_('S', 'H', 'D', 'R') +#define ID_DATA LWID_('D', 'A', 'T', 'A') /* vmap type */ -#define ID_PICK LWID_('P','I','C','K') -#define ID_WGHT LWID_('W','G','H','T') -#define ID_MNVW LWID_('M','N','V','W') -#define ID_TXUV LWID_('T','X','U','V') -#define ID_RGB LWID_('R','G','B',' ') -#define ID_RGBA LWID_('R','G','B','A') -#define ID_MORF LWID_('M','O','R','F') -#define ID_SPOT LWID_('S','P','O','T') +#define ID_PICK LWID_('P', 'I', 'C', 'K') +#define ID_WGHT LWID_('W', 'G', 'H', 'T') +#define ID_MNVW LWID_('M', 'N', 'V', 'W') +#define ID_TXUV LWID_('T', 'X', 'U', 'V') +#define ID_RGB LWID_('R', 'G', 'B', ' ') +#define ID_RGBA LWID_('R', 'G', 'B', 'A') +#define ID_MORF LWID_('M', 'O', 'R', 'F') +#define ID_SPOT LWID_('S', 'P', 'O', 'T') #endif diff --git a/src/plugins/Max/Export/resource.h b/src/plugins/Max/Export/resource.h index 2239109c5af..ce884075f5a 100644 --- a/src/plugins/Max/Export/resource.h +++ b/src/plugins/Max/Export/resource.h @@ -2,272 +2,272 @@ // Microsoft Visual C++ generated include file. // Used by GameMaterial.rc // -#define IDS_LIBDESCRIPTION 1 -#define IDS_CATEGORY 2 -#define IDS_CLASS_NAME 3 -#define IDS_PARAMS 4 -#define IDS_SPIN 5 -#define IDS_COMMENT 6 -#define IDS_MN_DIFFUSE 7 -#define IDS_MN_BRIGHTNESS 8 -#define IDS_MN_OPACITY 9 -#define IDS_MN_NONE 10 -#define IDS_COLOR 11 -#define IDS_PARAMCHG 12 -#define IDS_MN_DIFFUSE_I 13 -#define IDS_MN_BRIGHTNESS_I 14 -#define IDS_MN_OPACITY_I 15 -#define IDD_PANEL 101 -#define IDD_DMTL_EXTRA6 116 -#define IDB_DMTL_BUTTONS 122 -#define IDB_DMTL_MASKBUTTONS 123 -#define IDD_DMTL_SHADER4 125 -#define IDD_DMTL_TEXMAP4 145 -#define IDD_SHADER_SKEL1 148 -#define IDD_DMTL_SAMPLING3 151 -#define IDC_TF_EDIT 218 -#define IDC_IOR_EDIT 219 -#define IDC_TR_EDIT 220 -#define IDC_DIM_AMT 220 -#define IDC_WIRE_EDIT 221 -#define IDC_DIM_MULT 222 -#define IDC_TF_SPIN 328 -#define IDC_IOR_SPIN 329 -#define IDC_TR_SPIN 330 -#define IDC_DIM_AMTSPIN 330 -#define IDC_DIM_MULTSPIN 331 -#define IDC_WIRE_SPIN 332 -#define IDC_CLOSEBUTTON 1000 -#define IDC_DOSTUFF 1000 -#define IDC_TR_SUB2 1001 -#define IDC_TR_SUB 1002 -#define IDC_TR_ADD 1003 -#define IDC_CSHADER1 1003 -#define IDC_MAPON_TR 1038 -#define IDC_PIXELS 1043 -#define IDC_UNITS 1044 -#define IDC_WIRE 1048 -#define IDD_DMTL_DYNAM 1057 -#define IDD_DMTL_XRAY 1058 -#define IDC_FACE_MAP 1059 -#define IDC_FACETED 1060 -#define IDC_HIGHLIGHT 1062 -#define IDC_2SIDE 1067 -#define IDC_SUPER_SAMP 1068 -#define IDC_ADAPT_ON 1069 -#define IDC_SAMPLE_TEX 1070 -#define IDC_MAPON_FI 1107 -#define IDC_BOUNCE_EDIT 1193 -#define IDC_BOUNCE_SPIN 1194 -#define IDC_STATFRIC_EDIT 1195 -#define IDC_STATFRIC_SPIN 1196 -#define IDC_SLIDFRIC_EDIT 1197 -#define IDC_SLIDFRIC_SPIN 1198 -#define IDC_DIM_REFL 1252 -#define IDC_TF_IN 1300 -#define IDC_TF_OUT 1301 -#define IDC_COLOR_NEW 1456 -#define IDC_EDIT 1490 -#define IDC_SPIN 1496 -#define IDC_SHADER 1728 -#define IDC_ESHADER 1729 -#define IDC_SAMPLEQUALITY_SPIN 1729 -#define IDC_SHADER2 1729 -#define IDC_CSHADER 1730 -#define IDC_SAMPLEQUALITY_EDIT 1730 -#define IDC_PIX_SAMPLER 1731 -#define IDC_THRESHOLD_EDIT 1732 -#define IDC_THRESHOLD_SPIN 1733 -#define IDC_PARAM0_EDIT 1734 -#define IDC_PARAM0_SPIN 1735 -#define IDC_PARAM1_EDIT 1736 -#define IDC_FILTER_CS 1736 -#define IDC_USEMAP_0 1737 -#define IDC_PARAM1_SPIN 1737 -#define IDC_AMTEDIT_0 1738 -#define IDC_AMTSPIN_0 1739 -#define IDC_MAP_0 1740 -#define IDC_USEMAP_1 1741 -#define IDC_AMTEDIT_1 1742 -#define IDC_AMTSPIN_1 1743 -#define IDC_MAP_1 1744 -#define IDC_USEMAP_2 1745 -#define IDC_AMTEDIT_2 1746 -#define IDC_AMTSPIN_2 1747 -#define IDC_MAP_2 1748 -#define IDC_USEMAP_3 1749 -#define IDC_AMTEDIT_3 1750 -#define IDC_AMTSPIN_3 1751 -#define IDC_MAP_3 1752 -#define IDC_USEMAP_4 1753 -#define IDC_AMTEDIT_4 1754 -#define IDC_AMTSPIN_4 1755 -#define IDC_MAP_4 1756 -#define IDC_USEMAP_5 1757 -#define IDC_AMTEDIT_5 1758 -#define IDC_AMTSPIN_5 1759 -#define IDC_MAP_5 1760 -#define IDC_USEMAP_6 1761 -#define IDC_AMTEDIT_6 1762 -#define IDC_AMTSPIN_6 1763 -#define IDC_MAP_6 1764 -#define IDC_USEMAP_7 1765 -#define IDC_AMTEDIT_7 1766 -#define IDC_AMTSPIN_7 1767 -#define IDC_MAP_7 1768 -#define IDC_USEMAP_8 1769 -#define IDC_AMTEDIT_8 1770 -#define IDC_AMTSPIN_8 1771 -#define IDC_MAP_8 1772 -#define IDC_USEMAP_9 1773 -#define IDC_AMTEDIT_9 1774 -#define IDC_AMTSPIN_9 1775 -#define IDC_MAP_9 1776 -#define IDC_USEMAP_10 1777 -#define IDC_AMTEDIT_10 1778 -#define IDC_AMTSPIN_10 1779 -#define IDC_MAP_10 1780 -#define IDC_USEMAP_11 1781 -#define IDC_AMTEDIT_11 1782 -#define IDC_AMTSPIN_11 1783 -#define IDC_MAP_11 1784 -#define IDC_LOCK_TEX01 1785 -#define IDC_USEMAP_12 1786 -#define IDC_AMTEDIT_12 1787 -#define IDC_USEMAP_13 1788 -#define IDC_AMTEDIT_13 1789 -#define IDC_USEMAP_14 1790 -#define IDC_AMTEDIT_14 1791 -#define IDC_AMTSPIN_12 1792 -#define IDC_AMTSPIN_13 1793 -#define IDC_AMTSPIN_14 1794 -#define IDC_MAP_12 1795 -#define IDC_MAP_13 1796 -#define IDC_MAP_14 1797 -#define IDC_USEMAP_15 1798 -#define IDC_AMTEDIT_15 1799 -#define IDC_AMTSPIN_15 1800 -#define IDC_MAP_15 1801 -#define IDC_USEMAP_16 1802 -#define IDC_AMTEDIT_16 1803 -#define IDC_AMTSPIN_16 1804 -#define IDC_MAP_16 1805 -#define IDC_USEMAP_17 1806 -#define IDC_BR_EDIT 1807 -#define IDC_AMTEDIT_17 1807 -#define IDC_BR_SPIN 1808 -#define IDC_AMTSPIN_17 1808 -#define IDC_MAPON_BR 1809 -#define IDC_MAP_17 1809 -#define IDC_USEMAP_18 1810 -#define IDC_AMTEDIT_18 1811 -#define IDC_AMTSPIN_18 1812 -#define IDC_MAP_18 1813 -#define IDC_MAPON_CLR 1814 -#define IDC_USEMAP_19 1814 -#define IDC_AMTEDIT_19 1815 -#define IDC_AMTSPIN_19 1816 -#define IDC_MAP_19 1817 -#define IDC_USEMAP_20 1818 -#define IDC_AMTEDIT_20 1819 -#define IDC_AMTSPIN_20 1820 -#define IDC_MAP_20 1821 -#define IDC_USEMAP_21 1822 -#define IDC_AMTEDIT_21 1823 -#define IDC_AMTSPIN_21 1824 -#define IDC_MAP_21 1825 -#define IDC_USEMAP_22 1826 -#define IDC_AMTEDIT_22 1827 -#define IDC_AMTSPIN_22 1828 -#define IDC_MAP_22 1829 -#define IDC_USEMAP_23 1830 -#define IDC_AMTEDIT_23 1831 -#define IDC_AMTSPIN_23 1832 -#define IDC_MAP_23 1833 -#define IDC_ADAPT_STATIC 1861 -#define IDC_ADVANCED_BUTTON 1862 -#define IDC_OPAC_TEXT1 1865 -#define IDC_OPAC_TEXT2 1866 -#define IDC_REFR_TEXT1 1867 -#define IDC_OPAC_TEXT3 1868 -#define IDC_REFL_TEXT1 1869 -#define IDC_REFL_TEXT2 1870 -#define IDC_REFL_BOX 1871 -#define IDC_OPAC_BOX 1872 -#define IDC_FILTER_OVERLAY 1873 -#define IDC_COMMENT_BOX 1874 -#define IDC_QUALITY_TEXT 1875 -#define IDC_COMMENT_TEXT 1876 -#define IDC_PARAM0_TEXT 1877 -#define IDC_PARAM1_TEXT 1878 -#define IDS_DS_WIREFRAME 10049 -#define IDS_DS_SHIN_STR 10052 -#define IDS_DS_OPACITY 10053 -#define IDS_JW_SHADERTYPE 10057 -#define IDS_DS_EXTRA 10059 -#define IDS_DS_TEXMAP 10060 -#define IDS_JW_MAPENABLES 10064 -#define IDS_DS_BU 10067 -#define IDS_DS_RL 10068 -#define IDS_DS_RR 10069 -#define IDS_DS_TEXMAPS 10070 -#define IDS_DS_FILTER 10071 -#define IDS_DS_WIRESZ 10114 -#define IDS_DS_IOR 10115 -#define IDS_JW_MAPS 10127 -#define IDS_JW_MAPAMOUNTS 10128 -#define IDS_JW_ENABLE 10133 -#define IDS_JW_AMOUNT 10134 -#define IDS_JW_SHADERBYNAME 10139 -#define IDS_JW_SAMPLERBYNAME 10140 -#define IDS_DS_AMOUNT 11442 -#define IDS_DS_CLASSTEXMAPS 11471 -#define IDS_DS_DYNAMICS 11484 -#define IDS_DS_BOUNCE 11485 -#define IDS_DS_STATFRIC 11486 -#define IDS_DS_SLIDFRIC 11487 -#define IDS_DS_FALLOFF 11495 -#define IDS_DS_DIMLEV 11514 -#define IDS_DS_DIMMULT 11515 -#define IDS_DS_DP 11530 -#define IDS_KE_STANDARD2 11534 -#define IDS_KE_SHADER 11535 -#define IDS_KE_SAMPLING 11536 -#define IDS_KE_XRAY 11537 -#define IDS_KE_NONE 11547 -#define IDS_JW_TWOSIDED 11585 -#define IDS_JW_FACEMAP 11586 -#define IDS_JW_OPACITYTYPE 11587 -#define IDS_JW_FILTERMAP 11588 -#define IDS_JW_FALLOFFTYPE 11589 -#define IDS_JW_WIREUNITS 11590 -#define IDS_JW_APPLYREFDIM 11591 -#define IDS_JW_PIXELSAMPLER 11592 -#define IDS_JW_SAMPLERQUAL 11593 -#define IDS_JW_SAMPLERENABLE 11594 -#define IDS_KE_STANDARD2_CDESC 11600 -#define IDS_JW_ADTEXLOCK 11620 -#define IDS_KE_FACETED 11672 -#define IDS_STRING_1 11673 -#define IDS_JW_ESHADERTYPE 11673 -#define IDS_STRING_2 11674 -#define IDS_JW_CSHADERTYPE 11674 -#define IDS_KE_SAMPLERADAPTTHRESH 11675 -#define IDS_KE_SAMPLERADAPTON 11676 -#define IDS_KE_SAMPLERADVANCED 11677 -#define IDS_JW_ESHADERBYNAME 11678 -#define IDS_JW_CSHADERBYNAME 11679 -#define IDS_KE_SUBSAMPLE_TEX_ON 11683 -#define IDS_KE_SAMPLER_PARAM0 11696 -#define IDS_KE_SAMPLER_PARAM1 11697 +#define IDS_LIBDESCRIPTION 1 +#define IDS_CATEGORY 2 +#define IDS_CLASS_NAME 3 +#define IDS_PARAMS 4 +#define IDS_SPIN 5 +#define IDS_COMMENT 6 +#define IDS_MN_DIFFUSE 7 +#define IDS_MN_BRIGHTNESS 8 +#define IDS_MN_OPACITY 9 +#define IDS_MN_NONE 10 +#define IDS_COLOR 11 +#define IDS_PARAMCHG 12 +#define IDS_MN_DIFFUSE_I 13 +#define IDS_MN_BRIGHTNESS_I 14 +#define IDS_MN_OPACITY_I 15 +#define IDD_PANEL 101 +#define IDD_DMTL_EXTRA6 116 +#define IDB_DMTL_BUTTONS 122 +#define IDB_DMTL_MASKBUTTONS 123 +#define IDD_DMTL_SHADER4 125 +#define IDD_DMTL_TEXMAP4 145 +#define IDD_SHADER_SKEL1 148 +#define IDD_DMTL_SAMPLING3 151 +#define IDC_TF_EDIT 218 +#define IDC_IOR_EDIT 219 +#define IDC_TR_EDIT 220 +#define IDC_DIM_AMT 220 +#define IDC_WIRE_EDIT 221 +#define IDC_DIM_MULT 222 +#define IDC_TF_SPIN 328 +#define IDC_IOR_SPIN 329 +#define IDC_TR_SPIN 330 +#define IDC_DIM_AMTSPIN 330 +#define IDC_DIM_MULTSPIN 331 +#define IDC_WIRE_SPIN 332 +#define IDC_CLOSEBUTTON 1000 +#define IDC_DOSTUFF 1000 +#define IDC_TR_SUB2 1001 +#define IDC_TR_SUB 1002 +#define IDC_TR_ADD 1003 +#define IDC_CSHADER1 1003 +#define IDC_MAPON_TR 1038 +#define IDC_PIXELS 1043 +#define IDC_UNITS 1044 +#define IDC_WIRE 1048 +#define IDD_DMTL_DYNAM 1057 +#define IDD_DMTL_XRAY 1058 +#define IDC_FACE_MAP 1059 +#define IDC_FACETED 1060 +#define IDC_HIGHLIGHT 1062 +#define IDC_2SIDE 1067 +#define IDC_SUPER_SAMP 1068 +#define IDC_ADAPT_ON 1069 +#define IDC_SAMPLE_TEX 1070 +#define IDC_MAPON_FI 1107 +#define IDC_BOUNCE_EDIT 1193 +#define IDC_BOUNCE_SPIN 1194 +#define IDC_STATFRIC_EDIT 1195 +#define IDC_STATFRIC_SPIN 1196 +#define IDC_SLIDFRIC_EDIT 1197 +#define IDC_SLIDFRIC_SPIN 1198 +#define IDC_DIM_REFL 1252 +#define IDC_TF_IN 1300 +#define IDC_TF_OUT 1301 +#define IDC_COLOR_NEW 1456 +#define IDC_EDIT 1490 +#define IDC_SPIN 1496 +#define IDC_SHADER 1728 +#define IDC_ESHADER 1729 +#define IDC_SAMPLEQUALITY_SPIN 1729 +#define IDC_SHADER2 1729 +#define IDC_CSHADER 1730 +#define IDC_SAMPLEQUALITY_EDIT 1730 +#define IDC_PIX_SAMPLER 1731 +#define IDC_THRESHOLD_EDIT 1732 +#define IDC_THRESHOLD_SPIN 1733 +#define IDC_PARAM0_EDIT 1734 +#define IDC_PARAM0_SPIN 1735 +#define IDC_PARAM1_EDIT 1736 +#define IDC_FILTER_CS 1736 +#define IDC_USEMAP_0 1737 +#define IDC_PARAM1_SPIN 1737 +#define IDC_AMTEDIT_0 1738 +#define IDC_AMTSPIN_0 1739 +#define IDC_MAP_0 1740 +#define IDC_USEMAP_1 1741 +#define IDC_AMTEDIT_1 1742 +#define IDC_AMTSPIN_1 1743 +#define IDC_MAP_1 1744 +#define IDC_USEMAP_2 1745 +#define IDC_AMTEDIT_2 1746 +#define IDC_AMTSPIN_2 1747 +#define IDC_MAP_2 1748 +#define IDC_USEMAP_3 1749 +#define IDC_AMTEDIT_3 1750 +#define IDC_AMTSPIN_3 1751 +#define IDC_MAP_3 1752 +#define IDC_USEMAP_4 1753 +#define IDC_AMTEDIT_4 1754 +#define IDC_AMTSPIN_4 1755 +#define IDC_MAP_4 1756 +#define IDC_USEMAP_5 1757 +#define IDC_AMTEDIT_5 1758 +#define IDC_AMTSPIN_5 1759 +#define IDC_MAP_5 1760 +#define IDC_USEMAP_6 1761 +#define IDC_AMTEDIT_6 1762 +#define IDC_AMTSPIN_6 1763 +#define IDC_MAP_6 1764 +#define IDC_USEMAP_7 1765 +#define IDC_AMTEDIT_7 1766 +#define IDC_AMTSPIN_7 1767 +#define IDC_MAP_7 1768 +#define IDC_USEMAP_8 1769 +#define IDC_AMTEDIT_8 1770 +#define IDC_AMTSPIN_8 1771 +#define IDC_MAP_8 1772 +#define IDC_USEMAP_9 1773 +#define IDC_AMTEDIT_9 1774 +#define IDC_AMTSPIN_9 1775 +#define IDC_MAP_9 1776 +#define IDC_USEMAP_10 1777 +#define IDC_AMTEDIT_10 1778 +#define IDC_AMTSPIN_10 1779 +#define IDC_MAP_10 1780 +#define IDC_USEMAP_11 1781 +#define IDC_AMTEDIT_11 1782 +#define IDC_AMTSPIN_11 1783 +#define IDC_MAP_11 1784 +#define IDC_LOCK_TEX01 1785 +#define IDC_USEMAP_12 1786 +#define IDC_AMTEDIT_12 1787 +#define IDC_USEMAP_13 1788 +#define IDC_AMTEDIT_13 1789 +#define IDC_USEMAP_14 1790 +#define IDC_AMTEDIT_14 1791 +#define IDC_AMTSPIN_12 1792 +#define IDC_AMTSPIN_13 1793 +#define IDC_AMTSPIN_14 1794 +#define IDC_MAP_12 1795 +#define IDC_MAP_13 1796 +#define IDC_MAP_14 1797 +#define IDC_USEMAP_15 1798 +#define IDC_AMTEDIT_15 1799 +#define IDC_AMTSPIN_15 1800 +#define IDC_MAP_15 1801 +#define IDC_USEMAP_16 1802 +#define IDC_AMTEDIT_16 1803 +#define IDC_AMTSPIN_16 1804 +#define IDC_MAP_16 1805 +#define IDC_USEMAP_17 1806 +#define IDC_BR_EDIT 1807 +#define IDC_AMTEDIT_17 1807 +#define IDC_BR_SPIN 1808 +#define IDC_AMTSPIN_17 1808 +#define IDC_MAPON_BR 1809 +#define IDC_MAP_17 1809 +#define IDC_USEMAP_18 1810 +#define IDC_AMTEDIT_18 1811 +#define IDC_AMTSPIN_18 1812 +#define IDC_MAP_18 1813 +#define IDC_MAPON_CLR 1814 +#define IDC_USEMAP_19 1814 +#define IDC_AMTEDIT_19 1815 +#define IDC_AMTSPIN_19 1816 +#define IDC_MAP_19 1817 +#define IDC_USEMAP_20 1818 +#define IDC_AMTEDIT_20 1819 +#define IDC_AMTSPIN_20 1820 +#define IDC_MAP_20 1821 +#define IDC_USEMAP_21 1822 +#define IDC_AMTEDIT_21 1823 +#define IDC_AMTSPIN_21 1824 +#define IDC_MAP_21 1825 +#define IDC_USEMAP_22 1826 +#define IDC_AMTEDIT_22 1827 +#define IDC_AMTSPIN_22 1828 +#define IDC_MAP_22 1829 +#define IDC_USEMAP_23 1830 +#define IDC_AMTEDIT_23 1831 +#define IDC_AMTSPIN_23 1832 +#define IDC_MAP_23 1833 +#define IDC_ADAPT_STATIC 1861 +#define IDC_ADVANCED_BUTTON 1862 +#define IDC_OPAC_TEXT1 1865 +#define IDC_OPAC_TEXT2 1866 +#define IDC_REFR_TEXT1 1867 +#define IDC_OPAC_TEXT3 1868 +#define IDC_REFL_TEXT1 1869 +#define IDC_REFL_TEXT2 1870 +#define IDC_REFL_BOX 1871 +#define IDC_OPAC_BOX 1872 +#define IDC_FILTER_OVERLAY 1873 +#define IDC_COMMENT_BOX 1874 +#define IDC_QUALITY_TEXT 1875 +#define IDC_COMMENT_TEXT 1876 +#define IDC_PARAM0_TEXT 1877 +#define IDC_PARAM1_TEXT 1878 +#define IDS_DS_WIREFRAME 10049 +#define IDS_DS_SHIN_STR 10052 +#define IDS_DS_OPACITY 10053 +#define IDS_JW_SHADERTYPE 10057 +#define IDS_DS_EXTRA 10059 +#define IDS_DS_TEXMAP 10060 +#define IDS_JW_MAPENABLES 10064 +#define IDS_DS_BU 10067 +#define IDS_DS_RL 10068 +#define IDS_DS_RR 10069 +#define IDS_DS_TEXMAPS 10070 +#define IDS_DS_FILTER 10071 +#define IDS_DS_WIRESZ 10114 +#define IDS_DS_IOR 10115 +#define IDS_JW_MAPS 10127 +#define IDS_JW_MAPAMOUNTS 10128 +#define IDS_JW_ENABLE 10133 +#define IDS_JW_AMOUNT 10134 +#define IDS_JW_SHADERBYNAME 10139 +#define IDS_JW_SAMPLERBYNAME 10140 +#define IDS_DS_AMOUNT 11442 +#define IDS_DS_CLASSTEXMAPS 11471 +#define IDS_DS_DYNAMICS 11484 +#define IDS_DS_BOUNCE 11485 +#define IDS_DS_STATFRIC 11486 +#define IDS_DS_SLIDFRIC 11487 +#define IDS_DS_FALLOFF 11495 +#define IDS_DS_DIMLEV 11514 +#define IDS_DS_DIMMULT 11515 +#define IDS_DS_DP 11530 +#define IDS_KE_STANDARD2 11534 +#define IDS_KE_SHADER 11535 +#define IDS_KE_SAMPLING 11536 +#define IDS_KE_XRAY 11537 +#define IDS_KE_NONE 11547 +#define IDS_JW_TWOSIDED 11585 +#define IDS_JW_FACEMAP 11586 +#define IDS_JW_OPACITYTYPE 11587 +#define IDS_JW_FILTERMAP 11588 +#define IDS_JW_FALLOFFTYPE 11589 +#define IDS_JW_WIREUNITS 11590 +#define IDS_JW_APPLYREFDIM 11591 +#define IDS_JW_PIXELSAMPLER 11592 +#define IDS_JW_SAMPLERQUAL 11593 +#define IDS_JW_SAMPLERENABLE 11594 +#define IDS_KE_STANDARD2_CDESC 11600 +#define IDS_JW_ADTEXLOCK 11620 +#define IDS_KE_FACETED 11672 +#define IDS_STRING_1 11673 +#define IDS_JW_ESHADERTYPE 11673 +#define IDS_STRING_2 11674 +#define IDS_JW_CSHADERTYPE 11674 +#define IDS_KE_SAMPLERADAPTTHRESH 11675 +#define IDS_KE_SAMPLERADAPTON 11676 +#define IDS_KE_SAMPLERADVANCED 11677 +#define IDS_JW_ESHADERBYNAME 11678 +#define IDS_JW_CSHADERBYNAME 11679 +#define IDS_KE_SUBSAMPLE_TEX_ON 11683 +#define IDS_KE_SAMPLER_PARAM0 11696 +#define IDS_KE_SAMPLER_PARAM1 11697 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1004 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1004 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/Max/Export/stdafx.cpp b/src/plugins/Max/Export/stdafx.cpp index 47ba185752c..d12030476ed 100644 --- a/src/plugins/Max/Export/stdafx.cpp +++ b/src/plugins/Max/Export/stdafx.cpp @@ -1,3 +1,2 @@ #include "stdafx.h" #pragma hdrstop - diff --git a/src/plugins/Max/Material/DllEntry.cpp b/src/plugins/Max/Material/DllEntry.cpp index 39c4d72d9d7..1cf6451355e 100644 --- a/src/plugins/Max/Material/DllEntry.cpp +++ b/src/plugins/Max/Material/DllEntry.cpp @@ -3,70 +3,64 @@ #include "plugins/Shared/GameMaterial.h" -extern ClassDesc2* GetXRayMtlDesc (); -extern TCHAR* GetString (int id); +extern ClassDesc2* GetXRayMtlDesc(); +extern TCHAR* GetString(int id); HINSTANCE hInstance; int controlsInit = FALSE; -BOOL WINAPI DllMain(HINSTANCE hinstDLL, - ULONG fdwReason, - LPVOID lpvReserved) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, ULONG fdwReason, LPVOID lpvReserved) { - hInstance = hinstDLL; // Hang on to this DLL's instance handle. + hInstance = hinstDLL; // Hang on to this DLL's instance handle. - if(!controlsInit) - { - controlsInit = TRUE; - Core._initialize("S.T.A.L.K.E.R.Plugin", 0, FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - FPU::m64r (); // ����� ����� ���� �� ��������� ���������� � 0 - InitCustomControls(hInstance); // Initialize MAX's custom controls - InitCommonControls(); // Initialize Win95 controls - // load shader list - XRayMtl::LoadXRayShaderList(); - } + if (!controlsInit) { + controlsInit = TRUE; + Core._initialize("S.T.A.L.K.E.R.Plugin", 0, FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + FPU::m64r(); // ����� ����� ���� �� ��������� ���������� � 0 + InitCustomControls(hInstance); // Initialize MAX's custom controls + InitCommonControls(); // Initialize Win95 controls + // load shader list + XRayMtl::LoadXRayShaderList(); + } - if (DLL_PROCESS_DETACH==fdwReason){ - Core._destroy(); - XRayMtl::UnloadXRayShaderList(); - } + if (DLL_PROCESS_DETACH == fdwReason) { + Core._destroy(); + XRayMtl::UnloadXRayShaderList(); + } - return (TRUE); + return (TRUE); } __declspec(dllexport) const TCHAR* LibDescription() { - return GetString(IDS_LIBDESCRIPTION); + return GetString(IDS_LIBDESCRIPTION); } __declspec(dllexport) int LibNumberClasses() { - return 1; + return 1; } __declspec(dllexport) ClassDesc* LibClassDesc(int i) { - switch(i) - { - case 0: - return GetXRayMtlDesc(); - default: - return 0; - } + switch (i) + { + case 0: return GetXRayMtlDesc(); + default: return 0; + } } __declspec(dllexport) ULONG LibVersion() { - return VERSION_3DSMAX; + return VERSION_3DSMAX; } -TCHAR *GetString(int id) +TCHAR* GetString(int id) { - static TCHAR buf[256]; + static TCHAR buf[256]; - if(hInstance) - return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL; + if (hInstance) return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL; - return NULL; + return NULL; } diff --git a/src/plugins/Max/Material/GameMaterial.rc b/src/plugins/Max/Material/GameMaterial.rc index d8fe2510118..9a061cfcd3a 100644 --- a/src/plugins/Max/Material/GameMaterial.rc +++ b/src/plugins/Max/Material/GameMaterial.rc @@ -19,316 +19,156 @@ #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_PANEL DIALOGEX 0, 0, 216, 80 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - RTEXT " Color :",IDC_STATIC,22,26,26,10 - CONTROL "User1",IDC_COLOR_NEW,"ColorSwatch",0x0,51,18,50,26 - CONTROL "M",IDC_MAPON_CLR,"CustButton",0x0,106,27,10,10 - CONTROL "",IDC_HIGHLIGHT,"Static",SS_BLACKFRAME,135,25,67,47 - LTEXT " Opacity :",IDC_STATIC,19,60,31,8 - CONTROL "",IDC_TR_EDIT,"CustEdit",WS_TABSTOP,52,60,22,10 - CONTROL "0,255,0",IDC_TR_SPIN,"SpinnerControl",WS_TABSTOP,74,60, - 11,10 - CONTROL "M",IDC_MAPON_TR,"CustButton",0x0,91,60,10,10 - RTEXT "Brightness :",IDC_STATIC,12,48,37,8 - CONTROL "",IDC_BR_EDIT,"CustEdit",WS_TABSTOP,52,48,22,10 - CONTROL "0,255,0",IDC_BR_SPIN,"SpinnerControl",WS_TABSTOP,74,48, - 11,10 - CONTROL "M",IDC_MAPON_BR,"CustButton",0x0,91,48,10,10 - GROUPBOX "Shading Settings",IDC_STATIC,4,4,119,72 - CTEXT "Specular Curve",IDC_STATIC,135,11,67,12,SS_CENTERIMAGE | - SS_SUNKEN -END - -IDD_DMTL_SHADER4 DIALOGEX 0, 0, 216, 28 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - COMBOBOX IDC_SHADER,8,3,85,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - CONTROL "Wire",IDC_WIRE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, - 109,2,27,10 - CONTROL "2-Sided",IDC_2SIDE,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,162,2,36,10 - CONTROL "Face Map",IDC_FACE_MAP,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,110,14,44,10 - CONTROL "Faceted",IDC_FACETED,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,162,14,44,10 -END - -IDD_DMTL_DYNAM DIALOG 0, 0, 216, 49 -STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE -FONT 8, "MS Sans Serif" -BEGIN - CONTROL "",IDC_BOUNCE_EDIT,"CustEdit",WS_TABSTOP,108,6,35,10 - LTEXT "Bounce Coefficient:",IDC_STATIC,44,7,63,9 - CONTROL "0,255,0",IDC_BOUNCE_SPIN,"SpinnerControl",0x0,144,6,11, - 10 - CONTROL "",IDC_STATFRIC_EDIT,"CustEdit",WS_TABSTOP,108,20,35,10 - LTEXT "Static Friction:",IDC_STATIC,58,21,49,9 - CONTROL "0,255,0",IDC_STATFRIC_SPIN,"SpinnerControl",0x0,144,20, - 11,10 - CONTROL "",IDC_SLIDFRIC_EDIT,"CustEdit",WS_TABSTOP,108,33,35,10 - LTEXT "Sliding Friction:",IDC_STATIC,56,33,50,9 - CONTROL "0,255,0",IDC_SLIDFRIC_SPIN,"SpinnerControl",0x0,144,33, - 11,10 -END - -IDD_DMTL_TEXMAP4 DIALOG 0, 0, 216, 309 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Amount",IDC_STATIC,76,4,24,8 - LTEXT "Map Type",IDC_STATIC,152,4,16,8 - CONTROL "",IDC_USEMAP_0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 16,68,10 - CONTROL "",IDC_AMTEDIT_0,"CustEdit",WS_TABSTOP,72,16,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_0,"SpinnerControl",0x0,92,16,11,10 - CONTROL "",IDC_MAP_0,"CustButton",WS_TABSTOP,104,16,100,10 - CONTROL "User1",IDC_LOCK_TEX01,"CustButton",0x0,206,22,10,10 - CONTROL "",IDC_USEMAP_1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 28,68,10 - CONTROL "",IDC_AMTEDIT_1,"CustEdit",WS_TABSTOP,72,28,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_1,"SpinnerControl",0x0,92,28,11,10 - CONTROL "",IDC_MAP_1,"CustButton",WS_TABSTOP,104,28,100,10 - CONTROL "",IDC_USEMAP_2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 40,68,10 - CONTROL "",IDC_AMTEDIT_2,"CustEdit",WS_TABSTOP,72,40,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_2,"SpinnerControl",0x0,92,40,11,10 - CONTROL "",IDC_MAP_2,"CustButton",WS_TABSTOP,104,40,100,10 - CONTROL "",IDC_USEMAP_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 52,68,10 - CONTROL "",IDC_AMTEDIT_3,"CustEdit",WS_TABSTOP,72,52,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_3,"SpinnerControl",0x0,92,52,11,10 - CONTROL "",IDC_MAP_3,"CustButton",WS_TABSTOP,104,52,100,10 - CONTROL "",IDC_USEMAP_4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 64,68,10 - CONTROL "",IDC_AMTEDIT_4,"CustEdit",WS_TABSTOP,72,64,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_4,"SpinnerControl",0x0,92,64,11,10 - CONTROL "",IDC_MAP_4,"CustButton",WS_TABSTOP,104,64,100,10 - CONTROL "",IDC_USEMAP_5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 76,68,10 - CONTROL "",IDC_AMTEDIT_5,"CustEdit",WS_TABSTOP,72,76,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_5,"SpinnerControl",0x0,92,76,11,10 - CONTROL "",IDC_MAP_5,"CustButton",WS_TABSTOP,104,76,100,10 - CONTROL "",IDC_USEMAP_6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 88,68,10 - CONTROL "",IDC_AMTEDIT_6,"CustEdit",WS_TABSTOP,72,88,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_6,"SpinnerControl",0x0,92,88,11,10 - CONTROL "",IDC_MAP_6,"CustButton",WS_TABSTOP,104,88,100,10 - CONTROL "",IDC_USEMAP_7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 100,68,10 - CONTROL "",IDC_AMTEDIT_7,"CustEdit",WS_TABSTOP,72,100,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_7,"SpinnerControl",0x0,92,100,11, - 10 - CONTROL "",IDC_MAP_7,"CustButton",WS_TABSTOP,104,100,100,10 - CONTROL "",IDC_USEMAP_8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 112,68,10 - CONTROL "",IDC_AMTEDIT_8,"CustEdit",WS_TABSTOP,72,112,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_8,"SpinnerControl",0x0,92,112,11, - 10 - CONTROL "",IDC_MAP_8,"CustButton",WS_TABSTOP,104,112,100,10 - CONTROL "",IDC_USEMAP_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 124,68,10 - CONTROL "",IDC_AMTEDIT_9,"CustEdit",WS_TABSTOP,72,124,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_9,"SpinnerControl",0x0,92,124,11, - 10 - CONTROL "",IDC_MAP_9,"CustButton",WS_TABSTOP,104,124,100,10 - CONTROL "",IDC_USEMAP_10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 136,68,10 - CONTROL "",IDC_AMTEDIT_10,"CustEdit",WS_TABSTOP,72,136,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_10,"SpinnerControl",0x0,92,136,11, - 10 - CONTROL "",IDC_MAP_10,"CustButton",WS_TABSTOP,104,136,100,10 - CONTROL "",IDC_USEMAP_11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 148,68,10 - CONTROL "",IDC_AMTEDIT_11,"CustEdit",WS_TABSTOP,72,148,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_11,"SpinnerControl",0x0,92,148,11, - 10 - CONTROL "",IDC_MAP_11,"CustButton",WS_TABSTOP,104,148,100,10 - CONTROL "",IDC_USEMAP_12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 160,68,10 - CONTROL "",IDC_AMTEDIT_12,"CustEdit",WS_TABSTOP,72,160,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_12,"SpinnerControl",0x0,92,160,11, - 10 - CONTROL "",IDC_MAP_12,"CustButton",WS_TABSTOP,104,160,100,10 - CONTROL "",IDC_USEMAP_13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 172,68,10 - CONTROL "",IDC_AMTEDIT_13,"CustEdit",WS_TABSTOP,72,172,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_13,"SpinnerControl",0x0,92,172,11, - 10 - CONTROL "",IDC_MAP_13,"CustButton",WS_TABSTOP,104,172,100,10 - CONTROL "",IDC_USEMAP_14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 184,68,10 - CONTROL "",IDC_AMTEDIT_14,"CustEdit",WS_TABSTOP,72,184,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_14,"SpinnerControl",0x0,92,184,11, - 10 - CONTROL "",IDC_MAP_14,"CustButton",WS_TABSTOP,104,184,100,10 - CONTROL "",IDC_USEMAP_15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 196,68,10 - CONTROL "",IDC_AMTEDIT_15,"CustEdit",WS_TABSTOP,72,196,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_15,"SpinnerControl",0x0,92,196,11, - 10 - CONTROL "",IDC_MAP_15,"CustButton",WS_TABSTOP,104,196,100,10 - CONTROL "",IDC_USEMAP_16,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 208,68,10 - CONTROL "",IDC_AMTEDIT_16,"CustEdit",WS_TABSTOP,72,208,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_16,"SpinnerControl",0x0,92,208,11, - 10 - CONTROL "",IDC_MAP_16,"CustButton",WS_TABSTOP,104,208,100,10 - CONTROL "",IDC_USEMAP_17,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 220,68,10 - CONTROL "",IDC_AMTEDIT_17,"CustEdit",WS_TABSTOP,72,220,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_17,"SpinnerControl",0x0,92,220,11, - 10 - CONTROL "",IDC_MAP_17,"CustButton",WS_TABSTOP,104,220,100,10 - CONTROL "",IDC_USEMAP_18,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 232,68,10 - CONTROL "",IDC_AMTEDIT_18,"CustEdit",WS_TABSTOP,72,232,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_18,"SpinnerControl",0x0,92,232,11, - 10 - CONTROL "",IDC_MAP_18,"CustButton",WS_TABSTOP,104,232,100,10 - CONTROL "",IDC_USEMAP_19,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 244,68,10 - CONTROL "",IDC_AMTEDIT_19,"CustEdit",WS_TABSTOP,72,244,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_19,"SpinnerControl",0x0,92,244,11, - 10 - CONTROL "",IDC_MAP_19,"CustButton",WS_TABSTOP,104,244,100,10 - CONTROL "",IDC_USEMAP_20,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 256,68,10 - CONTROL "",IDC_AMTEDIT_20,"CustEdit",WS_TABSTOP,72,256,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_20,"SpinnerControl",0x0,92,256,11, - 10 - CONTROL "",IDC_MAP_20,"CustButton",WS_TABSTOP,104,256,100,10 - CONTROL "",IDC_USEMAP_21,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 268,68,10 - CONTROL "",IDC_AMTEDIT_21,"CustEdit",WS_TABSTOP,72,268,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_21,"SpinnerControl",0x0,92,268,11, - 10 - CONTROL "",IDC_MAP_21,"CustButton",WS_TABSTOP,104,268,100,10 - CONTROL "",IDC_USEMAP_22,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 280,68,10 - CONTROL "",IDC_AMTEDIT_22,"CustEdit",WS_TABSTOP,72,280,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_22,"SpinnerControl",0x0,92,280,11, - 10 - CONTROL "",IDC_MAP_22,"CustButton",WS_TABSTOP,104,280,100,10 - CONTROL "",IDC_USEMAP_23,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 292,68,10 - CONTROL "",IDC_AMTEDIT_23,"CustEdit",WS_TABSTOP,72,292,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_23,"SpinnerControl",0x0,92,292,11, - 10 - CONTROL "",IDC_MAP_23,"CustButton",WS_TABSTOP,104,292,100,10 -END - -IDD_DMTL_SAMPLING3 DIALOG 0, 0, 216, 59 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif" -BEGIN - CONTROL "Enable Sampler",IDC_SUPER_SAMP,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,3,5,64,10 - COMBOBOX IDC_PIX_SAMPLER,75,3,80,84,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - RTEXT "Quality:",IDC_QUALITY_TEXT,155,4,27,9,NOT WS_GROUP - CONTROL "",IDC_SAMPLEQUALITY_EDIT,"CustEdit",WS_TABSTOP,183,3,19, - 10 - CONTROL "0,255,0",IDC_SAMPLEQUALITY_SPIN,"SpinnerControl", - WS_TABSTOP,202,3,11,10 - CONTROL "Supersamp. Tex.",IDC_SAMPLE_TEX,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,3,18,71,10 - GROUPBOX "",IDC_COMMENT_BOX,75,16,80,41 - LTEXT "No Comment",IDC_COMMENT_TEXT,77,21,76,34 - RTEXT "Param0",IDC_PARAM0_TEXT,155,17,27,9,NOT WS_GROUP - CONTROL "",IDC_PARAM0_EDIT,"CustEdit",WS_TABSTOP,183,16,19,10 - CONTROL "0,255,0",IDC_PARAM0_SPIN,"SpinnerControl",WS_TABSTOP, - 202,16,11,10 - CONTROL "Adaptive",IDC_ADAPT_ON,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,3,32,56,10 - RTEXT "Param1",IDC_PARAM1_TEXT,155,30,27,9,NOT WS_GROUP - CONTROL "",IDC_PARAM1_EDIT,"CustEdit",WS_TABSTOP,183,30,19,10 - CONTROL "0,255,0",IDC_PARAM1_SPIN,"SpinnerControl",WS_TABSTOP, - 201,30,11,10 - RTEXT "Threshold:",IDC_ADAPT_STATIC,2,46,34,8,NOT WS_GROUP - CONTROL "",IDC_THRESHOLD_EDIT,"CustEdit",WS_TABSTOP,38,45,25,10 - CONTROL "0,255,0",IDC_THRESHOLD_SPIN,"SpinnerControl",WS_TABSTOP, - 63,45,11,10 - PUSHBUTTON "Advanced...",IDC_ADVANCED_BUTTON,166,43,46,12 -END - -IDD_DMTL_EXTRA6 DIALOGEX 0, 0, 216, 101 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x1 -BEGIN - GROUPBOX "Advanced Transparency",IDC_OPAC_BOX,4,1,147,71 - LTEXT "Falloff:",IDC_OPAC_TEXT1,9,11,22,8 - LTEXT "Type:",IDC_OPAC_TEXT3,56,11,18,8 - CONTROL "In",IDC_TF_IN,"Button",BS_AUTORADIOBUTTON | WS_GROUP | - WS_TABSTOP,26,21,20,8 - CONTROL "Out",IDC_TF_OUT,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,26,32,24,10 - RTEXT "Refraction Filter: ",IDC_FILTER_OVERLAY,44,19,59,11 - CONTROL "Filter:",IDC_TR_SUB2,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,72,20,29,8 - CONTROL "Subtractive",IDC_TR_SUB,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,72,33,52,8 - CONTROL "Additive",IDC_TR_ADD,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,72,45,37,8 - CONTROL "User1",IDC_FILTER_CS,"ColorSwatch",WS_TABSTOP,105,17,27, - 14 - CONTROL "M",IDC_MAPON_FI,"CustButton",WS_TABSTOP,136,20,10,10 - GROUPBOX "Wire",IDC_STATIC,153,1,59,71 - LTEXT "Size:",IDC_STATIC,156,21,16,9,0,WS_EX_RIGHT - CONTROL "",IDC_WIRE_EDIT,"CustEdit",WS_TABSTOP,174,20,22,10 - CONTROL "0,255,0",IDC_WIRE_SPIN,"SpinnerControl",0x0,196,20,11, - 10 - LTEXT "In:",IDC_STATIC,160,45,8,8 - CONTROL "Pixels",IDC_PIXELS,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,172,41,32,8 - CONTROL "Units",IDC_UNITS,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,172,52,28,8 - LTEXT "Index of Refraction:",IDC_REFR_TEXT1,11,57,91,9,0, - WS_EX_RIGHT - CONTROL "",IDC_IOR_EDIT,"CustEdit",WS_TABSTOP,105,57,19,10 - CONTROL "0,255,0",IDC_IOR_SPIN,"SpinnerControl",0x0,124,57,11,10 - GROUPBOX "Reflection Dimming",IDC_REFL_BOX,4,72,209,27 - CONTROL "Apply",IDC_DIM_REFL,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,11,83,36,10 - LTEXT "Dim Level:",IDC_REFL_TEXT1,52,84,33,8,0,WS_EX_RIGHT - CONTROL "",IDC_DIM_AMT,"CustEdit",WS_TABSTOP,87,83,24,10 - CONTROL "0,255,0",IDC_DIM_AMTSPIN,"SpinnerControl",0x0,112,83,11, - 10 - LTEXT "Refl. Level:",IDC_REFL_TEXT2,132,84,38,8 - CONTROL "",IDC_DIM_MULT,"CustEdit",WS_TABSTOP,173,83,24,10 - CONTROL "0,255,0",IDC_DIM_MULTSPIN,"SpinnerControl",0x0,198,83, - 11,10 - LTEXT "Amt:",IDC_OPAC_TEXT2,12,44,16,8 - CONTROL "",IDC_TF_EDIT,"CustEdit",WS_TABSTOP,28,44,20,10 - CONTROL "0,255,0",IDC_TF_SPIN,"SpinnerControl",0x0,48,44,11,10 -END - -IDD_DMTL_XRAY DIALOGEX 0, 0, 216, 50 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - LTEXT "Engine Shader",IDC_STATIC,8,7,52,8 - COMBOBOX IDC_ESHADER,63,4,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - COMBOBOX IDC_CSHADER,63,19,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - LTEXT "Compiler Shader",IDC_STATIC,8,22,52,8 - COMBOBOX IDC_GAMEMTL,63,34,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - LTEXT "Game Material",IDC_STATIC,8,37,46,8 -END - +#endif //_WIN32 + + ///////////////////////////////////////////////////////////////////////////// + // + // Dialog + // + + IDD_PANEL DIALOGEX 0, + 0, 216, 80 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN RTEXT " Color :", IDC_STATIC, 22, + 26, 26, 10 CONTROL "User1", IDC_COLOR_NEW, "ColorSwatch", 0x0, 51, 18, 50, 26 CONTROL "M", IDC_MAPON_CLR, + "CustButton", 0x0, 106, 27, 10, 10 CONTROL "", IDC_HIGHLIGHT, "Static", SS_BLACKFRAME, 135, 25, 67, + 47 LTEXT " Opacity :", IDC_STATIC, 19, 60, 31, 8 CONTROL "", IDC_TR_EDIT, "CustEdit", WS_TABSTOP, 52, 60, 22, + 10 CONTROL "0,255,0", IDC_TR_SPIN, "SpinnerControl", WS_TABSTOP, 74, 60, 11, 10 CONTROL "M", IDC_MAPON_TR, + "CustButton", 0x0, 91, 60, 10, 10 RTEXT "Brightness :", IDC_STATIC, 12, 48, 37, 8 CONTROL "", IDC_BR_EDIT, + "CustEdit", WS_TABSTOP, 52, 48, 22, 10 CONTROL "0,255,0", IDC_BR_SPIN, "SpinnerControl", WS_TABSTOP, 74, 48, 11, + 10 CONTROL "M", IDC_MAPON_BR, "CustButton", 0x0, 91, 48, 10, 10 GROUPBOX "Shading Settings", IDC_STATIC, 4, 4, 119, + 72 CTEXT "Specular Curve", IDC_STATIC, 135, 11, 67, 12, SS_CENTERIMAGE | SS_SUNKEN END + + IDD_DMTL_SHADER4 DIALOGEX 0, + 0, 216, 28 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN COMBOBOX IDC_SHADER, 8, 3, 85, 75, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Wire", IDC_WIRE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 109, 2, + 27, 10 CONTROL "2-Sided", IDC_2SIDE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 162, 2, 36, 10 CONTROL "Face Map", + IDC_FACE_MAP, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 110, 14, 44, 10 CONTROL "Faceted", IDC_FACETED, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 162, 14, 44, 10 END + + IDD_DMTL_DYNAM DIALOG 0, + 0, 216, 49 STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE FONT 8, "MS Sans Serif" BEGIN CONTROL "", IDC_BOUNCE_EDIT, + "CustEdit", WS_TABSTOP, 108, 6, 35, 10 LTEXT "Bounce Coefficient:", IDC_STATIC, 44, 7, 63, 9 CONTROL "0,255,0", + IDC_BOUNCE_SPIN, "SpinnerControl", 0x0, 144, 6, 11, 10 CONTROL "", IDC_STATFRIC_EDIT, "CustEdit", WS_TABSTOP, 108, + 20, 35, 10 LTEXT "Static Friction:", IDC_STATIC, 58, 21, 49, 9 CONTROL "0,255,0", IDC_STATFRIC_SPIN, + "SpinnerControl", 0x0, 144, 20, 11, 10 CONTROL "", IDC_SLIDFRIC_EDIT, "CustEdit", WS_TABSTOP, 108, 33, 35, + 10 LTEXT "Sliding Friction:", IDC_STATIC, 56, 33, 50, 9 CONTROL "0,255,0", IDC_SLIDFRIC_SPIN, "SpinnerControl", 0x0, + 144, 33, 11, 10 END + + IDD_DMTL_TEXMAP4 DIALOG 0, + 0, 216, 309 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif" BEGIN LTEXT "Amount", IDC_STATIC, 76, 4, 24, + 8 LTEXT "Map Type", IDC_STATIC, 152, 4, 16, 8 CONTROL "", IDC_USEMAP_0, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, + 16, 68, 10 CONTROL "", IDC_AMTEDIT_0, "CustEdit", WS_TABSTOP, 72, 16, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_0, + "SpinnerControl", 0x0, 92, 16, 11, 10 CONTROL "", IDC_MAP_0, "CustButton", WS_TABSTOP, 104, 16, 100, + 10 CONTROL "User1", IDC_LOCK_TEX01, "CustButton", 0x0, 206, 22, 10, 10 CONTROL "", IDC_USEMAP_1, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 28, 68, 10 CONTROL "", IDC_AMTEDIT_1, "CustEdit", WS_TABSTOP, 72, 28, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_1, "SpinnerControl", 0x0, 92, 28, 11, 10 CONTROL "", IDC_MAP_1, "CustButton", + WS_TABSTOP, 104, 28, 100, 10 CONTROL "", IDC_USEMAP_2, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 40, 68, + 10 CONTROL "", IDC_AMTEDIT_2, "CustEdit", WS_TABSTOP, 72, 40, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_2, + "SpinnerControl", 0x0, 92, 40, 11, 10 CONTROL "", IDC_MAP_2, "CustButton", WS_TABSTOP, 104, 40, 100, 10 CONTROL "", + IDC_USEMAP_3, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 52, 68, 10 CONTROL "", IDC_AMTEDIT_3, "CustEdit", + WS_TABSTOP, 72, 52, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_3, "SpinnerControl", 0x0, 92, 52, 11, 10 CONTROL "", + IDC_MAP_3, "CustButton", WS_TABSTOP, 104, 52, 100, 10 CONTROL "", IDC_USEMAP_4, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 64, 68, 10 CONTROL "", IDC_AMTEDIT_4, "CustEdit", WS_TABSTOP, 72, 64, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_4, "SpinnerControl", 0x0, 92, 64, 11, 10 CONTROL "", IDC_MAP_4, "CustButton", + WS_TABSTOP, 104, 64, 100, 10 CONTROL "", IDC_USEMAP_5, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 76, 68, + 10 CONTROL "", IDC_AMTEDIT_5, "CustEdit", WS_TABSTOP, 72, 76, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_5, + "SpinnerControl", 0x0, 92, 76, 11, 10 CONTROL "", IDC_MAP_5, "CustButton", WS_TABSTOP, 104, 76, 100, 10 CONTROL "", + IDC_USEMAP_6, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 88, 68, 10 CONTROL "", IDC_AMTEDIT_6, "CustEdit", + WS_TABSTOP, 72, 88, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_6, "SpinnerControl", 0x0, 92, 88, 11, 10 CONTROL "", + IDC_MAP_6, "CustButton", WS_TABSTOP, 104, 88, 100, 10 CONTROL "", IDC_USEMAP_7, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 100, 68, 10 CONTROL "", IDC_AMTEDIT_7, "CustEdit", WS_TABSTOP, 72, 100, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_7, "SpinnerControl", 0x0, 92, 100, 11, 10 CONTROL "", IDC_MAP_7, "CustButton", + WS_TABSTOP, 104, 100, 100, 10 CONTROL "", IDC_USEMAP_8, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 112, 68, + 10 CONTROL "", IDC_AMTEDIT_8, "CustEdit", WS_TABSTOP, 72, 112, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_8, + "SpinnerControl", 0x0, 92, 112, 11, 10 CONTROL "", IDC_MAP_8, "CustButton", WS_TABSTOP, 104, 112, 100, + 10 CONTROL "", IDC_USEMAP_9, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 124, 68, 10 CONTROL "", IDC_AMTEDIT_9, + "CustEdit", WS_TABSTOP, 72, 124, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_9, "SpinnerControl", 0x0, 92, 124, 11, + 10 CONTROL "", IDC_MAP_9, "CustButton", WS_TABSTOP, 104, 124, 100, 10 CONTROL "", IDC_USEMAP_10, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 136, 68, 10 CONTROL "", IDC_AMTEDIT_10, "CustEdit", WS_TABSTOP, 72, 136, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_10, "SpinnerControl", 0x0, 92, 136, 11, 10 CONTROL "", IDC_MAP_10, "CustButton", + WS_TABSTOP, 104, 136, 100, 10 CONTROL "", IDC_USEMAP_11, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 148, 68, + 10 CONTROL "", IDC_AMTEDIT_11, "CustEdit", WS_TABSTOP, 72, 148, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_11, + "SpinnerControl", 0x0, 92, 148, 11, 10 CONTROL "", IDC_MAP_11, "CustButton", WS_TABSTOP, 104, 148, 100, + 10 CONTROL "", IDC_USEMAP_12, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 160, 68, 10 CONTROL "", IDC_AMTEDIT_12, + "CustEdit", WS_TABSTOP, 72, 160, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_12, "SpinnerControl", 0x0, 92, 160, 11, + 10 CONTROL "", IDC_MAP_12, "CustButton", WS_TABSTOP, 104, 160, 100, 10 CONTROL "", IDC_USEMAP_13, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 172, 68, 10 CONTROL "", IDC_AMTEDIT_13, "CustEdit", WS_TABSTOP, 72, 172, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_13, "SpinnerControl", 0x0, 92, 172, 11, 10 CONTROL "", IDC_MAP_13, "CustButton", + WS_TABSTOP, 104, 172, 100, 10 CONTROL "", IDC_USEMAP_14, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 184, 68, + 10 CONTROL "", IDC_AMTEDIT_14, "CustEdit", WS_TABSTOP, 72, 184, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_14, + "SpinnerControl", 0x0, 92, 184, 11, 10 CONTROL "", IDC_MAP_14, "CustButton", WS_TABSTOP, 104, 184, 100, + 10 CONTROL "", IDC_USEMAP_15, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 196, 68, 10 CONTROL "", IDC_AMTEDIT_15, + "CustEdit", WS_TABSTOP, 72, 196, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_15, "SpinnerControl", 0x0, 92, 196, 11, + 10 CONTROL "", IDC_MAP_15, "CustButton", WS_TABSTOP, 104, 196, 100, 10 CONTROL "", IDC_USEMAP_16, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 208, 68, 10 CONTROL "", IDC_AMTEDIT_16, "CustEdit", WS_TABSTOP, 72, 208, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_16, "SpinnerControl", 0x0, 92, 208, 11, 10 CONTROL "", IDC_MAP_16, "CustButton", + WS_TABSTOP, 104, 208, 100, 10 CONTROL "", IDC_USEMAP_17, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 220, 68, + 10 CONTROL "", IDC_AMTEDIT_17, "CustEdit", WS_TABSTOP, 72, 220, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_17, + "SpinnerControl", 0x0, 92, 220, 11, 10 CONTROL "", IDC_MAP_17, "CustButton", WS_TABSTOP, 104, 220, 100, + 10 CONTROL "", IDC_USEMAP_18, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 232, 68, 10 CONTROL "", IDC_AMTEDIT_18, + "CustEdit", WS_TABSTOP, 72, 232, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_18, "SpinnerControl", 0x0, 92, 232, 11, + 10 CONTROL "", IDC_MAP_18, "CustButton", WS_TABSTOP, 104, 232, 100, 10 CONTROL "", IDC_USEMAP_19, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 244, 68, 10 CONTROL "", IDC_AMTEDIT_19, "CustEdit", WS_TABSTOP, 72, 244, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_19, "SpinnerControl", 0x0, 92, 244, 11, 10 CONTROL "", IDC_MAP_19, "CustButton", + WS_TABSTOP, 104, 244, 100, 10 CONTROL "", IDC_USEMAP_20, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 256, 68, + 10 CONTROL "", IDC_AMTEDIT_20, "CustEdit", WS_TABSTOP, 72, 256, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_20, + "SpinnerControl", 0x0, 92, 256, 11, 10 CONTROL "", IDC_MAP_20, "CustButton", WS_TABSTOP, 104, 256, 100, + 10 CONTROL "", IDC_USEMAP_21, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 268, 68, 10 CONTROL "", IDC_AMTEDIT_21, + "CustEdit", WS_TABSTOP, 72, 268, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_21, "SpinnerControl", 0x0, 92, 268, 11, + 10 CONTROL "", IDC_MAP_21, "CustButton", WS_TABSTOP, 104, 268, 100, 10 CONTROL "", IDC_USEMAP_22, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 280, 68, 10 CONTROL "", IDC_AMTEDIT_22, "CustEdit", WS_TABSTOP, 72, 280, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_22, "SpinnerControl", 0x0, 92, 280, 11, 10 CONTROL "", IDC_MAP_22, "CustButton", + WS_TABSTOP, 104, 280, 100, 10 CONTROL "", IDC_USEMAP_23, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 292, 68, + 10 CONTROL "", IDC_AMTEDIT_23, "CustEdit", WS_TABSTOP, 72, 292, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_23, + "SpinnerControl", 0x0, 92, 292, 11, 10 CONTROL "", IDC_MAP_23, "CustButton", WS_TABSTOP, 104, 292, 100, + 10 END + + IDD_DMTL_SAMPLING3 DIALOG 0, + 0, 216, 59 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif" BEGIN CONTROL "Enable Sampler", IDC_SUPER_SAMP, + "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 5, 64, 10 COMBOBOX IDC_PIX_SAMPLER, 75, 3, 80, 84, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP RTEXT "Quality:", IDC_QUALITY_TEXT, 155, 4, 27, 9, + NOT WS_GROUP CONTROL "", IDC_SAMPLEQUALITY_EDIT, "CustEdit", WS_TABSTOP, 183, 3, 19, 10 CONTROL "0,255,0", + IDC_SAMPLEQUALITY_SPIN, "SpinnerControl", WS_TABSTOP, 202, 3, 11, 10 CONTROL "Supersamp. Tex.", IDC_SAMPLE_TEX, + "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 18, 71, 10 GROUPBOX "", IDC_COMMENT_BOX, 75, 16, 80, + 41 LTEXT "No Comment", IDC_COMMENT_TEXT, 77, 21, 76, 34 RTEXT "Param0", IDC_PARAM0_TEXT, 155, 17, 27, 9, + NOT WS_GROUP CONTROL "", IDC_PARAM0_EDIT, "CustEdit", WS_TABSTOP, 183, 16, 19, 10 CONTROL "0,255,0", + IDC_PARAM0_SPIN, "SpinnerControl", WS_TABSTOP, 202, 16, 11, 10 CONTROL "Adaptive", IDC_ADAPT_ON, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 32, 56, 10 RTEXT "Param1", IDC_PARAM1_TEXT, 155, 30, 27, 9, + NOT WS_GROUP CONTROL "", IDC_PARAM1_EDIT, "CustEdit", WS_TABSTOP, 183, 30, 19, 10 CONTROL "0,255,0", + IDC_PARAM1_SPIN, "SpinnerControl", WS_TABSTOP, 201, 30, 11, 10 RTEXT "Threshold:", IDC_ADAPT_STATIC, 2, 46, 34, 8, + NOT WS_GROUP CONTROL "", IDC_THRESHOLD_EDIT, "CustEdit", WS_TABSTOP, 38, 45, 25, 10 CONTROL "0,255,0", + IDC_THRESHOLD_SPIN, "SpinnerControl", WS_TABSTOP, 63, 45, 11, 10 PUSHBUTTON "Advanced...", IDC_ADVANCED_BUTTON, 166, + 43, 46, 12 END + + IDD_DMTL_EXTRA6 DIALOGEX 0, + 0, 216, 101 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN GROUPBOX "Advanced Transparency", + IDC_OPAC_BOX, 4, 1, 147, 71 LTEXT "Falloff:", IDC_OPAC_TEXT1, 9, 11, 22, 8 LTEXT "Type:", IDC_OPAC_TEXT3, 56, 11, + 18, 8 CONTROL "In", IDC_TF_IN, "Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 26, 21, 20, 8 CONTROL "Out", + IDC_TF_OUT, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, 26, 32, 24, 10 RTEXT "Refraction Filter: ", + IDC_FILTER_OVERLAY, 44, 19, 59, 11 CONTROL "Filter:", IDC_TR_SUB2, "Button", + BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 72, 20, 29, 8 CONTROL "Subtractive", IDC_TR_SUB, "Button", + BS_AUTORADIOBUTTON | WS_TABSTOP, 72, 33, 52, 8 CONTROL "Additive", IDC_TR_ADD, "Button", + BS_AUTORADIOBUTTON | WS_TABSTOP, 72, 45, 37, 8 CONTROL "User1", IDC_FILTER_CS, "ColorSwatch", WS_TABSTOP, 105, 17, + 27, 14 CONTROL "M", IDC_MAPON_FI, "CustButton", WS_TABSTOP, 136, 20, 10, 10 GROUPBOX "Wire", IDC_STATIC, 153, 1, 59, + 71 LTEXT "Size:", IDC_STATIC, 156, 21, 16, 9, 0, WS_EX_RIGHT CONTROL "", IDC_WIRE_EDIT, "CustEdit", WS_TABSTOP, 174, + 20, 22, 10 CONTROL "0,255,0", IDC_WIRE_SPIN, "SpinnerControl", 0x0, 196, 20, 11, 10 LTEXT "In:", IDC_STATIC, 160, + 45, 8, 8 CONTROL "Pixels", IDC_PIXELS, "Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 172, 41, 32, + 8 CONTROL "Units", IDC_UNITS, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, 172, 52, 28, + 8 LTEXT "Index of Refraction:", IDC_REFR_TEXT1, 11, 57, 91, 9, 0, WS_EX_RIGHT CONTROL "", IDC_IOR_EDIT, "CustEdit", + WS_TABSTOP, 105, 57, 19, 10 CONTROL "0,255,0", IDC_IOR_SPIN, "SpinnerControl", 0x0, 124, 57, 11, + 10 GROUPBOX "Reflection Dimming", IDC_REFL_BOX, 4, 72, 209, 27 CONTROL "Apply", IDC_DIM_REFL, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 11, 83, 36, 10 LTEXT "Dim Level:", IDC_REFL_TEXT1, 52, 84, 33, 8, 0, + WS_EX_RIGHT CONTROL "", IDC_DIM_AMT, "CustEdit", WS_TABSTOP, 87, 83, 24, 10 CONTROL "0,255,0", IDC_DIM_AMTSPIN, + "SpinnerControl", 0x0, 112, 83, 11, 10 LTEXT "Refl. Level:", IDC_REFL_TEXT2, 132, 84, 38, 8 CONTROL "", + IDC_DIM_MULT, "CustEdit", WS_TABSTOP, 173, 83, 24, 10 CONTROL "0,255,0", IDC_DIM_MULTSPIN, "SpinnerControl", 0x0, + 198, 83, 11, 10 LTEXT "Amt:", IDC_OPAC_TEXT2, 12, 44, 16, 8 CONTROL "", IDC_TF_EDIT, "CustEdit", WS_TABSTOP, 28, 44, + 20, 10 CONTROL "0,255,0", IDC_TF_SPIN, "SpinnerControl", 0x0, 48, 44, 11, 10 END + + IDD_DMTL_XRAY DIALOGEX 0, + 0, 216, 50 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN LTEXT "Engine Shader", IDC_STATIC, + 8, 7, 52, 8 COMBOBOX IDC_ESHADER, 63, 4, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_CSHADER, + 63, 19, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Compiler Shader", IDC_STATIC, 8, 22, 52, + 8 COMBOBOX IDC_GAMEMTL, 63, 34, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Game Material", + IDC_STATIC, 8, 37, 46, 8 END ///////////////////////////////////////////////////////////////////////////// // @@ -336,265 +176,126 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_PANEL, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 101 - TOPMARGIN, 7 - END - - IDD_DMTL_SHADER4, DIALOG - BEGIN - VERTGUIDE, 8 - VERTGUIDE, 206 - END - - IDD_DMTL_EXTRA6, DIALOG - BEGIN - TOPMARGIN, 1 - END - - IDD_DMTL_XRAY, DIALOG - BEGIN - VERTGUIDE, 8 - VERTGUIDE, 206 - BOTTOMMARGIN, 46 - END -END -#endif // APSTUDIO_INVOKED + GUIDELINES DESIGNINFO BEGIN IDD_PANEL, + DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 101 TOPMARGIN, 7 END + IDD_DMTL_SHADER4, + DIALOG BEGIN VERTGUIDE, 8 VERTGUIDE, 206 END -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// + IDD_DMTL_EXTRA6, + DIALOG BEGIN TOPMARGIN, 1 END -1 TEXTINCLUDE -BEGIN - "XRayMtlRes.h\0" -END + IDD_DMTL_XRAY, + DIALOG BEGIN VERTGUIDE, 8 VERTGUIDE, 206 BOTTOMMARGIN, 46 END END +#endif // APSTUDIO_INVOKED -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END +#ifdef APSTUDIO_INVOKED + ///////////////////////////////////////////////////////////////////////////// + // + // TEXTINCLUDE + // -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END + 1 TEXTINCLUDE BEGIN "XRayMtlRes.h\0" END -#endif // APSTUDIO_INVOKED + 2 TEXTINCLUDE BEGIN "#include " + "afxres.h" + "\r\n" + "\0" END + 3 TEXTINCLUDE BEGIN "\r\n" + "\0" END -///////////////////////////////////////////////////////////////////////////// -// -// Version -// +#endif // APSTUDIO_INVOKED + + ///////////////////////////////////////////////////////////////////////////// + // + // Version + // -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,0,0,0 - PRODUCTVERSION 3,0,0,0 - FILEFLAGSMASK 0x3fL + VS_VERSION_INFO VERSIONINFO FILEVERSION 3, + 0, 0, 0 PRODUCTVERSION 3, 0, 0, 0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG - FILEFLAGS 0x1L + FILEFLAGS 0x1L #else - FILEFLAGS 0x0L + FILEFLAGS 0x0L #endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "TECH: " - VALUE "FileDescription", "Demo Material for testing" - VALUE "FileVersion", "4.0.0.0" - VALUE "InternalName", "DemoMtl" - VALUE "LegalTrademarks", "3D Studio MAX, Biped, Character Studio, Heidi, Kinetix and Physique are registered trademarks and 3ds max, combustion, Discreet, DWG Unplugged, DXF, FLI and FLC are trademarks of Autodesk, Inc." - VALUE "OriginalFilename", "DemoMtl.dlb" - VALUE "ProductName", "3ds max" - VALUE "ProductVersion", "4.0.0.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END + FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE + "Comments", + "TECH: " VALUE "FileDescription", "Demo Material for testing" VALUE "FileVersion", "4.0.0.0" VALUE "InternalName", + "DemoMtl" VALUE "LegalTrademarks", "3D Studio MAX, Biped, Character Studio, Heidi, Kinetix and Physique are " + "registered trademarks and 3ds max, combustion, Discreet, DWG Unplugged, DXF, " + "FLI and FLC are trademarks of Autodesk, Inc." VALUE "OriginalFilename", + "DemoMtl.dlb" VALUE "ProductName", "3ds max" VALUE "ProductVersion", + "4.0.0.0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END + ///////////////////////////////////////////////////////////////////////////// + // + // Bitmap + // -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// + IDB_DMTL_MASKBUTTONS BITMAP + "dmtlmsk.bmp" IDB_DMTL_BUTTONS BITMAP "dmtlbut.bmp" -IDB_DMTL_MASKBUTTONS BITMAP "dmtlmsk.bmp" -IDB_DMTL_BUTTONS BITMAP "dmtlbut.bmp" + ///////////////////////////////////////////////////////////////////////////// + // + // String Table + // -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// + STRINGTABLE BEGIN IDS_LIBDESCRIPTION "Demo Shader for testing" IDS_CATEGORY + "S.T.A.L.K.E.R. Game Material" IDS_CLASS_NAME "S.T.A.L.K.E.R.Mtl" IDS_PARAMS "Parameters" IDS_SPIN + "Spin" IDS_COMMENT "Appwizard generated Plugin" IDS_MN_DIFFUSE "Diffuse" IDS_MN_BRIGHTNESS + "Brightness" IDS_MN_OPACITY "Opacity" IDS_MN_NONE "None" IDS_COLOR "Diffuse Color" IDS_PARAMCHG + "Parameter Change" IDS_MN_DIFFUSE_I "Diffuse" IDS_MN_BRIGHTNESS_I "Brightness" IDS_MN_OPACITY_I "Opacity" END -STRINGTABLE -BEGIN - IDS_LIBDESCRIPTION "Demo Shader for testing" - IDS_CATEGORY "S.T.A.L.K.E.R. Game Material" - IDS_CLASS_NAME "S.T.A.L.K.E.R.Mtl" - IDS_PARAMS "Parameters" - IDS_SPIN "Spin" - IDS_COMMENT "Appwizard generated Plugin" - IDS_MN_DIFFUSE "Diffuse" - IDS_MN_BRIGHTNESS "Brightness" - IDS_MN_OPACITY "Opacity" - IDS_MN_NONE "None" - IDS_COLOR "Diffuse Color" - IDS_PARAMCHG "Parameter Change" - IDS_MN_DIFFUSE_I "Diffuse" - IDS_MN_BRIGHTNESS_I "Brightness" - IDS_MN_OPACITY_I "Opacity" -END - -STRINGTABLE -BEGIN - IDS_DS_DP "Displacement" - IDS_KE_STANDARD2 "Standard" - IDS_KE_SHADER "Shader Basic Parameters" -END - -STRINGTABLE -BEGIN - IDS_DS_WIREFRAME "Wire" - IDS_DS_SHIN_STR "Specular Level" - IDS_DS_OPACITY "Opacity" - IDS_JW_SHADERTYPE "Shader Type" - IDS_DS_EXTRA "Extended Parameters" - IDS_DS_TEXMAP "Maps" -END - -STRINGTABLE -BEGIN - IDS_JW_TWOSIDED "Two-sided" - IDS_JW_FACEMAP "Face Map" - IDS_JW_OPACITYTYPE "Opacity Type" - IDS_JW_FILTERMAP "Filter Map" - IDS_JW_FALLOFFTYPE "Falloff Type" - IDS_JW_WIREUNITS "Wire Units" - IDS_JW_APPLYREFDIM "Apply Reflection Dimming" - IDS_JW_PIXELSAMPLER "Pixel Sampler" - IDS_JW_SAMPLERQUAL "Sampler Quality" - IDS_JW_SAMPLERENABLE "Sampler Enable" -END - -STRINGTABLE -BEGIN - IDS_JW_MAPAMOUNTS "Map Amounts" - IDS_JW_ENABLE "Enable" - IDS_JW_AMOUNT "Amount" - IDS_JW_SHADERBYNAME "Shader Name" - IDS_JW_SAMPLERBYNAME "Sampler Name" -END - -STRINGTABLE -BEGIN - IDS_KE_FACETED "Faceted" - IDS_JW_ESHADERTYPE "EShader Type" - IDS_JW_CSHADERTYPE "CShader Type" - IDS_KE_SAMPLERADAPTTHRESH "Adaptive Threshold" - IDS_KE_SAMPLERADAPTON "Adaptive On" - IDS_KE_SAMPLERADVANCED "Advanced Options..." - IDS_JW_ESHADERBYNAME "EShader Name" - IDS_JW_CSHADERBYNAME "CShader Name" -END - -STRINGTABLE -BEGIN - IDS_KE_STANDARD2_CDESC "Standard" -END - -STRINGTABLE -BEGIN - IDS_DS_DYNAMICS "Dynamics Properties" - IDS_DS_BOUNCE "Bounce Coefficient" - IDS_DS_STATFRIC "Static Friction" - IDS_DS_SLIDFRIC "Sliding Friction" -END - -STRINGTABLE -BEGIN - IDS_JW_MAPENABLES "Map Enables" - IDS_DS_BU "Bump" - IDS_DS_RL "Reflection" - IDS_DS_RR "Refraction" - IDS_DS_TEXMAPS "Maps" - IDS_DS_FILTER "Filter Color" -END - -STRINGTABLE -BEGIN - IDS_DS_DIMLEV "Dim Level" - IDS_DS_DIMMULT "Reflection Level" -END - -STRINGTABLE -BEGIN - IDS_DS_FALLOFF "Falloff" -END - -STRINGTABLE -BEGIN - IDS_DS_WIRESZ "Wire Size" - IDS_DS_IOR "Index of Refraction" - IDS_JW_MAPS "Maps" -END - -STRINGTABLE -BEGIN - IDS_JW_ADTEXLOCK "Ambient-Diffuse Texture Lock" -END - -STRINGTABLE -BEGIN - IDS_KE_SAMPLING "SuperSampling" - IDS_KE_XRAY "S.T.A.L.K.E.R. Params" - IDS_KE_NONE "None" -END - -STRINGTABLE -BEGIN - IDS_KE_SAMPLER_PARAM0 "Optional Param0" - IDS_KE_SAMPLER_PARAM1 "Optional Param1" -END - -STRINGTABLE -BEGIN - IDS_KE_SUBSAMPLE_TEX_ON "SubSample Textures" -END - -STRINGTABLE -BEGIN - IDS_DS_CLASSTEXMAPS "Texmaps" -END - -STRINGTABLE -BEGIN - IDS_DS_AMOUNT "Amount" - IDS_JW_GAMEMTLTYPE "Game Mtl Type" - IDS_JW_GAMEMTLBYNAME "Game Mtl Name" -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// + STRINGTABLE BEGIN IDS_DS_DP "Displacement" IDS_KE_STANDARD2 "Standard" IDS_KE_SHADER + "Shader Basic Parameters" END + + STRINGTABLE BEGIN IDS_DS_WIREFRAME "Wire" IDS_DS_SHIN_STR "Specular Level" IDS_DS_OPACITY + "Opacity" IDS_JW_SHADERTYPE "Shader Type" IDS_DS_EXTRA "Extended Parameters" IDS_DS_TEXMAP "Maps" END + + STRINGTABLE BEGIN IDS_JW_TWOSIDED "Two-sided" IDS_JW_FACEMAP "Face Map" IDS_JW_OPACITYTYPE + "Opacity Type" IDS_JW_FILTERMAP "Filter Map" IDS_JW_FALLOFFTYPE "Falloff Type" IDS_JW_WIREUNITS + "Wire Units" IDS_JW_APPLYREFDIM "Apply Reflection Dimming" IDS_JW_PIXELSAMPLER "Pixel Sampler" IDS_JW_SAMPLERQUAL + "Sampler Quality" IDS_JW_SAMPLERENABLE "Sampler Enable" END + + STRINGTABLE BEGIN IDS_JW_MAPAMOUNTS "Map Amounts" IDS_JW_ENABLE "Enable" IDS_JW_AMOUNT + "Amount" IDS_JW_SHADERBYNAME "Shader Name" IDS_JW_SAMPLERBYNAME "Sampler Name" END + + STRINGTABLE BEGIN IDS_KE_FACETED "Faceted" IDS_JW_ESHADERTYPE "EShader Type" IDS_JW_CSHADERTYPE + "CShader Type" IDS_KE_SAMPLERADAPTTHRESH "Adaptive Threshold" IDS_KE_SAMPLERADAPTON + "Adaptive On" IDS_KE_SAMPLERADVANCED "Advanced Options..." IDS_JW_ESHADERBYNAME "EShader Name" IDS_JW_CSHADERBYNAME + "CShader Name" END + + STRINGTABLE BEGIN IDS_KE_STANDARD2_CDESC "Standard" END + + STRINGTABLE BEGIN IDS_DS_DYNAMICS "Dynamics Properties" IDS_DS_BOUNCE "Bounce Coefficient" IDS_DS_STATFRIC + "Static Friction" IDS_DS_SLIDFRIC "Sliding Friction" END + + STRINGTABLE BEGIN IDS_JW_MAPENABLES "Map Enables" IDS_DS_BU "Bump" IDS_DS_RL "Reflection" IDS_DS_RR + "Refraction" IDS_DS_TEXMAPS "Maps" IDS_DS_FILTER "Filter Color" END + + STRINGTABLE BEGIN IDS_DS_DIMLEV "Dim Level" IDS_DS_DIMMULT "Reflection Level" END + STRINGTABLE BEGIN IDS_DS_FALLOFF "Falloff" END + STRINGTABLE BEGIN IDS_DS_WIRESZ "Wire Size" IDS_DS_IOR "Index of Refraction" IDS_JW_MAPS "Maps" END + + STRINGTABLE BEGIN IDS_JW_ADTEXLOCK "Ambient-Diffuse Texture Lock" END + + STRINGTABLE BEGIN IDS_KE_SAMPLING "SuperSampling" IDS_KE_XRAY + "S.T.A.L.K.E.R. Params" IDS_KE_NONE "None" END + + STRINGTABLE BEGIN IDS_KE_SAMPLER_PARAM0 "Optional Param0" IDS_KE_SAMPLER_PARAM1 "Optional Param1" END + + STRINGTABLE BEGIN IDS_KE_SUBSAMPLE_TEX_ON "SubSample Textures" END + + STRINGTABLE BEGIN IDS_DS_CLASSTEXMAPS "Texmaps" END + + STRINGTABLE BEGIN IDS_DS_AMOUNT "Amount" IDS_JW_GAMEMTLTYPE "Game Mtl Type" IDS_JW_GAMEMTLBYNAME + "Game Mtl Name" END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -602,7 +303,5 @@ END // Generated from the TEXTINCLUDE 3 resource. // - ///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +#endif // not APSTUDIO_INVOKED diff --git a/src/plugins/Max/Material/Stdafx.h b/src/plugins/Max/Material/Stdafx.h index 1f5aa661389..78d3dfbc666 100644 --- a/src/plugins/Max/Material/Stdafx.h +++ b/src/plugins/Max/Material/Stdafx.h @@ -6,9 +6,9 @@ #pragma once -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0500 -#pragma warning (disable:4995) +#pragma warning(disable : 4995) #include "Max.h" #include "xrCore/xrCore.h" @@ -16,12 +16,18 @@ #undef _MIN #undef _MAX -#define _MIN(a,b) (a)<(b)?(a):(b) -#define _MAX(a,b) (a)>(b)?(a):(b) +#define _MIN(a, b) (a) < (b) ? (a) : (b) +#define _MAX(a, b) (a) > (b) ? (a) : (b) template -T min(T a, T b) { return _MIN(a,b); } +T min(T a, T b) +{ + return _MIN(a, b); +} template -T max(T a, T b) { return _MAX(a,b); } +T max(T a, T b) +{ + return _MAX(a, b); +} using std::string; #undef _MIN #undef _MAX @@ -34,21 +40,21 @@ using std::string; #define FLT_MIN flt_max +#include #include #include -#include #include -#include "istdplug.h" +#include "UTILAPI.H" #include "iparamb2.h" #include "iparamm2.h" +#include "istdplug.h" #include "stdmat.h" -#include "UTILAPI.H" // CS SDK #ifdef _MAX_EXPORT -# include "phyexp.h" -# include "bipexp.h" +#include "phyexp.h" +#include "bipexp.h" #endif #include @@ -56,38 +62,50 @@ using std::string; #define ENGINE_API #define ECORE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; #include #define AnsiString string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); - - - +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #include "plugins/Shared/ELog.h" #define THROW R_ASSERT(0) #ifdef _MAX_EXPORT - #define _EDITOR_FILE_NAME_ "max_export" +#define _EDITOR_FILE_NAME_ "max_export" #else - #ifdef _MAX_MATERIAL - #define _EDITOR_FILE_NAME_ "max_material" - #endif +#ifdef _MAX_MATERIAL +#define _EDITOR_FILE_NAME_ "max_material" +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" -#pragma warning (default:4995) +#pragma warning(default : 4995) #endif /*_INCDEF_STDAFX_H_*/ - - - - - diff --git a/src/plugins/Max/Material/XRayMtlRes.h b/src/plugins/Max/Material/XRayMtlRes.h index 5b5cb043ed5..7ac219ba65e 100644 --- a/src/plugins/Max/Material/XRayMtlRes.h +++ b/src/plugins/Max/Material/XRayMtlRes.h @@ -2,275 +2,275 @@ // Microsoft Visual C++ generated include file. // Used by GameMaterial.rc // -#define IDS_LIBDESCRIPTION 1 -#define IDS_CATEGORY 2 -#define IDS_CLASS_NAME 3 -#define IDS_PARAMS 4 -#define IDS_SPIN 5 -#define IDS_COMMENT 6 -#define IDS_MN_DIFFUSE 7 -#define IDS_MN_BRIGHTNESS 8 -#define IDS_MN_OPACITY 9 -#define IDS_MN_NONE 10 -#define IDS_COLOR 11 -#define IDS_PARAMCHG 12 -#define IDS_MN_DIFFUSE_I 13 -#define IDS_MN_BRIGHTNESS_I 14 -#define IDS_MN_OPACITY_I 15 -#define IDD_PANEL 101 -#define IDD_DMTL_EXTRA6 116 -#define IDB_DMTL_BUTTONS 122 -#define IDB_DMTL_MASKBUTTONS 123 -#define IDD_DMTL_SHADER4 125 -#define IDD_DMTL_TEXMAP4 145 -#define IDD_SHADER_SKEL1 148 -#define IDD_DMTL_SAMPLING3 151 -#define IDC_TF_EDIT 218 -#define IDC_IOR_EDIT 219 -#define IDC_TR_EDIT 220 -#define IDC_DIM_AMT 220 -#define IDC_WIRE_EDIT 221 -#define IDC_DIM_MULT 222 -#define IDC_TF_SPIN 328 -#define IDC_IOR_SPIN 329 -#define IDC_TR_SPIN 330 -#define IDC_DIM_AMTSPIN 330 -#define IDC_DIM_MULTSPIN 331 -#define IDC_WIRE_SPIN 332 -#define IDC_CLOSEBUTTON 1000 -#define IDC_DOSTUFF 1000 -#define IDC_TR_SUB2 1001 -#define IDC_TR_SUB 1002 -#define IDC_TR_ADD 1003 -#define IDC_CSHADER1 1003 -#define IDC_MAPON_TR 1038 -#define IDC_PIXELS 1043 -#define IDC_UNITS 1044 -#define IDC_WIRE 1048 -#define IDD_DMTL_DYNAM 1057 -#define IDD_DMTL_XRAY 1058 -#define IDC_FACE_MAP 1059 -#define IDC_FACETED 1060 -#define IDC_HIGHLIGHT 1062 -#define IDC_2SIDE 1067 -#define IDC_SUPER_SAMP 1068 -#define IDC_ADAPT_ON 1069 -#define IDC_SAMPLE_TEX 1070 -#define IDC_MAPON_FI 1107 -#define IDC_BOUNCE_EDIT 1193 -#define IDC_BOUNCE_SPIN 1194 -#define IDC_STATFRIC_EDIT 1195 -#define IDC_STATFRIC_SPIN 1196 -#define IDC_SLIDFRIC_EDIT 1197 -#define IDC_SLIDFRIC_SPIN 1198 -#define IDC_DIM_REFL 1252 -#define IDC_TF_IN 1300 -#define IDC_TF_OUT 1301 -#define IDC_COLOR_NEW 1456 -#define IDC_EDIT 1490 -#define IDC_SPIN 1496 -#define IDC_SHADER 1728 -#define IDC_ESHADER 1729 -#define IDC_SAMPLEQUALITY_SPIN 1729 -#define IDC_SHADER2 1729 -#define IDC_CSHADER 1730 -#define IDC_SAMPLEQUALITY_EDIT 1730 -#define IDC_PIX_SAMPLER 1731 -#define IDC_GAMEMTL 1731 -#define IDC_THRESHOLD_EDIT 1732 -#define IDC_THRESHOLD_SPIN 1733 -#define IDC_PARAM0_EDIT 1734 -#define IDC_PARAM0_SPIN 1735 -#define IDC_PARAM1_EDIT 1736 -#define IDC_FILTER_CS 1736 -#define IDC_USEMAP_0 1737 -#define IDC_PARAM1_SPIN 1737 -#define IDC_AMTEDIT_0 1738 -#define IDC_AMTSPIN_0 1739 -#define IDC_MAP_0 1740 -#define IDC_USEMAP_1 1741 -#define IDC_AMTEDIT_1 1742 -#define IDC_AMTSPIN_1 1743 -#define IDC_MAP_1 1744 -#define IDC_USEMAP_2 1745 -#define IDC_AMTEDIT_2 1746 -#define IDC_AMTSPIN_2 1747 -#define IDC_MAP_2 1748 -#define IDC_USEMAP_3 1749 -#define IDC_AMTEDIT_3 1750 -#define IDC_AMTSPIN_3 1751 -#define IDC_MAP_3 1752 -#define IDC_USEMAP_4 1753 -#define IDC_AMTEDIT_4 1754 -#define IDC_AMTSPIN_4 1755 -#define IDC_MAP_4 1756 -#define IDC_USEMAP_5 1757 -#define IDC_AMTEDIT_5 1758 -#define IDC_AMTSPIN_5 1759 -#define IDC_MAP_5 1760 -#define IDC_USEMAP_6 1761 -#define IDC_AMTEDIT_6 1762 -#define IDC_AMTSPIN_6 1763 -#define IDC_MAP_6 1764 -#define IDC_USEMAP_7 1765 -#define IDC_AMTEDIT_7 1766 -#define IDC_AMTSPIN_7 1767 -#define IDC_MAP_7 1768 -#define IDC_USEMAP_8 1769 -#define IDC_AMTEDIT_8 1770 -#define IDC_AMTSPIN_8 1771 -#define IDC_MAP_8 1772 -#define IDC_USEMAP_9 1773 -#define IDC_AMTEDIT_9 1774 -#define IDC_AMTSPIN_9 1775 -#define IDC_MAP_9 1776 -#define IDC_USEMAP_10 1777 -#define IDC_AMTEDIT_10 1778 -#define IDC_AMTSPIN_10 1779 -#define IDC_MAP_10 1780 -#define IDC_USEMAP_11 1781 -#define IDC_AMTEDIT_11 1782 -#define IDC_AMTSPIN_11 1783 -#define IDC_MAP_11 1784 -#define IDC_LOCK_TEX01 1785 -#define IDC_USEMAP_12 1786 -#define IDC_AMTEDIT_12 1787 -#define IDC_USEMAP_13 1788 -#define IDC_AMTEDIT_13 1789 -#define IDC_USEMAP_14 1790 -#define IDC_AMTEDIT_14 1791 -#define IDC_AMTSPIN_12 1792 -#define IDC_AMTSPIN_13 1793 -#define IDC_AMTSPIN_14 1794 -#define IDC_MAP_12 1795 -#define IDC_MAP_13 1796 -#define IDC_MAP_14 1797 -#define IDC_USEMAP_15 1798 -#define IDC_AMTEDIT_15 1799 -#define IDC_AMTSPIN_15 1800 -#define IDC_MAP_15 1801 -#define IDC_USEMAP_16 1802 -#define IDC_AMTEDIT_16 1803 -#define IDC_AMTSPIN_16 1804 -#define IDC_MAP_16 1805 -#define IDC_USEMAP_17 1806 -#define IDC_BR_EDIT 1807 -#define IDC_AMTEDIT_17 1807 -#define IDC_BR_SPIN 1808 -#define IDC_AMTSPIN_17 1808 -#define IDC_MAPON_BR 1809 -#define IDC_MAP_17 1809 -#define IDC_USEMAP_18 1810 -#define IDC_AMTEDIT_18 1811 -#define IDC_AMTSPIN_18 1812 -#define IDC_MAP_18 1813 -#define IDC_MAPON_CLR 1814 -#define IDC_USEMAP_19 1814 -#define IDC_AMTEDIT_19 1815 -#define IDC_AMTSPIN_19 1816 -#define IDC_MAP_19 1817 -#define IDC_USEMAP_20 1818 -#define IDC_AMTEDIT_20 1819 -#define IDC_AMTSPIN_20 1820 -#define IDC_MAP_20 1821 -#define IDC_USEMAP_21 1822 -#define IDC_AMTEDIT_21 1823 -#define IDC_AMTSPIN_21 1824 -#define IDC_MAP_21 1825 -#define IDC_USEMAP_22 1826 -#define IDC_AMTEDIT_22 1827 -#define IDC_AMTSPIN_22 1828 -#define IDC_MAP_22 1829 -#define IDC_USEMAP_23 1830 -#define IDC_AMTEDIT_23 1831 -#define IDC_AMTSPIN_23 1832 -#define IDC_MAP_23 1833 -#define IDC_ADAPT_STATIC 1861 -#define IDC_ADVANCED_BUTTON 1862 -#define IDC_OPAC_TEXT1 1865 -#define IDC_OPAC_TEXT2 1866 -#define IDC_REFR_TEXT1 1867 -#define IDC_OPAC_TEXT3 1868 -#define IDC_REFL_TEXT1 1869 -#define IDC_REFL_TEXT2 1870 -#define IDC_REFL_BOX 1871 -#define IDC_OPAC_BOX 1872 -#define IDC_FILTER_OVERLAY 1873 -#define IDC_COMMENT_BOX 1874 -#define IDC_QUALITY_TEXT 1875 -#define IDC_COMMENT_TEXT 1876 -#define IDC_PARAM0_TEXT 1877 -#define IDC_PARAM1_TEXT 1878 -#define IDS_DS_WIREFRAME 10049 -#define IDS_DS_SHIN_STR 10052 -#define IDS_DS_OPACITY 10053 -#define IDS_JW_SHADERTYPE 10057 -#define IDS_DS_EXTRA 10059 -#define IDS_DS_TEXMAP 10060 -#define IDS_JW_MAPENABLES 10064 -#define IDS_DS_BU 10067 -#define IDS_DS_RL 10068 -#define IDS_DS_RR 10069 -#define IDS_DS_TEXMAPS 10070 -#define IDS_DS_FILTER 10071 -#define IDS_DS_WIRESZ 10114 -#define IDS_DS_IOR 10115 -#define IDS_JW_MAPS 10127 -#define IDS_JW_MAPAMOUNTS 10128 -#define IDS_JW_ENABLE 10133 -#define IDS_JW_AMOUNT 10134 -#define IDS_JW_SHADERBYNAME 10139 -#define IDS_JW_SAMPLERBYNAME 10140 -#define IDS_DS_AMOUNT 11442 -#define IDS_JW_GAMEMTLTYPE 11443 -#define IDS_JW_GAMEMTLBYNAME 11444 -#define IDS_DS_CLASSTEXMAPS 11471 -#define IDS_DS_DYNAMICS 11484 -#define IDS_DS_BOUNCE 11485 -#define IDS_DS_STATFRIC 11486 -#define IDS_DS_SLIDFRIC 11487 -#define IDS_DS_FALLOFF 11495 -#define IDS_DS_DIMLEV 11514 -#define IDS_DS_DIMMULT 11515 -#define IDS_DS_DP 11530 -#define IDS_KE_STANDARD2 11534 -#define IDS_KE_SHADER 11535 -#define IDS_KE_SAMPLING 11536 -#define IDS_KE_XRAY 11537 -#define IDS_KE_NONE 11547 -#define IDS_JW_TWOSIDED 11585 -#define IDS_JW_FACEMAP 11586 -#define IDS_JW_OPACITYTYPE 11587 -#define IDS_JW_FILTERMAP 11588 -#define IDS_JW_FALLOFFTYPE 11589 -#define IDS_JW_WIREUNITS 11590 -#define IDS_JW_APPLYREFDIM 11591 -#define IDS_JW_PIXELSAMPLER 11592 -#define IDS_JW_SAMPLERQUAL 11593 -#define IDS_JW_SAMPLERENABLE 11594 -#define IDS_KE_STANDARD2_CDESC 11600 -#define IDS_JW_ADTEXLOCK 11620 -#define IDS_KE_FACETED 11672 -#define IDS_STRING_1 11673 -#define IDS_JW_ESHADERTYPE 11673 -#define IDS_STRING_2 11674 -#define IDS_JW_CSHADERTYPE 11674 -#define IDS_KE_SAMPLERADAPTTHRESH 11675 -#define IDS_KE_SAMPLERADAPTON 11676 -#define IDS_KE_SAMPLERADVANCED 11677 -#define IDS_JW_ESHADERBYNAME 11678 -#define IDS_JW_CSHADERBYNAME 11679 -#define IDS_KE_SUBSAMPLE_TEX_ON 11683 -#define IDS_KE_SAMPLER_PARAM0 11696 -#define IDS_KE_SAMPLER_PARAM1 11697 +#define IDS_LIBDESCRIPTION 1 +#define IDS_CATEGORY 2 +#define IDS_CLASS_NAME 3 +#define IDS_PARAMS 4 +#define IDS_SPIN 5 +#define IDS_COMMENT 6 +#define IDS_MN_DIFFUSE 7 +#define IDS_MN_BRIGHTNESS 8 +#define IDS_MN_OPACITY 9 +#define IDS_MN_NONE 10 +#define IDS_COLOR 11 +#define IDS_PARAMCHG 12 +#define IDS_MN_DIFFUSE_I 13 +#define IDS_MN_BRIGHTNESS_I 14 +#define IDS_MN_OPACITY_I 15 +#define IDD_PANEL 101 +#define IDD_DMTL_EXTRA6 116 +#define IDB_DMTL_BUTTONS 122 +#define IDB_DMTL_MASKBUTTONS 123 +#define IDD_DMTL_SHADER4 125 +#define IDD_DMTL_TEXMAP4 145 +#define IDD_SHADER_SKEL1 148 +#define IDD_DMTL_SAMPLING3 151 +#define IDC_TF_EDIT 218 +#define IDC_IOR_EDIT 219 +#define IDC_TR_EDIT 220 +#define IDC_DIM_AMT 220 +#define IDC_WIRE_EDIT 221 +#define IDC_DIM_MULT 222 +#define IDC_TF_SPIN 328 +#define IDC_IOR_SPIN 329 +#define IDC_TR_SPIN 330 +#define IDC_DIM_AMTSPIN 330 +#define IDC_DIM_MULTSPIN 331 +#define IDC_WIRE_SPIN 332 +#define IDC_CLOSEBUTTON 1000 +#define IDC_DOSTUFF 1000 +#define IDC_TR_SUB2 1001 +#define IDC_TR_SUB 1002 +#define IDC_TR_ADD 1003 +#define IDC_CSHADER1 1003 +#define IDC_MAPON_TR 1038 +#define IDC_PIXELS 1043 +#define IDC_UNITS 1044 +#define IDC_WIRE 1048 +#define IDD_DMTL_DYNAM 1057 +#define IDD_DMTL_XRAY 1058 +#define IDC_FACE_MAP 1059 +#define IDC_FACETED 1060 +#define IDC_HIGHLIGHT 1062 +#define IDC_2SIDE 1067 +#define IDC_SUPER_SAMP 1068 +#define IDC_ADAPT_ON 1069 +#define IDC_SAMPLE_TEX 1070 +#define IDC_MAPON_FI 1107 +#define IDC_BOUNCE_EDIT 1193 +#define IDC_BOUNCE_SPIN 1194 +#define IDC_STATFRIC_EDIT 1195 +#define IDC_STATFRIC_SPIN 1196 +#define IDC_SLIDFRIC_EDIT 1197 +#define IDC_SLIDFRIC_SPIN 1198 +#define IDC_DIM_REFL 1252 +#define IDC_TF_IN 1300 +#define IDC_TF_OUT 1301 +#define IDC_COLOR_NEW 1456 +#define IDC_EDIT 1490 +#define IDC_SPIN 1496 +#define IDC_SHADER 1728 +#define IDC_ESHADER 1729 +#define IDC_SAMPLEQUALITY_SPIN 1729 +#define IDC_SHADER2 1729 +#define IDC_CSHADER 1730 +#define IDC_SAMPLEQUALITY_EDIT 1730 +#define IDC_PIX_SAMPLER 1731 +#define IDC_GAMEMTL 1731 +#define IDC_THRESHOLD_EDIT 1732 +#define IDC_THRESHOLD_SPIN 1733 +#define IDC_PARAM0_EDIT 1734 +#define IDC_PARAM0_SPIN 1735 +#define IDC_PARAM1_EDIT 1736 +#define IDC_FILTER_CS 1736 +#define IDC_USEMAP_0 1737 +#define IDC_PARAM1_SPIN 1737 +#define IDC_AMTEDIT_0 1738 +#define IDC_AMTSPIN_0 1739 +#define IDC_MAP_0 1740 +#define IDC_USEMAP_1 1741 +#define IDC_AMTEDIT_1 1742 +#define IDC_AMTSPIN_1 1743 +#define IDC_MAP_1 1744 +#define IDC_USEMAP_2 1745 +#define IDC_AMTEDIT_2 1746 +#define IDC_AMTSPIN_2 1747 +#define IDC_MAP_2 1748 +#define IDC_USEMAP_3 1749 +#define IDC_AMTEDIT_3 1750 +#define IDC_AMTSPIN_3 1751 +#define IDC_MAP_3 1752 +#define IDC_USEMAP_4 1753 +#define IDC_AMTEDIT_4 1754 +#define IDC_AMTSPIN_4 1755 +#define IDC_MAP_4 1756 +#define IDC_USEMAP_5 1757 +#define IDC_AMTEDIT_5 1758 +#define IDC_AMTSPIN_5 1759 +#define IDC_MAP_5 1760 +#define IDC_USEMAP_6 1761 +#define IDC_AMTEDIT_6 1762 +#define IDC_AMTSPIN_6 1763 +#define IDC_MAP_6 1764 +#define IDC_USEMAP_7 1765 +#define IDC_AMTEDIT_7 1766 +#define IDC_AMTSPIN_7 1767 +#define IDC_MAP_7 1768 +#define IDC_USEMAP_8 1769 +#define IDC_AMTEDIT_8 1770 +#define IDC_AMTSPIN_8 1771 +#define IDC_MAP_8 1772 +#define IDC_USEMAP_9 1773 +#define IDC_AMTEDIT_9 1774 +#define IDC_AMTSPIN_9 1775 +#define IDC_MAP_9 1776 +#define IDC_USEMAP_10 1777 +#define IDC_AMTEDIT_10 1778 +#define IDC_AMTSPIN_10 1779 +#define IDC_MAP_10 1780 +#define IDC_USEMAP_11 1781 +#define IDC_AMTEDIT_11 1782 +#define IDC_AMTSPIN_11 1783 +#define IDC_MAP_11 1784 +#define IDC_LOCK_TEX01 1785 +#define IDC_USEMAP_12 1786 +#define IDC_AMTEDIT_12 1787 +#define IDC_USEMAP_13 1788 +#define IDC_AMTEDIT_13 1789 +#define IDC_USEMAP_14 1790 +#define IDC_AMTEDIT_14 1791 +#define IDC_AMTSPIN_12 1792 +#define IDC_AMTSPIN_13 1793 +#define IDC_AMTSPIN_14 1794 +#define IDC_MAP_12 1795 +#define IDC_MAP_13 1796 +#define IDC_MAP_14 1797 +#define IDC_USEMAP_15 1798 +#define IDC_AMTEDIT_15 1799 +#define IDC_AMTSPIN_15 1800 +#define IDC_MAP_15 1801 +#define IDC_USEMAP_16 1802 +#define IDC_AMTEDIT_16 1803 +#define IDC_AMTSPIN_16 1804 +#define IDC_MAP_16 1805 +#define IDC_USEMAP_17 1806 +#define IDC_BR_EDIT 1807 +#define IDC_AMTEDIT_17 1807 +#define IDC_BR_SPIN 1808 +#define IDC_AMTSPIN_17 1808 +#define IDC_MAPON_BR 1809 +#define IDC_MAP_17 1809 +#define IDC_USEMAP_18 1810 +#define IDC_AMTEDIT_18 1811 +#define IDC_AMTSPIN_18 1812 +#define IDC_MAP_18 1813 +#define IDC_MAPON_CLR 1814 +#define IDC_USEMAP_19 1814 +#define IDC_AMTEDIT_19 1815 +#define IDC_AMTSPIN_19 1816 +#define IDC_MAP_19 1817 +#define IDC_USEMAP_20 1818 +#define IDC_AMTEDIT_20 1819 +#define IDC_AMTSPIN_20 1820 +#define IDC_MAP_20 1821 +#define IDC_USEMAP_21 1822 +#define IDC_AMTEDIT_21 1823 +#define IDC_AMTSPIN_21 1824 +#define IDC_MAP_21 1825 +#define IDC_USEMAP_22 1826 +#define IDC_AMTEDIT_22 1827 +#define IDC_AMTSPIN_22 1828 +#define IDC_MAP_22 1829 +#define IDC_USEMAP_23 1830 +#define IDC_AMTEDIT_23 1831 +#define IDC_AMTSPIN_23 1832 +#define IDC_MAP_23 1833 +#define IDC_ADAPT_STATIC 1861 +#define IDC_ADVANCED_BUTTON 1862 +#define IDC_OPAC_TEXT1 1865 +#define IDC_OPAC_TEXT2 1866 +#define IDC_REFR_TEXT1 1867 +#define IDC_OPAC_TEXT3 1868 +#define IDC_REFL_TEXT1 1869 +#define IDC_REFL_TEXT2 1870 +#define IDC_REFL_BOX 1871 +#define IDC_OPAC_BOX 1872 +#define IDC_FILTER_OVERLAY 1873 +#define IDC_COMMENT_BOX 1874 +#define IDC_QUALITY_TEXT 1875 +#define IDC_COMMENT_TEXT 1876 +#define IDC_PARAM0_TEXT 1877 +#define IDC_PARAM1_TEXT 1878 +#define IDS_DS_WIREFRAME 10049 +#define IDS_DS_SHIN_STR 10052 +#define IDS_DS_OPACITY 10053 +#define IDS_JW_SHADERTYPE 10057 +#define IDS_DS_EXTRA 10059 +#define IDS_DS_TEXMAP 10060 +#define IDS_JW_MAPENABLES 10064 +#define IDS_DS_BU 10067 +#define IDS_DS_RL 10068 +#define IDS_DS_RR 10069 +#define IDS_DS_TEXMAPS 10070 +#define IDS_DS_FILTER 10071 +#define IDS_DS_WIRESZ 10114 +#define IDS_DS_IOR 10115 +#define IDS_JW_MAPS 10127 +#define IDS_JW_MAPAMOUNTS 10128 +#define IDS_JW_ENABLE 10133 +#define IDS_JW_AMOUNT 10134 +#define IDS_JW_SHADERBYNAME 10139 +#define IDS_JW_SAMPLERBYNAME 10140 +#define IDS_DS_AMOUNT 11442 +#define IDS_JW_GAMEMTLTYPE 11443 +#define IDS_JW_GAMEMTLBYNAME 11444 +#define IDS_DS_CLASSTEXMAPS 11471 +#define IDS_DS_DYNAMICS 11484 +#define IDS_DS_BOUNCE 11485 +#define IDS_DS_STATFRIC 11486 +#define IDS_DS_SLIDFRIC 11487 +#define IDS_DS_FALLOFF 11495 +#define IDS_DS_DIMLEV 11514 +#define IDS_DS_DIMMULT 11515 +#define IDS_DS_DP 11530 +#define IDS_KE_STANDARD2 11534 +#define IDS_KE_SHADER 11535 +#define IDS_KE_SAMPLING 11536 +#define IDS_KE_XRAY 11537 +#define IDS_KE_NONE 11547 +#define IDS_JW_TWOSIDED 11585 +#define IDS_JW_FACEMAP 11586 +#define IDS_JW_OPACITYTYPE 11587 +#define IDS_JW_FILTERMAP 11588 +#define IDS_JW_FALLOFFTYPE 11589 +#define IDS_JW_WIREUNITS 11590 +#define IDS_JW_APPLYREFDIM 11591 +#define IDS_JW_PIXELSAMPLER 11592 +#define IDS_JW_SAMPLERQUAL 11593 +#define IDS_JW_SAMPLERENABLE 11594 +#define IDS_KE_STANDARD2_CDESC 11600 +#define IDS_JW_ADTEXLOCK 11620 +#define IDS_KE_FACETED 11672 +#define IDS_STRING_1 11673 +#define IDS_JW_ESHADERTYPE 11673 +#define IDS_STRING_2 11674 +#define IDS_JW_CSHADERTYPE 11674 +#define IDS_KE_SAMPLERADAPTTHRESH 11675 +#define IDS_KE_SAMPLERADAPTON 11676 +#define IDS_KE_SAMPLERADVANCED 11677 +#define IDS_JW_ESHADERBYNAME 11678 +#define IDS_JW_CSHADERBYNAME 11679 +#define IDS_KE_SUBSAMPLE_TEX_ON 11683 +#define IDS_KE_SAMPLER_PARAM0 11696 +#define IDS_KE_SAMPLER_PARAM1 11697 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1004 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1004 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/Max/Material/resource.h b/src/plugins/Max/Material/resource.h index 2239109c5af..ce884075f5a 100644 --- a/src/plugins/Max/Material/resource.h +++ b/src/plugins/Max/Material/resource.h @@ -2,272 +2,272 @@ // Microsoft Visual C++ generated include file. // Used by GameMaterial.rc // -#define IDS_LIBDESCRIPTION 1 -#define IDS_CATEGORY 2 -#define IDS_CLASS_NAME 3 -#define IDS_PARAMS 4 -#define IDS_SPIN 5 -#define IDS_COMMENT 6 -#define IDS_MN_DIFFUSE 7 -#define IDS_MN_BRIGHTNESS 8 -#define IDS_MN_OPACITY 9 -#define IDS_MN_NONE 10 -#define IDS_COLOR 11 -#define IDS_PARAMCHG 12 -#define IDS_MN_DIFFUSE_I 13 -#define IDS_MN_BRIGHTNESS_I 14 -#define IDS_MN_OPACITY_I 15 -#define IDD_PANEL 101 -#define IDD_DMTL_EXTRA6 116 -#define IDB_DMTL_BUTTONS 122 -#define IDB_DMTL_MASKBUTTONS 123 -#define IDD_DMTL_SHADER4 125 -#define IDD_DMTL_TEXMAP4 145 -#define IDD_SHADER_SKEL1 148 -#define IDD_DMTL_SAMPLING3 151 -#define IDC_TF_EDIT 218 -#define IDC_IOR_EDIT 219 -#define IDC_TR_EDIT 220 -#define IDC_DIM_AMT 220 -#define IDC_WIRE_EDIT 221 -#define IDC_DIM_MULT 222 -#define IDC_TF_SPIN 328 -#define IDC_IOR_SPIN 329 -#define IDC_TR_SPIN 330 -#define IDC_DIM_AMTSPIN 330 -#define IDC_DIM_MULTSPIN 331 -#define IDC_WIRE_SPIN 332 -#define IDC_CLOSEBUTTON 1000 -#define IDC_DOSTUFF 1000 -#define IDC_TR_SUB2 1001 -#define IDC_TR_SUB 1002 -#define IDC_TR_ADD 1003 -#define IDC_CSHADER1 1003 -#define IDC_MAPON_TR 1038 -#define IDC_PIXELS 1043 -#define IDC_UNITS 1044 -#define IDC_WIRE 1048 -#define IDD_DMTL_DYNAM 1057 -#define IDD_DMTL_XRAY 1058 -#define IDC_FACE_MAP 1059 -#define IDC_FACETED 1060 -#define IDC_HIGHLIGHT 1062 -#define IDC_2SIDE 1067 -#define IDC_SUPER_SAMP 1068 -#define IDC_ADAPT_ON 1069 -#define IDC_SAMPLE_TEX 1070 -#define IDC_MAPON_FI 1107 -#define IDC_BOUNCE_EDIT 1193 -#define IDC_BOUNCE_SPIN 1194 -#define IDC_STATFRIC_EDIT 1195 -#define IDC_STATFRIC_SPIN 1196 -#define IDC_SLIDFRIC_EDIT 1197 -#define IDC_SLIDFRIC_SPIN 1198 -#define IDC_DIM_REFL 1252 -#define IDC_TF_IN 1300 -#define IDC_TF_OUT 1301 -#define IDC_COLOR_NEW 1456 -#define IDC_EDIT 1490 -#define IDC_SPIN 1496 -#define IDC_SHADER 1728 -#define IDC_ESHADER 1729 -#define IDC_SAMPLEQUALITY_SPIN 1729 -#define IDC_SHADER2 1729 -#define IDC_CSHADER 1730 -#define IDC_SAMPLEQUALITY_EDIT 1730 -#define IDC_PIX_SAMPLER 1731 -#define IDC_THRESHOLD_EDIT 1732 -#define IDC_THRESHOLD_SPIN 1733 -#define IDC_PARAM0_EDIT 1734 -#define IDC_PARAM0_SPIN 1735 -#define IDC_PARAM1_EDIT 1736 -#define IDC_FILTER_CS 1736 -#define IDC_USEMAP_0 1737 -#define IDC_PARAM1_SPIN 1737 -#define IDC_AMTEDIT_0 1738 -#define IDC_AMTSPIN_0 1739 -#define IDC_MAP_0 1740 -#define IDC_USEMAP_1 1741 -#define IDC_AMTEDIT_1 1742 -#define IDC_AMTSPIN_1 1743 -#define IDC_MAP_1 1744 -#define IDC_USEMAP_2 1745 -#define IDC_AMTEDIT_2 1746 -#define IDC_AMTSPIN_2 1747 -#define IDC_MAP_2 1748 -#define IDC_USEMAP_3 1749 -#define IDC_AMTEDIT_3 1750 -#define IDC_AMTSPIN_3 1751 -#define IDC_MAP_3 1752 -#define IDC_USEMAP_4 1753 -#define IDC_AMTEDIT_4 1754 -#define IDC_AMTSPIN_4 1755 -#define IDC_MAP_4 1756 -#define IDC_USEMAP_5 1757 -#define IDC_AMTEDIT_5 1758 -#define IDC_AMTSPIN_5 1759 -#define IDC_MAP_5 1760 -#define IDC_USEMAP_6 1761 -#define IDC_AMTEDIT_6 1762 -#define IDC_AMTSPIN_6 1763 -#define IDC_MAP_6 1764 -#define IDC_USEMAP_7 1765 -#define IDC_AMTEDIT_7 1766 -#define IDC_AMTSPIN_7 1767 -#define IDC_MAP_7 1768 -#define IDC_USEMAP_8 1769 -#define IDC_AMTEDIT_8 1770 -#define IDC_AMTSPIN_8 1771 -#define IDC_MAP_8 1772 -#define IDC_USEMAP_9 1773 -#define IDC_AMTEDIT_9 1774 -#define IDC_AMTSPIN_9 1775 -#define IDC_MAP_9 1776 -#define IDC_USEMAP_10 1777 -#define IDC_AMTEDIT_10 1778 -#define IDC_AMTSPIN_10 1779 -#define IDC_MAP_10 1780 -#define IDC_USEMAP_11 1781 -#define IDC_AMTEDIT_11 1782 -#define IDC_AMTSPIN_11 1783 -#define IDC_MAP_11 1784 -#define IDC_LOCK_TEX01 1785 -#define IDC_USEMAP_12 1786 -#define IDC_AMTEDIT_12 1787 -#define IDC_USEMAP_13 1788 -#define IDC_AMTEDIT_13 1789 -#define IDC_USEMAP_14 1790 -#define IDC_AMTEDIT_14 1791 -#define IDC_AMTSPIN_12 1792 -#define IDC_AMTSPIN_13 1793 -#define IDC_AMTSPIN_14 1794 -#define IDC_MAP_12 1795 -#define IDC_MAP_13 1796 -#define IDC_MAP_14 1797 -#define IDC_USEMAP_15 1798 -#define IDC_AMTEDIT_15 1799 -#define IDC_AMTSPIN_15 1800 -#define IDC_MAP_15 1801 -#define IDC_USEMAP_16 1802 -#define IDC_AMTEDIT_16 1803 -#define IDC_AMTSPIN_16 1804 -#define IDC_MAP_16 1805 -#define IDC_USEMAP_17 1806 -#define IDC_BR_EDIT 1807 -#define IDC_AMTEDIT_17 1807 -#define IDC_BR_SPIN 1808 -#define IDC_AMTSPIN_17 1808 -#define IDC_MAPON_BR 1809 -#define IDC_MAP_17 1809 -#define IDC_USEMAP_18 1810 -#define IDC_AMTEDIT_18 1811 -#define IDC_AMTSPIN_18 1812 -#define IDC_MAP_18 1813 -#define IDC_MAPON_CLR 1814 -#define IDC_USEMAP_19 1814 -#define IDC_AMTEDIT_19 1815 -#define IDC_AMTSPIN_19 1816 -#define IDC_MAP_19 1817 -#define IDC_USEMAP_20 1818 -#define IDC_AMTEDIT_20 1819 -#define IDC_AMTSPIN_20 1820 -#define IDC_MAP_20 1821 -#define IDC_USEMAP_21 1822 -#define IDC_AMTEDIT_21 1823 -#define IDC_AMTSPIN_21 1824 -#define IDC_MAP_21 1825 -#define IDC_USEMAP_22 1826 -#define IDC_AMTEDIT_22 1827 -#define IDC_AMTSPIN_22 1828 -#define IDC_MAP_22 1829 -#define IDC_USEMAP_23 1830 -#define IDC_AMTEDIT_23 1831 -#define IDC_AMTSPIN_23 1832 -#define IDC_MAP_23 1833 -#define IDC_ADAPT_STATIC 1861 -#define IDC_ADVANCED_BUTTON 1862 -#define IDC_OPAC_TEXT1 1865 -#define IDC_OPAC_TEXT2 1866 -#define IDC_REFR_TEXT1 1867 -#define IDC_OPAC_TEXT3 1868 -#define IDC_REFL_TEXT1 1869 -#define IDC_REFL_TEXT2 1870 -#define IDC_REFL_BOX 1871 -#define IDC_OPAC_BOX 1872 -#define IDC_FILTER_OVERLAY 1873 -#define IDC_COMMENT_BOX 1874 -#define IDC_QUALITY_TEXT 1875 -#define IDC_COMMENT_TEXT 1876 -#define IDC_PARAM0_TEXT 1877 -#define IDC_PARAM1_TEXT 1878 -#define IDS_DS_WIREFRAME 10049 -#define IDS_DS_SHIN_STR 10052 -#define IDS_DS_OPACITY 10053 -#define IDS_JW_SHADERTYPE 10057 -#define IDS_DS_EXTRA 10059 -#define IDS_DS_TEXMAP 10060 -#define IDS_JW_MAPENABLES 10064 -#define IDS_DS_BU 10067 -#define IDS_DS_RL 10068 -#define IDS_DS_RR 10069 -#define IDS_DS_TEXMAPS 10070 -#define IDS_DS_FILTER 10071 -#define IDS_DS_WIRESZ 10114 -#define IDS_DS_IOR 10115 -#define IDS_JW_MAPS 10127 -#define IDS_JW_MAPAMOUNTS 10128 -#define IDS_JW_ENABLE 10133 -#define IDS_JW_AMOUNT 10134 -#define IDS_JW_SHADERBYNAME 10139 -#define IDS_JW_SAMPLERBYNAME 10140 -#define IDS_DS_AMOUNT 11442 -#define IDS_DS_CLASSTEXMAPS 11471 -#define IDS_DS_DYNAMICS 11484 -#define IDS_DS_BOUNCE 11485 -#define IDS_DS_STATFRIC 11486 -#define IDS_DS_SLIDFRIC 11487 -#define IDS_DS_FALLOFF 11495 -#define IDS_DS_DIMLEV 11514 -#define IDS_DS_DIMMULT 11515 -#define IDS_DS_DP 11530 -#define IDS_KE_STANDARD2 11534 -#define IDS_KE_SHADER 11535 -#define IDS_KE_SAMPLING 11536 -#define IDS_KE_XRAY 11537 -#define IDS_KE_NONE 11547 -#define IDS_JW_TWOSIDED 11585 -#define IDS_JW_FACEMAP 11586 -#define IDS_JW_OPACITYTYPE 11587 -#define IDS_JW_FILTERMAP 11588 -#define IDS_JW_FALLOFFTYPE 11589 -#define IDS_JW_WIREUNITS 11590 -#define IDS_JW_APPLYREFDIM 11591 -#define IDS_JW_PIXELSAMPLER 11592 -#define IDS_JW_SAMPLERQUAL 11593 -#define IDS_JW_SAMPLERENABLE 11594 -#define IDS_KE_STANDARD2_CDESC 11600 -#define IDS_JW_ADTEXLOCK 11620 -#define IDS_KE_FACETED 11672 -#define IDS_STRING_1 11673 -#define IDS_JW_ESHADERTYPE 11673 -#define IDS_STRING_2 11674 -#define IDS_JW_CSHADERTYPE 11674 -#define IDS_KE_SAMPLERADAPTTHRESH 11675 -#define IDS_KE_SAMPLERADAPTON 11676 -#define IDS_KE_SAMPLERADVANCED 11677 -#define IDS_JW_ESHADERBYNAME 11678 -#define IDS_JW_CSHADERBYNAME 11679 -#define IDS_KE_SUBSAMPLE_TEX_ON 11683 -#define IDS_KE_SAMPLER_PARAM0 11696 -#define IDS_KE_SAMPLER_PARAM1 11697 +#define IDS_LIBDESCRIPTION 1 +#define IDS_CATEGORY 2 +#define IDS_CLASS_NAME 3 +#define IDS_PARAMS 4 +#define IDS_SPIN 5 +#define IDS_COMMENT 6 +#define IDS_MN_DIFFUSE 7 +#define IDS_MN_BRIGHTNESS 8 +#define IDS_MN_OPACITY 9 +#define IDS_MN_NONE 10 +#define IDS_COLOR 11 +#define IDS_PARAMCHG 12 +#define IDS_MN_DIFFUSE_I 13 +#define IDS_MN_BRIGHTNESS_I 14 +#define IDS_MN_OPACITY_I 15 +#define IDD_PANEL 101 +#define IDD_DMTL_EXTRA6 116 +#define IDB_DMTL_BUTTONS 122 +#define IDB_DMTL_MASKBUTTONS 123 +#define IDD_DMTL_SHADER4 125 +#define IDD_DMTL_TEXMAP4 145 +#define IDD_SHADER_SKEL1 148 +#define IDD_DMTL_SAMPLING3 151 +#define IDC_TF_EDIT 218 +#define IDC_IOR_EDIT 219 +#define IDC_TR_EDIT 220 +#define IDC_DIM_AMT 220 +#define IDC_WIRE_EDIT 221 +#define IDC_DIM_MULT 222 +#define IDC_TF_SPIN 328 +#define IDC_IOR_SPIN 329 +#define IDC_TR_SPIN 330 +#define IDC_DIM_AMTSPIN 330 +#define IDC_DIM_MULTSPIN 331 +#define IDC_WIRE_SPIN 332 +#define IDC_CLOSEBUTTON 1000 +#define IDC_DOSTUFF 1000 +#define IDC_TR_SUB2 1001 +#define IDC_TR_SUB 1002 +#define IDC_TR_ADD 1003 +#define IDC_CSHADER1 1003 +#define IDC_MAPON_TR 1038 +#define IDC_PIXELS 1043 +#define IDC_UNITS 1044 +#define IDC_WIRE 1048 +#define IDD_DMTL_DYNAM 1057 +#define IDD_DMTL_XRAY 1058 +#define IDC_FACE_MAP 1059 +#define IDC_FACETED 1060 +#define IDC_HIGHLIGHT 1062 +#define IDC_2SIDE 1067 +#define IDC_SUPER_SAMP 1068 +#define IDC_ADAPT_ON 1069 +#define IDC_SAMPLE_TEX 1070 +#define IDC_MAPON_FI 1107 +#define IDC_BOUNCE_EDIT 1193 +#define IDC_BOUNCE_SPIN 1194 +#define IDC_STATFRIC_EDIT 1195 +#define IDC_STATFRIC_SPIN 1196 +#define IDC_SLIDFRIC_EDIT 1197 +#define IDC_SLIDFRIC_SPIN 1198 +#define IDC_DIM_REFL 1252 +#define IDC_TF_IN 1300 +#define IDC_TF_OUT 1301 +#define IDC_COLOR_NEW 1456 +#define IDC_EDIT 1490 +#define IDC_SPIN 1496 +#define IDC_SHADER 1728 +#define IDC_ESHADER 1729 +#define IDC_SAMPLEQUALITY_SPIN 1729 +#define IDC_SHADER2 1729 +#define IDC_CSHADER 1730 +#define IDC_SAMPLEQUALITY_EDIT 1730 +#define IDC_PIX_SAMPLER 1731 +#define IDC_THRESHOLD_EDIT 1732 +#define IDC_THRESHOLD_SPIN 1733 +#define IDC_PARAM0_EDIT 1734 +#define IDC_PARAM0_SPIN 1735 +#define IDC_PARAM1_EDIT 1736 +#define IDC_FILTER_CS 1736 +#define IDC_USEMAP_0 1737 +#define IDC_PARAM1_SPIN 1737 +#define IDC_AMTEDIT_0 1738 +#define IDC_AMTSPIN_0 1739 +#define IDC_MAP_0 1740 +#define IDC_USEMAP_1 1741 +#define IDC_AMTEDIT_1 1742 +#define IDC_AMTSPIN_1 1743 +#define IDC_MAP_1 1744 +#define IDC_USEMAP_2 1745 +#define IDC_AMTEDIT_2 1746 +#define IDC_AMTSPIN_2 1747 +#define IDC_MAP_2 1748 +#define IDC_USEMAP_3 1749 +#define IDC_AMTEDIT_3 1750 +#define IDC_AMTSPIN_3 1751 +#define IDC_MAP_3 1752 +#define IDC_USEMAP_4 1753 +#define IDC_AMTEDIT_4 1754 +#define IDC_AMTSPIN_4 1755 +#define IDC_MAP_4 1756 +#define IDC_USEMAP_5 1757 +#define IDC_AMTEDIT_5 1758 +#define IDC_AMTSPIN_5 1759 +#define IDC_MAP_5 1760 +#define IDC_USEMAP_6 1761 +#define IDC_AMTEDIT_6 1762 +#define IDC_AMTSPIN_6 1763 +#define IDC_MAP_6 1764 +#define IDC_USEMAP_7 1765 +#define IDC_AMTEDIT_7 1766 +#define IDC_AMTSPIN_7 1767 +#define IDC_MAP_7 1768 +#define IDC_USEMAP_8 1769 +#define IDC_AMTEDIT_8 1770 +#define IDC_AMTSPIN_8 1771 +#define IDC_MAP_8 1772 +#define IDC_USEMAP_9 1773 +#define IDC_AMTEDIT_9 1774 +#define IDC_AMTSPIN_9 1775 +#define IDC_MAP_9 1776 +#define IDC_USEMAP_10 1777 +#define IDC_AMTEDIT_10 1778 +#define IDC_AMTSPIN_10 1779 +#define IDC_MAP_10 1780 +#define IDC_USEMAP_11 1781 +#define IDC_AMTEDIT_11 1782 +#define IDC_AMTSPIN_11 1783 +#define IDC_MAP_11 1784 +#define IDC_LOCK_TEX01 1785 +#define IDC_USEMAP_12 1786 +#define IDC_AMTEDIT_12 1787 +#define IDC_USEMAP_13 1788 +#define IDC_AMTEDIT_13 1789 +#define IDC_USEMAP_14 1790 +#define IDC_AMTEDIT_14 1791 +#define IDC_AMTSPIN_12 1792 +#define IDC_AMTSPIN_13 1793 +#define IDC_AMTSPIN_14 1794 +#define IDC_MAP_12 1795 +#define IDC_MAP_13 1796 +#define IDC_MAP_14 1797 +#define IDC_USEMAP_15 1798 +#define IDC_AMTEDIT_15 1799 +#define IDC_AMTSPIN_15 1800 +#define IDC_MAP_15 1801 +#define IDC_USEMAP_16 1802 +#define IDC_AMTEDIT_16 1803 +#define IDC_AMTSPIN_16 1804 +#define IDC_MAP_16 1805 +#define IDC_USEMAP_17 1806 +#define IDC_BR_EDIT 1807 +#define IDC_AMTEDIT_17 1807 +#define IDC_BR_SPIN 1808 +#define IDC_AMTSPIN_17 1808 +#define IDC_MAPON_BR 1809 +#define IDC_MAP_17 1809 +#define IDC_USEMAP_18 1810 +#define IDC_AMTEDIT_18 1811 +#define IDC_AMTSPIN_18 1812 +#define IDC_MAP_18 1813 +#define IDC_MAPON_CLR 1814 +#define IDC_USEMAP_19 1814 +#define IDC_AMTEDIT_19 1815 +#define IDC_AMTSPIN_19 1816 +#define IDC_MAP_19 1817 +#define IDC_USEMAP_20 1818 +#define IDC_AMTEDIT_20 1819 +#define IDC_AMTSPIN_20 1820 +#define IDC_MAP_20 1821 +#define IDC_USEMAP_21 1822 +#define IDC_AMTEDIT_21 1823 +#define IDC_AMTSPIN_21 1824 +#define IDC_MAP_21 1825 +#define IDC_USEMAP_22 1826 +#define IDC_AMTEDIT_22 1827 +#define IDC_AMTSPIN_22 1828 +#define IDC_MAP_22 1829 +#define IDC_USEMAP_23 1830 +#define IDC_AMTEDIT_23 1831 +#define IDC_AMTSPIN_23 1832 +#define IDC_MAP_23 1833 +#define IDC_ADAPT_STATIC 1861 +#define IDC_ADVANCED_BUTTON 1862 +#define IDC_OPAC_TEXT1 1865 +#define IDC_OPAC_TEXT2 1866 +#define IDC_REFR_TEXT1 1867 +#define IDC_OPAC_TEXT3 1868 +#define IDC_REFL_TEXT1 1869 +#define IDC_REFL_TEXT2 1870 +#define IDC_REFL_BOX 1871 +#define IDC_OPAC_BOX 1872 +#define IDC_FILTER_OVERLAY 1873 +#define IDC_COMMENT_BOX 1874 +#define IDC_QUALITY_TEXT 1875 +#define IDC_COMMENT_TEXT 1876 +#define IDC_PARAM0_TEXT 1877 +#define IDC_PARAM1_TEXT 1878 +#define IDS_DS_WIREFRAME 10049 +#define IDS_DS_SHIN_STR 10052 +#define IDS_DS_OPACITY 10053 +#define IDS_JW_SHADERTYPE 10057 +#define IDS_DS_EXTRA 10059 +#define IDS_DS_TEXMAP 10060 +#define IDS_JW_MAPENABLES 10064 +#define IDS_DS_BU 10067 +#define IDS_DS_RL 10068 +#define IDS_DS_RR 10069 +#define IDS_DS_TEXMAPS 10070 +#define IDS_DS_FILTER 10071 +#define IDS_DS_WIRESZ 10114 +#define IDS_DS_IOR 10115 +#define IDS_JW_MAPS 10127 +#define IDS_JW_MAPAMOUNTS 10128 +#define IDS_JW_ENABLE 10133 +#define IDS_JW_AMOUNT 10134 +#define IDS_JW_SHADERBYNAME 10139 +#define IDS_JW_SAMPLERBYNAME 10140 +#define IDS_DS_AMOUNT 11442 +#define IDS_DS_CLASSTEXMAPS 11471 +#define IDS_DS_DYNAMICS 11484 +#define IDS_DS_BOUNCE 11485 +#define IDS_DS_STATFRIC 11486 +#define IDS_DS_SLIDFRIC 11487 +#define IDS_DS_FALLOFF 11495 +#define IDS_DS_DIMLEV 11514 +#define IDS_DS_DIMMULT 11515 +#define IDS_DS_DP 11530 +#define IDS_KE_STANDARD2 11534 +#define IDS_KE_SHADER 11535 +#define IDS_KE_SAMPLING 11536 +#define IDS_KE_XRAY 11537 +#define IDS_KE_NONE 11547 +#define IDS_JW_TWOSIDED 11585 +#define IDS_JW_FACEMAP 11586 +#define IDS_JW_OPACITYTYPE 11587 +#define IDS_JW_FILTERMAP 11588 +#define IDS_JW_FALLOFFTYPE 11589 +#define IDS_JW_WIREUNITS 11590 +#define IDS_JW_APPLYREFDIM 11591 +#define IDS_JW_PIXELSAMPLER 11592 +#define IDS_JW_SAMPLERQUAL 11593 +#define IDS_JW_SAMPLERENABLE 11594 +#define IDS_KE_STANDARD2_CDESC 11600 +#define IDS_JW_ADTEXLOCK 11620 +#define IDS_KE_FACETED 11672 +#define IDS_STRING_1 11673 +#define IDS_JW_ESHADERTYPE 11673 +#define IDS_STRING_2 11674 +#define IDS_JW_CSHADERTYPE 11674 +#define IDS_KE_SAMPLERADAPTTHRESH 11675 +#define IDS_KE_SAMPLERADAPTON 11676 +#define IDS_KE_SAMPLERADVANCED 11677 +#define IDS_JW_ESHADERBYNAME 11678 +#define IDS_JW_CSHADERBYNAME 11679 +#define IDS_KE_SUBSAMPLE_TEX_ON 11683 +#define IDS_KE_SAMPLER_PARAM0 11696 +#define IDS_KE_SAMPLER_PARAM1 11697 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1004 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1004 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/Max/Material/stdafx.cpp b/src/plugins/Max/Material/stdafx.cpp index 47ba185752c..d12030476ed 100644 --- a/src/plugins/Max/Material/stdafx.cpp +++ b/src/plugins/Max/Material/stdafx.cpp @@ -1,3 +1,2 @@ #include "stdafx.h" #pragma hdrstop - diff --git a/src/plugins/Maya/Export/ExportDefines.cpp b/src/plugins/Maya/Export/ExportDefines.cpp index 2d3da298e22..9f20a4f40e1 100644 --- a/src/plugins/Maya/Export/ExportDefines.cpp +++ b/src/plugins/Maya/Export/ExportDefines.cpp @@ -8,115 +8,105 @@ MObject findShader(MObject& setNode, SXRShaderData& d) // Find the shading node for the given shading group set node. // { - MFnDependencyNode fnNode(setNode); - d.name = fnNode.name(); - // cout << "looking for shader in node " << fnNode.name().asChar() << "\n"; - MPlug shaderPlug = fnNode.findPlug("surfaceShader"); - - if (!shaderPlug.isNull()) { - MPlugArray connectedPlugs; - bool asSrc = false; - bool asDst = true; - shaderPlug.connectedTo( connectedPlugs, asDst, asSrc ); - - if (connectedPlugs.length() != 1) - Msg("!Error getting shader"); - else - return connectedPlugs[0].node(); - } - - Msg("!Error finding surface shader for node '%s'",fnNode.name().asChar()); - return MObject::kNullObj; + MFnDependencyNode fnNode(setNode); + d.name = fnNode.name(); + // cout << "looking for shader in node " << fnNode.name().asChar() << "\n"; + MPlug shaderPlug = fnNode.findPlug("surfaceShader"); + + if (!shaderPlug.isNull()) { + MPlugArray connectedPlugs; + bool asSrc = false; + bool asDst = true; + shaderPlug.connectedTo(connectedPlugs, asDst, asSrc); + + if (connectedPlugs.length() != 1) + Msg("!Error getting shader"); + else + return connectedPlugs[0].node(); + } + + Msg("!Error finding surface shader for node '%s'", fnNode.name().asChar()); + return MObject::kNullObj; } -MStatus parseShader(MObject &src, SXRShaderData& d) +MStatus parseShader(MObject& src, SXRShaderData& d) { - MStatus status; - - MFnSet fnSet( src, &status ); - if (status == MStatus::kFailure) { - status.perror("Unable to lookup shader from set of shaders for object"); - return status; - } - - MObject shaderNode = findShader(src,d); - if (shaderNode == MObject::kNullObj) - return (MStatus::kFailure); - - MPlug colorPlug = MFnDependencyNode(shaderNode).findPlug("color", &status); - if (status == MStatus::kFailure) - return (status); - - MItDependencyGraph dgIt(colorPlug, MFn::kFileTexture, - MItDependencyGraph::kUpstream, - MItDependencyGraph::kBreadthFirst, - MItDependencyGraph::kNodeLevel, - &status); - - if (status == MStatus::kFailure) - return (status); - - dgIt.disablePruningOnFilter(); - - // If no texture file node was found, just continue. - // - if (dgIt.isDone()) { - // cout << "no textures found for " << colorPlug.name() << "\n"; - return (MStatus::kSuccess); - } - - // Print out the texture node name and texture file that it references. - // - MObject textureNode = dgIt.thisNode(); - MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); - MString textureName; - filenamePlug.getValue(textureName); - - MStringArray rgFolders; - - if (strchr (textureName.asChar(), '\\')) - { - textureName.split ('\\', rgFolders); - } else { - textureName.split ('/', rgFolders); - } - d.tex_name = rgFolders[rgFolders.length() -1]; - // cout << "Found texture file: '" << filename.asChar() << "'\n"; - - short index; - //double side flag - MPlug xrDoubleSidePlug= MFnDependencyNode(shaderNode).findPlug("xrayDoubleSide", &status); - if (status == MS::kSuccess) - { - MFnEnumAttribute enm = xrDoubleSidePlug.attribute(); - if ((status == MS::kSuccess)&&(MS::kSuccess==xrDoubleSidePlug.getValue(index))) - d.double_side = index; - } - //engine - MPlug xrEnginePlug= MFnDependencyNode(shaderNode).findPlug("xrayEngineShader", &status); - if (status == MS::kSuccess) - { - MFnEnumAttribute enm = xrEnginePlug.attribute(); - - if ((status == MS::kSuccess)&&(MS::kSuccess==xrEnginePlug.getValue(index))) - d.eng_name = enm.fieldName(index); - } - //compiler - MPlug xrCompilerPlug = MFnDependencyNode(shaderNode).findPlug("xrayCompilerShader", &status); - if (status == MS::kSuccess) - { - MFnEnumAttribute enm = xrCompilerPlug.attribute(); - if ((status == MS::kSuccess)&&(MS::kSuccess==xrCompilerPlug.getValue(index))) - d.comp_name = enm.fieldName(index); - } - //game material - MPlug xrGameMaterialPlug = MFnDependencyNode(shaderNode).findPlug("xrayGameMaterial", &status); - if (status == MS::kSuccess) - { - MFnEnumAttribute enm = xrGameMaterialPlug.attribute(); - if ((status == MS::kSuccess)&&(MS::kSuccess==xrGameMaterialPlug.getValue(index))) - d.gmat_name = enm.fieldName(index); - } - - return (MStatus::kSuccess); + MStatus status; + + MFnSet fnSet(src, &status); + if (status == MStatus::kFailure) { + status.perror("Unable to lookup shader from set of shaders for object"); + return status; + } + + MObject shaderNode = findShader(src, d); + if (shaderNode == MObject::kNullObj) return (MStatus::kFailure); + + MPlug colorPlug = MFnDependencyNode(shaderNode).findPlug("color", &status); + if (status == MStatus::kFailure) return (status); + + MItDependencyGraph dgIt(colorPlug, MFn::kFileTexture, MItDependencyGraph::kUpstream, + MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel, &status); + + if (status == MStatus::kFailure) return (status); + + dgIt.disablePruningOnFilter(); + + // If no texture file node was found, just continue. + // + if (dgIt.isDone()) { + // cout << "no textures found for " << colorPlug.name() << "\n"; + return (MStatus::kSuccess); + } + + // Print out the texture node name and texture file that it references. + // + MObject textureNode = dgIt.thisNode(); + MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); + MString textureName; + filenamePlug.getValue(textureName); + + MStringArray rgFolders; + + if (strchr(textureName.asChar(), '\\')) { + textureName.split('\\', rgFolders); + } + else + { + textureName.split('/', rgFolders); + } + d.tex_name = rgFolders[rgFolders.length() - 1]; + // cout << "Found texture file: '" << filename.asChar() << "'\n"; + + short index; + // double side flag + MPlug xrDoubleSidePlug = MFnDependencyNode(shaderNode).findPlug("xrayDoubleSide", &status); + if (status == MS::kSuccess) { + MFnEnumAttribute enm = xrDoubleSidePlug.attribute(); + if ((status == MS::kSuccess) && (MS::kSuccess == xrDoubleSidePlug.getValue(index))) d.double_side = index; + } + // engine + MPlug xrEnginePlug = MFnDependencyNode(shaderNode).findPlug("xrayEngineShader", &status); + if (status == MS::kSuccess) { + MFnEnumAttribute enm = xrEnginePlug.attribute(); + + if ((status == MS::kSuccess) && (MS::kSuccess == xrEnginePlug.getValue(index))) + d.eng_name = enm.fieldName(index); + } + // compiler + MPlug xrCompilerPlug = MFnDependencyNode(shaderNode).findPlug("xrayCompilerShader", &status); + if (status == MS::kSuccess) { + MFnEnumAttribute enm = xrCompilerPlug.attribute(); + if ((status == MS::kSuccess) && (MS::kSuccess == xrCompilerPlug.getValue(index))) + d.comp_name = enm.fieldName(index); + } + // game material + MPlug xrGameMaterialPlug = MFnDependencyNode(shaderNode).findPlug("xrayGameMaterial", &status); + if (status == MS::kSuccess) { + MFnEnumAttribute enm = xrGameMaterialPlug.attribute(); + if ((status == MS::kSuccess) && (MS::kSuccess == xrGameMaterialPlug.getValue(index))) + d.gmat_name = enm.fieldName(index); + } + + return (MStatus::kSuccess); } diff --git a/src/plugins/Maya/Export/ExportDefines.h b/src/plugins/Maya/Export/ExportDefines.h index a039088a1cd..6f07c11b88b 100644 --- a/src/plugins/Maya/Export/ExportDefines.h +++ b/src/plugins/Maya/Export/ExportDefines.h @@ -7,25 +7,27 @@ class CSurface; // // Edge info structure // -typedef struct SXREdgeInfo { - int polyIds[2]; // Id's of polygons that reference edge - int vertId; // The second vertex of this edge - struct SXREdgeInfo* next; // Pointer to next edge - bool smooth; // Is this edge smooth +typedef struct SXREdgeInfo +{ + int polyIds[2]; // Id's of polygons that reference edge + int vertId; // The second vertex of this edge + struct SXREdgeInfo* next; // Pointer to next edge + bool smooth; // Is this edge smooth } * SXREdgeInfoPtr; struct SXRShaderData { - MString name; - MString tex_name; - MString eng_name; - MString comp_name; - MString gmat_name; - BOOL double_side; - SXRShaderData():double_side(FALSE),name(""),tex_name(""),eng_name("default"),comp_name("default"),gmat_name("default"){}; + MString name; + MString tex_name; + MString eng_name; + MString comp_name; + MString gmat_name; + BOOL double_side; + SXRShaderData() + : double_side(FALSE), name(""), tex_name(""), eng_name("default"), comp_name("default"), gmat_name("default"){}; }; -DEFINE_VECTOR(SXRShaderData,XRShaderDataVec,XRShaderDataIt); +DEFINE_VECTOR(SXRShaderData, XRShaderDataVec, XRShaderDataIt); -extern MStatus parseShader (MObject &src, SXRShaderData& d); -extern MObject findShader (MObject& setNode, SXRShaderData& d); +extern MStatus parseShader(MObject& src, SXRShaderData& d); +extern MObject findShader(MObject& setNode, SXRShaderData& d); #endif \ No newline at end of file diff --git a/src/plugins/Maya/Export/MayaExport.cpp b/src/plugins/Maya/Export/MayaExport.cpp index 6ca34fe3434..af0fb6a3381 100644 --- a/src/plugins/Maya/Export/MayaExport.cpp +++ b/src/plugins/Maya/Export/MayaExport.cpp @@ -1,39 +1,42 @@ #include "stdafx.h" #pragma hdrstop -#include "maTranslator.h" -#include "editors/ECore/Editor/EditObject.h" #include "editors/ECore/Editor/EditMesh.h" +#include "editors/ECore/Editor/EditObject.h" +#include "maTranslator.h" #include "smoth_flags.h" //----------------------------------------------------------------------------------------- BOOL CEditableObject::ParseMAMaterial(CSurface* dest, SXRShaderData& d) { string1024 tmp; - strcpy_s (tmp, d.tex_name.asChar()); - if (strext(tmp)) *strext(tmp)=0; - - dest->SetTexture (EFS.AppendFolderToName(tmp, sizeof(tmp), 1, TRUE)); - dest->SetFVF (D3DFVF_XYZ|D3DFVF_NORMAL|(1<SetVMap ("Texture"); - dest->m_Flags.set (CSurface::sf2Sided,d.double_side); - LPCSTR sh_name = _ChangeSymbol(strcpy(tmp,d.eng_name.asChar()),'/','\\'); - if (!sh_name||!sh_name[0]){ - Log("!Empty shader name, material: ",d.name.asChar()); + strcpy_s(tmp, d.tex_name.asChar()); + if (strext(tmp)) *strext(tmp) = 0; + + dest->SetTexture(EFS.AppendFolderToName(tmp, sizeof(tmp), 1, TRUE)); + dest->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | (1 << D3DFVF_TEXCOUNT_SHIFT)); + dest->SetVMap("Texture"); + dest->m_Flags.set(CSurface::sf2Sided, d.double_side); + LPCSTR sh_name = _ChangeSymbol(strcpy(tmp, d.eng_name.asChar()), '/', '\\'); + if (!sh_name || !sh_name[0]) { + Log("!Empty shader name, material: ", d.name.asChar()); return FALSE; } - dest->SetShader (sh_name); - dest->SetShaderXRLC (_ChangeSymbol(strcpy(tmp,d.comp_name.asChar()),'/','\\')); - dest->SetGameMtl (_ChangeSymbol(strcpy(tmp,d.gmat_name.asChar()),'/','\\')); + dest->SetShader(sh_name); + dest->SetShaderXRLC(_ChangeSymbol(strcpy(tmp, d.comp_name.asChar()), '/', '\\')); + dest->SetGameMtl(_ChangeSymbol(strcpy(tmp, d.gmat_name.asChar()), '/', '\\')); return TRUE; } CSurface* CEditableObject::CreateSurface(LPCSTR m_name, SXRShaderData& d) { - CSurface* S = FindSurfaceByName(m_name); - if (!S){ - S = new CSurface(); - S->SetName (m_name); - if (!ParseMAMaterial(S,d)){ xr_delete(S); return 0; } + CSurface* S = FindSurfaceByName(m_name); + if (!S) { + S = new CSurface(); + S->SetName(m_name); + if (!ParseMAMaterial(S, d)) { + xr_delete(S); + return 0; + } m_Surfaces.push_back(S); } return S; @@ -41,60 +44,67 @@ CSurface* CEditableObject::CreateSurface(LPCSTR m_name, SXRShaderData& d) MStatus CXRayObjectExport::ExportAll(CEditableObject* O) { - MStatus status = MS::kSuccess; + MStatus status = MS::kSuccess; - if (initializeSetsAndLookupTables( true )){ - MItDag dagIterator( MItDag::kBreadthFirst, MFn::kInvalid, &status); + if (initializeSetsAndLookupTables(true)) { + MItDag dagIterator(MItDag::kBreadthFirst, MFn::kInvalid, &status); - if ( MS::kSuccess != status) { - fprintf(stderr,"Failure in DAG iterator setup.\n"); + if (MS::kSuccess != status) { + fprintf(stderr, "Failure in DAG iterator setup.\n"); return MS::kFailure; } - for ( ; !dagIterator.isDone(); dagIterator.next() ){ + for (; !dagIterator.isDone(); dagIterator.next()) + { MDagPath dagPath; - MObject component = MObject::kNullObj; + MObject component = MObject::kNullObj; status = dagIterator.getPath(dagPath); if (!status) { - fprintf(stderr,"Failure getting DAG path.\n"); + fprintf(stderr, "Failure getting DAG path.\n"); freeLookupTables(); return MS::kFailure; } // skip over intermediate objects // - MFnDagNode dagNode( dagPath, &status ); + MFnDagNode dagNode(dagPath, &status); if (dagNode.isIntermediateObject()) continue; - if ((dagPath.hasFn(MFn::kNurbsSurface)) && (dagPath.hasFn(MFn::kTransform))){ + if ((dagPath.hasFn(MFn::kNurbsSurface)) && (dagPath.hasFn(MFn::kTransform))) { status = MS::kSuccess; - fprintf(stderr,"Warning: skipping Nurbs Surface.\n"); - }else if ((dagPath.hasFn(MFn::kMesh)) && (dagPath.hasFn(MFn::kTransform))){ - // We want only the shape, + fprintf(stderr, "Warning: skipping Nurbs Surface.\n"); + } + else if ((dagPath.hasFn(MFn::kMesh)) && (dagPath.hasFn(MFn::kTransform))) + { + // We want only the shape, // not the transform-extended-to-shape. continue; - }else if (dagPath.hasFn(MFn::kMesh)){ - // Build a lookup table so we can determine which + } + else if (dagPath.hasFn(MFn::kMesh)) + { + // Build a lookup table so we can determine which // polygons belong to a particular edge as well as // smoothing information // - buildEdgeTable( dagPath ); + buildEdgeTable(dagPath); // Now output the polygon information // status = ExportPart(O, dagPath, component); objectId++; if (status != MS::kSuccess) { - fprintf(stderr,"Error: exporting geom failed.\n"); - freeLookupTables(); - destroyEdgeTable(); // Free up the edge table + fprintf(stderr, "Error: exporting geom failed.\n"); + freeLookupTables(); + destroyEdgeTable(); // Free up the edge table return MS::kFailure; } - destroyEdgeTable(); // Free up the edge table + destroyEdgeTable(); // Free up the edge table } } - }else{ + } + else + { status = MS::kFailure; } @@ -109,102 +119,107 @@ MStatus CXRayObjectExport::ExportSelected(CEditableObject* O) MStatus status; MString filename; - if (initializeSetsAndLookupTables( false )){ + if (initializeSetsAndLookupTables(false)) { // Create an iterator for the active selection list // MSelectionList slist; - MGlobal::getActiveSelectionList( slist ); - MItSelectionList iter( slist ); + MGlobal::getActiveSelectionList(slist); + MItSelectionList iter(slist); - if (iter.isDone()){ - fprintf(stderr,"Error: Nothing is selected.\n"); + if (iter.isDone()) { + fprintf(stderr, "Error: Nothing is selected.\n"); return MS::kFailure; } - // We will need to interate over a selected node's heirarchy + // We will need to interate over a selected node's heirarchy // in the case where shapes are grouped, and the group is selected. - MItDag dagIterator( MItDag::kDepthFirst, MFn::kInvalid, &status); + MItDag dagIterator(MItDag::kDepthFirst, MFn::kInvalid, &status); // Selection list loop - for ( ; !iter.isDone(); iter.next()) + for (; !iter.isDone(); iter.next()) { MDagPath objectPath; // get the selected node - status = iter.getDagPath( objectPath); + status = iter.getDagPath(objectPath); // reset iterator's root node to be the selected node. - status = dagIterator.reset (objectPath.node(), - MItDag::kDepthFirst, MFn::kInvalid ); + status = dagIterator.reset(objectPath.node(), MItDag::kDepthFirst, MFn::kInvalid); // DAG iteration beginning at at selected node - for ( ; !dagIterator.isDone(); dagIterator.next()){ + for (; !dagIterator.isDone(); dagIterator.next()) + { MDagPath dagPath; - MObject component = MObject::kNullObj; + MObject component = MObject::kNullObj; status = dagIterator.getPath(dagPath); if (!status) { - fprintf(stderr,"Failure getting DAG path.\n"); + fprintf(stderr, "Failure getting DAG path.\n"); freeLookupTables(); return MS::kFailure; } - if (status ){ + if (status) { // skip over intermediate objects // - MFnDagNode dagNode( dagPath, &status ); - if (dagNode.isIntermediateObject()) - continue; + MFnDagNode dagNode(dagPath, &status); + if (dagNode.isIntermediateObject()) continue; - if (dagPath.hasFn(MFn::kNurbsSurface)){ + if (dagPath.hasFn(MFn::kNurbsSurface)) { status = MS::kSuccess; - fprintf(stderr,"Warning: skipping Nurbs Surface.\n"); - }else if (( dagPath.hasFn(MFn::kMesh)) && ( dagPath.hasFn(MFn::kTransform))){ - // We want only the shape, + fprintf(stderr, "Warning: skipping Nurbs Surface.\n"); + } + else if ((dagPath.hasFn(MFn::kMesh)) && (dagPath.hasFn(MFn::kTransform))) + { + // We want only the shape, // not the transform-extended-to-shape. continue; - }else if ( dagPath.hasFn(MFn::kMesh)){ - // Build a lookup table so we can determine which + } + else if (dagPath.hasFn(MFn::kMesh)) + { + // Build a lookup table so we can determine which // polygons belong to a particular edge as well as // smoothing information // - buildEdgeTable( dagPath ); + buildEdgeTable(dagPath); status = ExportPart(O, dagPath, component); objectId++; if (status != MS::kSuccess) { fprintf(stderr, "Error: exporting geom failed, check your selection.\n"); freeLookupTables(); - destroyEdgeTable(); // Free up the edge table + destroyEdgeTable(); // Free up the edge table return MS::kFailure; } - destroyEdgeTable(); // Free up the edge table + destroyEdgeTable(); // Free up the edge table } } } } - }else{ + } + else + { status = MS::kFailure; } - + freeLookupTables(); - + return status; } //----------------------------------------------------------------------------------------- typedef xr_map PtLookupMap; int AppendVertex(FvectorVec& _points, MPoint& _pt) { - Fvector pt; + Fvector pt; // convert from internal units to the current ui units - MDistance dst_x (_pt.x); - MDistance dst_y (_pt.y); - MDistance dst_z (_pt.z); - pt.set ((float)dst_x.asMeters(),(float)dst_y.asMeters(),-(float)dst_z.asMeters()); + MDistance dst_x(_pt.x); + MDistance dst_y(_pt.y); + MDistance dst_z(_pt.z); + pt.set((float)dst_x.asMeters(), (float)dst_y.asMeters(), -(float)dst_z.asMeters()); - for (FvectorIt it=_points.begin(); it!=_points.end(); it++) - if (it->similar(pt)) return it-_points.begin(); + for (FvectorIt it = _points.begin(); it != _points.end(); it++) + if (it->similar(pt)) return it - _points.begin(); _points.push_back(pt); - return _points.size()-1; + return _points.size() - 1; } int AppendUV(st_VMap*& VM, Fvector2& _uv) { @@ -213,20 +228,20 @@ int AppendUV(st_VMap*& VM, Fvector2& _uv) return sz; } - -MStatus CXRayObjectExport::set_smoth_flags( u32 &flags, const MIntArray& tri_vert_indeces )// const MFnMesh &fnMesh, const MItMeshPolygon &meshPoly, +MStatus CXRayObjectExport::set_smoth_flags( + u32& flags, const MIntArray& tri_vert_indeces) // const MFnMesh &fnMesh, const MItMeshPolygon &meshPoly, { - return t_set_smoth_flags( *this, flags, tri_vert_indeces ); + return t_set_smoth_flags(*this, flags, tri_vert_indeces); } -MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MObject& mComponent) +MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MObject& mComponent) { MStatus stat = MS::kSuccess; MSpace::Space space = MSpace::kWorld; - MFnMesh fnMesh( mdagPath, &stat ); - if ( MS::kSuccess != stat) { - fprintf(stderr,"Failure in MFnMesh initialization.\n"); + MFnMesh fnMesh(mdagPath, &stat); + if (MS::kSuccess != stat) { + fprintf(stderr, "Failure in MFnMesh initialization.\n"); return MS::kFailure; } @@ -234,30 +249,28 @@ MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MO MFnDagNode dagNode1(mdagPath); u32 pc = dagNode1.parentCount(); - for(u32 ip=0;ipm_VMaps; - _vmaps.resize (1); - st_VMap*& VM = _vmaps.back(); - VM = new st_VMap("Texture",vmtUV,false); + _vmaps.resize(1); + st_VMap*& VM = _vmaps.back(); + VM = new st_VMap("Texture", vmtUV, false); } // write faces { - DEFINE_VECTOR(st_Face,FaceVec,FaceIt); + DEFINE_VECTOR(st_Face, FaceVec, FaceIt); + + VMapVec& _vmaps = MESH->m_VMaps; + SurfFaces& _surf_faces = MESH->m_SurfFaces; + VMRefsVec& _vmrefs = MESH->m_VMRefs; - VMapVec& _vmaps = MESH->m_VMaps; - SurfFaces& _surf_faces = MESH->m_SurfFaces; - VMRefsVec& _vmrefs = MESH->m_VMRefs; - // temp variables - FvectorVec _points; + FvectorVec _points; FaceVec _faces; U32Vec _sgs; - int f_cnt = fnMesh.numPolygons(); + int f_cnt = fnMesh.numPolygons(); - _sgs.reserve (f_cnt); - _faces.reserve (f_cnt); - _vmrefs.reserve (f_cnt*3); + _sgs.reserve(f_cnt); + _faces.reserve(f_cnt); + _vmrefs.reserve(f_cnt * 3); -// int lastSmoothingGroup = INITIALIZE_SMOOTHING; + // int lastSmoothingGroup = INITIALIZE_SMOOTHING; MPointArray rgpt; MIntArray rgint; PtLookupMap ptMap; - CSurface* surf = 0; - for ( ; !meshPoly.isDone(); meshPoly.next()){ + CSurface* surf = 0; + for (; !meshPoly.isDone(); meshPoly.next()) + { // Write out the smoothing group that this polygon belongs to // We only write out the smoothing group if it is different // from the last polygon. // int compIdx = meshPoly.index(); - int smoothingGroup = polySmoothingGroups[ compIdx ]; + int smoothingGroup = polySmoothingGroups[compIdx]; // for each polygon, first setup the reverse mapping // between object-relative vertex indices and face-relative // vertex indices ptMap.clear(); - for (int i=0; i<(int)meshPoly.polygonVertexCount(); i++) - ptMap.insert (PtLookupMap::value_type(meshPoly.vertexIndex(i), i) ); + for (int i = 0; i < (int)meshPoly.polygonVertexCount(); i++) + ptMap.insert(PtLookupMap::value_type(meshPoly.vertexIndex(i), i)); // verify polygon zero area - if (meshPoly.zeroArea()){ + if (meshPoly.zeroArea()) { status = MS::kFailure; - Log("!polygon have zero area:",meshPoly.index()); + Log("!polygon have zero area:", meshPoly.index()); return status; } // verify polygon zero UV area -/* if (meshPoly.zeroUVArea()){ - status = MS::kFailure; - Log("!polygon have zero UV area:",meshPoly.index()); - return status; - } -*/ + /* if (meshPoly.zeroUVArea()){ + status = MS::kFailure; + Log("!polygon have zero UV area:",meshPoly.index()); + return status; + } + */ // verify polygon has UV information - if (!meshPoly.hasUVs (&status)) { + if (!meshPoly.hasUVs(&status)) { status = MS::kFailure; - Log("!polygon is missing UV information:",meshPoly.index()); + Log("!polygon is missing UV information:", meshPoly.index()); return status; } int cTri; // now iterate through each triangle on this polygon and create a triangle object in our list - status = meshPoly.numTriangles (cTri); + status = meshPoly.numTriangles(cTri); if (!status) { Log("!can't getting triangle count"); return status; } - for (int i=0; i < cTri; i++) { - + for (int i = 0; i < cTri; i++) + { // for each triangle, first get the triangle data - rgpt.clear();//triangle vertices - rgint.clear();//triangle vertex indices + rgpt.clear(); // triangle vertices + rgint.clear(); // triangle vertex indices // triangles that come from object are retrieved in world space - status = meshPoly.getTriangle (i, rgpt, rgint, MSpace::kWorld); + status = meshPoly.getTriangle(i, rgpt, rgint, MSpace::kWorld); if (!status) { Log("can't getting triangle for mesh poly"); @@ -409,14 +423,15 @@ MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MO // Write out vertex/uv index information // - R_ASSERT2(fnMesh.numUVs()>0,"Can't find uvmaps."); + R_ASSERT2(fnMesh.numUVs() > 0, "Can't find uvmaps."); _faces.push_back(st_Face()); _sgs.push_back(smoothingGroup); - //set_smooth - set_smoth_flags( _sgs.back(), rgint ); + // set_smooth + set_smoth_flags(_sgs.back(), rgint); - st_Face& f_it = _faces.back(); - for ( int vtx=0; vtx<3; vtx++ ) { + st_Face& f_it = _faces.back(); + for (int vtx = 0; vtx < 3; vtx++) + { // get face-relative vertex PtLookupMap::iterator mapIt; @@ -424,79 +439,77 @@ MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MO int vt = rgint[vtx]; mapIt = ptMap.find(vt); Fvector2 uv; - if (mapIt == ptMap.end()){ + if (mapIt == ptMap.end()) { Msg("!Can't find local index."); return MS::kFailure; } vtLocal = (*mapIt).second; - status = meshPoly.getUVIndex (vtLocal, vtUV, uv.x, uv.y); + status = meshPoly.getUVIndex(vtLocal, vtUV, uv.x, uv.y); if (!status) { - Msg("!error getting UV Index for local vertex '%d' and object vertex '%d'",vtLocal,vt); + Msg("!error getting UV Index for local vertex '%d' and object vertex '%d'", vtLocal, vt); return status; } - // flip v-part - uv.y=1.f-uv.y; - - f_it.pv[2-vtx].pindex = AppendVertex(_points,rgpt[vtx]); - f_it.pv[2-vtx].vmref = _vmrefs.size(); - _vmrefs.push_back (st_VMapPtLst()); - st_VMapPtLst& vm_lst = _vmrefs.back(); - vm_lst.count = 1; - vm_lst.pts = xr_alloc(vm_lst.count); - vm_lst.pts[0].vmap_index= 0; - vm_lst.pts[0].index = AppendUV(_vmaps.back(),uv); + // flip v-part + uv.y = 1.f - uv.y; + + f_it.pv[2 - vtx].pindex = AppendVertex(_points, rgpt[vtx]); + f_it.pv[2 - vtx].vmref = _vmrefs.size(); + _vmrefs.push_back(st_VMapPtLst()); + st_VMapPtLst& vm_lst = _vmrefs.back(); + vm_lst.count = 1; + vm_lst.pts = xr_alloc(vm_lst.count); + vm_lst.pts[0].vmap_index = 0; + vm_lst.pts[0].index = AppendUV(_vmaps.back(), uv); } // out face material - int iTexture = texMap[meshPoly.index()]; - if (iTexture<0) - xrDebug::Fatal(DEBUG_INFO,"Can't find material for polygon: %d",meshPoly.index()); - SXRShaderData& D= xr_data[iTexture]; + int iTexture = texMap[meshPoly.index()]; + if (iTexture < 0) xrDebug::Fatal(DEBUG_INFO, "Can't find material for polygon: %d", meshPoly.index()); + SXRShaderData& D = xr_data[iTexture]; int compIdx = meshPoly.index(); - surf = MESH->Parent()->CreateSurface(getMaterialName(mdagPath, compIdx, objectIdx),D); - if (!surf) return MStatus::kFailure; - _surf_faces[surf].push_back(_faces.size()-1); + surf = MESH->Parent()->CreateSurface(getMaterialName(mdagPath, compIdx, objectIdx), D); + if (!surf) return MStatus::kFailure; + _surf_faces[surf].push_back(_faces.size() - 1); } } { // copy from temp - MESH->m_VertCount = _points.size(); - MESH->m_FaceCount = _faces.size(); - MESH->m_Vertices = xr_alloc(MESH->m_VertCount); - memcpy(MESH->m_Vertices,&*_points.begin(),MESH->m_VertCount*sizeof(Fvector)); - MESH->m_Faces = xr_alloc(MESH->m_FaceCount); - memcpy(MESH->m_Faces,&*_faces.begin(),MESH->m_FaceCount*sizeof(st_Face)); + MESH->m_VertCount = _points.size(); + MESH->m_FaceCount = _faces.size(); + MESH->m_Vertices = xr_alloc(MESH->m_VertCount); + memcpy(MESH->m_Vertices, &*_points.begin(), MESH->m_VertCount * sizeof(Fvector)); + MESH->m_Faces = xr_alloc(MESH->m_FaceCount); + memcpy(MESH->m_Faces, &*_faces.begin(), MESH->m_FaceCount * sizeof(st_Face)); MESH->m_SmoothGroups = xr_alloc(MESH->m_FaceCount); - memcpy(MESH->m_SmoothGroups,&*_sgs.begin(),MESH->m_FaceCount*sizeof(u32)); + memcpy(MESH->m_SmoothGroups, &*_sgs.begin(), MESH->m_FaceCount * sizeof(u32)); - MESH->RecomputeBBox (); + MESH->RecomputeBBox(); } - if ((MESH->GetVertexCount()<4)||(MESH->GetFaceCount(true, false)<2)) - { - Log ("!Invalid mesh: '%s'. Faces<2 or Verts<4",*MESH->Name()); + if ((MESH->GetVertexCount() < 4) || (MESH->GetFaceCount(true, false) < 2)) { + Log("!Invalid mesh: '%s'. Faces<2 or Verts<4", *MESH->Name()); return MS::kFailure; } } return stat; } //----------------------------------------------------------------------------------------- -LPCSTR CXRayObjectExport::getMaterialName(MDagPath & mdagPath, int cid, int objectIdx) +LPCSTR CXRayObjectExport::getMaterialName(MDagPath& mdagPath, int cid, int objectIdx) { MStatus stat; - + int i, length; - MIntArray * currentMaterials = new MIntArray(); + MIntArray* currentMaterials = new MIntArray(); MStringArray mArray; - - for ( i=0; iappend( i ); - mArray.append( fnSet.name() ); + for (i = 0; i < numSets; i++) + { + if (lookup(mdagPath, i, cid)) { + MFnSet fnSet((*sets)[i]); + if (MFnSet::kRenderableOnly == fnSet.restriction(&stat)) { + currentMaterials->append(i); + mArray.append(fnSet.name()); } } } @@ -504,28 +517,31 @@ LPCSTR CXRayObjectExport::getMaterialName(MDagPath & mdagPath, int cid, int obje // Test for equivalent materials // bool materialsEqual = false; - if ((lastMaterials != NULL) && (lastMaterials->length() == currentMaterials->length())){ + if ((lastMaterials != NULL) && (lastMaterials->length() == currentMaterials->length())) { materialsEqual = true; length = lastMaterials->length(); - for (i=0; i1){ - xrDebug::Fatal(DEBUG_INFO,"Object '%s' has polygon '%d' with more than one material.",0,cid); + int mLength = mArray.length(); + if (mLength == 0) xrDebug::Fatal(DEBUG_INFO, "Object '%s' has polygon '%d' without material.", 0, cid); + if (mLength > 1) { + xrDebug::Fatal(DEBUG_INFO, "Object '%s' has polygon '%d' with more than one material.", 0, cid); } - }else{ + } + else + { xr_delete(currentMaterials); } return mArray[0].asChar(); diff --git a/src/plugins/Maya/Export/SmdBone.cpp b/src/plugins/Maya/Export/SmdBone.cpp index ae784466828..2ab2ba614d7 100644 --- a/src/plugins/Maya/Export/SmdBone.cpp +++ b/src/plugins/Maya/Export/SmdBone.cpp @@ -6,7 +6,7 @@ // ////////////////////////////////////////////////////////////////////// -#include "stdafx.h" +#include "stdafx.h" #include "SmdBone.h" @@ -14,14 +14,14 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -SmdBone::SmdBone() +SmdBone::SmdBone() { - id = -1; - parentId = -1; - name = NULL; + id = -1; + parentId = -1; + name = NULL; } SmdBone::~SmdBone() { - xr_free(name); + xr_free(name); } diff --git a/src/plugins/Maya/Export/SmdBone.h b/src/plugins/Maya/Export/SmdBone.h index ea91b2f9e75..d999c228e4b 100644 --- a/src/plugins/Maya/Export/SmdBone.h +++ b/src/plugins/Maya/Export/SmdBone.h @@ -11,24 +11,25 @@ #if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 +#endif // _MSC_VER > 1000 #include #include -class SmdBone +class SmdBone { public: - Fvector trans; - Fvector orient; + Fvector trans; + Fvector orient; + + int id; + int parentId; + LPSTR name; + MDagPath path; - int id; - int parentId; - LPSTR name; - MDagPath path; public: - SmdBone(); - virtual ~SmdBone(); + SmdBone(); + virtual ~SmdBone(); }; -#endif // !defined(AFX_SMDBONE_H__27691F7E_CEE4_422A_9FDE_7972C7C13819__INCLUDED_) +#endif // !defined(AFX_SMDBONE_H__27691F7E_CEE4_422A_9FDE_7972C7C13819__INCLUDED_) diff --git a/src/plugins/Maya/Export/SmdMaya.cpp b/src/plugins/Maya/Export/SmdMaya.cpp index 8e03f9770d3..d5f67a76d3d 100644 --- a/src/plugins/Maya/Export/SmdMaya.cpp +++ b/src/plugins/Maya/Export/SmdMaya.cpp @@ -1,25 +1,25 @@ -#include "stdafx.h" +#include "stdafx.h" #include "SmdMaya.h" -#include "editors/ECore/Editor/EditObject.h" #include "editors/ECore/Editor/EditMesh.h" -#include "xrCore/Animation/Motion.hpp" -#include "xrCore/Animation/Envelope.hpp" +#include "editors/ECore/Editor/EditObject.h" #include "smoth_flags.h" +#include "xrCore/Animation/Envelope.hpp" +#include "xrCore/Animation/Motion.hpp" -#pragma warning ( disable : 4786 ) +#pragma warning(disable : 4786) -//using namespace std; -#define NO_SMOOTHING_GROUP -1 -#define INITIALIZE_SMOOTHING -2 -#define INVALID_ID -1 +// using namespace std; +#define NO_SMOOTHING_GROUP -1 +#define INITIALIZE_SMOOTHING -2 +#define INVALID_ID -1 CXRaySkinExport::CXRaySkinExport(bool bReference) { - m_bReferenceFile = bReference; - polySmoothingGroups = 0; - edgeTable = 0; - m_rgWeights = 0; + m_bReferenceFile = bReference; + polySmoothingGroups = 0; + edgeTable = 0; + m_rgWeights = 0; }; CXRaySkinExport::~CXRaySkinExport() @@ -31,258 +31,244 @@ CXRaySkinExport::~CXRaySkinExport() ////////////////////////////////////////////////////////////// -MString CXRaySkinExport::filter()const +MString CXRaySkinExport::filter() const { - std::cerr <<"Dbg : MString CXRaySkinExport::filter()const\n"; - return m_bReferenceFile?"*.ob*":"*.skl"; + std::cerr << "Dbg : MString CXRaySkinExport::filter()const\n"; + return m_bReferenceFile ? "*.ob*" : "*.skl"; } -bool CXRaySkinExport::haveWriteMethod () const +bool CXRaySkinExport::haveWriteMethod() const { - std::cerr <<"Dbg : bool CXRaySkinExport::haveWriteMethod () const\n"; + std::cerr << "Dbg : bool CXRaySkinExport::haveWriteMethod () const\n"; return true; } /* MString CXRaySkinExport::defaultExtension () const { - std::cerr <<"Dbg : MString CXRaySkinExport::defaultExtension () const\n"; - return m_bReferenceFile?"object":"skl"; + std::cerr <<"Dbg : MString CXRaySkinExport::defaultExtension () const\n"; + return m_bReferenceFile?"object":"skl"; } */ -MPxFileTranslator::MFileKind CXRaySkinExport::identifyFile (const MFileObject& fileName, const char* buffer, short size) const +MPxFileTranslator::MFileKind CXRaySkinExport::identifyFile( + const MFileObject& fileName, const char* buffer, short size) const { - const char * name = fileName.name().asChar(); - int nameLength = xr_strlen(name); - - if (m_bReferenceFile){ - if ((nameLength > 7) && !strcasecmp(name+nameLength-7, ".object")) - return kCouldBeMyFileType; - else - return kNotMyFileType; - }else{ - if ((nameLength > 4) && !strcasecmp(name+nameLength-7, ".skl")) - return kCouldBeMyFileType; - else - return kNotMyFileType; - } + const char* name = fileName.name().asChar(); + int nameLength = xr_strlen(name); + + if (m_bReferenceFile) { + if ((nameLength > 7) && !strcasecmp(name + nameLength - 7, ".object")) + return kCouldBeMyFileType; + else + return kNotMyFileType; + } + else + { + if ((nameLength > 4) && !strcasecmp(name + nameLength - 7, ".skl")) + return kCouldBeMyFileType; + else + return kNotMyFileType; + } } void* CXRaySkinExport::creator_skin() { - return new CXRaySkinExport(true); + return new CXRaySkinExport(true); } void* CXRaySkinExport::creator_skin_motion() { - return new CXRaySkinExport(false); + return new CXRaySkinExport(false); } ////////////////////////////////////////////////////////////// // the key routine which does all the work -MStatus CXRaySkinExport::writer (const MFileObject& file, const MString& options, FileAccessMode mode) +MStatus CXRaySkinExport::writer(const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status; - clearData(); // initialize all data structures + clearData(); // initialize all data structures - bool b_ogf = false; - MString locator_name; - if (options.length() > 0) - { + bool b_ogf = false; + MString locator_name; + if (options.length() > 0) { int i, length; // Start parsing. MStringArray optionList; MStringArray theOption; - options.split(';', optionList); // break out all the options. + options.split(';', optionList); // break out all the options. - length = optionList.length(); - for( i = 0; i < length; ++i ) - { + length = optionList.length(); + for (i = 0; i < length; ++i) + { theOption.clear(); - optionList[i].split( '=', theOption ); - if( theOption[0] == MString("SkinCluster") ) - { - if (theOption.length() > 1 ) - { - m_strSkinCluster = theOption[1]; - } else { - m_strSkinCluster.clear(); - } - }else - if( theOption[0] == MString("locator") ) - { - if(theOption.length() > 1) - locator_name = theOption[1]; - else - locator_name.clear(); - }else - if( theOption[0] == MString("ogf") ) - { - if(theOption.length() > 1) - b_ogf = (theOption[1]==MString("on")); - } + optionList[i].split('=', theOption); + if (theOption[0] == MString("SkinCluster")) { + if (theOption.length() > 1) { + m_strSkinCluster = theOption[1]; + } + else + { + m_strSkinCluster.clear(); + } + } + else if (theOption[0] == MString("locator")) + { + if (theOption.length() > 1) + locator_name = theOption[1]; + else + locator_name.clear(); + } + else if (theOption[0] == MString("ogf")) + { + if (theOption.length() > 1) b_ogf = (theOption[1] == MString("on")); + } + } + } + // sanity check the options + if (m_strSkinCluster.length() == 0) { + m_fSkinCluster = false; + } + else + { + m_fSkinCluster = true; + } + MString mname; + if (m_bReferenceFile) { + mname = file.fullName() + ".object"; + } + else + { + mname = file.fullName() + ".skl"; + } + LPCSTR fname = mname.asChar(); + + // now load the bones themselves and store the skeleton hierarchy in memory + if (mode == kExportActiveAccessMode) { + MSelectionList activeList; + MGlobal::getActiveSelectionList(activeList); + MItSelectionList iter(activeList); + int count = 0; + for (; !iter.isDone(); iter.next()) + { + MObject obj; + MDagPath DagPath; + iter.getDagPath(DagPath, obj); + const char* aptTypePtr = obj.apiTypeStr(); + + DagPath.extendToShape(); + const char* fullpath = DagPath.fullPathName().asChar(); + + obj = DagPath.node(); + aptTypePtr = obj.apiTypeStr(); + //------------------------------- + MStatus stat; + MFnDagNode dagNode(DagPath); // path to the visible mesh + MFnMesh meshFn(DagPath, &stat); // this is the visible mesh + MObject inObj; + MObject dataObj1; + + // the deformed mesh comes into the visible mesh + // through its "inmesh" plug + MPlug inMeshPlug = dagNode.findPlug("inMesh", &stat); + + if (stat == MS::kSuccess && inMeshPlug.isConnected()) { + // walk the tree of stuff upstream from this plug + MItDependencyGraph dgIt(inMeshPlug, MFn::kInvalid, MItDependencyGraph::kUpstream, + MItDependencyGraph::kDepthFirst, MItDependencyGraph::kPlugLevel, &stat); + + if (MS::kSuccess == stat) { + dgIt.disablePruningOnFilter(); + int count = 0; + + for (; !dgIt.isDone(); dgIt.next()) + { + MObject thisNode = dgIt.thisNode(); + aptTypePtr = thisNode.apiTypeStr(); + + // go until we find a skinCluster + + if (thisNode.apiType() == MFn::kSkinClusterFilter) { + MFnSkinCluster skinCluster(thisNode); + const char* Name = skinCluster.name().asChar(); + Msg("Found Selected skin - %s", Name); + m_fSkinCluster = true; + m_strSkinCluster = skinCluster.name(); + + status = setUpBoneMap(&(thisNode)); + } + } + } + } + //------------------------------- + } + } + else + { + status = setUpBoneMap(NULL); + } + Msg("Starting skin export..."); + + if (m_fSkinCluster) Msg("Trying to export mesh - %s", m_strSkinCluster.asChar()); + + if (!status) { + Msg("!problem setting up bone table"); + return status; + } + + // first look through the scene for skin cluster objects. Find any bones used in these + // clusters and load and store their weights in table by vertex. + status = getBones(); + if (!status) Msg("!problem loading bone weights"); + + // now look through the scene for any geometry directly attached to bones + // this is most commonly found when creating mechanical models vs. organic models + status = parseBoneGeometry(); + if (!status) Msg("!problem loading skin information"); + + // now load the geometry information for any skin cluster objects detected earlier + if (m_skinPath.isValid()) { + status = parseShape(m_skinPath); + if (!status) { + Msg("!problem loading skin information"); + return status; } - } - - // sanity check the options - if (m_strSkinCluster.length() == 0) { - m_fSkinCluster = false; - } else { - m_fSkinCluster = true; - } - MString mname; - if (m_bReferenceFile){ - mname = file.fullName()+".object"; - }else{ - mname = file.fullName()+".skl"; - } - LPCSTR fname = mname.asChar(); - - - - // now load the bones themselves and store the skeleton hierarchy in memory - if (mode == kExportActiveAccessMode) - { - - MSelectionList activeList; - MGlobal::getActiveSelectionList(activeList); - MItSelectionList iter( activeList); - int count = 0; - for ( ; !iter.isDone(); iter.next() ) { - - MObject obj; - MDagPath DagPath; - iter.getDagPath(DagPath, obj); - const char * aptTypePtr = obj.apiTypeStr(); - - - DagPath.extendToShape(); - const char* fullpath = DagPath.fullPathName().asChar(); - - - obj = DagPath.node(); - aptTypePtr = obj.apiTypeStr(); - //------------------------------- - MStatus stat; - MFnDagNode dagNode(DagPath); // path to the visible mesh - MFnMesh meshFn(DagPath, &stat); // this is the visible mesh - MObject inObj; - MObject dataObj1; - - // the deformed mesh comes into the visible mesh - // through its "inmesh" plug - MPlug inMeshPlug = dagNode.findPlug("inMesh", &stat); - - if (stat == MS::kSuccess && inMeshPlug.isConnected()) - { - // walk the tree of stuff upstream from this plug - MItDependencyGraph dgIt(inMeshPlug, - MFn::kInvalid, - MItDependencyGraph::kUpstream, - MItDependencyGraph::kDepthFirst, - MItDependencyGraph::kPlugLevel, - &stat); - - if (MS::kSuccess == stat) - { - dgIt.disablePruningOnFilter(); - int count = 0; - - for ( ; ! dgIt.isDone(); dgIt.next() ) - { - MObject thisNode = dgIt.thisNode(); - aptTypePtr = thisNode.apiTypeStr(); - - // go until we find a skinCluster - - if (thisNode.apiType() == MFn::kSkinClusterFilter) - { - MFnSkinCluster skinCluster(thisNode); - const char* Name = skinCluster.name().asChar(); - Msg("Found Selected skin - %s", Name); - m_fSkinCluster = true; - m_strSkinCluster = skinCluster.name(); - - status = setUpBoneMap(&(thisNode)); - } - } - } - } - //------------------------------- - } - } - else - { - status = setUpBoneMap (NULL); - } - Msg("Starting skin export..."); - - if (m_fSkinCluster) - Msg("Trying to export mesh - %s",m_strSkinCluster.asChar()); - - if (!status) { - Msg("!problem setting up bone table"); - return status; - } - - // first look through the scene for skin cluster objects. Find any bones used in these - // clusters and load and store their weights in table by vertex. - status = getBones(); - if (!status) - Msg("!problem loading bone weights"); - - // now look through the scene for any geometry directly attached to bones - // this is most commonly found when creating mechanical models vs. organic models - status = parseBoneGeometry (); - if (!status) - Msg("!problem loading skin information"); - - // now load the geometry information for any skin cluster objects detected earlier - if (m_skinPath.isValid()) { - status = parseShape (m_skinPath); - if (!status) { - Msg("!problem loading skin information"); - return status; - } - } - MMatrix Mlocator = MMatrix::identity; - if(locator_name.length()) - { - MSelectionList L; - L.add (locator_name); - - MItSelectionList li (L); - for ( ; !li.isDone(); li.next() ) - { - - MObject obj_locator; - MDagPath DagPath; - li.getDagPath (DagPath, obj_locator); - - if( DagPath.hasFn(MFn::kLocator) ) - { - MFnTransform fn(DagPath.transform()); - MTransformationMatrix M = fn.transformation(); - Mlocator = M.asMatrix(); - break; - } - //. - } - } - // now create the actual SMD file - if( (mode==MPxFileTranslator::kExportAccessMode)|| - (mode==MPxFileTranslator::kSaveAccessMode)|| - (mode==MPxFileTranslator::kExportActiveAccessMode)) - status = (m_bReferenceFile) ? exportObject(fname, b_ogf) : exportMotion(fname, Mlocator); - if (MS::kSuccess==status){ - Msg("Object succesfully exported."); - }else{ - Msg("!Export failed."); - } - return status; + } + MMatrix Mlocator = MMatrix::identity; + if (locator_name.length()) { + MSelectionList L; + L.add(locator_name); + + MItSelectionList li(L); + for (; !li.isDone(); li.next()) + { + MObject obj_locator; + MDagPath DagPath; + li.getDagPath(DagPath, obj_locator); + + if (DagPath.hasFn(MFn::kLocator)) { + MFnTransform fn(DagPath.transform()); + MTransformationMatrix M = fn.transformation(); + Mlocator = M.asMatrix(); + break; + } + //. + } + } + // now create the actual SMD file + if ((mode == MPxFileTranslator::kExportAccessMode) || (mode == MPxFileTranslator::kSaveAccessMode) || + (mode == MPxFileTranslator::kExportActiveAccessMode)) + status = (m_bReferenceFile) ? exportObject(fname, b_ogf) : exportMotion(fname, Mlocator); + if (MS::kSuccess == status) { + Msg("Object succesfully exported."); + } + else + { + Msg("!Export failed."); + } + return status; } -MStatus CXRaySkinExport::reader (const MFileObject& file, const MString& options, FileAccessMode mode) +MStatus CXRaySkinExport::reader(const MFileObject& file, const MString& options, FileAccessMode mode) { Msg("!reader called in error."); return MS::kFailure; @@ -292,24 +278,27 @@ MStatus CXRaySkinExport::reader (const MFileObject& file, const MString& options CSurface* CEditableObject::CreateSurface(MObject shader) { - CSurface* S = 0; - for(SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++) - if ((*s_it)->tag==*((int*)&shader)) return *s_it; - if (!S){ - S = new CSurface(); - S->tag = *((int*)&shader); - SXRShaderData d; - MStatus status = parseShader(shader, d); - if (status == MStatus::kFailure) { - Msg ("!Unable to retrieve filename of texture"); - xr_delete (S); - return 0; - } - S->SetName (d.name.asChar()); - if (!ParseMAMaterial(S,d)){ xr_delete(S); return 0; } - m_Surfaces.push_back(S); - } - return S; + CSurface* S = 0; + for (SurfaceIt s_it = m_Surfaces.begin(); s_it != m_Surfaces.end(); s_it++) + if ((*s_it)->tag == *((int*)&shader)) return *s_it; + if (!S) { + S = new CSurface(); + S->tag = *((int*)&shader); + SXRShaderData d; + MStatus status = parseShader(shader, d); + if (status == MStatus::kFailure) { + Msg("!Unable to retrieve filename of texture"); + xr_delete(S); + return 0; + } + S->SetName(d.name.asChar()); + if (!ParseMAMaterial(S, d)) { + xr_delete(S); + return 0; + } + m_Surfaces.push_back(S); + } + return S; } //////////////////////////////////////////////////// @@ -323,314 +312,336 @@ CSurface* CEditableObject::CreateSurface(MObject shader) // dumpPose prints out the position & rotation of each bone //////////////////////////////////////////////////// -MStatus CXRaySkinExport::gotoBindPose(void) +MStatus CXRaySkinExport::gotoBindPose(void) { - MStatus status; - if (m_bReferenceFile){ - for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++){ - if ((*itBones)->parentId==-1){ - MFnTransform fnJoint = (*itBones)->path.node(&status); - if (!status) { - Msg("!Unable to cast as Transform!"); - break; - } - MString cmd = "dagPose -r -g -bp "+fnJoint.fullPathName(); - MGlobal::executeCommand(cmd, status ); - if (!status) { - Msg("!Unable goto bind pose!"); - break; - } - } - } - } - return status; + MStatus status; + if (m_bReferenceFile) { + for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++) + { + if ((*itBones)->parentId == -1) { + MFnTransform fnJoint = (*itBones)->path.node(&status); + if (!status) { + Msg("!Unable to cast as Transform!"); + break; + } + MString cmd = "dagPose -r -g -bp " + fnJoint.fullPathName(); + MGlobal::executeCommand(cmd, status); + if (!status) { + Msg("!Unable goto bind pose!"); + break; + } + } + } + } + return status; } MStatus CXRaySkinExport::exportObject(LPCSTR fn, bool b_ogf) { - MStatus status; - MGlobal::executeCommand("DisableAll"); - - R_ASSERT(m_bReferenceFile); - - - string_path fname; - strcpy (fname,fn); - if (strext(fname)) - *strext(fname)=0; - - CEditableObject* OBJECT = new CEditableObject(fname); - OBJECT->SetVersionToCurrent(TRUE,TRUE); - CEditableMesh* MESH = new CEditableMesh(OBJECT); - MESH->SetName ("skin"); - OBJECT->Meshes().push_back(MESH); - // IMPORT MESH - SurfFaces& _surf_faces = MESH->m_SurfFaces; - VMRefsVec& _vmrefs = MESH->m_VMRefs; - VMapVec& _vmaps = MESH->m_VMaps; - Fvector*& _points = MESH->m_Vertices; - // temp variables - st_Face*& _faces = MESH->m_Faces; - u32*& _sgs = MESH->m_SmoothGroups; - // maps - // Weight maps - _vmaps.resize (m_boneList.size()+1); - for (DWORD b_i=0; b_iname,vmtWeight,false); - // UV map - int VM_UV_idx = _vmaps.size()-1; - st_VMap*& VM_UV = _vmaps[VM_UV_idx]; - VM_UV = new st_VMap("texture",vmtUV,false); - // Write out the vertex table - { - MESH->m_VertCount = m_vertList.size(); - MESH->m_Vertices = xr_alloc(MESH->m_VertCount); - Fvector* pt_it = _points; - - for (SmdVertIt it=m_vertList.begin(); it!=m_vertList.end(); it++,pt_it++){ - // convert from internal units to the current ui units - MDistance dst_x ((*it)->pos.x); - MDistance dst_y ((*it)->pos.y); - MDistance dst_z ((*it)->pos.z); - pt_it->set ((float)dst_x.asMeters(),(float)dst_y.asMeters(),(float)dst_z.asMeters()); - VM_UV->appendUV ((*it)->uv.x,(*it)->uv.y); - } - } - - // faces - { - // reserve space for faces and references - MESH->m_FaceCount = m_triList.size(); - _sgs = xr_alloc(MESH->m_FaceCount); - _faces = xr_alloc(MESH->m_FaceCount); - _vmrefs.resize (m_vertList.size()); - - int f_id = 0; - CSurface* surf = 0; - for (SmdTriIt it=m_triList.begin(); it!=m_triList.end(); it++,f_id++){ - // FACES - _sgs[f_id] = ((*it)->sm_group); - - //set_smooth - //set_smoth_flags( _sgs.back(), rgint ); - - st_Face& F = _faces[f_id]; - for (int k=0; k<3; k++){ - int v_idx = (*it)->v[k]; - st_FaceVert& vt = F.pv[k]; - SmdVertex* V = m_vertList[v_idx]; - vt.pindex = v_idx; - st_VMapPtLst& vm_lst= _vmrefs[vt.pindex]; - vm_lst.count = V->influence.size()+1; - vm_lst.pts = xr_alloc(vm_lst.count); - vm_lst.pts[0].vmap_index= VM_UV_idx; - vm_lst.pts[0].index = vt.pindex; - for (WBIt vd_it=V->influence.begin(); vd_it!=V->influence.end(); vd_it++){ - u32 idx = vd_it-V->influence.begin()+1; - st_VMap* vm = _vmaps[vd_it->bone]; - vm->appendW (vd_it->weight); - vm_lst.pts[idx].vmap_index = vd_it->bone; - vm_lst.pts[idx].index = vm->size()-1; - } - vt.vmref = vt.pindex; - } - SXRShaderData D; - surf = MESH->Parent()->CreateSurface((*it)->shader); - if (!surf) return MStatus::kFailure; - _surf_faces[surf].push_back(f_id); - } - } - - // BONES - OBJECT->Bones().reserve(m_boneList.size()); - status = getBoneData(MMatrix::identity); - if (!status) - { - Msg("!error getting bind pose."); - MGlobal::executeCommand("doEnableNodeItems true all"); - return status; - } - for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); ++boneIt) - { - float length = 0.5f; - Fvector offset,rotate; - offset.set ((*boneIt)->trans); - rotate.set ((*boneIt)->orient); - OBJECT->Bones().push_back(new CBone()); - CBone* BONE = OBJECT->Bones().back(); - BONE->SetWMap ((*boneIt)->name); - BONE->SetName ((*boneIt)->name); - BONE->SetParentName ((*boneIt)->parentId>-1?m_boneList[(*boneIt)->parentId]->name:0); //. need convert space - BONE->SetRestParams (length,offset,rotate); - } - - // default bone part - OBJECT->BoneParts().push_back(SBonePart()); - SBonePart& BP = OBJECT->BoneParts().back(); - BP.alias = "default"; - - for (int b_i=0; b_i<(int)OBJECT->Bones().size(); ++b_i) - BP.bones.push_back(OBJECT->Bones()[b_i]->Name()); - - OBJECT->m_objectFlags.set(CEditableObject::eoDynamic, TRUE); - - if ((MESH->GetVertexCount()<4)||(MESH->GetFaceCount()<2)) - { - Log ("!Invalid mesh: '%s'. Faces<2 or Verts<4",*MESH->Name()); - MGlobal::executeCommand("doEnableNodeItems true all"); - return MStatus::kFailure; - } - - MESH->RecomputeBBox (); - - string_path object_name; - string_path ogf_name; - strconcat (sizeof(object_name), object_name, fname, ".object"); - strconcat (sizeof(ogf_name), ogf_name, fname, ".ogf"); - OBJECT->Optimize (); - Msg ("Exporting to Object [%s]",object_name); - OBJECT->Save (object_name); - Msg ("success."); - if(b_ogf) - { - Msg ("Exporting to OGF [%s]",ogf_name); - OBJECT->ExportOGF (ogf_name, 4); - Msg ("success."); - } - xr_delete (OBJECT); - - MGlobal::executeCommand("doEnableNodeItems true all"); - - return MStatus::kSuccess; + MStatus status; + MGlobal::executeCommand("DisableAll"); + + R_ASSERT(m_bReferenceFile); + + string_path fname; + strcpy(fname, fn); + if (strext(fname)) *strext(fname) = 0; + + CEditableObject* OBJECT = new CEditableObject(fname); + OBJECT->SetVersionToCurrent(TRUE, TRUE); + CEditableMesh* MESH = new CEditableMesh(OBJECT); + MESH->SetName("skin"); + OBJECT->Meshes().push_back(MESH); + // IMPORT MESH + SurfFaces& _surf_faces = MESH->m_SurfFaces; + VMRefsVec& _vmrefs = MESH->m_VMRefs; + VMapVec& _vmaps = MESH->m_VMaps; + Fvector*& _points = MESH->m_Vertices; + // temp variables + st_Face*& _faces = MESH->m_Faces; + u32*& _sgs = MESH->m_SmoothGroups; + // maps + // Weight maps + _vmaps.resize(m_boneList.size() + 1); + for (DWORD b_i = 0; b_i < m_boneList.size(); b_i++) + _vmaps[b_i] = new st_VMap(m_boneList[b_i]->name, vmtWeight, false); + // UV map + int VM_UV_idx = _vmaps.size() - 1; + st_VMap*& VM_UV = _vmaps[VM_UV_idx]; + VM_UV = new st_VMap("texture", vmtUV, false); + // Write out the vertex table + { + MESH->m_VertCount = m_vertList.size(); + MESH->m_Vertices = xr_alloc(MESH->m_VertCount); + Fvector* pt_it = _points; + + for (SmdVertIt it = m_vertList.begin(); it != m_vertList.end(); it++, pt_it++) + { + // convert from internal units to the current ui units + MDistance dst_x((*it)->pos.x); + MDistance dst_y((*it)->pos.y); + MDistance dst_z((*it)->pos.z); + pt_it->set((float)dst_x.asMeters(), (float)dst_y.asMeters(), (float)dst_z.asMeters()); + VM_UV->appendUV((*it)->uv.x, (*it)->uv.y); + } + } + + // faces + { + // reserve space for faces and references + MESH->m_FaceCount = m_triList.size(); + _sgs = xr_alloc(MESH->m_FaceCount); + _faces = xr_alloc(MESH->m_FaceCount); + _vmrefs.resize(m_vertList.size()); + + int f_id = 0; + CSurface* surf = 0; + for (SmdTriIt it = m_triList.begin(); it != m_triList.end(); it++, f_id++) + { + // FACES + _sgs[f_id] = ((*it)->sm_group); + + // set_smooth + // set_smoth_flags( _sgs.back(), rgint ); + + st_Face& F = _faces[f_id]; + for (int k = 0; k < 3; k++) + { + int v_idx = (*it)->v[k]; + st_FaceVert& vt = F.pv[k]; + SmdVertex* V = m_vertList[v_idx]; + vt.pindex = v_idx; + st_VMapPtLst& vm_lst = _vmrefs[vt.pindex]; + vm_lst.count = V->influence.size() + 1; + vm_lst.pts = xr_alloc(vm_lst.count); + vm_lst.pts[0].vmap_index = VM_UV_idx; + vm_lst.pts[0].index = vt.pindex; + for (WBIt vd_it = V->influence.begin(); vd_it != V->influence.end(); vd_it++) + { + u32 idx = vd_it - V->influence.begin() + 1; + st_VMap* vm = _vmaps[vd_it->bone]; + vm->appendW(vd_it->weight); + vm_lst.pts[idx].vmap_index = vd_it->bone; + vm_lst.pts[idx].index = vm->size() - 1; + } + vt.vmref = vt.pindex; + } + SXRShaderData D; + surf = MESH->Parent()->CreateSurface((*it)->shader); + if (!surf) return MStatus::kFailure; + _surf_faces[surf].push_back(f_id); + } + } + + // BONES + OBJECT->Bones().reserve(m_boneList.size()); + status = getBoneData(MMatrix::identity); + if (!status) { + Msg("!error getting bind pose."); + MGlobal::executeCommand("doEnableNodeItems true all"); + return status; + } + for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); ++boneIt) + { + float length = 0.5f; + Fvector offset, rotate; + offset.set((*boneIt)->trans); + rotate.set((*boneIt)->orient); + OBJECT->Bones().push_back(new CBone()); + CBone* BONE = OBJECT->Bones().back(); + BONE->SetWMap((*boneIt)->name); + BONE->SetName((*boneIt)->name); + BONE->SetParentName( + (*boneIt)->parentId > -1 ? m_boneList[(*boneIt)->parentId]->name : 0); //. need convert space + BONE->SetRestParams(length, offset, rotate); + } + + // default bone part + OBJECT->BoneParts().push_back(SBonePart()); + SBonePart& BP = OBJECT->BoneParts().back(); + BP.alias = "default"; + + for (int b_i = 0; b_i < (int)OBJECT->Bones().size(); ++b_i) + BP.bones.push_back(OBJECT->Bones()[b_i]->Name()); + + OBJECT->m_objectFlags.set(CEditableObject::eoDynamic, TRUE); + + if ((MESH->GetVertexCount() < 4) || (MESH->GetFaceCount() < 2)) { + Log("!Invalid mesh: '%s'. Faces<2 or Verts<4", *MESH->Name()); + MGlobal::executeCommand("doEnableNodeItems true all"); + return MStatus::kFailure; + } + + MESH->RecomputeBBox(); + + string_path object_name; + string_path ogf_name; + strconcat(sizeof(object_name), object_name, fname, ".object"); + strconcat(sizeof(ogf_name), ogf_name, fname, ".ogf"); + OBJECT->Optimize(); + Msg("Exporting to Object [%s]", object_name); + OBJECT->Save(object_name); + Msg("success."); + if (b_ogf) { + Msg("Exporting to OGF [%s]", ogf_name); + OBJECT->ExportOGF(ogf_name, 4); + Msg("success."); + } + xr_delete(OBJECT); + + MGlobal::executeCommand("doEnableNodeItems true all"); + + return MStatus::kSuccess; } MStatus CXRaySkinExport::exportMotion(LPCSTR fn, const MMatrix& locator) { - R_ASSERT(!m_bReferenceFile); - string256 nm; - strcpy(nm,fn); - if (strext(nm)) *strext(nm)=0; - - int frameFirst; - int frameLast; - MTime tmNew; - MStatus status; - - // Remember the frame the scene was at so we can restore it later. - MTime currentFrame = MAnimControl::currentTime(); - MTime startFrame = MAnimControl::minTime(); - MTime endFrame = MAnimControl::maxTime(); - - frameFirst = (int) startFrame.as( MTime::uiUnit() ); - frameLast = (int) endFrame.as( MTime::uiUnit() ); - tmNew.setUnit (MTime::uiUnit()); - - if (currentFrame.unit()!=MTime::kNTSCFrame){ - Msg("!Can't export animation with FPS!=30.f"); - return MStatus::kFailure; - } - float iFPS = 30.f; - - // build motion - CSMotion* MOT = new CSMotion(); - MOT->SetParam (frameFirst,frameLast,(float)iFPS); - MOT->SetName (nm); - - // cout << "Exporting animation frames from " << frameFirst << " to " << frameLast << "\n"; - { - BoneMotionVec& BMVec= MOT->BoneMotions(); - BMVec.reserve (m_boneList.size()); - - for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); boneIt++) - { - SmdBone* bone = *boneIt; - - BMVec.push_back (st_BoneMotion()); - st_BoneMotion& BM = BMVec.back(); - BM.SetName (bone->name); - - BM.envs[ctPositionX] = new CEnvelope(); - BM.envs[ctPositionY] = new CEnvelope(); - BM.envs[ctPositionZ] = new CEnvelope(); - BM.envs[ctRotationH] = new CEnvelope(); - BM.envs[ctRotationP] = new CEnvelope(); - BM.envs[ctRotationB] = new CEnvelope(); - - BM.envs[ctPositionX]->behavior[0]=1; BM.envs[ctPositionX]->behavior[1]=1; - BM.envs[ctPositionY]->behavior[0]=1; BM.envs[ctPositionY]->behavior[1]=1; - BM.envs[ctPositionZ]->behavior[0]=1; BM.envs[ctPositionZ]->behavior[1]=1; - BM.envs[ctRotationH]->behavior[0]=1; BM.envs[ctRotationH]->behavior[1]=1; - BM.envs[ctRotationP]->behavior[0]=1; BM.envs[ctRotationP]->behavior[1]=1; - BM.envs[ctRotationB]->behavior[0]=1; BM.envs[ctRotationB]->behavior[1]=1; - } - - for (int i=frameFirst; i<=frameLast; i++) - { - tmNew.setValue (i); - MGlobal::viewFrame( tmNew ); - - status = getBoneData(locator); - if (!status){ - Msg("!error getting bone data at frame: ",i); - continue; - } - - float displacedTime = (float)tmNew.as(MTime::kSeconds); - - st_Key *X,*Y,*Z,*H,*P,*B; - for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); boneIt++) - { - SmdBone* bone = *boneIt; - st_BoneMotion& BM = BMVec[boneIt-m_boneList.begin()]; - - X = new st_Key(); Y = new st_Key(); Z = new st_Key(); - H = new st_Key(); P = new st_Key(); B = new st_Key(); - BM.envs[ctPositionX]->keys.push_back(X); - BM.envs[ctPositionY]->keys.push_back(Y); - BM.envs[ctPositionZ]->keys.push_back(Z); - BM.envs[ctRotationH]->keys.push_back(H); - BM.envs[ctRotationP]->keys.push_back(P); - BM.envs[ctRotationB]->keys.push_back(B); - - float h,p,b, x,y,z; - x=bone->trans.x; - y=bone->trans.y; - z=bone->trans.z; - h=bone->orient.y; - p=bone->orient.x; - b=bone->orient.z; - - X->time = displacedTime; Y->time = displacedTime; Z->time = displacedTime; - H->time = displacedTime; P->time = displacedTime; B->time = displacedTime; - - X->shape = 4; Y->shape = 4; Z->shape = 4; - H->shape = 4; P->shape = 4; B->shape = 4; - X->value = x; Y->value = y; Z->value = z; - H->value = h; P->value = p; B->value = b; - } - } - strcat(nm,".skl"); - MOT->SaveMotion(nm); - xr_delete(MOT); - } - - // now restore the original frame - MGlobal::viewFrame( currentFrame ); - - return MStatus::kSuccess; + R_ASSERT(!m_bReferenceFile); + string256 nm; + strcpy(nm, fn); + if (strext(nm)) *strext(nm) = 0; + + int frameFirst; + int frameLast; + MTime tmNew; + MStatus status; + + // Remember the frame the scene was at so we can restore it later. + MTime currentFrame = MAnimControl::currentTime(); + MTime startFrame = MAnimControl::minTime(); + MTime endFrame = MAnimControl::maxTime(); + + frameFirst = (int)startFrame.as(MTime::uiUnit()); + frameLast = (int)endFrame.as(MTime::uiUnit()); + tmNew.setUnit(MTime::uiUnit()); + + if (currentFrame.unit() != MTime::kNTSCFrame) { + Msg("!Can't export animation with FPS!=30.f"); + return MStatus::kFailure; + } + float iFPS = 30.f; + + // build motion + CSMotion* MOT = new CSMotion(); + MOT->SetParam(frameFirst, frameLast, (float)iFPS); + MOT->SetName(nm); + + // cout << "Exporting animation frames from " << frameFirst << " to " << frameLast << "\n"; + { + BoneMotionVec& BMVec = MOT->BoneMotions(); + BMVec.reserve(m_boneList.size()); + + for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); boneIt++) + { + SmdBone* bone = *boneIt; + + BMVec.push_back(st_BoneMotion()); + st_BoneMotion& BM = BMVec.back(); + BM.SetName(bone->name); + + BM.envs[ctPositionX] = new CEnvelope(); + BM.envs[ctPositionY] = new CEnvelope(); + BM.envs[ctPositionZ] = new CEnvelope(); + BM.envs[ctRotationH] = new CEnvelope(); + BM.envs[ctRotationP] = new CEnvelope(); + BM.envs[ctRotationB] = new CEnvelope(); + + BM.envs[ctPositionX]->behavior[0] = 1; + BM.envs[ctPositionX]->behavior[1] = 1; + BM.envs[ctPositionY]->behavior[0] = 1; + BM.envs[ctPositionY]->behavior[1] = 1; + BM.envs[ctPositionZ]->behavior[0] = 1; + BM.envs[ctPositionZ]->behavior[1] = 1; + BM.envs[ctRotationH]->behavior[0] = 1; + BM.envs[ctRotationH]->behavior[1] = 1; + BM.envs[ctRotationP]->behavior[0] = 1; + BM.envs[ctRotationP]->behavior[1] = 1; + BM.envs[ctRotationB]->behavior[0] = 1; + BM.envs[ctRotationB]->behavior[1] = 1; + } + + for (int i = frameFirst; i <= frameLast; i++) + { + tmNew.setValue(i); + MGlobal::viewFrame(tmNew); + + status = getBoneData(locator); + if (!status) { + Msg("!error getting bone data at frame: ", i); + continue; + } + + float displacedTime = (float)tmNew.as(MTime::kSeconds); + + st_Key *X, *Y, *Z, *H, *P, *B; + for (SmdBoneIt boneIt = m_boneList.begin(); boneIt != m_boneList.end(); boneIt++) + { + SmdBone* bone = *boneIt; + st_BoneMotion& BM = BMVec[boneIt - m_boneList.begin()]; + + X = new st_Key(); + Y = new st_Key(); + Z = new st_Key(); + H = new st_Key(); + P = new st_Key(); + B = new st_Key(); + BM.envs[ctPositionX]->keys.push_back(X); + BM.envs[ctPositionY]->keys.push_back(Y); + BM.envs[ctPositionZ]->keys.push_back(Z); + BM.envs[ctRotationH]->keys.push_back(H); + BM.envs[ctRotationP]->keys.push_back(P); + BM.envs[ctRotationB]->keys.push_back(B); + + float h, p, b, x, y, z; + x = bone->trans.x; + y = bone->trans.y; + z = bone->trans.z; + h = bone->orient.y; + p = bone->orient.x; + b = bone->orient.z; + + X->time = displacedTime; + Y->time = displacedTime; + Z->time = displacedTime; + H->time = displacedTime; + P->time = displacedTime; + B->time = displacedTime; + + X->shape = 4; + Y->shape = 4; + Z->shape = 4; + H->shape = 4; + P->shape = 4; + B->shape = 4; + X->value = x; + Y->value = y; + Z->value = z; + H->value = h; + P->value = p; + B->value = b; + } + } + strcat(nm, ".skl"); + MOT->SaveMotion(nm); + xr_delete(MOT); + } + + // now restore the original frame + MGlobal::viewFrame(currentFrame); + + return MStatus::kSuccess; } int CXRaySkinExport::AppendVertex(MPoint pt, float u, float v, const WBVec& wb) { - for (SmdVertIt it=m_vertList.begin(); it!=m_vertList.end(); it++) - { - if ( (*it)->similar( pt.x, pt.y, pt.z, u, v, wb ) ) - return it-m_vertList.begin(); - } - { - m_vertList.push_back( new SmdVertex( pt, u, v, wb ) ); - return m_vertList.size()-1; - } + for (SmdVertIt it = m_vertList.begin(); it != m_vertList.end(); it++) + { + if ((*it)->similar(pt.x, pt.y, pt.z, u, v, wb)) return it - m_vertList.begin(); + } + { + m_vertList.push_back(new SmdVertex(pt, u, v, wb)); + return m_vertList.size() - 1; + } } //////////////////////////////////////////////////// @@ -649,911 +660,916 @@ int CXRaySkinExport::AppendVertex(MPoint pt, float u, float v, const WBVec& wb) // otherwise vertex influences are pulled from the mesh directly //////////////////////////////////////////////////// -MStatus CXRaySkinExport::parsePolySet(MItMeshPolygon &meshPoly, MObjectArray& rgShaders, MIntArray texMap, int presetBone = -1) +MStatus CXRaySkinExport::parsePolySet( + MItMeshPolygon& meshPoly, MObjectArray& rgShaders, MIntArray texMap, int presetBone = -1) { - SmdTriangle *tri; - MPointArray rgpt; - MIntArray rgint; - MVector pt; - float u,v; - int weight; - - MStatus status; - int cTri; -// u32 i; - - PtLookupMap ptMap; - - // cout << "Mesh has " << meshPoly.count() << " polygons\n"; - - for ( ; !meshPoly.isDone(); meshPoly.next() ) { - // Write out the smoothing group that this polygon belongs to - // We only write out the smoothing group if it is different - // from the last polygon. - // - int compIdx = meshPoly.index(); - int smoothingGroup = polySmoothingGroups[ compIdx ]; - // for each polygon, first setup the reverse mapping - // between object-relative vertex indices and face-relative - // vertex indices - ptMap.clear(); - for (int i=0; i<(int)meshPoly.polygonVertexCount(); i++) { - ptMap.insert (PtLookupMap::value_type(meshPoly.vertexIndex(i), i) ); - } - - // verify polygon zero area - if (meshPoly.zeroArea()){ - status = MS::kFailure; - Log("!polygon have zero area:",meshPoly.index()); - return status; - } - - // verify polygon zero UV area -/* if (meshPoly.zeroUVArea()){ - status = MS::kFailure; - Log("!polygon have zero UV area:",meshPoly.index()); - return status; - } -*/ - // verify polygon has UV information - if (!meshPoly.hasUVs ()) { - status = MS::kFailure; - Log("!polygon is missing UV information:",meshPoly.index()); - return status; - } - - // now iterate through each triangle on this polygon and create a triangle object in our list - status = meshPoly.numTriangles (cTri); - if (!status) { - status.perror ("error getting triangle count"); - return status; - } - - for (u32 i=0; i < u32(cTri); ++i) - { - // for each triangle, first get the triangle data - rgpt.clear(); - rgint.clear(); - - // triangles that come from a skin are retrieved in world space - // trianges that are directly attached are retrieved in object space - if (presetBone > -1) - status = meshPoly.getTriangle (i, rgpt, rgint, MSpace::kObject); - else - status = meshPoly.getTriangle (i, rgpt, rgint, MSpace::kWorld); - - if (!status) { - status.perror ("error getting triangle for mesh poly"); - return status; - } - - if ((rgpt.length() != 3) || (rgint.length() != 3)) { - Msg("!3 points not returned for triangle"); - status = MS::kFailure; - return status; - } - - tri = new SmdTriangle(); - if (tri == NULL) { - Msg("!error creating triangle"); - status = MS::kFailure; - return status; - } - - // set the bitmap filename for the triangle - int iMat = texMap[meshPoly.index()]; - if (iMat >= 0) - tri->shader = rgShaders[iMat]; - - WBVec wb; - // VERTEX #1 - wb.clear(); - pt = rgpt[2]; pt.z = -pt.z; - CalculateTriangleVertex (rgint[2], pt, u, v, wb, meshPoly, ptMap); - if (presetBone > -1) - weight = presetBone; - tri->v[0] = AppendVertex(pt, u, 1.f-v, wb); - - // VERTEX #2 - wb.clear(); - pt = rgpt[1]; pt.z = -pt.z; - CalculateTriangleVertex (rgint[1], pt, u, v, wb, meshPoly, ptMap); - if (presetBone > -1) - weight = presetBone; - tri->v[1] = AppendVertex(pt, u, 1.f-v, wb); - - // VERTEX #3 - wb.clear(); - pt = rgpt[0]; pt.z = -pt.z; - CalculateTriangleVertex (rgint[0], pt, u, v, wb, meshPoly, ptMap); - if (presetBone > -1) - weight = presetBone; - tri->v[2] = AppendVertex(pt, u, 1.f-v, wb); - - tri->sm_group = smoothingGroup; -// - //set_smooth - t_set_smoth_flags(*this, tri->sm_group, rgint ); -// - m_triList.push_back (tri); - } - } + SmdTriangle* tri; + MPointArray rgpt; + MIntArray rgint; + MVector pt; + float u, v; + int weight; + + MStatus status; + int cTri; + // u32 i; + + PtLookupMap ptMap; + + // cout << "Mesh has " << meshPoly.count() << " polygons\n"; + + for (; !meshPoly.isDone(); meshPoly.next()) + { + // Write out the smoothing group that this polygon belongs to + // We only write out the smoothing group if it is different + // from the last polygon. + // + int compIdx = meshPoly.index(); + int smoothingGroup = polySmoothingGroups[compIdx]; + // for each polygon, first setup the reverse mapping + // between object-relative vertex indices and face-relative + // vertex indices + ptMap.clear(); + for (int i = 0; i < (int)meshPoly.polygonVertexCount(); i++) + { + ptMap.insert(PtLookupMap::value_type(meshPoly.vertexIndex(i), i)); + } + + // verify polygon zero area + if (meshPoly.zeroArea()) { + status = MS::kFailure; + Log("!polygon have zero area:", meshPoly.index()); + return status; + } - return MS::kSuccess; + // verify polygon zero UV area + /* if (meshPoly.zeroUVArea()){ + status = MS::kFailure; + Log("!polygon have zero UV area:",meshPoly.index()); + return status; + } + */ + // verify polygon has UV information + if (!meshPoly.hasUVs()) { + status = MS::kFailure; + Log("!polygon is missing UV information:", meshPoly.index()); + return status; + } + + // now iterate through each triangle on this polygon and create a triangle object in our list + status = meshPoly.numTriangles(cTri); + if (!status) { + status.perror("error getting triangle count"); + return status; + } + + for (u32 i = 0; i < u32(cTri); ++i) + { + // for each triangle, first get the triangle data + rgpt.clear(); + rgint.clear(); + + // triangles that come from a skin are retrieved in world space + // trianges that are directly attached are retrieved in object space + if (presetBone > -1) + status = meshPoly.getTriangle(i, rgpt, rgint, MSpace::kObject); + else + status = meshPoly.getTriangle(i, rgpt, rgint, MSpace::kWorld); + + if (!status) { + status.perror("error getting triangle for mesh poly"); + return status; + } + + if ((rgpt.length() != 3) || (rgint.length() != 3)) { + Msg("!3 points not returned for triangle"); + status = MS::kFailure; + return status; + } + + tri = new SmdTriangle(); + if (tri == NULL) { + Msg("!error creating triangle"); + status = MS::kFailure; + return status; + } + + // set the bitmap filename for the triangle + int iMat = texMap[meshPoly.index()]; + if (iMat >= 0) tri->shader = rgShaders[iMat]; + + WBVec wb; + // VERTEX #1 + wb.clear(); + pt = rgpt[2]; + pt.z = -pt.z; + CalculateTriangleVertex(rgint[2], pt, u, v, wb, meshPoly, ptMap); + if (presetBone > -1) weight = presetBone; + tri->v[0] = AppendVertex(pt, u, 1.f - v, wb); + + // VERTEX #2 + wb.clear(); + pt = rgpt[1]; + pt.z = -pt.z; + CalculateTriangleVertex(rgint[1], pt, u, v, wb, meshPoly, ptMap); + if (presetBone > -1) weight = presetBone; + tri->v[1] = AppendVertex(pt, u, 1.f - v, wb); + + // VERTEX #3 + wb.clear(); + pt = rgpt[0]; + pt.z = -pt.z; + CalculateTriangleVertex(rgint[0], pt, u, v, wb, meshPoly, ptMap); + if (presetBone > -1) weight = presetBone; + tri->v[2] = AppendVertex(pt, u, 1.f - v, wb); + + tri->sm_group = smoothingGroup; + // + // set_smooth + t_set_smoth_flags(*this, tri->sm_group, rgint); + // + m_triList.push_back(tri); + } + } + + return MS::kSuccess; } // this function is at the heart of the polygon parsing routine // given a mesh-relative vertex index it returns all the information // needed to fill in a single vertex of the triangle -MStatus CXRaySkinExport::CalculateTriangleVertex (int vt, MVector &pt, float &u, float &v, WBVec& weights, MItMeshPolygon &meshPoly, PtLookupMap &ptMap) +MStatus CXRaySkinExport::CalculateTriangleVertex( + int vt, MVector& pt, float& u, float& v, WBVec& weights, MItMeshPolygon& meshPoly, PtLookupMap& ptMap) { - MStatus status; - int vtLocal; - int vtUV; + MStatus status; + int vtLocal; + int vtUV; - // get face-relative vertex - PtLookupMap::iterator mapIt; + // get face-relative vertex + PtLookupMap::iterator mapIt; - mapIt = ptMap.find(vt); - if (mapIt != ptMap.end()) { - vtLocal = (*mapIt).second; - } + mapIt = ptMap.find(vt); + if (mapIt != ptMap.end()) { + vtLocal = (*mapIt).second; + } -/* - status = meshPoly.getNormal (vtLocal, n, MSpace::kWorld); - if (!status) { - Msg("!error getting normal for local vertex '%d' and object vertex '%d'",vtLocal,vt); - return status; - } -*/ + /* + status = meshPoly.getNormal (vtLocal, n, MSpace::kWorld); + if (!status) { + Msg("!error getting normal for local vertex '%d' and object vertex '%d'",vtLocal,vt); + return status; + } + */ - status = meshPoly.getUVIndex (vtLocal, vtUV, u, v); - if (!status) { - Msg("!error getting UV Index for local vertex '%d' and object vertex '%d'",vtLocal,vt); - return status; - } + status = meshPoly.getUVIndex(vtLocal, vtUV, u, v); + if (!status) { + Msg("!error getting UV Index for local vertex '%d' and object vertex '%d'", vtLocal, vt); + return status; + } - weights = (*m_rgWeights)[vt]; -/* -//. - // determine which bone affects this vertex - if (!m_rgWeights.empty()) { - weight = m_rgWeights[vt]; - - // now need to look up appropriate bone for this vertex - MDagPath path = m_rgInfs[weight]; - MFnDependencyNode joint (path.node()); - char *name = (char *)joint.name().asChar(); - NameIntMap::iterator mapIt2; - mapIt2 = m_jointMap.find(name); - if (mapIt2 != m_jointMap.end()) { - weight = (*mapIt2).second; - } else { - // error - bone not found! - Msg("!can't find weight bone with index '%d' and name '%s' in joint map.",weight,name); - return MS::kFailure; - } - } else { - weight = 0; - } -*/ + weights = (*m_rgWeights)[vt]; + /* + //. + // determine which bone affects this vertex + if (!m_rgWeights.empty()) { + weight = m_rgWeights[vt]; + + // now need to look up appropriate bone for this vertex + MDagPath path = m_rgInfs[weight]; + MFnDependencyNode joint (path.node()); + char *name = (char *)joint.name().asChar(); + NameIntMap::iterator mapIt2; + mapIt2 = m_jointMap.find(name); + if (mapIt2 != m_jointMap.end()) { + weight = (*mapIt2).second; + } else { + // error - bone not found! + Msg("!can't find weight bone with index '%d' and name '%s' in joint map.",weight,name); + return MS::kFailure; + } + } else { + weight = 0; + } + */ - return MS::kSuccess; + return MS::kSuccess; } // iterate through entire scene and find all interesting objects // looks for mesh objects. for each mesh objects, locate skin clusters // for each skin cluster, find out its bones and other data MStatus CXRaySkinExport::getBones(void) -{ - size_t count = 0; - - // Iterate through graph and search for skinCluster nodes - MItDependencyNodes iter( MFn::kSkinClusterFilter ); - for ( ; !iter.isDone(); iter.next() ) { - MObject object = iter.item(); - count++; - - MFnSkinCluster skinCluster(object); - - // did the user specify a skin cluster? - if (m_fSkinCluster) { - // If so, is this not it? - if (xr_strcmp(skinCluster.name().asChar(), m_strSkinCluster.asChar())) { - continue; - } - } else { - m_strSkinCluster = skinCluster.name(); - } - - // otherwise proceed with analyzing this skinCluster - // get the list of influence objects. store all influence objects in the array "m_rgInfs" - // only used if the user decides not to export all bones - - MStatus stat; - unsigned int nInfs = skinCluster.influenceObjects(m_rgInfs, &stat); - if (!stat) { - stat.perror("Error getting influence objects"); - continue; - } - - if (0 == nInfs) { - stat = MStatus::kFailure; - stat.perror("Error: No influence objects found."); - return stat; - } - - // loop through the geometries affected by this cluster - unsigned int nGeoms = skinCluster.numOutputConnections(); - for (size_t ii = 0; ii < nGeoms; ++ii) { - unsigned int index = skinCluster.indexForOutputConnection(ii,&stat); - if (!stat) { - Msg("!Error getting geometry index."); - return stat; - } - - // get the dag path of the ii'th geometry - stat = skinCluster.getPathAtIndex(index,m_skinPath); - if (!stat) { - Msg("!Error getting geometry path."); - return stat; - } - - // iterate through the components of this geometry - MItGeometry gIter(m_skinPath); - - // print out the path name of the skin, vertexCount & influenceCount - // cout << "found skin: '" << m_skinPath.partialPathName().asChar() << "' with " << gIter.count() << " vertices " << "and " << nInfs << " influences\n"; - - // set up the array for all vertices - xr_delete(m_rgWeights); - m_rgWeights = new VWBVec(); - m_rgWeights->resize(gIter.count(&stat)); - if (!stat) { - Msg("!Error creating array of vertices"); - return stat; - } - - for (; !gIter.isDone(); gIter.next()) { - MObject comp = gIter.component(&stat); - if (!stat) { - Msg("!Error getting component."); - return stat; - } - - // Get the weights for this vertex (one per influence object) - MFloatArray wts; - unsigned int infCount; - stat = skinCluster.getWeights(m_skinPath,comp,wts,infCount); - if (!stat) { - Msg("!Error getting weights."); - return stat; - } - - if (0==infCount) { Msg("!0 influence objects."); return MStatus::kFailure; } - - // find the strongest influencer for this vertex - st_VertexWB& wb = (*m_rgWeights)[gIter.index()]; - for (u32 iInf = 0; iInf < infCount ; ++iInf ) { - if (!fis_zero(wts[iInf])){ - int bone_idx=-1; - { - int cnt = m_rgInfs.length(); - // now need to look up appropriate bone for this vertex - MDagPath path = m_rgInfs[iInf]; - MFnDependencyNode joint (path.node()); - char *name = (char *)joint.name().asChar(); - NameIntMap::iterator mapIt2; - mapIt2 = m_jointMap.find(name); - if (mapIt2 != m_jointMap.end()) { - bone_idx = (*mapIt2).second; - } else { - // error - bone not found! - Msg("!can't find weight bone with name '%s' in joint map.",name); - return MS::kFailure; - } - } - if (bone_idx!=iInf){ - Msg("!bone_idx!=iInf.[%d-%d]",bone_idx,iInf); - } - wb.push_back (st_WB(bone_idx,wts[iInf])); - } - } - wb.prepare_weights(4/*2*/); - } - } - } - - - if (0 == count) { - Msg("!No skinned meshes found in this scene. Is your mesh bound to a skeleton?"); - return MStatus::kFailure; - } else if (m_skinPath.partialPathName().length() == 0) { - Msg("!Could not find desired skin cluster '%s'",m_strSkinCluster.asChar()); - return MStatus::kFailure; - } else { - Msg("Processing skin cluster '%s'",m_strSkinCluster.asChar()); - } - return MStatus::kSuccess; +{ + size_t count = 0; + + // Iterate through graph and search for skinCluster nodes + MItDependencyNodes iter(MFn::kSkinClusterFilter); + for (; !iter.isDone(); iter.next()) + { + MObject object = iter.item(); + count++; + + MFnSkinCluster skinCluster(object); + + // did the user specify a skin cluster? + if (m_fSkinCluster) { + // If so, is this not it? + if (xr_strcmp(skinCluster.name().asChar(), m_strSkinCluster.asChar())) { + continue; + } + } + else + { + m_strSkinCluster = skinCluster.name(); + } + + // otherwise proceed with analyzing this skinCluster + // get the list of influence objects. store all influence objects in the array "m_rgInfs" + // only used if the user decides not to export all bones + + MStatus stat; + unsigned int nInfs = skinCluster.influenceObjects(m_rgInfs, &stat); + if (!stat) { + stat.perror("Error getting influence objects"); + continue; + } + + if (0 == nInfs) { + stat = MStatus::kFailure; + stat.perror("Error: No influence objects found."); + return stat; + } + + // loop through the geometries affected by this cluster + unsigned int nGeoms = skinCluster.numOutputConnections(); + for (size_t ii = 0; ii < nGeoms; ++ii) + { + unsigned int index = skinCluster.indexForOutputConnection(ii, &stat); + if (!stat) { + Msg("!Error getting geometry index."); + return stat; + } + + // get the dag path of the ii'th geometry + stat = skinCluster.getPathAtIndex(index, m_skinPath); + if (!stat) { + Msg("!Error getting geometry path."); + return stat; + } + + // iterate through the components of this geometry + MItGeometry gIter(m_skinPath); + + // print out the path name of the skin, vertexCount & influenceCount + // cout << "found skin: '" << m_skinPath.partialPathName().asChar() << "' with " << gIter.count() << " + // vertices " << "and " << nInfs << " influences\n"; + + // set up the array for all vertices + xr_delete(m_rgWeights); + m_rgWeights = new VWBVec(); + m_rgWeights->resize(gIter.count(&stat)); + if (!stat) { + Msg("!Error creating array of vertices"); + return stat; + } + + for (; !gIter.isDone(); gIter.next()) + { + MObject comp = gIter.component(&stat); + if (!stat) { + Msg("!Error getting component."); + return stat; + } + + // Get the weights for this vertex (one per influence object) + MFloatArray wts; + unsigned int infCount; + stat = skinCluster.getWeights(m_skinPath, comp, wts, infCount); + if (!stat) { + Msg("!Error getting weights."); + return stat; + } + + if (0 == infCount) { + Msg("!0 influence objects."); + return MStatus::kFailure; + } + + // find the strongest influencer for this vertex + st_VertexWB& wb = (*m_rgWeights)[gIter.index()]; + for (u32 iInf = 0; iInf < infCount; ++iInf) + { + if (!fis_zero(wts[iInf])) { + int bone_idx = -1; + { + int cnt = m_rgInfs.length(); + // now need to look up appropriate bone for this vertex + MDagPath path = m_rgInfs[iInf]; + MFnDependencyNode joint(path.node()); + char* name = (char*)joint.name().asChar(); + NameIntMap::iterator mapIt2; + mapIt2 = m_jointMap.find(name); + if (mapIt2 != m_jointMap.end()) { + bone_idx = (*mapIt2).second; + } + else + { + // error - bone not found! + Msg("!can't find weight bone with name '%s' in joint map.", name); + return MS::kFailure; + } + } + if (bone_idx != iInf) { + Msg("!bone_idx!=iInf.[%d-%d]", bone_idx, iInf); + } + wb.push_back(st_WB(bone_idx, wts[iInf])); + } + } + wb.prepare_weights(4 /*2*/); + } + } + } + + if (0 == count) { + Msg("!No skinned meshes found in this scene. Is your mesh bound to a skeleton?"); + return MStatus::kFailure; + } + else if (m_skinPath.partialPathName().length() == 0) + { + Msg("!Could not find desired skin cluster '%s'", m_strSkinCluster.asChar()); + return MStatus::kFailure; + } + else + { + Msg("Processing skin cluster '%s'", m_strSkinCluster.asChar()); + } + return MStatus::kSuccess; } // create the bone mapping that we will use to store animation data for each // frame of animation MStatus CXRaySkinExport::setUpBoneMap(MObject* pSkinObject) { - MStatus status; - int lastJointID = -1; - m_jointMap.clear(); - - if (!pSkinObject) - { - // get list of all bones that are in this file - MItDependencyNodes iter( MFn::kJoint); - for ( ; !iter.isDone(); iter.next() ) - { - MObject object = iter.item(); - MDagPath jointPath; - - MFnDagNode joint(object); - char *name = (char *)joint.name().asChar(); - - NameIntMap::iterator mapIt; - mapIt = m_jointMap.find(name); - - if (mapIt == m_jointMap.end()) - { - // this is a new bone; need to add it to the list - - SmdBone *bone = new SmdBone(); - bone->id = ++lastJointID; - bone->name = xr_strdup(joint.name().asChar()); - joint.getPath (jointPath); - bone->path = jointPath; - - // Add this joint to our joint map so we can look it up by name - m_jointMap.insert ( NameIntMap::value_type(bone->name, bone->id) ); - - // Pop one up the path stack to get our parent - jointPath.pop (1); - - MFnDagNode parentNode(jointPath, &status); - if ( !status ) - { - status.perror("MFnDagNode constructor"); - return status; - } - else - { - char *parentName = (char *)parentNode.name().asChar(); - mapIt = m_jointMap.find(parentName); - - if (mapIt != m_jointMap.end()) - bone->parentId = (*mapIt).second; - } - - m_boneList.push_back(bone); - } - } - } else - { - MFnSkinCluster skinCluster(*pSkinObject); - - MDagPathArray tmp_rgInfs; - MStatus stat; - unsigned int nInfs = skinCluster.influenceObjects(tmp_rgInfs, &stat); - if (!stat) - { - stat.perror("Error getting influence objects"); - return MStatus::kFailure; - } - // now go through only the skinned bones... - for (u32 i=0; iid = ++lastJointID; - bone->name = xr_strdup(fnJoint.name().asChar()); - bone->path = jointPath; - - // Add this joint to our joint map so we can look it up by name - // cout << "Added bone '" << bone->m_name << "' to bone map\n"; - m_jointMap.insert ( NameIntMap::value_type(bone->name, bone->id) ); - - // Pop one up the path stack to get our parent - jointPath.pop(1); - - MFnDagNode parentNode(jointPath, &status); - if ( !status ) - { - status.perror("MFnDagNode constructor"); - return status; - } - else - { - char *parentName = (char *)parentNode.name().asChar(); - NameIntMap::iterator mapIt; - mapIt = m_jointMap.find(parentName); - if (mapIt != m_jointMap.end()) { - bone->parentId = (*mapIt).second; - } - } - - m_boneList.push_back(bone); - } - } - - - return MStatus::kSuccess; + MStatus status; + int lastJointID = -1; + m_jointMap.clear(); + + if (!pSkinObject) { + // get list of all bones that are in this file + MItDependencyNodes iter(MFn::kJoint); + for (; !iter.isDone(); iter.next()) + { + MObject object = iter.item(); + MDagPath jointPath; + + MFnDagNode joint(object); + char* name = (char*)joint.name().asChar(); + + NameIntMap::iterator mapIt; + mapIt = m_jointMap.find(name); + + if (mapIt == m_jointMap.end()) { + // this is a new bone; need to add it to the list + + SmdBone* bone = new SmdBone(); + bone->id = ++lastJointID; + bone->name = xr_strdup(joint.name().asChar()); + joint.getPath(jointPath); + bone->path = jointPath; + + // Add this joint to our joint map so we can look it up by name + m_jointMap.insert(NameIntMap::value_type(bone->name, bone->id)); + + // Pop one up the path stack to get our parent + jointPath.pop(1); + + MFnDagNode parentNode(jointPath, &status); + if (!status) { + status.perror("MFnDagNode constructor"); + return status; + } + else + { + char* parentName = (char*)parentNode.name().asChar(); + mapIt = m_jointMap.find(parentName); + + if (mapIt != m_jointMap.end()) bone->parentId = (*mapIt).second; + } + + m_boneList.push_back(bone); + } + } + } + else + { + MFnSkinCluster skinCluster(*pSkinObject); + + MDagPathArray tmp_rgInfs; + MStatus stat; + unsigned int nInfs = skinCluster.influenceObjects(tmp_rgInfs, &stat); + if (!stat) { + stat.perror("Error getting influence objects"); + return MStatus::kFailure; + } + // now go through only the skinned bones... + for (u32 i = 0; i < tmp_rgInfs.length(); i++) + { + MDagPath jointPath = tmp_rgInfs[i]; + + SmdBone* bone = new SmdBone; + MFnDependencyNode fnJoint = jointPath.node(); + bone->id = ++lastJointID; + bone->name = xr_strdup(fnJoint.name().asChar()); + bone->path = jointPath; + + // Add this joint to our joint map so we can look it up by name + // cout << "Added bone '" << bone->m_name << "' to bone map\n"; + m_jointMap.insert(NameIntMap::value_type(bone->name, bone->id)); + + // Pop one up the path stack to get our parent + jointPath.pop(1); + + MFnDagNode parentNode(jointPath, &status); + if (!status) { + status.perror("MFnDagNode constructor"); + return status; + } + else + { + char* parentName = (char*)parentNode.name().asChar(); + NameIntMap::iterator mapIt; + mapIt = m_jointMap.find(parentName); + if (mapIt != m_jointMap.end()) { + bone->parentId = (*mapIt).second; + } + } + + m_boneList.push_back(bone); + } + } + + return MStatus::kSuccess; } -static IC void ParseMatrix (MTransformationMatrix& mat, Fvector& t, Fvector& r, bool bRoot) +static IC void ParseMatrix(MTransformationMatrix& mat, Fvector& t, Fvector& r, bool bRoot) { - MEulerRotation rot; - MTransformationMatrix::RotationOrder ro=MTransformationMatrix::kZXY; - mat.reorderRotation(ro); - rot = mat.eulerRotation(); + MEulerRotation rot; + MTransformationMatrix::RotationOrder ro = MTransformationMatrix::kZXY; + mat.reorderRotation(ro); + rot = mat.eulerRotation(); - r.set(-(float)rot.x,-(float)rot.y,(float)rot.z); + r.set(-(float)rot.x, -(float)rot.y, (float)rot.z); - MVector trans; - trans = mat.translation(MSpace::kTransform); + MVector trans; + trans = mat.translation(MSpace::kTransform); - MDistance dst_x(trans.x); - MDistance dst_y(trans.y); - MDistance dst_z(trans.z); + MDistance dst_x(trans.x); + MDistance dst_y(trans.y); + MDistance dst_z(trans.z); - t.set((float)dst_x.asMeters(),(float)dst_y.asMeters(),-(float)dst_z.asMeters()); + t.set((float)dst_x.asMeters(), (float)dst_y.asMeters(), -(float)dst_z.asMeters()); } IC MMatrix CalculateFullTransform(MFnTransform node) { - MStatus status; - MMatrix mat = node.transformationMatrix(&status); - int pcnt=node.parentCount(); - R_ASSERT3(pcnt<=1,"Joint has more than 1 parent: ",node.name().asChar()); - if (1==pcnt){ - MObject obj=node.parent(0); - if (obj.hasFn(MFn::kTransform)){ - mat *= CalculateFullTransform(obj); - } - } - return mat; + MStatus status; + MMatrix mat = node.transformationMatrix(&status); + int pcnt = node.parentCount(); + R_ASSERT3(pcnt <= 1, "Joint has more than 1 parent: ", node.name().asChar()); + if (1 == pcnt) { + MObject obj = node.parent(0); + if (obj.hasFn(MFn::kTransform)) { + mat *= CalculateFullTransform(obj); + } + } + return mat; } // this function goes through the list of bones for this model and updates // the bone positions and rotations for the current animation frame // note: the "m_rgInfs" array must already be set up with the DAG path to each bone -MStatus CXRaySkinExport::getBoneData (const MMatrix& locator) +MStatus CXRaySkinExport::getBoneData(const MMatrix& locator) { - MMatrix locator_i = locator.inverse(); - MStatus status; - - status = gotoBindPose(); - - if (status==MS::kSuccess) - { - for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++) - { - MFnTransform fnJoint = (*itBones)->path.node(&status); - LPCSTR nm = fnJoint.name().asChar(); - if (!status) - { - Msg("!Unable to cast as Transform!"); - return status; - } - - // get rotation/translation from the transformation matrix - MTransformationMatrix mat = fnJoint.transformationMatrix(&status); - if (!status) { - Msg("!Unable to get transformation matrix!"); - return status; - } - - if ((*itBones)->parentId==-1) - { - MMatrix FT = CalculateFullTransform(fnJoint); - MMatrix FT2; - FT2.setToProduct (FT, locator_i); - mat = FT2; - } - - ParseMatrix(mat,(*itBones)->trans,(*itBones)->orient,(*itBones)->parentId==-1); - - } - } - - return status; + MMatrix locator_i = locator.inverse(); + MStatus status; + + status = gotoBindPose(); + + if (status == MS::kSuccess) { + for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++) + { + MFnTransform fnJoint = (*itBones)->path.node(&status); + LPCSTR nm = fnJoint.name().asChar(); + if (!status) { + Msg("!Unable to cast as Transform!"); + return status; + } + + // get rotation/translation from the transformation matrix + MTransformationMatrix mat = fnJoint.transformationMatrix(&status); + if (!status) { + Msg("!Unable to get transformation matrix!"); + return status; + } + + if ((*itBones)->parentId == -1) { + MMatrix FT = CalculateFullTransform(fnJoint); + MMatrix FT2; + FT2.setToProduct(FT, locator_i); + mat = FT2; + } + + ParseMatrix(mat, (*itBones)->trans, (*itBones)->orient, (*itBones)->parentId == -1); + } + } + + return status; } // export all objects parented to bones // this is designed for mechanical objects where we simply want to parent // geometry to bones -MStatus CXRaySkinExport::parseBoneGeometry( ) +MStatus CXRaySkinExport::parseBoneGeometry() // we want to iterate through all bones // for each bone, find list of all meshes attached to it // for each mesh, export geometry // { - MStatus status; - - // goto bind pose - status = gotoBindPose(); - - if (MStatus::kSuccess==status) - { - for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++) - { - MFnDagNode fnJoint = (*itBones)->path.node(&status); - // go through children looking for geometry - for (unsigned int i=0; i < fnJoint.childCount (&status); i++) - { - MObject obj = fnJoint.child(i, &status); - if (status == MStatus::kFailure) - { - status.perror("Unable to load child for bone"); - return (MStatus::kFailure); - } - MFnDagNode fnNode (obj); - MDagPath path; - status = fnNode.getPath (path); - if (status == MStatus::kFailure) - { - status.perror ("unable to lookup path for child of bone"); - return (MStatus::kFailure); - } - - - // Have to make the path include the shape below it so that - // we can determine if the underlying shape node is instanced. - // By default, dag paths only include transform nodes. - // - status = path.extendToShape(); - if (status != MStatus::kSuccess) { - // no geometry under this node... - continue; - } - - // If the shape is instanced then we need to determine which - // instance this path refers to. - // - int instanceNum = 0; - if (path.isInstanced()) - instanceNum = path.instanceNumber(); - - MFnMesh fnMesh(path, &status); - if (status != MStatus::kSuccess) { - // this object is not a mesh - continue; - } - - // cout << "processing mesh " << fnMesh.name().asChar() << "\n"; - - // Get a list of all shaders attached to this mesh - - MObjectArray rgShaders; - MIntArray rgFaces; - status = fnMesh.getConnectedShaders (instanceNum, rgShaders, rgFaces); - if (status == MStatus::kFailure) - { - Msg("!Unable to load shaders for mesh"); - return (MStatus::kFailure); - } - - buildEdgeTable(path); - - // now iterate through all polygons and set up that data - MItMeshPolygon piter(path, MObject::kNullObj, &status); - parsePolySet(piter, rgShaders, rgFaces, (*itBones)->id); - - destroyEdgeTable(); // Free up the edge table - } - } - } - return status; -} + MStatus status; + + // goto bind pose + status = gotoBindPose(); + if (MStatus::kSuccess == status) { + for (SmdBoneIt itBones = m_boneList.begin(); itBones != m_boneList.end(); itBones++) + { + MFnDagNode fnJoint = (*itBones)->path.node(&status); + // go through children looking for geometry + for (unsigned int i = 0; i < fnJoint.childCount(&status); i++) + { + MObject obj = fnJoint.child(i, &status); + if (status == MStatus::kFailure) { + status.perror("Unable to load child for bone"); + return (MStatus::kFailure); + } + MFnDagNode fnNode(obj); + MDagPath path; + status = fnNode.getPath(path); + if (status == MStatus::kFailure) { + status.perror("unable to lookup path for child of bone"); + return (MStatus::kFailure); + } + + // Have to make the path include the shape below it so that + // we can determine if the underlying shape node is instanced. + // By default, dag paths only include transform nodes. + // + status = path.extendToShape(); + if (status != MStatus::kSuccess) { + // no geometry under this node... + continue; + } + + // If the shape is instanced then we need to determine which + // instance this path refers to. + // + int instanceNum = 0; + if (path.isInstanced()) instanceNum = path.instanceNumber(); + + MFnMesh fnMesh(path, &status); + if (status != MStatus::kSuccess) { + // this object is not a mesh + continue; + } + + // cout << "processing mesh " << fnMesh.name().asChar() << "\n"; + + // Get a list of all shaders attached to this mesh + + MObjectArray rgShaders; + MIntArray rgFaces; + status = fnMesh.getConnectedShaders(instanceNum, rgShaders, rgFaces); + if (status == MStatus::kFailure) { + Msg("!Unable to load shaders for mesh"); + return (MStatus::kFailure); + } + + buildEdgeTable(path); + + // now iterate through all polygons and set up that data + MItMeshPolygon piter(path, MObject::kNullObj, &status); + parsePolySet(piter, rgShaders, rgFaces, (*itBones)->id); + + destroyEdgeTable(); // Free up the edge table + } + } + } + return status; +} -MStatus CXRaySkinExport::parseShape( MDagPath path) +MStatus CXRaySkinExport::parseShape(MDagPath path) // // Description: // Find the texture files that apply to the color of each polygon of // a selected shape if the shape has its polygons organized into sets. // { + // cout << "processing mesh " << path.partialPathName().asChar() << "\n"; + MStatus status; - // cout << "processing mesh " << path.partialPathName().asChar() << "\n"; - MStatus status; + // Have to make the path include the shape below it so that + // we can determine if the underlying shape node is instanced. + // By default, dag paths only include transform nodes. + // + path.extendToShape(); - // Have to make the path include the shape below it so that - // we can determine if the underlying shape node is instanced. - // By default, dag paths only include transform nodes. - // - path.extendToShape(); + // If the shape is instanced then we need to determine which + // instance this path refers to. + // + int instanceNum = 0; + if (path.isInstanced()) instanceNum = path.instanceNumber(); - // If the shape is instanced then we need to determine which - // instance this path refers to. - // - int instanceNum = 0; - if (path.isInstanced()) - instanceNum = path.instanceNumber(); + MFnMesh fnMesh(path); - MFnMesh fnMesh(path); + // Get a list of all shaders attached to this mesh - // Get a list of all shaders attached to this mesh - - MObjectArray rgShaders; - MIntArray rgFaces; - status = fnMesh.getConnectedShaders (instanceNum, rgShaders, rgFaces); - if (status == MStatus::kFailure) - { - status.perror("Unable to load shaders for mesh"); - return (MStatus::kFailure); - } + MObjectArray rgShaders; + MIntArray rgFaces; + status = fnMesh.getConnectedShaders(instanceNum, rgShaders, rgFaces); + if (status == MStatus::kFailure) { + status.perror("Unable to load shaders for mesh"); + return (MStatus::kFailure); + } - buildEdgeTable(path); + buildEdgeTable(path); - // now iterate through all polygons and set up that data - MItMeshPolygon piter(path, MObject::kNullObj, &status); - parsePolySet(piter, rgShaders, rgFaces); + // now iterate through all polygons and set up that data + MItMeshPolygon piter(path, MObject::kNullObj, &status); + parsePolySet(piter, rgShaders, rgFaces); - destroyEdgeTable(); // Free up the edge table + destroyEdgeTable(); // Free up the edge table - return MStatus::kSuccess; + return MStatus::kSuccess; } // reset all data tables in between function calls void CXRaySkinExport::clearData(void) { - for (SmdTriIt t_it=m_triList.begin(); t_it!=m_triList.end(); t_it++) - { - xr_delete(*t_it); - } - - for (SmdVertIt v_it=m_vertList.begin(); v_it!=m_vertList.end(); v_it++) - { - xr_delete(*v_it); - } - - for (SmdBoneIt b_it=m_boneList.begin(); b_it!=m_boneList.end(); b_it++) - { - xr_delete(*b_it); - } - xr_delete (m_rgWeights); - xr_free (polySmoothingGroups); - - m_triList.clear (); - m_vertList.clear(); - m_jointMap.clear(); - m_boneList.clear(); - m_rgInfs.clear (); - m_strSkinCluster.clear(); + for (SmdTriIt t_it = m_triList.begin(); t_it != m_triList.end(); t_it++) + { + xr_delete(*t_it); + } + + for (SmdVertIt v_it = m_vertList.begin(); v_it != m_vertList.end(); v_it++) + { + xr_delete(*v_it); + } + + for (SmdBoneIt b_it = m_boneList.begin(); b_it != m_boneList.end(); b_it++) + { + xr_delete(*b_it); + } + xr_delete(m_rgWeights); + xr_free(polySmoothingGroups); + + m_triList.clear(); + m_vertList.clear(); + m_jointMap.clear(); + m_boneList.clear(); + m_rgInfs.clear(); + m_strSkinCluster.clear(); } -void CXRaySkinExport::CreateSMGFacegroups ( MFnMesh& fnMesh ) +void CXRaySkinExport::CreateSMGFacegroups(MFnMesh& fnMesh) { - // Now create a polyId->smoothingGroup table - // - int numPolygons = fnMesh.numPolygons(); - polySmoothingGroups = xr_alloc(numPolygons); //(int*)malloc( sizeof(int) * numPolygons ); - for ( int i=0; i< numPolygons; i++ ) { - polySmoothingGroups[i] = NO_SMOOTHING_GROUP; - } - - // Now call the smoothingAlgorithm to fill in the polySmoothingGroups - // table. - // Note: we have to traverse ALL polygons to handle the case - // of disjoint polygons. - // - nextSmoothingGroup = 1; - currSmoothingGroup = 1; - for ( int pid=0; pidsmoothingGroup table + // + int numPolygons = fnMesh.numPolygons(); + polySmoothingGroups = xr_alloc(numPolygons); //(int*)malloc( sizeof(int) * numPolygons ); + for (int i = 0; i < numPolygons; i++) + { + polySmoothingGroups[i] = NO_SMOOTHING_GROUP; + } + + // Now call the smoothingAlgorithm to fill in the polySmoothingGroups + // table. + // Note: we have to traverse ALL polygons to handle the case + // of disjoint polygons. + // + nextSmoothingGroup = 1; + currSmoothingGroup = 1; + for (int pid = 0; pid < numPolygons; pid++) + { + newSmoothingGroup = true; + // Check polygon has not already been visited + if (NO_SMOOTHING_GROUP == polySmoothingGroups[pid]) { + if (!smoothingAlgorithm(pid, fnMesh)) { + // No smooth edges for this polygon so we set + // the smoothing group to NO_SMOOTHING_GROUP (off) + polySmoothingGroups[pid] = NO_SMOOTHING_GROUP; + } + } + } } -void CXRaySkinExport::CreateSMGEdgeAttrs ( MFnMesh& fnMesh ) +void CXRaySkinExport::CreateSMGEdgeAttrs(MFnMesh& fnMesh) { - } -void CXRaySkinExport:: CreateSmoothingGroups ( MFnMesh& fnMesh ) +void CXRaySkinExport::CreateSmoothingGroups(MFnMesh& fnMesh) { - CreateSMGEdgeAttrs ( fnMesh ); - CreateSMGFacegroups ( fnMesh ); + CreateSMGEdgeAttrs(fnMesh); + CreateSMGFacegroups(fnMesh); } - //----------------------------------------------------------------------------------------------- -void CXRaySkinExport::buildEdgeTable( MDagPath& mesh ) +void CXRaySkinExport::buildEdgeTable(MDagPath& mesh) { - //. if ( !smoothing ) return; - - // Create our edge lookup table and initialize all entries to NULL - // - MFnMesh fnMesh( mesh ); - edgeTableSize = fnMesh.numVertices(); - edgeTable = xr_alloc(edgeTableSize); - ZeroMemory(edgeTable,edgeTableSize*sizeof(int)); - - // Add entries, for each edge, to the lookup table - // - MItMeshEdge eIt( mesh ); - for ( ; !eIt.isDone(); eIt.next() ) - { - bool smooth = eIt.isSmooth(); - addEdgeInfo( eIt.index(0), eIt.index(1), smooth ); - } - - // Fill in referenced polygons - // - MItMeshPolygon pIt( mesh ); - for ( ; !pIt.isDone(); pIt.next() ) - { - int pvc = pIt.polygonVertexCount(); - for ( int v=0; vpolyIds[0] ) { - elem->polyIds[0] = edgeId; - } - else { - elem->polyIds[1] = edgeId; - } - - } - } - } - - CreateSmoothingGroups ( fnMesh ); + //. if ( !smoothing ) return; + + // Create our edge lookup table and initialize all entries to NULL + // + MFnMesh fnMesh(mesh); + edgeTableSize = fnMesh.numVertices(); + edgeTable = xr_alloc(edgeTableSize); + ZeroMemory(edgeTable, edgeTableSize * sizeof(int)); + + // Add entries, for each edge, to the lookup table + // + MItMeshEdge eIt(mesh); + for (; !eIt.isDone(); eIt.next()) + { + bool smooth = eIt.isSmooth(); + addEdgeInfo(eIt.index(0), eIt.index(1), smooth); + } + + // Fill in referenced polygons + // + MItMeshPolygon pIt(mesh); + for (; !pIt.isDone(); pIt.next()) + { + int pvc = pIt.polygonVertexCount(); + for (int v = 0; v < pvc; v++) + { + int a = pIt.vertexIndex(v); + int b = pIt.vertexIndex(v == (pvc - 1) ? 0 : v + 1); + + SXREdgeInfoPtr elem = findEdgeInfo(a, b); + if (NULL != elem) { + int edgeId = pIt.index(); + + if (INVALID_ID == elem->polyIds[0]) { + elem->polyIds[0] = edgeId; + } + else + { + elem->polyIds[1] = edgeId; + } + } + } + } + + CreateSmoothingGroups(fnMesh); } -bool CXRaySkinExport::smoothingAlgorithm( int polyId, MFnMesh& fnMesh ) +bool CXRaySkinExport::smoothingAlgorithm(int polyId, MFnMesh& fnMesh) { - MIntArray vertexList; - fnMesh.getPolygonVertices( polyId, vertexList ); - int vcount = vertexList.length(); - bool smoothEdgeFound = false; - - for ( int vid=0; vidpolyIds[1] ) { // Edge not a border - - // We are starting a new smoothing group - // - if ( newSmoothingGroup ) { - currSmoothingGroup = nextSmoothingGroup++; - newSmoothingGroup = false; - - // This is a SEED (starting) polygon and so we always - // give it the new smoothing group id. - // Even if all edges are hard this must be done so - // that we know we have visited the polygon. - // - polySmoothingGroups[polyId] = currSmoothingGroup; - } - - // If we have a smooth edge then this poly must be a member - // of the current smoothing group. - // - if ( elem->smooth ) { - polySmoothingGroups[polyId] = currSmoothingGroup; - smoothEdgeFound = true; - } - else { // Hard edge so ignore this polygon - continue; - } - - // Find the adjacent poly id - // - int adjPoly = elem->polyIds[0]; - if ( adjPoly == polyId ) { - adjPoly = elem->polyIds[1]; - } - - // If we are this far then adjacent poly belongs in this - // smoothing group. - // If the adjacent polygon's smoothing group is not - // NO_SMOOTHING_GROUP then it has already been visited - // so we ignore it. - // - if ( NO_SMOOTHING_GROUP == polySmoothingGroups[adjPoly] ) { - smoothingAlgorithm( adjPoly, fnMesh ); - } - else if ( polySmoothingGroups[adjPoly] != currSmoothingGroup ) { - Msg("!smoothing group problem at polygon %d",adjPoly); - } - } - } - } - return smoothEdgeFound; + MIntArray vertexList; + fnMesh.getPolygonVertices(polyId, vertexList); + int vcount = vertexList.length(); + bool smoothEdgeFound = false; + + for (int vid = 0; vid < vcount; vid++) + { + int a = vertexList[vid]; + int b = vertexList[vid == (vcount - 1) ? 0 : vid + 1]; + + SXREdgeInfoPtr elem = findEdgeInfo(a, b); + if (NULL != elem) { + // NOTE: We assume there are at most 2 polygons per edge + // halfEdge polygons get a smoothing group of + // NO_SMOOTHING_GROUP which is equivalent to "s off" + // + if (NO_SMOOTHING_GROUP != elem->polyIds[1]) { // Edge not a border + + // We are starting a new smoothing group + // + if (newSmoothingGroup) { + currSmoothingGroup = nextSmoothingGroup++; + newSmoothingGroup = false; + + // This is a SEED (starting) polygon and so we always + // give it the new smoothing group id. + // Even if all edges are hard this must be done so + // that we know we have visited the polygon. + // + polySmoothingGroups[polyId] = currSmoothingGroup; + } + + // If we have a smooth edge then this poly must be a member + // of the current smoothing group. + // + if (elem->smooth) { + polySmoothingGroups[polyId] = currSmoothingGroup; + smoothEdgeFound = true; + } + else + { // Hard edge so ignore this polygon + continue; + } + + // Find the adjacent poly id + // + int adjPoly = elem->polyIds[0]; + if (adjPoly == polyId) { + adjPoly = elem->polyIds[1]; + } + + // If we are this far then adjacent poly belongs in this + // smoothing group. + // If the adjacent polygon's smoothing group is not + // NO_SMOOTHING_GROUP then it has already been visited + // so we ignore it. + // + if (NO_SMOOTHING_GROUP == polySmoothingGroups[adjPoly]) { + smoothingAlgorithm(adjPoly, fnMesh); + } + else if (polySmoothingGroups[adjPoly] != currSmoothingGroup) + { + Msg("!smoothing group problem at polygon %d", adjPoly); + } + } + } + } + return smoothEdgeFound; } ////////////////////////////////////////////////////////////// -void CXRaySkinExport::addEdgeInfo( int v1, int v2, bool smooth ) +void CXRaySkinExport::addEdgeInfo(int v1, int v2, bool smooth) // // Adds a new edge info element to the vertex table. // { - SXREdgeInfoPtr element = NULL; - - if ( NULL == edgeTable[v1] ) { - edgeTable[v1] = xr_alloc(1);//(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); - element = edgeTable[v1]; - } - else { - element = edgeTable[v1]; - while ( NULL != element->next ) { - element = element->next; - } - element->next = xr_alloc(1);//(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); - element = element->next; - } - - // Setup data for new edge - // - element->vertId = v2; - element->smooth = smooth; - element->next = NULL; - - // Initialize array of id's of polygons that reference this edge. - // There are at most 2 polygons per edge. - // - element->polyIds[0] = INVALID_ID; - element->polyIds[1] = INVALID_ID; + SXREdgeInfoPtr element = NULL; + + if (NULL == edgeTable[v1]) { + edgeTable[v1] = xr_alloc(1); //(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); + element = edgeTable[v1]; + } + else + { + element = edgeTable[v1]; + while (NULL != element->next) + { + element = element->next; + } + element->next = xr_alloc(1); //(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); + element = element->next; + } + + // Setup data for new edge + // + element->vertId = v2; + element->smooth = smooth; + element->next = NULL; + + // Initialize array of id's of polygons that reference this edge. + // There are at most 2 polygons per edge. + // + element->polyIds[0] = INVALID_ID; + element->polyIds[1] = INVALID_ID; } ////////////////////////////////////////////////////////////// -SXREdgeInfoPtr CXRaySkinExport::findEdgeInfo( int v1, int v2 ) +SXREdgeInfoPtr CXRaySkinExport::findEdgeInfo(int v1, int v2) // // Finds the info for the specified edge. // { - SXREdgeInfoPtr element = NULL; - element = edgeTable[v1]; - - while ( NULL != element ) { - if ( v2 == element->vertId ) { - return element; - } - element = element->next; - } - - if ( element == NULL ) { - element = edgeTable[v2]; - - while ( NULL != element ) { - if ( v1 == element->vertId ) { - return element; - } - element = element->next; - } - } - - return NULL; + SXREdgeInfoPtr element = NULL; + element = edgeTable[v1]; + + while (NULL != element) + { + if (v2 == element->vertId) { + return element; + } + element = element->next; + } + + if (element == NULL) { + element = edgeTable[v2]; + + while (NULL != element) + { + if (v1 == element->vertId) { + return element; + } + element = element->next; + } + } + + return NULL; } ////////////////////////////////////////////////////////////// @@ -1566,24 +1582,24 @@ void CXRaySkinExport::destroyEdgeTable() SXREdgeInfoPtr element = NULL; SXREdgeInfoPtr tmp = NULL; - for ( int v=0; vnext; - xr_free( tmp ); + xr_free(tmp); } } - if ( NULL != edgeTable ) { - xr_free( edgeTable ); + if (NULL != edgeTable) { + xr_free(edgeTable); edgeTable = NULL; } - - if ( NULL != polySmoothingGroups ) { - xr_free( polySmoothingGroups ); + + if (NULL != polySmoothingGroups) { + xr_free(polySmoothingGroups); polySmoothingGroups = NULL; } } diff --git a/src/plugins/Maya/Export/SmdMaya.h b/src/plugins/Maya/Export/SmdMaya.h index cc474ca83ee..463a36c3038 100644 --- a/src/plugins/Maya/Export/SmdMaya.h +++ b/src/plugins/Maya/Export/SmdMaya.h @@ -1,102 +1,103 @@ #ifndef SmdMayaH #define SmdMayaH -#include "editors/ECore/Editor/EditMesh.H" #include "ExportDefines.H" #include "SmdBone.h" #include "SmdTriangle.h" +#include "editors/ECore/Editor/EditMesh.H" // refs class CEditableObject; -struct lstr { - bool operator() (char *s1, char *s2) const - { - return (xr_strcmp(s1, s2)< 0); - } +struct lstr +{ + bool operator()(char* s1, char* s2) const { return (xr_strcmp(s1, s2) < 0); } }; -typedef xr_map NameIntMap; +typedef xr_map NameIntMap; typedef xr_map PtLookupMap; -DEFINE_VECTOR(SmdBone*, SmdBoneVec, SmdBoneIt); -DEFINE_VECTOR(SmdTriangle*, SmdTriVec, SmdTriIt); -DEFINE_VECTOR(SmdVertex*, SmdVertVec, SmdVertIt); +DEFINE_VECTOR(SmdBone*, SmdBoneVec, SmdBoneIt); +DEFINE_VECTOR(SmdTriangle*, SmdTriVec, SmdTriIt); +DEFINE_VECTOR(SmdVertex*, SmdVertVec, SmdVertIt); -class CXRaySkinExport: public MPxFileTranslator +class CXRaySkinExport : public MPxFileTranslator { public: - CXRaySkinExport (bool bReference); - virtual ~CXRaySkinExport (); - - // these functions are all used to initialize this as a Maya - // file exporter plug-in - static void* creator_skin (); - static void* creator_skin_motion (); - MStatus reader (const MFileObject& file, const MString& optionsString, FileAccessMode mode); - MStatus writer (const MFileObject& file, const MString& optionsString, FileAccessMode mode); - - bool haveWriteMethod () const ; - virtual MString filter () const; - //virtual MString defaultExtension () const; - MFileKind identifyFile (const MFileObject& fileName, const char* buffer, short size) const; + CXRaySkinExport(bool bReference); + virtual ~CXRaySkinExport(); + + // these functions are all used to initialize this as a Maya + // file exporter plug-in + static void* creator_skin(); + static void* creator_skin_motion(); + MStatus reader(const MFileObject& file, const MString& optionsString, FileAccessMode mode); + MStatus writer(const MFileObject& file, const MString& optionsString, FileAccessMode mode); + + bool haveWriteMethod() const; + virtual MString filter() const; + // virtual MString defaultExtension () const; + MFileKind identifyFile(const MFileObject& fileName, const char* buffer, short size) const; + private: - // these functions are all used to iterate across geometry, filling data structures - MStatus gotoBindPose (void); - MStatus getBones (void); // loads geometry from scene - MStatus getBoneData (const MMatrix& locator); // loads bone position per animation frame - MStatus setUpBoneMap (MObject* pSkinObject); // creates data structure to store data - void parseMesh (MObject &mesh, MDagPath path); - MStatus parseBoneGeometry (); - MStatus parseShape (MDagPath path); - MStatus parsePolySet (MItMeshPolygon &meshPoly, MObjectArray& rgShaders, MIntArray texMap, int weight); - MStatus CalculateTriangleVertex (int vt, MVector &pt, float &u, float &v, WBVec& weights, MItMeshPolygon &meshPoly, PtLookupMap &ptMap); - void clearData (void); // call inbetween function calls -// MStatus GetShaderFileName (MString &filename, MObject &set); - int AppendVertex (MPoint pt, float u, float v, const WBVec& wb); - - // Edge lookup methods - // - void buildEdgeTable (MDagPath&); - void CreateSmoothingGroups ( MFnMesh& ); - void CreateSMGFacegroups ( MFnMesh& ); - void CreateSMGEdgeAttrs ( MFnMesh& ); - void addEdgeInfo (int, int, bool); + // these functions are all used to iterate across geometry, filling data structures + MStatus gotoBindPose(void); + MStatus getBones(void); // loads geometry from scene + MStatus getBoneData(const MMatrix& locator); // loads bone position per animation frame + MStatus setUpBoneMap(MObject* pSkinObject); // creates data structure to store data + void parseMesh(MObject& mesh, MDagPath path); + MStatus parseBoneGeometry(); + MStatus parseShape(MDagPath path); + MStatus parsePolySet(MItMeshPolygon& meshPoly, MObjectArray& rgShaders, MIntArray texMap, int weight); + MStatus CalculateTriangleVertex( + int vt, MVector& pt, float& u, float& v, WBVec& weights, MItMeshPolygon& meshPoly, PtLookupMap& ptMap); + void clearData(void); // call inbetween function calls + // MStatus GetShaderFileName (MString &filename, MObject &set); + int AppendVertex(MPoint pt, float u, float v, const WBVec& wb); + + // Edge lookup methods + // + void buildEdgeTable(MDagPath&); + void CreateSmoothingGroups(MFnMesh&); + void CreateSMGFacegroups(MFnMesh&); + void CreateSMGEdgeAttrs(MFnMesh&); + void addEdgeInfo(int, int, bool); public: - SXREdgeInfoPtr findEdgeInfo (int, int); + SXREdgeInfoPtr findEdgeInfo(int, int); private: - void destroyEdgeTable (); - bool smoothingAlgorithm (int, MFnMesh&); - // Edge lookup table (by vertex id) and smoothing group info - // - SXREdgeInfoPtr* edgeTable; - int * polySmoothingGroups; - int edgeTableSize; - int nextSmoothingGroup; - int currSmoothingGroup; - bool newSmoothingGroup; - - // functions for printing out the animation data into files - MStatus exportObject (LPCSTR fname, bool b_ogf); - MStatus exportMotion (LPCSTR fname, const MMatrix& locator); - - // these are various data structures used to store scene geometry - NameIntMap m_jointMap; - SmdBoneVec m_boneList; - SmdTriVec m_triList; - SmdVertVec m_vertList; - MDagPath m_skinPath; // path to the mesh we discover - MDagPathArray m_rgInfs; // array of paths to the bones we discover - - VWBVec* m_rgWeights; // for each vertex, store index of influence joint - MString m_strFilename; // filename for file - - // options used to drive export behavior - bool m_bReferenceFile; // true for a reference file, false for an animation file - bool m_fSkinCluster; // true if we should only export the cluster named by "m_strSkinCluster" - MString m_strSkinCluster; // name of skin cluster selected by user to be exported. if empty, use first cluster in list + void destroyEdgeTable(); + bool smoothingAlgorithm(int, MFnMesh&); + // Edge lookup table (by vertex id) and smoothing group info + // + SXREdgeInfoPtr* edgeTable; + int* polySmoothingGroups; + int edgeTableSize; + int nextSmoothingGroup; + int currSmoothingGroup; + bool newSmoothingGroup; + + // functions for printing out the animation data into files + MStatus exportObject(LPCSTR fname, bool b_ogf); + MStatus exportMotion(LPCSTR fname, const MMatrix& locator); + + // these are various data structures used to store scene geometry + NameIntMap m_jointMap; + SmdBoneVec m_boneList; + SmdTriVec m_triList; + SmdVertVec m_vertList; + MDagPath m_skinPath; // path to the mesh we discover + MDagPathArray m_rgInfs; // array of paths to the bones we discover + + VWBVec* m_rgWeights; // for each vertex, store index of influence joint + MString m_strFilename; // filename for file + + // options used to drive export behavior + bool m_bReferenceFile; // true for a reference file, false for an animation file + bool m_fSkinCluster; // true if we should only export the cluster named by "m_strSkinCluster" + MString + m_strSkinCluster; // name of skin cluster selected by user to be exported. if empty, use first cluster in list }; -#endif //SmdMayaH \ No newline at end of file +#endif // SmdMayaH \ No newline at end of file diff --git a/src/plugins/Maya/Export/SmdTriangle.cpp b/src/plugins/Maya/Export/SmdTriangle.cpp index efbb4b025d0..63076a6e0ca 100644 --- a/src/plugins/Maya/Export/SmdTriangle.cpp +++ b/src/plugins/Maya/Export/SmdTriangle.cpp @@ -6,7 +6,7 @@ // ////////////////////////////////////////////////////////////////////// -#include "stdafx.h" +#include "stdafx.h" #include "SmdTriangle.h" @@ -14,29 +14,27 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// - SmdVertex::SmdVertex() { - id = -1; + id = -1; } SmdVertex::~SmdVertex() { - } SmdVertex::SmdVertex(MPoint pt, float u, float v, const WBVec& wb) { - pos.set ((float)pt.x,(float)pt.y,(float)pt.z); - uv.set (u,v); - influence = wb; - id = -1; + pos.set((float)pt.x, (float)pt.y, (float)pt.z); + uv.set(u, v); + influence = wb; + id = -1; } SmdTriangle::SmdTriangle() { - id = -1; - sm_group = -1; + id = -1; + sm_group = -1; } SmdTriangle::~SmdTriangle() diff --git a/src/plugins/Maya/Export/SmdTriangle.h b/src/plugins/Maya/Export/SmdTriangle.h index f1593fb7045..3db4197672f 100644 --- a/src/plugins/Maya/Export/SmdTriangle.h +++ b/src/plugins/Maya/Export/SmdTriangle.h @@ -15,44 +15,47 @@ class SmdVertex { public: - WBVec influence; - Fvector pos; - Fvector2 uv; - int id; + WBVec influence; + Fvector pos; + Fvector2 uv; + int id; + public: - SmdVertex (); - SmdVertex (MPoint pt, float u, float v, const WBVec& wb); - virtual ~SmdVertex (); - - void set (double x, double y, double z, float u, float v); - void set (MPoint pt, float u, float v, int ID); - - IC bool similar (double x, double y, double z, float u, float v, const WBVec& wb)const - { - if (influence.size()!=wb.size()) return false; - if (!fsimilar(pos.x,(float)x)) return false; - if (!fsimilar(pos.y,(float)y)) return false; - if (!fsimilar(pos.z,(float)z)) return false; - if (!fsimilar(uv.x,u)) return false; - if (!fsimilar(uv.y,v)) return false; - for (u32 k=0; k #define REQUIRE_IOSTREAM #define _BCL -#include -#include -#include -#include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include +#include +#include #include +#include #include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -72,22 +72,42 @@ #define ENGINE_API #define ECORE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; #pragma warning(push) -#pragma warning(disable:4995) +#pragma warning(disable : 4995) #include "plugins/Shared/ELog.h" #pragma warning(pop) #include "xrCore/Animation/Bone.hpp" #pragma warning(push) -#pragma warning(disable:4995) -# include -# include -# include +#pragma warning(disable : 4995) +#include +#include +#include #pragma warning(pop) #include @@ -96,27 +116,22 @@ typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; //#define AnsiString std::string #define AnsiString xr_string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #define THROW R_ASSERT(0) #ifdef _MAYA_EXPORT - #define _EDITOR_FILE_NAME_ "maya_export" +#define _EDITOR_FILE_NAME_ "maya_export" #else - #ifdef _MAYA_MATERIAL - #define _EDITOR_FILE_NAME_ "maya_material" - #endif +#ifdef _MAYA_MATERIAL +#define _EDITOR_FILE_NAME_ "maya_material" +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" -#pragma comment(lib,"d3dx9.lib") -#pragma comment(lib,"xrQSlim.lib") +#pragma comment(lib, "d3dx9.lib") +#pragma comment(lib, "xrQSlim.lib") #endif /*_INCDEF_STDAFX_H_*/ - - - - - diff --git a/src/plugins/Maya/Export/XRayExport.cpp b/src/plugins/Maya/Export/XRayExport.cpp index c7ccf35d0c1..4cfbad34a58 100644 --- a/src/plugins/Maya/Export/XRayExport.cpp +++ b/src/plugins/Maya/Export/XRayExport.cpp @@ -2,72 +2,70 @@ #pragma hdrstop #include "SmdMaya.h" -#include "maTranslator.h" #include "camera_exporter.h" +#include "maTranslator.h" -const char *const xrayObjectOptionScript = "xrayObjectExportOptions"; -const char *const xrayObjectDefaultOptions = 0; -const char *const xrayCameraMotionDefaultOptions = 0; +const char* const xrayObjectOptionScript = "xrayObjectExportOptions"; +const char* const xrayObjectDefaultOptions = 0; +const char* const xrayCameraMotionDefaultOptions = 0; -const char *const xraySkinOptionScript = "xraySkinExportOptions"; -const char *const xraySkinDefaultOptions = - "SkinCluster=;" - ; +const char* const xraySkinOptionScript = "xraySkinExportOptions"; +const char* const xraySkinDefaultOptions = "SkinCluster=;"; -const char *const xraySkinMotionOptionScript = "xraySkinMotionExportOptions"; -const char *const xraySkinMotionDefaultOptions = - "SkinCluster=;" -; +const char* const xraySkinMotionOptionScript = "xraySkinMotionExportOptions"; +const char* const xraySkinMotionDefaultOptions = "SkinCluster=;"; -MStatus uninitializePlugin( MObject obj ) +MStatus uninitializePlugin(MObject obj) { - MFnPlugin plugin( obj ); - MStatus status; - plugin.deregisterFileTranslator("XRay_Object_Export"); - plugin.deregisterFileTranslator("XRay_Skin_Export"); - plugin.deregisterFileTranslator("XRay_Skin_Motion_Export"); - - Core._destroy(); + MFnPlugin plugin(obj); + MStatus status; + plugin.deregisterFileTranslator("XRay_Object_Export"); + plugin.deregisterFileTranslator("XRay_Skin_Export"); + plugin.deregisterFileTranslator("XRay_Skin_Motion_Export"); + + Core._destroy(); - return status; + return status; } ////////////////////////////////////////////////////////////// -static MObject INIT_OBJ=MObject::kNullObj; +static MObject INIT_OBJ = MObject::kNullObj; void uninitialize(void*) { - if (!INIT_OBJ.isNull()){ - uninitializePlugin(INIT_OBJ); - INIT_OBJ=MObject::kNullObj; - } - Core._destroy(); + if (!INIT_OBJ.isNull()) { + uninitializePlugin(INIT_OBJ); + INIT_OBJ = MObject::kNullObj; + } + Core._destroy(); } -MStatus initializePlugin( MObject obj ) +MStatus initializePlugin(MObject obj) { - INIT_OBJ = obj; - Core._initialize("XRayMayaPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); + INIT_OBJ = obj; + Core._initialize("XRayMayaPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); - MFnPlugin plugin( obj, "GSC Game World", "1.00", "Any"); + MFnPlugin plugin(obj, "GSC Game World", "1.00", "Any"); - // add callbacks -// MSceneMessage::addCallback(MSceneMessage::kMayaExiting, uninitialize, 0); + // add callbacks + // MSceneMessage::addCallback(MSceneMessage::kMayaExiting, uninitialize, 0); - MStatus status; - // Register the translator with the system - status = plugin.registerFileTranslator("XRay_Object_Export", "none", CXRayObjectExport::creator, (char *)xrayObjectOptionScript, (char *)xrayObjectDefaultOptions ); - if (status!=MS::kSuccess) return status; - status = plugin.registerFileTranslator("XRay_Skin_Export", "none", CXRaySkinExport::creator_skin, (char *)xraySkinOptionScript, (char *)xraySkinDefaultOptions); - if (status!=MS::kSuccess) return status; - status = plugin.registerFileTranslator("XRay_Skin_Motion_Export", "none", CXRaySkinExport::creator_skin_motion, (char *)xraySkinMotionOptionScript, (char *)xraySkinMotionDefaultOptions); - if (status!=MS::kSuccess) return status; - status = plugin.registerFileTranslator("XRay_Camera_Motion_Export", "none", CXRayCameraExport::creator, (char *)xraySkinMotionOptionScript, (char *)xrayCameraMotionDefaultOptions); - if (status!=MS::kSuccess) return status; - - return status; + MStatus status; + // Register the translator with the system + status = plugin.registerFileTranslator("XRay_Object_Export", "none", CXRayObjectExport::creator, + (char*)xrayObjectOptionScript, (char*)xrayObjectDefaultOptions); + if (status != MS::kSuccess) return status; + status = plugin.registerFileTranslator("XRay_Skin_Export", "none", CXRaySkinExport::creator_skin, + (char*)xraySkinOptionScript, (char*)xraySkinDefaultOptions); + if (status != MS::kSuccess) return status; + status = plugin.registerFileTranslator("XRay_Skin_Motion_Export", "none", CXRaySkinExport::creator_skin_motion, + (char*)xraySkinMotionOptionScript, (char*)xraySkinMotionDefaultOptions); + if (status != MS::kSuccess) return status; + status = plugin.registerFileTranslator("XRay_Camera_Motion_Export", "none", CXRayCameraExport::creator, + (char*)xraySkinMotionOptionScript, (char*)xrayCameraMotionDefaultOptions); + if (status != MS::kSuccess) return status; + + return status; } ////////////////////////////////////////////////////////////// - - diff --git a/src/plugins/Maya/Export/camera_exporter.cpp b/src/plugins/Maya/Export/camera_exporter.cpp index 23bfa43c95b..142d4d4f174 100644 --- a/src/plugins/Maya/Export/camera_exporter.cpp +++ b/src/plugins/Maya/Export/camera_exporter.cpp @@ -1,23 +1,21 @@ -#include "stdafx.h" #include "camera_exporter.h" #include "editors/ECore/Editor/EditObject.h" +#include "stdafx.h" - - -bool CXRayCameraExport::haveReadMethod () const +bool CXRayCameraExport::haveReadMethod() const { return false; } -bool CXRayCameraExport::haveWriteMethod () const +bool CXRayCameraExport::haveWriteMethod() const { - std::cerr <<"Dbg : bool CXRayCameraExport::haveWriteMethod () const\n"; + std::cerr << "Dbg : bool CXRayCameraExport::haveWriteMethod () const\n"; return true; } void* CXRayCameraExport::creator() { - return new CXRayCameraExport(); + return new CXRayCameraExport(); } MStatus CXRayCameraExport::reader(const MFileObject& file, const MString& optionsString, FileAccessMode mode) @@ -31,182 +29,172 @@ MStatus CXRayCameraExport::writer(const MFileObject& file, const MString& option return ExportCamera(file); } -MString CXRayCameraExport::filter()const +MString CXRayCameraExport::filter() const { - std::cerr <<"Dbg : MString CXRayCameraExport::filter()const\n"; - return "*.anm"; + std::cerr << "Dbg : MString CXRayCameraExport::filter()const\n"; + return "*.anm"; } -MPxFileTranslator::MFileKind CXRayCameraExport::identifyFile ( - const MFileObject& fileName, - const char* buffer, - short size) const +MPxFileTranslator::MFileKind CXRayCameraExport::identifyFile( + const MFileObject& fileName, const char* buffer, short size) const { - const char * name = fileName.name().asChar(); - int nameLength = xr_strlen(name); - - if ((nameLength > 4) && !stricmp(name+nameLength-4, ".anm")) + const char* name = fileName.name().asChar(); + int nameLength = xr_strlen(name); + + if ((nameLength > 4) && !stricmp(name + nameLength - 4, ".anm")) return kCouldBeMyFileType; else return kNotMyFileType; } -static IC void ParseMatrix (MTransformationMatrix& mat, Fvector& t, Fvector& r, bool bRoot) +static IC void ParseMatrix(MTransformationMatrix& mat, Fvector& t, Fvector& r, bool bRoot) { - MEulerRotation rot; - MTransformationMatrix::RotationOrder ro=MTransformationMatrix::kZXY; - mat.reorderRotation(ro); - rot = mat.eulerRotation(); + MEulerRotation rot; + MTransformationMatrix::RotationOrder ro = MTransformationMatrix::kZXY; + mat.reorderRotation(ro); + rot = mat.eulerRotation(); - r.set(-(float)rot.x, -(float)rot.y, (float)rot.z); + r.set(-(float)rot.x, -(float)rot.y, (float)rot.z); - MVector trans; - trans = mat.translation(MSpace::kTransform); + MVector trans; + trans = mat.translation(MSpace::kTransform); - MDistance dst_x(trans.x); - MDistance dst_y(trans.y); - MDistance dst_z(trans.z); - t.set((float)dst_x.asMeters(),(float)dst_y.asMeters(),-(float)dst_z.asMeters()); + MDistance dst_x(trans.x); + MDistance dst_y(trans.y); + MDistance dst_z(trans.z); + t.set((float)dst_x.asMeters(), (float)dst_y.asMeters(), -(float)dst_z.asMeters()); - if (bRoot){ - t.set((float)dst_x.asMeters(),(float)dst_y.asMeters(),-(float)dst_z.asMeters()); - } + if (bRoot) { + t.set((float)dst_x.asMeters(), (float)dst_y.asMeters(), -(float)dst_z.asMeters()); + } } bool correction_needed(float prev_ang, float curr_ang) { - float dist = _abs(curr_ang - prev_ang); - if( _abs(dist-PI_MUL_2) < dist) - { -// Msg("needed [%f][%f]", prev_ang, curr_ang); - return true; - }else - return false; + float dist = _abs(curr_ang - prev_ang); + if (_abs(dist - PI_MUL_2) < dist) { + // Msg("needed [%f][%f]", prev_ang, curr_ang); + return true; + } + else + return false; } MStatus CXRayCameraExport::ExportCamera(const MFileObject& file) { - MDagPath node; - MObject component; - MSelectionList list; - MFnDagNode nodeFn; - MFnDagNode C; - MStatus st ; - - MGlobal::getActiveSelectionList( list ); - for ( u32 index = 0; index < list.length(); ++index ) - { - list.getDagPath ( index, node, component ); - nodeFn.setObject ( node ); - st = C.setObject (node); - if(st!=MStatus::kSuccess) - { - Msg ("Selected object is not a camera"); - return MStatus::kInvalidParameter; - } - - } - - Msg("exporting camera named [%s]", C.name().asChar()); - - MTime tmTemp,tmTemp2; - MTime tmQuant; - - // Remember the frame the scene was at so we can restore it later. - MTime storedFrame = MAnimControl::currentTime(); - MTime startFrame = MAnimControl::minTime(); - MTime endFrame = MAnimControl::maxTime(); - - tmTemp.setUnit (MTime::uiUnit()); - tmTemp2.setUnit (MTime::uiUnit()); - tmQuant.setUnit (MTime::uiUnit()); - tmQuant = 5.0; //10.0; //3 time in sec. temporary - - COMotion M; - int frms = (int)(endFrame-startFrame).as(MTime::uiUnit()); - M.SetParam (0, frms, 30); - - Fvector P,R,Rprev; - Rprev.set (0,0,0); - tmTemp = startFrame; - -// MObject cam_parent = C.parent(0); -// MFnTransform parentTransform(cam_parent); - MStatus stat; - MDagPath cam_path; - stat = C.getPath(cam_path); - stat = cam_path.extendToShape(); - - MDistance dist; - bool b_not_first = false; - u32 count = 0; - float add_ = 0.0f; - while(tmTemp <= endFrame) - { - MAnimControl::setCurrentTime (tmTemp); - MMatrix pM = cam_path.inclusiveMatrix(&stat); - MTransformationMatrix parentMatrix (pM); - - ParseMatrix (parentMatrix, P, R, true); - - R.y += add_; - - bool bpositive_y_prev = Rprev.y>0.0f; - bool bpositive_y_cur = R.y>0.0f; - if(b_not_first && correction_needed(Rprev.y, R.y)) - { - if(bpositive_y_prev && !bpositive_y_cur) - { - add_ = PI_MUL_2; - R.y += add_; - Msg("+2pi correction"); - }else - if(!bpositive_y_prev && bpositive_y_cur) - { - add_ = -PI_MUL_2; - R.y += add_; - Msg("-2pi correction"); - }else - { - float dist = (R.y - Rprev.y); - if(dist>0) - { - add_ = -PI_MUL_2; - R.y += add_; - }else - { - add_ = PI_MUL_2; - R.y += add_; - } - - } - } - - Rprev = R; - tmTemp2 = tmTemp-startFrame; - float time_ = float(tmTemp2.as(MTime::uiUnit()))/30.0f; - Msg ("%f - %f", time_, R.y); - M.CreateKey (time_, P, R); - count++; - if(tmTemp==endFrame) - break; - - tmTemp += tmQuant; - - if(tmTemp>endFrame) - tmTemp=endFrame; - - b_not_first =true; - }; - - - - MString fn_save_to = file.fullName(); - fn_save_to += ".anm"; - - Msg("file full name [%s]", fn_save_to); - M.SaveMotion (fn_save_to.asChar()); - - MAnimControl::setCurrentTime( storedFrame ); - - return MS::kSuccess; + MDagPath node; + MObject component; + MSelectionList list; + MFnDagNode nodeFn; + MFnDagNode C; + MStatus st; + + MGlobal::getActiveSelectionList(list); + for (u32 index = 0; index < list.length(); ++index) + { + list.getDagPath(index, node, component); + nodeFn.setObject(node); + st = C.setObject(node); + if (st != MStatus::kSuccess) { + Msg("Selected object is not a camera"); + return MStatus::kInvalidParameter; + } + } + + Msg("exporting camera named [%s]", C.name().asChar()); + + MTime tmTemp, tmTemp2; + MTime tmQuant; + + // Remember the frame the scene was at so we can restore it later. + MTime storedFrame = MAnimControl::currentTime(); + MTime startFrame = MAnimControl::minTime(); + MTime endFrame = MAnimControl::maxTime(); + + tmTemp.setUnit(MTime::uiUnit()); + tmTemp2.setUnit(MTime::uiUnit()); + tmQuant.setUnit(MTime::uiUnit()); + tmQuant = 5.0; // 10.0; //3 time in sec. temporary + + COMotion M; + int frms = (int)(endFrame - startFrame).as(MTime::uiUnit()); + M.SetParam(0, frms, 30); + + Fvector P, R, Rprev; + Rprev.set(0, 0, 0); + tmTemp = startFrame; + + // MObject cam_parent = C.parent(0); + // MFnTransform parentTransform(cam_parent); + MStatus stat; + MDagPath cam_path; + stat = C.getPath(cam_path); + stat = cam_path.extendToShape(); + + MDistance dist; + bool b_not_first = false; + u32 count = 0; + float add_ = 0.0f; + while (tmTemp <= endFrame) + { + MAnimControl::setCurrentTime(tmTemp); + MMatrix pM = cam_path.inclusiveMatrix(&stat); + MTransformationMatrix parentMatrix(pM); + + ParseMatrix(parentMatrix, P, R, true); + + R.y += add_; + + bool bpositive_y_prev = Rprev.y > 0.0f; + bool bpositive_y_cur = R.y > 0.0f; + if (b_not_first && correction_needed(Rprev.y, R.y)) { + if (bpositive_y_prev && !bpositive_y_cur) { + add_ = PI_MUL_2; + R.y += add_; + Msg("+2pi correction"); + } + else if (!bpositive_y_prev && bpositive_y_cur) + { + add_ = -PI_MUL_2; + R.y += add_; + Msg("-2pi correction"); + } + else + { + float dist = (R.y - Rprev.y); + if (dist > 0) { + add_ = -PI_MUL_2; + R.y += add_; + } + else + { + add_ = PI_MUL_2; + R.y += add_; + } + } + } + + Rprev = R; + tmTemp2 = tmTemp - startFrame; + float time_ = float(tmTemp2.as(MTime::uiUnit())) / 30.0f; + Msg("%f - %f", time_, R.y); + M.CreateKey(time_, P, R); + count++; + if (tmTemp == endFrame) break; + + tmTemp += tmQuant; + + if (tmTemp > endFrame) tmTemp = endFrame; + + b_not_first = true; + }; + + MString fn_save_to = file.fullName(); + fn_save_to += ".anm"; + + Msg("file full name [%s]", fn_save_to); + M.SaveMotion(fn_save_to.asChar()); + + MAnimControl::setCurrentTime(storedFrame); + + return MS::kSuccess; } diff --git a/src/plugins/Maya/Export/camera_exporter.h b/src/plugins/Maya/Export/camera_exporter.h index f56292c2a09..0c8d46ae4a0 100644 --- a/src/plugins/Maya/Export/camera_exporter.h +++ b/src/plugins/Maya/Export/camera_exporter.h @@ -1,25 +1,24 @@ #ifndef CAMERA_EXPORTER_H_INCLUDED #define CAMERA_EXPORTER_H_INCLUDED -class CXRayCameraExport: public MPxFileTranslator +class CXRayCameraExport : public MPxFileTranslator { public: - CXRayCameraExport () {}; - virtual ~CXRayCameraExport () {}; - static void* creator (); + CXRayCameraExport(){}; + virtual ~CXRayCameraExport(){}; + static void* creator(); - MStatus reader (const MFileObject& file, const MString& optionsString, FileAccessMode mode); - MStatus writer (const MFileObject& file, const MString& optionsString, FileAccessMode mode); + MStatus reader(const MFileObject& file, const MString& optionsString, FileAccessMode mode); + MStatus writer(const MFileObject& file, const MString& optionsString, FileAccessMode mode); - bool haveReadMethod () const; - bool haveWriteMethod () const; + bool haveReadMethod() const; + bool haveWriteMethod() const; - virtual MString filter () const; - MFileKind identifyFile (const MFileObject& fileName, const char* buffer, short size) const; -private: + virtual MString filter() const; + MFileKind identifyFile(const MFileObject& fileName, const char* buffer, short size) const; - MStatus ExportCamera (const MFileObject& file); - +private: + MStatus ExportCamera(const MFileObject& file); }; -#endif //CAMERA_EXPORTER_H_INCLUDED \ No newline at end of file +#endif // CAMERA_EXPORTER_H_INCLUDED \ No newline at end of file diff --git a/src/plugins/Maya/Export/maTranslator.cpp b/src/plugins/Maya/Export/maTranslator.cpp index 15c46ed8e70..a5aec60cbc6 100644 --- a/src/plugins/Maya/Export/maTranslator.cpp +++ b/src/plugins/Maya/Export/maTranslator.cpp @@ -1,149 +1,140 @@ #include "stdafx.h" #pragma hdrstop -#include "maTranslator.h" #include "editors/ECore/Editor/EditObject.h" +#include "maTranslator.h" -#define NO_SMOOTHING_GROUP -1 -#define INITIALIZE_SMOOTHING -2 -#define INVALID_ID -1 +#define NO_SMOOTHING_GROUP -1 +#define INITIALIZE_SMOOTHING -2 +#define INVALID_ID -1 ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// void* CXRayObjectExport::creator() { - return new CXRayObjectExport(); + return new CXRayObjectExport(); } ////////////////////////////////////////////////////////////// -MStatus CXRayObjectExport::reader ( const MFileObject& file, const MString& options, FileAccessMode mode) +MStatus CXRayObjectExport::reader(const MFileObject& file, const MString& options, FileAccessMode mode) { fprintf(stderr, "CXRayObjectExport::reader called in error\n"); return MS::kFailure; } ////////////////////////////////////////////////////////////// -MStatus CXRayObjectExport::writer ( const MFileObject& file, const MString& options, FileAccessMode mode ) +MStatus CXRayObjectExport::writer(const MFileObject& file, const MString& options, FileAccessMode mode) { - MStatus status= MS::kFailure; - int export_mode = 0; - if (options.length() > 0) - { + MStatus status = MS::kFailure; + int export_mode = 0; + if (options.length() > 0) { int i, length; // Start parsing. MStringArray optionList; MStringArray theOption; - options.split(';', optionList); // break out all the options. + options.split(';', optionList); // break out all the options. - length = optionList.length(); - for( i = 0; i < length; ++i ) - { + length = optionList.length(); + for (i = 0; i < length; ++i) + { theOption.clear(); - optionList[i].split( '=', theOption ); + optionList[i].split('=', theOption); + + if (theOption[0] == MString("ogf")) { + if (theOption.length() > 1) export_mode = theOption[1].asInt(); + } + } + } + Log("export_mode: ", export_mode); + + // move default extesion here.. + MString mname = file.fullName() + ".object"; + LPCSTR fname = mname.asChar(); + + Log("Export object: ", fname); + CEditableObject* OBJECT = new CEditableObject(fname); + OBJECT->SetVersionToCurrent(TRUE, TRUE); + + if ((mode == MPxFileTranslator::kExportAccessMode) || (mode == MPxFileTranslator::kSaveAccessMode)) { + status = ExportAll(OBJECT) ? MS::kSuccess : MS::kFailure; + } + else if (mode == MPxFileTranslator::kExportActiveAccessMode) + { + status = ExportSelected(OBJECT) ? MS::kSuccess : MS::kFailure; + } + if (MS::kSuccess == status) { + OBJECT->Optimize(); + OBJECT->Save(fname); + + Log("Object succesfully exported."); + Msg("%d vertices, %d faces", OBJECT->GetVertexCount(), OBJECT->GetFaceCount(true, false)); + if (export_mode) { + mname = file.fullName() + ".ogf"; + Log("Export OGF object: ", fname); + fname = mname.asChar(); + + OBJECT->m_objectFlags.set(CEditableObject::eoProgressive, (export_mode == 1)); - if( theOption[0] == MString("ogf") ) - { - if(theOption.length() > 1) - export_mode = theOption[1].asInt(); - } + OBJECT->ExportOGF(fname, 4); + Log("OGF object succesfully exported."); } - } - Log ("export_mode: ",export_mode); - - - //move default extesion here.. - MString mname = file.fullName()+".object"; - LPCSTR fname = mname.asChar(); - - Log ("Export object: ",fname); - CEditableObject* OBJECT = new CEditableObject(fname); - OBJECT->SetVersionToCurrent (TRUE,TRUE); - - if((mode==MPxFileTranslator::kExportAccessMode)||(mode==MPxFileTranslator::kSaveAccessMode)) - { - status = ExportAll(OBJECT)?MS::kSuccess:MS::kFailure; - }else - if(mode==MPxFileTranslator::kExportActiveAccessMode) - { - status = ExportSelected(OBJECT)?MS::kSuccess:MS::kFailure; - } - if (MS::kSuccess==status) - { - OBJECT->Optimize (); - OBJECT->Save (fname); - - Log ("Object succesfully exported."); - Msg ("%d vertices, %d faces", OBJECT->GetVertexCount(), OBJECT->GetFaceCount(true, false)); - if(export_mode) - { - mname = file.fullName()+".ogf"; - Log ("Export OGF object: ",fname); - fname = mname.asChar(); - - OBJECT->m_objectFlags.set(CEditableObject::eoProgressive, (export_mode==1) ); - - - OBJECT->ExportOGF (fname, 4); - Log ("OGF object succesfully exported."); - } - }else - { - Log("!Export failed."); - } - xr_delete(OBJECT); - - return status; + } + else + { + Log("!Export failed."); + } + xr_delete(OBJECT); + + return status; } ////////////////////////////////////////////////////////////// -MString CXRayObjectExport::filter()const +MString CXRayObjectExport::filter() const { - std::cerr <<"Dbg : MString CXRayObjectExport::filter()const\n"; - return "*.ob*"; + std::cerr << "Dbg : MString CXRayObjectExport::filter()const\n"; + return "*.ob*"; } ////////////////////////////////////////////////////////////// -bool CXRayObjectExport::haveReadMethod () const +bool CXRayObjectExport::haveReadMethod() const { return false; } ////////////////////////////////////////////////////////////// -bool CXRayObjectExport::haveWriteMethod () const +bool CXRayObjectExport::haveWriteMethod() const { - std::cerr <<"Dbg : bool CXRayObjectExport::haveWriteMethod () const\n"; + std::cerr << "Dbg : bool CXRayObjectExport::haveWriteMethod () const\n"; return true; } ////////////////////////////////////////////////////////////// /* MString CXRayObjectExport::defaultExtension () const { - std::cerr <<"Dbg : MString CXRayObjectExport::defaultExtension () const\n"; - return "object"; + std::cerr <<"Dbg : MString CXRayObjectExport::defaultExtension () const\n"; + return "object"; } */ ////////////////////////////////////////////////////////////// -MPxFileTranslator::MFileKind CXRayObjectExport::identifyFile ( - const MFileObject& fileName, - const char* buffer, - short size) const +MPxFileTranslator::MFileKind CXRayObjectExport::identifyFile( + const MFileObject& fileName, const char* buffer, short size) const { - const char * name = fileName.name().asChar(); - int nameLength = xr_strlen(name); - - //if ((nameLength > 7) && !stricmp(name+nameLength-7, ".object")) - if ((nameLength > 4) && !stricmp(name+nameLength-4, ".xro")) + const char* name = fileName.name().asChar(); + int nameLength = xr_strlen(name); + + // if ((nameLength > 7) && !stricmp(name+nameLength-7, ".object")) + if ((nameLength > 4) && !stricmp(name + nameLength - 4, ".xro")) return kCouldBeMyFileType; else return kNotMyFileType; } ////////////////////////////////////////////////////////////// -bool CXRayObjectExport::initializeSetsAndLookupTables( bool exportAll ) +bool CXRayObjectExport::initializeSetsAndLookupTables(bool exportAll) // // Description : // Creates a list of all sets in Maya, a list of mesh objects, @@ -151,431 +142,431 @@ bool CXRayObjectExport::initializeSetsAndLookupTables( bool exportAll ) // determine which sets are referenced by the poly components. // { - int i=0,j=0, length; - MStatus stat; - - // Initialize class data. - // Note: we cannot do this in the constructor as it - // only gets called upon registry of the plug-in. - // - numSets = 0; - sets = NULL; - lastSets = NULL; - lastMaterials = NULL; - objectId = 0; - objectCount = 0; - polygonTable = NULL; - vertexTable = NULL; - polygonTablePtr = NULL; - vertexTablePtr = NULL; - objectGroupsTablePtr = NULL; - objectNodeNamesArray.clear(); - transformNodeNameArray.clear(); - - ////////////////////////////////////////////////////////////////// - // - // Find all sets in Maya and store the ones we care about in - // the 'sets' array. Also make note of the number of sets. - // - ////////////////////////////////////////////////////////////////// - - // Get all of the sets in maya and put them into - // a selection list - // - MStringArray result; - MGlobal::executeCommand( "ls -sets", result ); - MSelectionList * setList = new MSelectionList(); - length = result.length(); - for ( i=0; iadd( result[i] ); - } - - // Extract each set as an MObject and add them to the - // sets array. - // We may be excluding groups, matierials, or ptGroups - // in which case we can ignore those sets. - // - MObject mset; - sets = new MObjectArray(); - length = setList->length(); - for ( i=0; igetDependNode( i, mset ); - - MFnSet fnSet( mset, &stat ); - if ( stat ) { - if ( MFnSet::kRenderableOnly == fnSet.restriction(&stat) ) { - sets->append( mset ); - } - } - } - xr_delete(setList); - - numSets = sets->length(); - - ////////////////////////////////////////////////////////////////// - // - // Do a dag-iteration and for every mesh found, create facet and - // vertex look-up tables. These tables will keep track of which - // sets each component belongs to. - // - // If exportAll is false then iterate over the activeSelection - // list instead of the entire DAG. - // - // These arrays have a corrisponding entry in the name - // stringArray. - // - ////////////////////////////////////////////////////////////////// - MIntArray vertexCounts; - MIntArray polygonCounts; - - if ( exportAll ) { - MItDag dagIterator( MItDag::kBreadthFirst, MFn::kInvalid, &stat); - - if ( MS::kSuccess != stat) { - fprintf(stderr,"Failure in DAG iterator setup.\n"); - return false; - } - - objectNames = new MStringArray(); - - for ( ; !dagIterator.isDone(); dagIterator.next() ) - { - MDagPath dagPath; - stat = dagIterator.getPath( dagPath ); - - if ( stat ) - { - // skip over intermediate objects - // - MFnDagNode dagNode( dagPath, &stat ); - if (dagNode.isIntermediateObject()) - { - continue; - } - - if (( dagPath.hasFn(MFn::kMesh)) && - ( dagPath.hasFn(MFn::kTransform))) - { - // We want only the shape, - // not the transform-extended-to-shape. - continue; - } - else if ( dagPath.hasFn(MFn::kMesh)) - { - // We have a mesh so create a vertex and polygon table - // for this object. - // - MFnMesh fnMesh( dagPath ); - int vtxCount = fnMesh.numVertices(); - int polygonCount = fnMesh.numPolygons(); - // we do not need this call anymore, we have the shape. - // dagPath.extendToShape(); - MString name = dagPath.fullPathName(); - objectNames->append( name ); - objectNodeNamesArray.append( fnMesh.name() ); - - vertexCounts.append( vtxCount ); - polygonCounts.append( polygonCount ); - - objectCount++; - } - } - } - }else{ - MSelectionList slist; - MGlobal::getActiveSelectionList( slist ); - MItSelectionList iter( slist ); - MStatus status; - - objectNames = new MStringArray(); - - // We will need to interate over a selected node's heirarchy - // in the case where shapes are grouped, and the group is selected. - MItDag dagIterator( MItDag::kDepthFirst, MFn::kInvalid, &status); - - for ( ; !iter.isDone(); iter.next() ){ - MDagPath objectPath; - stat = iter.getDagPath( objectPath ); - - // reset iterator's root node to be the selected node. - status = dagIterator.reset (objectPath.node(), - MItDag::kDepthFirst, MFn::kInvalid ); - - // DAG iteration beginning at at selected node - for ( ; !dagIterator.isDone(); dagIterator.next() ){ - MDagPath dagPath; - MObject component = MObject::kNullObj; - status = dagIterator.getPath(dagPath); - - if (!status){ - fprintf(stderr,"Failure getting DAG path.\n"); - freeLookupTables(); - return false; - } + int i = 0, j = 0, length; + MStatus stat; + + // Initialize class data. + // Note: we cannot do this in the constructor as it + // only gets called upon registry of the plug-in. + // + numSets = 0; + sets = NULL; + lastSets = NULL; + lastMaterials = NULL; + objectId = 0; + objectCount = 0; + polygonTable = NULL; + vertexTable = NULL; + polygonTablePtr = NULL; + vertexTablePtr = NULL; + objectGroupsTablePtr = NULL; + objectNodeNamesArray.clear(); + transformNodeNameArray.clear(); + + ////////////////////////////////////////////////////////////////// + // + // Find all sets in Maya and store the ones we care about in + // the 'sets' array. Also make note of the number of sets. + // + ////////////////////////////////////////////////////////////////// + + // Get all of the sets in maya and put them into + // a selection list + // + MStringArray result; + MGlobal::executeCommand("ls -sets", result); + MSelectionList* setList = new MSelectionList(); + length = result.length(); + for (i = 0; i < length; i++) + { + setList->add(result[i]); + } + + // Extract each set as an MObject and add them to the + // sets array. + // We may be excluding groups, matierials, or ptGroups + // in which case we can ignore those sets. + // + MObject mset; + sets = new MObjectArray(); + length = setList->length(); + for (i = 0; i < length; i++) + { + setList->getDependNode(i, mset); + + MFnSet fnSet(mset, &stat); + if (stat) { + if (MFnSet::kRenderableOnly == fnSet.restriction(&stat)) { + sets->append(mset); + } + } + } + xr_delete(setList); + + numSets = sets->length(); + + ////////////////////////////////////////////////////////////////// + // + // Do a dag-iteration and for every mesh found, create facet and + // vertex look-up tables. These tables will keep track of which + // sets each component belongs to. + // + // If exportAll is false then iterate over the activeSelection + // list instead of the entire DAG. + // + // These arrays have a corrisponding entry in the name + // stringArray. + // + ////////////////////////////////////////////////////////////////// + MIntArray vertexCounts; + MIntArray polygonCounts; + + if (exportAll) { + MItDag dagIterator(MItDag::kBreadthFirst, MFn::kInvalid, &stat); + + if (MS::kSuccess != stat) { + fprintf(stderr, "Failure in DAG iterator setup.\n"); + return false; + } + + objectNames = new MStringArray(); + + for (; !dagIterator.isDone(); dagIterator.next()) + { + MDagPath dagPath; + stat = dagIterator.getPath(dagPath); + if (stat) { // skip over intermediate objects // - MFnDagNode dagNode( dagPath, &stat ); + MFnDagNode dagNode(dagPath, &stat); + if (dagNode.isIntermediateObject()) { + continue; + } + + if ((dagPath.hasFn(MFn::kMesh)) && (dagPath.hasFn(MFn::kTransform))) { + // We want only the shape, + // not the transform-extended-to-shape. + continue; + } + else if (dagPath.hasFn(MFn::kMesh)) + { + // We have a mesh so create a vertex and polygon table + // for this object. + // + MFnMesh fnMesh(dagPath); + int vtxCount = fnMesh.numVertices(); + int polygonCount = fnMesh.numPolygons(); + // we do not need this call anymore, we have the shape. + // dagPath.extendToShape(); + MString name = dagPath.fullPathName(); + objectNames->append(name); + objectNodeNamesArray.append(fnMesh.name()); + + vertexCounts.append(vtxCount); + polygonCounts.append(polygonCount); + + objectCount++; + } + } + } + } + else + { + MSelectionList slist; + MGlobal::getActiveSelectionList(slist); + MItSelectionList iter(slist); + MStatus status; + + objectNames = new MStringArray(); + + // We will need to interate over a selected node's heirarchy + // in the case where shapes are grouped, and the group is selected. + MItDag dagIterator(MItDag::kDepthFirst, MFn::kInvalid, &status); + + for (; !iter.isDone(); iter.next()) + { + MDagPath objectPath; + stat = iter.getDagPath(objectPath); + + // reset iterator's root node to be the selected node. + status = dagIterator.reset(objectPath.node(), MItDag::kDepthFirst, MFn::kInvalid); + + // DAG iteration beginning at at selected node + for (; !dagIterator.isDone(); dagIterator.next()) + { + MDagPath dagPath; + MObject component = MObject::kNullObj; + status = dagIterator.getPath(dagPath); + + if (!status) { + fprintf(stderr, "Failure getting DAG path.\n"); + freeLookupTables(); + return false; + } + + // skip over intermediate objects + // + MFnDagNode dagNode(dagPath, &stat); if (dagNode.isIntermediateObject()) continue; - if (( dagPath.hasFn(MFn::kMesh)) && ( dagPath.hasFn(MFn::kTransform))){ - // We want only the shape, - // not the transform-extended-to-shape. - continue; - }else if ( dagPath.hasFn(MFn::kMesh)){ - // We have a mesh so create a vertex and polygon table - // for this object. - // - MFnMesh fnMesh( dagPath ); - int vtxCount = fnMesh.numVertices(); - int polygonCount = fnMesh.numPolygons(); - - // we do not need this call anymore, we have the shape. - // dagPath.extendToShape(); - MString name = dagPath.fullPathName(); - objectNames->append( name ); - objectNodeNamesArray.append( fnMesh.name() ); - - vertexCounts.append( vtxCount ); - polygonCounts.append( polygonCount ); - - objectCount++; - } - } - } - } - - // Now we know how many objects we are dealing with - // and we have counts of the vertices/polygons for each - // object so create the maya group look-up table. - // - if( objectCount > 0 ) { - // To export Maya groups we traverse the hierarchy starting at - // each objectNodeNamesArray[i] going towards the root collecting transform - // nodes as we go. - length = objectNodeNamesArray.length(); - for( i=0; i 0 ) { - objectGroupsTablePtr = xr_alloc(objectCount);// (bool**) malloc( sizeof(bool*)*objectCount ); - length = transformNodeNameArray.length(); - for ( i=0; i(length); - ZeroMemory(objectGroupsTablePtr[i],length*sizeof(bool)); - - if ( objectGroupsTablePtr[i] == NULL ) { - Log("!calloc returned NULL (objectGroupsTablePtr)"); - return false; - } - } - } -// else{ -// Log("!Can't find transform for node."); -// return false; -// } - } - - // Create the vertex/polygon look-up tables. - // - if ( objectCount > 0 ) { - - vertexTablePtr = xr_alloc(objectCount); //(bool**) malloc( sizeof(bool*)*objectCount ); - polygonTablePtr = xr_alloc(objectCount); //(bool**) malloc( sizeof(bool*)*objectCount ); - - for ( i=0; i(vertexCounts[i]*numSets); - ZeroMemory(vertexTablePtr[i],vertexCounts[i]*numSets*sizeof(bool)); - - if ( vertexTablePtr[i] == NULL ) { - Log("!calloc returned NULL (vertexTable)"); - return false; - } - -// polygonTablePtr[i] = (bool*)calloc( polygonCounts[i]*numSets, sizeof(bool) ); - polygonTablePtr[i] = xr_alloc(polygonCounts[i]*numSets); - ZeroMemory(polygonTablePtr[i],polygonCounts[i]*numSets*sizeof(bool)); - if ( polygonTablePtr[i] == NULL ) { - Log("!calloc returned NULL (polygonTable)"); - return false; - } - } - } - - // If we found no meshes then return - // - if ( objectCount == 0 ) { - return false; - } - - ////////////////////////////////////////////////////////////////// - // - // Go through all of the set members (flattened lists) and mark - // in the lookup-tables, the sets that each mesh component belongs - // to. - // - // - ////////////////////////////////////////////////////////////////// - bool flattenedList = true; - MDagPath object; - MObject component; - MSelectionList memberList; - - - for ( i=0; ilength(); - for ( o=0; olength(); - for ( o=0; o= polygonCounts[o] ) { - Msg("!Bad polygon index '%d' found. Polygon skipped",compIdx); - break; - } - - polygonTable = polygonTablePtr[o]; - *(polygonTable + numSets*compIdx + i) = true; - break; - } - } - } - } - } - else { - - // There are no components, therefore we can mark - // all polygons as members of the given set. - // - - if (object.hasFn(MFn::kMesh)) { - - MFnMesh fnMesh( object, &stat ); - if ( MS::kSuccess != stat) { - fprintf(stderr,"Failure in MFnMesh initialization.\n"); - return false; - } - - // We are going to iterate over all the polygons. - // - MItMeshPolygon piter( object, MObject::kNullObj, &stat ); - if ( MS::kSuccess != stat) { - fprintf(stderr, - "Failure in MItMeshPolygon initialization.\n"); - return false; - } - for ( ; !piter.isDone(); piter.next() ) - { - int compIdx = piter.index(); - MString name = object.fullPathName(); - - // Figure out which object polygonTable to get. - // - int o, numObjectNames; - numObjectNames = objectNames->length(); - for ( o=0; o= polygonCounts[o] ) { - Msg("!Bad polygon index '%d' found. Polygon skipped",compIdx); - break; - } - // Mark set i as true in the table - // - polygonTable = polygonTablePtr[o]; - *(polygonTable + numSets*compIdx + i) = true; - break; - } - } - } // end of piter.next() loop - } // end of condition if (object.hasFn(MFn::kMesh)) - } // end of else condifion if (!component.isNull()) - } // end of memberList.getDagPath(m,object,component) - } // end of memberList loop - } // end of for-loop for sets - - // Go through all of the group members and mark in the - // lookup-table, the group that each shape belongs to. - length = objectNodeNamesArray.length(); - if (objectGroupsTablePtr){ - for( i=0; iappend(name); + objectNodeNamesArray.append(fnMesh.name()); + + vertexCounts.append(vtxCount); + polygonCounts.append(polygonCount); + + objectCount++; + } + } + } + } + + // Now we know how many objects we are dealing with + // and we have counts of the vertices/polygons for each + // object so create the maya group look-up table. + // + if (objectCount > 0) { + // To export Maya groups we traverse the hierarchy starting at + // each objectNodeNamesArray[i] going towards the root collecting transform + // nodes as we go. + length = objectNodeNamesArray.length(); + for (i = 0; i < length; i++) + { + MIntArray transformNodeNameIndicesArray; + recFindTransformDAGNodes(objectNodeNamesArray[i], transformNodeNameIndicesArray); + } + + if (transformNodeNameArray.length() > 0) { + objectGroupsTablePtr = xr_alloc(objectCount); // (bool**) malloc( sizeof(bool*)*objectCount ); + length = transformNodeNameArray.length(); + for (i = 0; i < objectCount; i++) + { + // objectGroupsTablePtr[i] = (bool*)calloc( length, sizeof(bool) ); + objectGroupsTablePtr[i] = xr_alloc(length); + ZeroMemory(objectGroupsTablePtr[i], length * sizeof(bool)); + + if (objectGroupsTablePtr[i] == NULL) { + Log("!calloc returned NULL (objectGroupsTablePtr)"); + return false; + } + } + } + // else{ + // Log("!Can't find transform for node."); + // return false; + // } + } + + // Create the vertex/polygon look-up tables. + // + if (objectCount > 0) { + vertexTablePtr = xr_alloc(objectCount); //(bool**) malloc( sizeof(bool*)*objectCount ); + polygonTablePtr = xr_alloc(objectCount); //(bool**) malloc( sizeof(bool*)*objectCount ); + + for (i = 0; i < objectCount; i++) + { + // vertexTablePtr[i] = (bool*)calloc( vertexCounts[i]*numSets, sizeof(bool) ); + vertexTablePtr[i] = xr_alloc(vertexCounts[i] * numSets); + ZeroMemory(vertexTablePtr[i], vertexCounts[i] * numSets * sizeof(bool)); + + if (vertexTablePtr[i] == NULL) { + Log("!calloc returned NULL (vertexTable)"); + return false; + } + + // polygonTablePtr[i] = (bool*)calloc( polygonCounts[i]*numSets, sizeof(bool) ); + polygonTablePtr[i] = xr_alloc(polygonCounts[i] * numSets); + ZeroMemory(polygonTablePtr[i], polygonCounts[i] * numSets * sizeof(bool)); + if (polygonTablePtr[i] == NULL) { + Log("!calloc returned NULL (polygonTable)"); + return false; + } + } + } + + // If we found no meshes then return + // + if (objectCount == 0) { + return false; + } + + ////////////////////////////////////////////////////////////////// + // + // Go through all of the set members (flattened lists) and mark + // in the lookup-tables, the sets that each mesh component belongs + // to. + // + // + ////////////////////////////////////////////////////////////////// + bool flattenedList = true; + MDagPath object; + MObject component; + MSelectionList memberList; + + for (i = 0; i < numSets; i++) + { + MFnSet fnSet((*sets)[i]); + memberList.clear(); + stat = fnSet.getMembers(memberList, flattenedList); + + if (MS::kSuccess != stat) { + fprintf(stderr, "Error in fnSet.getMembers()!\n"); + } + + int m, numMembers; + numMembers = memberList.length(); + for (m = 0; m < numMembers; m++) + { + if (memberList.getDagPath(m, object, component)) { + if ((!component.isNull()) && (object.apiType() == MFn::kMesh)) { + if (component.apiType() == MFn::kMeshVertComponent) { + MItMeshVertex viter(object, component); + for (; !viter.isDone(); viter.next()) + { + int compIdx = viter.index(); + MString name = object.fullPathName(); + + // Figure out which object vertexTable + // to get. + // + + int o, numObjectNames; + numObjectNames = objectNames->length(); + for (o = 0; o < numObjectNames; o++) + { + if ((*objectNames)[o] == name) { + // Mark set i as true in the table + // + vertexTable = vertexTablePtr[o]; + *(vertexTable + numSets * compIdx + i) = true; + break; + } + } + } + } + else if (component.apiType() == MFn::kMeshPolygonComponent) + { + MItMeshPolygon piter(object, component); + for (; !piter.isDone(); piter.next()) + { + int compIdx = piter.index(); + MString name = object.fullPathName(); + + // Figure out which object polygonTable + // to get. + // + int o, numObjectNames; + numObjectNames = objectNames->length(); + for (o = 0; o < numObjectNames; o++) + { + if ((*objectNames)[o] == name) { + // Mark set i as true in the table + // + + // Check for bad components in the set + // + if (compIdx >= polygonCounts[o]) { + Msg("!Bad polygon index '%d' found. Polygon skipped", compIdx); + break; + } + + polygonTable = polygonTablePtr[o]; + *(polygonTable + numSets * compIdx + i) = true; + break; + } + } + } + } + } + else + { + // There are no components, therefore we can mark + // all polygons as members of the given set. + // + + if (object.hasFn(MFn::kMesh)) { + MFnMesh fnMesh(object, &stat); + if (MS::kSuccess != stat) { + fprintf(stderr, "Failure in MFnMesh initialization.\n"); + return false; + } + + // We are going to iterate over all the polygons. + // + MItMeshPolygon piter(object, MObject::kNullObj, &stat); + if (MS::kSuccess != stat) { + fprintf(stderr, "Failure in MItMeshPolygon initialization.\n"); + return false; + } + for (; !piter.isDone(); piter.next()) + { + int compIdx = piter.index(); + MString name = object.fullPathName(); + + // Figure out which object polygonTable to get. + // + int o, numObjectNames; + numObjectNames = objectNames->length(); + for (o = 0; o < numObjectNames; o++) + { + if ((*objectNames)[o] == name) { + // Check for bad components in the set + // + if (compIdx >= polygonCounts[o]) { + Msg("!Bad polygon index '%d' found. Polygon skipped", compIdx); + break; + } + // Mark set i as true in the table + // + polygonTable = polygonTablePtr[o]; + *(polygonTable + numSets * compIdx + i) = true; + break; + } + } + } // end of piter.next() loop + } // end of condition if (object.hasFn(MFn::kMesh)) + } // end of else condifion if (!component.isNull()) + } // end of memberList.getDagPath(m,object,component) + } // end of memberList loop + } // end of for-loop for sets + + // Go through all of the group members and mark in the + // lookup-table, the group that each shape belongs to. + length = objectNodeNamesArray.length(); + if (objectGroupsTablePtr) { + for (i = 0; i < length; i++) + { + MIntArray groupTableIndicesArray; + bool* objectGroupTable = objectGroupsTablePtr[i]; + int length2; + recFindTransformDAGNodes(objectNodeNamesArray[i], groupTableIndicesArray); + length2 = groupTableIndicesArray.length(); + for (j = 0; j < length2; j++) + { + int groupIdx = groupTableIndicesArray[j]; + objectGroupTable[groupIdx] = true; + } + } + } + return true; } ////////////////////////////////////////////////////////////// @@ -585,225 +576,227 @@ void CXRayObjectExport::freeLookupTables() // Frees up all tables and arrays allocated by this plug-in. // { - if (vertexTablePtr){ - for ( int i=0; i(edgeTableSize); - ZeroMemory(edgeTable,edgeTableSize*sizeof(int)); + edgeTable = xr_alloc(edgeTableSize); + ZeroMemory(edgeTable, edgeTableSize * sizeof(int)); // Add entries, for each edge, to the lookup table // - MItMeshEdge eIt( mesh ); - for ( ; !eIt.isDone(); eIt.next() ) + MItMeshEdge eIt(mesh); + for (; !eIt.isDone(); eIt.next()) { bool smooth = eIt.isSmooth(); - addEdgeInfo( eIt.index(0), eIt.index(1), smooth ); + addEdgeInfo(eIt.index(0), eIt.index(1), smooth); } // Fill in referenced polygons // - MItMeshPolygon pIt( mesh ); - for ( ; !pIt.isDone(); pIt.next() ) + MItMeshPolygon pIt(mesh); + for (; !pIt.isDone(); pIt.next()) { int pvc = pIt.polygonVertexCount(); - for ( int v=0; vpolyIds[0] ) { + + if (INVALID_ID == elem->polyIds[0]) { elem->polyIds[0] = edgeId; } - else { + else + { elem->polyIds[1] = edgeId; - } - + } } } } - CreateSmoothingGroups( fnMesh ); + CreateSmoothingGroups(fnMesh); } ////////////////////////////////////////////////////////////// -void CXRayObjectExport:: CreateSmoothingGroups ( MFnMesh& fnMesh ) +void CXRayObjectExport::CreateSmoothingGroups(MFnMesh& fnMesh) { - // Now create a polyId->smoothingGroup table - // + // Now create a polyId->smoothingGroup table + // int numPolygons = fnMesh.numPolygons(); - polySmoothingGroups = xr_alloc(numPolygons); //(int*)malloc( sizeof(int) * numPolygons ); - for ( int i=0; i< numPolygons; i++ ) { + polySmoothingGroups = xr_alloc(numPolygons); //(int*)malloc( sizeof(int) * numPolygons ); + for (int i = 0; i < numPolygons; i++) + { polySmoothingGroups[i] = NO_SMOOTHING_GROUP; - } - //CreateSMGFacegroups( fnMesh ); - // CreateSMGEdgeAttrs( fnMesh ); + } + // CreateSMGFacegroups( fnMesh ); + // CreateSMGEdgeAttrs( fnMesh ); } -void CXRayObjectExport:: CreateSMGFacegroups ( MFnMesh& fnMesh ) +void CXRayObjectExport::CreateSMGFacegroups(MFnMesh& fnMesh) { - // Now call the smoothingAlgorithm to fill in the polySmoothingGroups + // Now call the smoothingAlgorithm to fill in the polySmoothingGroups // table. // Note: we have to traverse ALL polygons to handle the case // of disjoint polygons. // - int numPolygons = fnMesh.numPolygons(); + int numPolygons = fnMesh.numPolygons(); nextSmoothingGroup = 1; currSmoothingGroup = 1; - for ( int pid=0; pidsmooth ); - } - } - } + int numPolygons = fnMesh.numPolygons(); + for (int pid = 0; pid < numPolygons; pid++) + { + MIntArray vertexList; + fnMesh.getPolygonVertices(pid, vertexList); + int vcount = vertexList.length(); + if (vcount != 3) Msg("poly vertex count not equel 3(is not a tri) vertex count = %d", vcount); + + for (int vid = 0; vid < vcount; vid++) + { + int a = vertexList[vid]; + int b = vertexList[vid == (vcount - 1) ? 0 : vid + 1]; + + SXREdgeInfoPtr elem = findEdgeInfo(a, b); + + if (NULL != elem) { + set_edge_smooth_flag(polySmoothingGroups[pid], vid, elem->smooth); + } + } + } } -bool CXRayObjectExport::smoothingAlgorithm( int polyId, MFnMesh& fnMesh ) +bool CXRayObjectExport::smoothingAlgorithm(int polyId, MFnMesh& fnMesh) { MIntArray vertexList; - fnMesh.getPolygonVertices( polyId, vertexList ); + fnMesh.getPolygonVertices(polyId, vertexList); int vcount = vertexList.length(); bool smoothEdgeFound = false; - - for ( int vid=0; vidpolyIds[1] ) { // Edge not a border - + if (NO_SMOOTHING_GROUP != elem->polyIds[1]) { // Edge not a border + // We are starting a new smoothing group - // - if ( newSmoothingGroup ) { + // + if (newSmoothingGroup) { currSmoothingGroup = nextSmoothingGroup++; newSmoothingGroup = false; - + // This is a SEED (starting) polygon and so we always // give it the new smoothing group id. // Even if all edges are hard this must be done so @@ -811,36 +804,38 @@ bool CXRayObjectExport::smoothingAlgorithm( int polyId, MFnMesh& fnMesh ) // polySmoothingGroups[polyId] = currSmoothingGroup; } - + // If we have a smooth edge then this poly must be a member // of the current smoothing group. // - if ( elem->smooth ) { + if (elem->smooth) { polySmoothingGroups[polyId] = currSmoothingGroup; smoothEdgeFound = true; } - else { // Hard edge so ignore this polygon + else + { // Hard edge so ignore this polygon continue; } - + // Find the adjacent poly id // int adjPoly = elem->polyIds[0]; - if ( adjPoly == polyId ) { + if (adjPoly == polyId) { adjPoly = elem->polyIds[1]; - } - + } + // If we are this far then adjacent poly belongs in this // smoothing group. // If the adjacent polygon's smoothing group is not // NO_SMOOTHING_GROUP then it has already been visited // so we ignore it. // - if ( NO_SMOOTHING_GROUP == polySmoothingGroups[adjPoly] ) { - smoothingAlgorithm( adjPoly, fnMesh ); + if (NO_SMOOTHING_GROUP == polySmoothingGroups[adjPoly]) { + smoothingAlgorithm(adjPoly, fnMesh); } - else if ( polySmoothingGroups[adjPoly] != currSmoothingGroup ) { - Msg("!smoothing group problem at polygon %d",adjPoly); + else if (polySmoothingGroups[adjPoly] != currSmoothingGroup) + { + Msg("!smoothing group problem at polygon %d", adjPoly); } } } @@ -850,32 +845,34 @@ bool CXRayObjectExport::smoothingAlgorithm( int polyId, MFnMesh& fnMesh ) ////////////////////////////////////////////////////////////// -void CXRayObjectExport::addEdgeInfo( int v1, int v2, bool smooth ) +void CXRayObjectExport::addEdgeInfo(int v1, int v2, bool smooth) // // Adds a new edge info element to the vertex table. // { SXREdgeInfoPtr element = NULL; - if ( NULL == edgeTable[v1] ) { - edgeTable[v1] = xr_alloc(1);//(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); + if (NULL == edgeTable[v1]) { + edgeTable[v1] = xr_alloc(1); //(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); element = edgeTable[v1]; } - else { + else + { element = edgeTable[v1]; - while ( NULL != element->next ) { + while (NULL != element->next) + { element = element->next; } - element->next = xr_alloc(1);//(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); + element->next = xr_alloc(1); //(EdgeInfoPtr)malloc( sizeof(struct EdgeInfo) ); element = element->next; } // Setup data for new edge // - element->vertId = v2; - element->smooth = smooth; - element->next = NULL; - + element->vertId = v2; + element->smooth = smooth; + element->next = NULL; + // Initialize array of id's of polygons that reference this edge. // There are at most 2 polygons per edge. // @@ -885,7 +882,7 @@ void CXRayObjectExport::addEdgeInfo( int v1, int v2, bool smooth ) ////////////////////////////////////////////////////////////// -SXREdgeInfoPtr CXRayObjectExport::findEdgeInfo( int v1, int v2 ) +SXREdgeInfoPtr CXRayObjectExport::findEdgeInfo(int v1, int v2) // // Finds the info for the specified edge. // @@ -893,18 +890,20 @@ SXREdgeInfoPtr CXRayObjectExport::findEdgeInfo( int v1, int v2 ) SXREdgeInfoPtr element = NULL; element = edgeTable[v1]; - while ( NULL != element ) { - if ( v2 == element->vertId ) { + while (NULL != element) + { + if (v2 == element->vertId) { return element; } element = element->next; } - - if ( element == NULL ) { + + if (element == NULL) { element = edgeTable[v2]; - while ( NULL != element ) { - if ( v1 == element->vertId ) { + while (NULL != element) + { + if (v1 == element->vertId) { return element; } element = element->next; @@ -921,72 +920,74 @@ void CXRayObjectExport::destroyEdgeTable() // Free up all of the memory used by the edgeTable. // { -//. if ( !smoothing ) return; - + //. if ( !smoothing ) return; + SXREdgeInfoPtr element = NULL; SXREdgeInfoPtr tmp = NULL; - for ( int v=0; vnext; - xr_free( tmp ); + xr_free(tmp); } } - if ( NULL != edgeTable ) { - xr_free( edgeTable ); + if (NULL != edgeTable) { + xr_free(edgeTable); edgeTable = NULL; } - - if ( NULL != polySmoothingGroups ) { - xr_free( polySmoothingGroups ); + + if (NULL != polySmoothingGroups) { + xr_free(polySmoothingGroups); polySmoothingGroups = NULL; } } ////////////////////////////////////////////////////////////// -void CXRayObjectExport::recFindTransformDAGNodes( MString& nodeName, MIntArray& transformNodeIndicesArray ) +void CXRayObjectExport::recFindTransformDAGNodes(MString& nodeName, MIntArray& transformNodeIndicesArray) { - // To handle Maya groups we traverse the hierarchy starting at - // each objectNames[i] going towards the root collecting transform - // nodes as we go. - MStringArray result; - MString cmdStr = "listRelatives -ap " + nodeName; - MGlobal::executeCommand( cmdStr, result ); - - if( result.length() == 0 ) - // nodeName must be at the root of the DAG. Stop recursing - return; - - for( unsigned int j=0; j -MStatus t_set_smoth_flags( export_class& export_obj, u32 &flags, const MIntArray& tri_vert_indeces ) +template +MStatus t_set_smoth_flags(export_class& export_obj, u32& flags, const MIntArray& tri_vert_indeces) { - if( tri_vert_indeces.length()!=3 ) - { - Msg("XRAY Plagin ERROR"); - return MS::kFailure; - } - flags = u32(0); - for( u16 i = 0; 3 > i; ++i ) - { - int a = tri_vert_indeces[ i ]; - int b = tri_vert_indeces[ (i+1)%3 ]; - SXREdgeInfoPtr elem = export_obj.findEdgeInfo( a, b ); + if (tri_vert_indeces.length() != 3) { + Msg("XRAY Plagin ERROR"); + return MS::kFailure; + } + flags = u32(0); + for (u16 i = 0; 3 > i; ++i) + { + int a = tri_vert_indeces[i]; + int b = tri_vert_indeces[(i + 1) % 3]; + SXREdgeInfoPtr elem = export_obj.findEdgeInfo(a, b); - if( elem && !elem->smooth ) - set_face_adge_hard( flags, i ); - } + if (elem && !elem->smooth) set_face_adge_hard(flags, i); + } - return MS::kSuccess; + return MS::kSuccess; } #endif \ No newline at end of file diff --git a/src/plugins/Maya/Material/MNormalMapConverter.cpp b/src/plugins/Maya/Material/MNormalMapConverter.cpp index 3cf42d56779..5217a6efcd9 100644 --- a/src/plugins/Maya/Material/MNormalMapConverter.cpp +++ b/src/plugins/Maya/Material/MNormalMapConverter.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// DESCRIPTION: +// DESCRIPTION: // Some utilities to do file format conversions and others ... // /////////////////////////////////////////////////////////////////// @@ -7,141 +7,126 @@ #include "MNormalMapConverter.h" - // Convert the heightfield texture to its corresponding normal map texture // -bool MNormalMapConverter::convertToNormalMap( - unsigned char* inImagePtr, - unsigned int width, - unsigned int height, - OutFormatType outputPixelFormat, - float bumpScale, - unsigned char* outImagePtr ) +bool MNormalMapConverter::convertToNormalMap(unsigned char* inImagePtr, unsigned int width, unsigned int height, + OutFormatType outputPixelFormat, float bumpScale, unsigned char* outImagePtr) { - bool isOK = true; - - // Firewall: The input image should not be a NULL pointer, - // - if( NULL == inImagePtr ) return false; - - // No output file specified: convert in place - // - if( NULL == outImagePtr ) - { - convertToNormalMap_InPlace( inImagePtr, width, height, outputPixelFormat, bumpScale ); - } - else - { - if( outputPixelFormat == RGBA ) { - // - // Not implemented yet - // - // similar to the convertToNormalMap_InPlace but we store - // the resulting texture in the outImagePtr and not - // in the inImagePtr texture - // - } - else if( outputPixelFormat == HILO ) { - // Not implemented yet - } - else { - isOK = false; - } - } - - return isOK; + bool isOK = true; + + // Firewall: The input image should not be a NULL pointer, + // + if (NULL == inImagePtr) return false; + + // No output file specified: convert in place + // + if (NULL == outImagePtr) { + convertToNormalMap_InPlace(inImagePtr, width, height, outputPixelFormat, bumpScale); + } + else + { + if (outputPixelFormat == RGBA) { + // + // Not implemented yet + // + // similar to the convertToNormalMap_InPlace but we store + // the resulting texture in the outImagePtr and not + // in the inImagePtr texture + // + } + else if (outputPixelFormat == HILO) + { + // Not implemented yet + } + else + { + isOK = false; + } + } + + return isOK; } - // The heightfield texture inImage will be replaced from grey levels in RGBA // to the normal map values as specified by the pixel format // -bool MNormalMapConverter::convertToNormalMap_InPlace( - unsigned char* inImagePtr, - unsigned int width, - unsigned int height, - OutFormatType outputPixelFormat, - float bumpScale ) +bool MNormalMapConverter::convertToNormalMap_InPlace(unsigned char* inImagePtr, unsigned int width, unsigned int height, + OutFormatType outputPixelFormat, float bumpScale) { - bool isOK = true; - - if( outputPixelFormat == RGBA ) { - - bumpScale /= 255.0f; // will be used on unsignedChar - - unsigned int widthMinus1 = width - 1; - unsigned int heightMinus1 = height - 1; - unsigned int offset = (4 * width); // = sizeof(rgba) * width - - // ================== - // Process the texels - // ================== - - // Get the current pointer to the starting texel at (0,0) - // - unsigned char* imagePtr = inImagePtr; - - // For each rows (except the last one) - // - unsigned int m, n; - for( m=0; m(m_numLevels); - for (i=0; i < m_numLevels; i++) - { - m_levels[i] = xr_alloc(width(i) * height(i) * 4); - } - - // Copy the base level. (the actual file texture) - Memory.mem_copy(m_levels[0], image.pixels(), m_width * m_height * 4); - - // Create the mipmapped levels. - // NOTE REGARDING THE width_ratio and height_ratio: - // The smallest mipmap levels of non-square textures must be handled - // carefully. Say we have a 8x2 texture. Mipmap levels will be - // 4x1, 2x1, 1x1. We cannot simply multiply the current st coordinate by - // 2 like we do for square textures to find the source st coordinates, - // or we'll end up fetching outside of the source level. Instead, we - // multiply the target s, t coordinates by the width and height ratio respectively. - for (unsigned int current_level = 1; current_level < m_numLevels; current_level++) - { - unsigned int width_ratio = width(i-1) / width(i); - unsigned int height_ratio = height(i-1) / height(i-1); - unsigned int previous_level = current_level - 1; - - for (unsigned int target_t = 0; target_t < height(current_level); target_t++) - { - for (unsigned int target_s = 0; target_s < width(current_level); target_s++) - { - // The st coordinates from the source level. - unsigned int source_s = target_s * width_ratio; - unsigned int source_t = target_t * height_ratio; - unsigned int source_s2 = source_s + ((width_ratio == 2) ? 1 : 0); - unsigned int source_t2 = source_t + ((height_ratio == 2) ? 1 : 0); - - unsigned char *destination = internalFetch(target_s, target_t, current_level); - unsigned char *source1 = internalFetch(source_s, source_t, previous_level); - unsigned char *source2 = internalFetch(source_s2, source_t, previous_level); - unsigned char *source3 = internalFetch(source_s, source_t2, previous_level); - unsigned char *source4 = internalFetch(source_s2, source_t2, previous_level); - - // Average byte per byte. - unsigned int average1 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; - *destination++ = average1; - - unsigned int average2 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; - *destination++ = average2; - - unsigned int average3 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; - *destination++ = average3; - - unsigned int average4 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; - *destination++ = average4; - } - } - } - - if( type == NMAP ) - { - // Convert each level to the NORMAL map format - // - MNormalMapConverter mapConverter; - - for (unsigned int i = 0; i < m_numLevels; i++) - { - mapConverter.convertToNormalMap( m_levels[i], width(i), height(i), MNormalMapConverter::RGBA, 2.0f ); - } - } - - specify(target); - - return true; + } + else + assert(0); + + // Get the dimension of the texture. + MStatus stat = image.getSize(m_width, m_height); + assert(stat); + m_mipmapped = mipmapped; + + unsigned int maxWidthLevels = highestPowerOf2(m_width); + unsigned int maxHeightLevels = highestPowerOf2(m_height); + + // Standard OpenGL doesn't accept width or height that are not power of 2. + // If that's the case we resize the picture to the closest larger valid rectangle. + bool widthIsExponent = (m_width == (unsigned int)(1 << maxWidthLevels)); + bool heightIsExponent = (m_height == (unsigned int)(1 << maxHeightLevels)); + + if (!widthIsExponent || !heightIsExponent) { + // Calculate the new width/height. + if (!widthIsExponent) maxWidthLevels++; + if (!heightIsExponent) maxHeightLevels++; + + // Resize the image, without bothering to preserve the aspect ratio. + m_width = 1 << maxWidthLevels; + m_height = 1 << maxHeightLevels; + image.resize(m_width, m_height, false); + } + + // Deallocate any existing levels + if (m_levels != NULL) { + for (i = 0; i < m_numLevels; i++) + { + if (m_levels[i]) { + xr_free(m_levels[i]); + m_levels[i] = NULL; + } + } + xr_free(m_levels); + } + + // The number of mipmap levels cannot be greater than the exponent of width or height. + // The number of mipmap levels is 1 for a non-mipmapped texture. + // For mipmapped textures, m_numLevels = max level + 1. + m_numLevels = mipmapped ? _max(maxWidthLevels, maxHeightLevels) + 1 : 1; + + // Allocate the proper amount of memory, for the base level and the mipmaps. + m_levels = xr_alloc(m_numLevels); + for (i = 0; i < m_numLevels; i++) + { + m_levels[i] = xr_alloc(width(i) * height(i) * 4); + } + + // Copy the base level. (the actual file texture) + Memory.mem_copy(m_levels[0], image.pixels(), m_width * m_height * 4); + + // Create the mipmapped levels. + // NOTE REGARDING THE width_ratio and height_ratio: + // The smallest mipmap levels of non-square textures must be handled + // carefully. Say we have a 8x2 texture. Mipmap levels will be + // 4x1, 2x1, 1x1. We cannot simply multiply the current st coordinate by + // 2 like we do for square textures to find the source st coordinates, + // or we'll end up fetching outside of the source level. Instead, we + // multiply the target s, t coordinates by the width and height ratio respectively. + for (unsigned int current_level = 1; current_level < m_numLevels; current_level++) + { + unsigned int width_ratio = width(i - 1) / width(i); + unsigned int height_ratio = height(i - 1) / height(i - 1); + unsigned int previous_level = current_level - 1; + + for (unsigned int target_t = 0; target_t < height(current_level); target_t++) + { + for (unsigned int target_s = 0; target_s < width(current_level); target_s++) + { + // The st coordinates from the source level. + unsigned int source_s = target_s * width_ratio; + unsigned int source_t = target_t * height_ratio; + unsigned int source_s2 = source_s + ((width_ratio == 2) ? 1 : 0); + unsigned int source_t2 = source_t + ((height_ratio == 2) ? 1 : 0); + + unsigned char* destination = internalFetch(target_s, target_t, current_level); + unsigned char* source1 = internalFetch(source_s, source_t, previous_level); + unsigned char* source2 = internalFetch(source_s2, source_t, previous_level); + unsigned char* source3 = internalFetch(source_s, source_t2, previous_level); + unsigned char* source4 = internalFetch(source_s2, source_t2, previous_level); + + // Average byte per byte. + unsigned int average1 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; + *destination++ = average1; + + unsigned int average2 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; + *destination++ = average2; + + unsigned int average3 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; + *destination++ = average3; + + unsigned int average4 = (*source1++ + *source2++ + *source3++ + *source4++) / 4; + *destination++ = average4; + } + } + } + + if (type == NMAP) { + // Convert each level to the NORMAL map format + // + MNormalMapConverter mapConverter; + + for (unsigned int i = 0; i < m_numLevels; i++) + { + mapConverter.convertToNormalMap(m_levels[i], width(i), height(i), MNormalMapConverter::RGBA, 2.0f); + } + } + + specify(target); + + return true; } bool MTexture::specify(GLenum target /* = GL_TEXTURE_2D */) { - assert(glGetError() == GL_NO_ERROR); + assert(glGetError() == GL_NO_ERROR); - m_texObj.bind(); + m_texObj.bind(); - assert(glGetError() == GL_NO_ERROR); + assert(glGetError() == GL_NO_ERROR); - for (unsigned int i=0; i < m_numLevels; i++) - { - glTexImage2D(target, i, m_internalFormat, width(i), height(i), 0, - m_format, m_componentFormat, m_levels[i]); + for (unsigned int i = 0; i < m_numLevels; i++) + { + glTexImage2D(target, i, m_internalFormat, width(i), height(i), 0, m_format, m_componentFormat, m_levels[i]); - assert(glGetError() == GL_NO_ERROR); - } + assert(glGetError() == GL_NO_ERROR); + } - if (mipmapped()) - { - // Mipmapping enabled - m_texObj.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - assert(glGetError() == GL_NO_ERROR); + if (mipmapped()) { + // Mipmapping enabled + m_texObj.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + assert(glGetError() == GL_NO_ERROR); - m_texObj.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); - assert(glGetError() == GL_NO_ERROR); - } - else - { - m_texObj.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR); - m_texObj.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } + m_texObj.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); + assert(glGetError() == GL_NO_ERROR); + } + else + { + m_texObj.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR); + m_texObj.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } - m_texObj.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP); - m_texObj.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP); + m_texObj.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP); + m_texObj.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP); - return true; + return true; } bool MTexture::bind() { - m_texObj.bind(); - //specify(GL_TEXTURE_2D); + m_texObj.bind(); + // specify(GL_TEXTURE_2D); - return true; + return true; } - int highestPowerOf2(int num) { - int power = 0; + int power = 0; - while (num > 1) - { - power++; - num = num >> 1; - } + while (num > 1) + { + power++; + num = num >> 1; + } - return power; + return power; } - - diff --git a/src/plugins/Maya/Material/MTexture.h b/src/plugins/Maya/Material/MTexture.h index 15d8bd731bc..6e9929296d3 100644 --- a/src/plugins/Maya/Material/MTexture.h +++ b/src/plugins/Maya/Material/MTexture.h @@ -9,9 +9,9 @@ // /////////////////////////////////////////////////////////////////// +#include #include #include -#include #include #include @@ -21,179 +21,159 @@ int highestPowerOf2(int num); class TexObj { public: - TexObj(GLenum target = GL_TEXTURE_2D) - { - assert(glGetError() == GL_NO_ERROR); - - // Get a texture identifier. - glGenTextures(1, &fTextureNum); - assert(glGetError() == GL_NO_ERROR); - - fTarget = target; - - // Set up default values for the texture parameters. - // They are the same as the OpenGL default. - fMinFilterParam = GL_NEAREST; - fMagFilterParam = GL_LINEAR; - fWrapSParam = GL_REPEAT; - fWrapTParam = GL_REPEAT; - } - - ~TexObj() - { - glDeleteTextures(1, &fTextureNum); - } - - void bind() - { - assert(glGetError() == GL_NO_ERROR); - - // Bind the texture. - glBindTexture(fTarget, fTextureNum); - assert(glGetError() == GL_NO_ERROR); - - // Set up the texture parameters. - glTexParameteri(fTarget, GL_TEXTURE_MIN_FILTER, fMinFilterParam); - assert(glGetError() == GL_NO_ERROR); - glTexParameteri(fTarget, GL_TEXTURE_MAG_FILTER, fMagFilterParam); - assert(glGetError() == GL_NO_ERROR); - glTexParameteri(fTarget, GL_TEXTURE_WRAP_S, fWrapSParam); - assert(glGetError() == GL_NO_ERROR); - glTexParameteri(fTarget, GL_TEXTURE_WRAP_T, fWrapTParam); - assert(glGetError() == GL_NO_ERROR); - } - - void parameter(GLenum pname, GLint param) - { - switch (pname) - { - case GL_TEXTURE_MIN_FILTER: fMinFilterParam = param; break; - case GL_TEXTURE_MAG_FILTER: fMagFilterParam = param; break; - case GL_TEXTURE_WRAP_S: fWrapSParam = param; break; - case GL_TEXTURE_WRAP_T: fWrapTParam = param; break; - } - } + TexObj(GLenum target = GL_TEXTURE_2D) + { + assert(glGetError() == GL_NO_ERROR); + + // Get a texture identifier. + glGenTextures(1, &fTextureNum); + assert(glGetError() == GL_NO_ERROR); + + fTarget = target; + + // Set up default values for the texture parameters. + // They are the same as the OpenGL default. + fMinFilterParam = GL_NEAREST; + fMagFilterParam = GL_LINEAR; + fWrapSParam = GL_REPEAT; + fWrapTParam = GL_REPEAT; + } + + ~TexObj() { glDeleteTextures(1, &fTextureNum); } + void bind() + { + assert(glGetError() == GL_NO_ERROR); + + // Bind the texture. + glBindTexture(fTarget, fTextureNum); + assert(glGetError() == GL_NO_ERROR); + + // Set up the texture parameters. + glTexParameteri(fTarget, GL_TEXTURE_MIN_FILTER, fMinFilterParam); + assert(glGetError() == GL_NO_ERROR); + glTexParameteri(fTarget, GL_TEXTURE_MAG_FILTER, fMagFilterParam); + assert(glGetError() == GL_NO_ERROR); + glTexParameteri(fTarget, GL_TEXTURE_WRAP_S, fWrapSParam); + assert(glGetError() == GL_NO_ERROR); + glTexParameteri(fTarget, GL_TEXTURE_WRAP_T, fWrapTParam); + assert(glGetError() == GL_NO_ERROR); + } + + void parameter(GLenum pname, GLint param) + { + switch (pname) + { + case GL_TEXTURE_MIN_FILTER: fMinFilterParam = param; break; + case GL_TEXTURE_MAG_FILTER: fMagFilterParam = param; break; + case GL_TEXTURE_WRAP_S: fWrapSParam = param; break; + case GL_TEXTURE_WRAP_T: fWrapTParam = param; break; + } + } private: - GLenum fTarget; - - // Various parameters. See glTexParameterf() in MSDN for more info. - GLint fMinFilterParam; - GLint fMagFilterParam; - GLint fWrapSParam; - GLint fWrapTParam; - - GLuint fTextureNum; + GLenum fTarget; + + // Various parameters. See glTexParameterf() in MSDN for more info. + GLint fMinFilterParam; + GLint fMagFilterParam; + GLint fWrapSParam; + GLint fWrapTParam; + + GLuint fTextureNum; }; class MTexture { public: - enum Type - { - RGBA, - HILO, - NMAP - }; - - MTexture(); - - ~MTexture() - { - if (m_levels) - { - for (unsigned int i=0; i < m_numLevels; i++) - { - if (m_levels[i]) - { - xr_free(m_levels[i]); - } - } - - xr_free(m_levels); - } - } - - bool set(MImage &image, Type type, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); - - // This function assumes that the file texture is square, and - // that its dimensions are exponents of 2. - bool load(MString filename, Type type, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); - - bool specify(GLenum target); - - // Returns 1 if no mipmapping, >1 otherwise. - unsigned int levels() { return m_numLevels; } - - bool bind(); - - unsigned char* fetch(unsigned int s, unsigned int t, unsigned int level = 0) - { - // Verify that the mipmap level exists. - if (level > m_numLevels || m_levels == NULL || m_levels[level] == NULL) - return NULL; - - return internalFetch(s, t, level); - } - - inline bool square() - { - return m_width == m_height; - } - - inline bool mipmapped() - { - return levels() > 1; - } - - // Return the width of a specific mipmap level. - // If level == 0, return the width of the base level (source image). - // Width is always >= 1, to prevent non-square textures from having zero-sized levels. - inline unsigned int width(unsigned int level = 0) - { - unsigned int w = m_width >> level; - if (w > 0) - return w; - else - return 1; - } - - inline unsigned int height(unsigned int level = 0) - { - unsigned int h = m_height >> level; - if (h > 0) - return h; - else - return 1; - } + enum Type + { + RGBA, + HILO, + NMAP + }; + + MTexture(); + + ~MTexture() + { + if (m_levels) { + for (unsigned int i = 0; i < m_numLevels; i++) + { + if (m_levels[i]) { + xr_free(m_levels[i]); + } + } + + xr_free(m_levels); + } + } + + bool set(MImage& image, Type type, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); + + // This function assumes that the file texture is square, and + // that its dimensions are exponents of 2. + bool load(MString filename, Type type, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); + + bool specify(GLenum target); + + // Returns 1 if no mipmapping, >1 otherwise. + unsigned int levels() { return m_numLevels; } + bool bind(); + + unsigned char* fetch(unsigned int s, unsigned int t, unsigned int level = 0) + { + // Verify that the mipmap level exists. + if (level > m_numLevels || m_levels == NULL || m_levels[level] == NULL) return NULL; + + return internalFetch(s, t, level); + } + + inline bool square() { return m_width == m_height; } + inline bool mipmapped() { return levels() > 1; } + // Return the width of a specific mipmap level. + // If level == 0, return the width of the base level (source image). + // Width is always >= 1, to prevent non-square textures from having zero-sized levels. + inline unsigned int width(unsigned int level = 0) + { + unsigned int w = m_width >> level; + if (w > 0) + return w; + else + return 1; + } + + inline unsigned int height(unsigned int level = 0) + { + unsigned int h = m_height >> level; + if (h > 0) + return h; + else + return 1; + } protected: - - inline unsigned char* internalFetch(unsigned int s, unsigned int t, unsigned int level) - { - assert((s >= 0) && (s < width(level))); - assert((t >= 0) && (t < height(level))); - return m_levels[level] + 4 * ((width(level) * t) + s); - } - + inline unsigned char* internalFetch(unsigned int s, unsigned int t, unsigned int level) + { + assert((s >= 0) && (s < width(level))); + assert((t >= 0) && (t < height(level))); + return m_levels[level] + 4 * ((width(level) * t) + s); + } private: - - // Fairly permanent variables - unsigned int m_width, m_height; - Type m_type; - TexObj m_texObj; - bool m_mipmapped; - - // Pyramid levels (assumes 4 bytes per pixel for now) - unsigned char **m_levels; - unsigned int m_numLevels; // Number of mipmaps + base texture - - // Cached variables (Depend on previous private variables) - GLint m_internalFormat; - GLenum m_format; - GLenum m_componentFormat; + // Fairly permanent variables + unsigned int m_width, m_height; + Type m_type; + TexObj m_texObj; + bool m_mipmapped; + + // Pyramid levels (assumes 4 bytes per pixel for now) + unsigned char** m_levels; + unsigned int m_numLevels; // Number of mipmaps + base texture + + // Cached variables (Depend on previous private variables) + GLint m_internalFormat; + GLenum m_format; + GLenum m_componentFormat; }; - -#endif // MAYA_API_MTexture +#endif // MAYA_API_MTexture diff --git a/src/plugins/Maya/Material/MTextureCache.cpp b/src/plugins/Maya/Material/MTextureCache.cpp index 830a0b0ca7a..874a6058ca8 100644 --- a/src/plugins/Maya/Material/MTextureCache.cpp +++ b/src/plugins/Maya/Material/MTextureCache.cpp @@ -4,7 +4,7 @@ // texture cache to plug-ins to improve memory utilization // and performance. // -// PS: Thanks to sbrew@lucasarts.com for contributing several fixes +// PS: Thanks to sbrew@lucasarts.com for contributing several fixes // to this class! ;-) // /////////////////////////////////////////////////////////////////// @@ -18,135 +18,118 @@ MTextureCache* MTextureCache::m_instance = NULL; /*static*/ int MTextureCache::refcount = 0; MTextureCacheElement::~MTextureCacheElement() -{ - if (m_texture) - { - xr_delete(m_texture); - m_texture = NULL; - } +{ + if (m_texture) { + xr_delete(m_texture); + m_texture = NULL; + } } - MTextureCache::~MTextureCache() { - if (m_textureTable.empty()) - return; - - // Delete all texture cache elements. - // - string_to_cacheElement_map::iterator p = m_textureTable.begin(); - for ( ; p != m_textureTable.end(); ++p) - { - xr_delete(p->second); - } + if (m_textureTable.empty()) return; + + // Delete all texture cache elements. + // + string_to_cacheElement_map::iterator p = m_textureTable.begin(); + for (; p != m_textureTable.end(); ++p) + { + xr_delete(p->second); + } } // Return a reference to the texture. Need to dereference by calling "release". -MTexture* MTextureCache::texture(MObject textureObj, - MTexture::Type type /* = MTexture::RGBA */, - bool mipmapped /* = true */, - GLenum target /* = GL_TEXTURE_2D */) +MTexture* MTextureCache::texture(MObject textureObj, MTexture::Type type /* = MTexture::RGBA */, + bool mipmapped /* = true */, GLenum target /* = GL_TEXTURE_2D */) { - // Get the name of the texture object. - MString textureName = getNameFromObj(textureObj); - - // If this isn't a file texture node, or if it has no valid name, - // return NULL. - if (!textureObj.hasFn(MFn::kFileTexture) || - textureName == "") - return NULL; - - // Check if we already have a texCacheElement assigned to the given texture name. - MTextureCacheElement *texCacheElement = - m_textureTable[textureName.asChar()]; - bool newTexture = !texCacheElement; - bool textureDirty = texCacheElement && texCacheElement->fMonitor.dirty(); - - if (textureDirty) - { - texCacheElement->fMonitor.stopWatching(); - xr_delete(texCacheElement->m_texture); - texCacheElement->m_texture = NULL; - } - - if (newTexture) - { - texCacheElement = xr_new(); - - texCacheElement->fMonitor.setManager(this); - - // Add it to the map. - m_textureTable[textureName.asChar()] = texCacheElement; - } - - if (textureDirty || newTexture) - { - // Get the filename of the file texture node. - MString textureFilename; - MFnDependencyNode textureNode(textureObj); - MPlug filenamePlug( textureObj, - textureNode.attribute(MString("fileTextureName")) ); - filenamePlug.getValue(textureFilename); - - // Create the MTexture - texCacheElement->m_texture = xr_new(); - - // Monitor the given texture node for "dirty" or "rename" messages. - texCacheElement->fMonitor.watch(textureObj); - - // Attempt to load the texture from disk and bind it in the OpenGL driver. - if (texCacheElement->m_texture->load(textureFilename, - type, mipmapped, target) == false) - { - // An error occured. Most likely, it was impossible to - // open the given filename. - // Clean up and return NULL. - xr_delete(texCacheElement); - texCacheElement = NULL; - m_textureTable.erase(textureName.asChar()); - return NULL; - } - } - - // Update the last updated timestamp. - texCacheElement->lastAccessedTimestamp = m_currentTimestamp; - - return texCacheElement->texture(); + // Get the name of the texture object. + MString textureName = getNameFromObj(textureObj); + + // If this isn't a file texture node, or if it has no valid name, + // return NULL. + if (!textureObj.hasFn(MFn::kFileTexture) || textureName == "") return NULL; + + // Check if we already have a texCacheElement assigned to the given texture name. + MTextureCacheElement* texCacheElement = m_textureTable[textureName.asChar()]; + bool newTexture = !texCacheElement; + bool textureDirty = texCacheElement && texCacheElement->fMonitor.dirty(); + + if (textureDirty) { + texCacheElement->fMonitor.stopWatching(); + xr_delete(texCacheElement->m_texture); + texCacheElement->m_texture = NULL; + } + + if (newTexture) { + texCacheElement = xr_new(); + + texCacheElement->fMonitor.setManager(this); + + // Add it to the map. + m_textureTable[textureName.asChar()] = texCacheElement; + } + + if (textureDirty || newTexture) { + // Get the filename of the file texture node. + MString textureFilename; + MFnDependencyNode textureNode(textureObj); + MPlug filenamePlug(textureObj, textureNode.attribute(MString("fileTextureName"))); + filenamePlug.getValue(textureFilename); + + // Create the MTexture + texCacheElement->m_texture = xr_new(); + + // Monitor the given texture node for "dirty" or "rename" messages. + texCacheElement->fMonitor.watch(textureObj); + + // Attempt to load the texture from disk and bind it in the OpenGL driver. + if (texCacheElement->m_texture->load(textureFilename, type, mipmapped, target) == false) { + // An error occured. Most likely, it was impossible to + // open the given filename. + // Clean up and return NULL. + xr_delete(texCacheElement); + texCacheElement = NULL; + m_textureTable.erase(textureName.asChar()); + return NULL; + } + } + + // Update the last updated timestamp. + texCacheElement->lastAccessedTimestamp = m_currentTimestamp; + + return texCacheElement->texture(); } -// Returns true if the texture was found and bound; +// Returns true if the texture was found and bound; // returns false otherwise. -bool MTextureCache::bind(MObject textureObj, - MTexture::Type type /* = MTexture::RGBA */, - bool mipmapped /* = true */, - GLenum target /* = GL_TEXTURE_2D */) +bool MTextureCache::bind(MObject textureObj, MTexture::Type type /* = MTexture::RGBA */, bool mipmapped /* = true */, + GLenum target /* = GL_TEXTURE_2D */) { - // Get a reference to the texture, allocating it if necessary. - MTexture* pTex = texture(textureObj, type, mipmapped, target); - - if (pTex) - { - // bind the texture. - pTex->bind(); - - return true; - } - - return false; + // Get a reference to the texture, allocating it if necessary. + MTexture* pTex = texture(textureObj, type, mipmapped, target); + + if (pTex) { + // bind the texture. + pTex->bind(); + + return true; + } + + return false; } void MTextureCache::onNodeRenamed(MObject& node, MString oldName, MString newName) { - // Remove the texture from the cache. - MTextureCacheElement *texCacheElement = m_textureTable[oldName.asChar()]; - xr_delete(texCacheElement->m_texture); - texCacheElement->m_texture = NULL; + // Remove the texture from the cache. + MTextureCacheElement* texCacheElement = m_textureTable[oldName.asChar()]; + xr_delete(texCacheElement->m_texture); + texCacheElement->m_texture = NULL; } void MTextureCache::incrementTimestamp(unsigned int increment /* = 1 */) { - m_currentTimestamp += increment; - - // Optionally, go through all textures and get rid of each of them that - // is too old. + m_currentTimestamp += increment; + + // Optionally, go through all textures and get rid of each of them that + // is too old. } diff --git a/src/plugins/Maya/Material/MTextureCache.h b/src/plugins/Maya/Material/MTextureCache.h index 91f43be19bb..9d0af497acf 100644 --- a/src/plugins/Maya/Material/MTextureCache.h +++ b/src/plugins/Maya/Material/MTextureCache.h @@ -1,10 +1,9 @@ #ifndef MAYA_API_MTextureCache #define MAYA_API_MTextureCache - /////////////////////////////////////////////////////////////////// // DESCRIPTION: Texture cache, used to temporarily store textures. -// Eventually, this class will likely end up in the +// Eventually, this class will likely end up in the // Maya API. // // This class is not currently thread-safe. @@ -14,39 +13,37 @@ /////////////////////////////////////////////////////////////////// #ifdef WIN32 -#pragma warning( disable : 4786 ) // Disable stupid STL warnings. +#pragma warning(disable : 4786) // Disable stupid STL warnings. #endif -#include +#include #include +#include #include -#include #include "MTexture.h" #include "NodeMonitor.h" - class MTextureCache; class MTextureCacheElement { -friend class MTextureCache; + friend class MTextureCache; public: - MTextureCacheElement() - { - lastAccessedTimestamp = -1; - m_texture = NULL; - } - - ~MTextureCacheElement(); + MTextureCacheElement() + { + lastAccessedTimestamp = -1; + m_texture = NULL; + } - MTexture* texture() { return m_texture; } + ~MTextureCacheElement(); + MTexture* texture() { return m_texture; } private: - MTexture* m_texture; - unsigned int lastAccessedTimestamp; // can be used to track when the texture was last used. - NodeMonitor fMonitor; + MTexture* m_texture; + unsigned int lastAccessedTimestamp; // can be used to track when the texture was last used. + NodeMonitor fMonitor; }; // This class implements a singleton node with reference counting. @@ -58,71 +55,60 @@ friend class MTextureCache; class MTextureCache : public NodeMonitorManager { protected: -// MTextureCache() -// { -// m_currentTimestamp = 0; -// } + // MTextureCache() + // { + // m_currentTimestamp = 0; + // } public: - MTextureCache() - { - m_currentTimestamp = 0; - } - ~MTextureCache(); - - static MTextureCache* instance() - { - if (!m_instance) - { - m_instance = xr_new(); - } - - refcount++; - - return m_instance; - } - - static void release() - { - assert(m_instance); - - refcount--; - - if (refcount == 0 && m_instance) - { - xr_delete(m_instance); - m_instance = NULL; - } - } - - // Return a reference to the texture. There's no reference counting yet. - MTexture* texture(MObject textureObj, - MTexture::Type type = MTexture::RGBA, - bool mipmapped = true, - GLenum target = GL_TEXTURE_2D); - - // Returns true if the texture was found and bound; returns false otherwise. - bool bind(MObject textureObj, - MTexture::Type type = MTexture::RGBA, - bool mipmapped = true, - GLenum target = GL_TEXTURE_2D); - - void incrementTimestamp(unsigned int increment=1); - - // Called by a node monitor when the watched node is renamed. - void onNodeRenamed(MObject& node, MString oldName, MString newName); + MTextureCache() { m_currentTimestamp = 0; } + ~MTextureCache(); -private: - static int refcount; + static MTextureCache* instance() + { + if (!m_instance) { + m_instance = xr_new(); + } - xr_map m_textureTable; - typedef xr_map string_to_cacheElement_map; + refcount++; - unsigned int m_currentTimestamp; + return m_instance; + } - static MTextureCache* m_instance; -}; + static void release() + { + assert(m_instance); + + refcount--; + if (refcount == 0 && m_instance) { + xr_delete(m_instance); + m_instance = NULL; + } + } + // Return a reference to the texture. There's no reference counting yet. + MTexture* texture( + MObject textureObj, MTexture::Type type = MTexture::RGBA, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); + + // Returns true if the texture was found and bound; returns false otherwise. + bool bind( + MObject textureObj, MTexture::Type type = MTexture::RGBA, bool mipmapped = true, GLenum target = GL_TEXTURE_2D); + + void incrementTimestamp(unsigned int increment = 1); + + // Called by a node monitor when the watched node is renamed. + void onNodeRenamed(MObject& node, MString oldName, MString newName); + +private: + static int refcount; + + xr_map m_textureTable; + typedef xr_map string_to_cacheElement_map; + + unsigned int m_currentTimestamp; + + static MTextureCache* m_instance; +}; -#endif // MAYA_API_MTextureCache \ No newline at end of file +#endif // MAYA_API_MTextureCache \ No newline at end of file diff --git a/src/plugins/Maya/Material/NodeMonitor.cpp b/src/plugins/Maya/Material/NodeMonitor.cpp index 718b4a29a1b..926cdddf716 100644 --- a/src/plugins/Maya/Material/NodeMonitor.cpp +++ b/src/plugins/Maya/Material/NodeMonitor.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////// -// DESCRIPTION: This class monitors a given node. +// DESCRIPTION: This class monitors a given node. // // TODO: Take care of renamed nodes. // @@ -12,189 +12,176 @@ MObject getObjFromName(MString name, MStatus& stat) { - MObject obj; - - MSelectionList list; - - // Attempt to add the given name to the selection list, - // then get the corresponding dependency node handle. - if (!list.add(name) || - !list.getDependNode(0, obj)) - { - // Failed. - stat = MStatus::kInvalidParameter; - return obj; - } - - // Successful. - stat = MStatus::kSuccess; - return obj; + MObject obj; + + MSelectionList list; + + // Attempt to add the given name to the selection list, + // then get the corresponding dependency node handle. + if (!list.add(name) || !list.getDependNode(0, obj)) { + // Failed. + stat = MStatus::kInvalidParameter; + return obj; + } + + // Successful. + stat = MStatus::kSuccess; + return obj; } // If a problem occurs, this function returns an empty string. MString getNameFromObj(MObject obj) { - MString nodeName; - - // If this object is a MFnDagNode, we should store the dag name. - // Otherwise, use the MFnDependencyNode name. - if (obj.hasFn(MFn::kDagNode)) - { - MFnDagNode dagNode(obj); - nodeName = dagNode.fullPathName(); - } - else if (obj.hasFn(MFn::kDependencyNode)) - { - MFnDependencyNode node(obj); - nodeName = node.name(); - } - - return nodeName; + MString nodeName; + + // If this object is a MFnDagNode, we should store the dag name. + // Otherwise, use the MFnDependencyNode name. + if (obj.hasFn(MFn::kDagNode)) { + MFnDagNode dagNode(obj); + nodeName = dagNode.fullPathName(); + } + else if (obj.hasFn(MFn::kDependencyNode)) + { + MFnDependencyNode node(obj); + nodeName = node.name(); + } + + return nodeName; } - //----------------------------------------------------------- // Public interface: //----------------------------------------------------------- NodeMonitor::NodeMonitor(NodeMonitorManager* manager /* = NULL */) { - fNodeName = ""; - fIsDirty = false; - - fRenamedCallbackId = 0; - fDirtyCallbackId = 0; + fNodeName = ""; + fIsDirty = false; + + fRenamedCallbackId = 0; + fDirtyCallbackId = 0; - fManager = manager; + fManager = manager; } NodeMonitor::~NodeMonitor() { - stopWatching(); + stopWatching(); } bool NodeMonitor::watch(MString nodeName) { - // if already watching another object, release the callbacks. - stopWatching(); + // if already watching another object, release the callbacks. + stopWatching(); - fNodeName = nodeName; - return attachCallbacks(); + fNodeName = nodeName; + return attachCallbacks(); } bool NodeMonitor::watch(MObject nodeObj) { - MString newNodeName = getNameFromObj(nodeObj); + MString newNodeName = getNameFromObj(nodeObj); - // If already watching another object, release the callbacks. - stopWatching(); + // If already watching another object, release the callbacks. + stopWatching(); - // Get the name of the given object... since an MObject is not - // persistent. We'll use the name of the object to attach/re-attach - // callbacks when necessary. - if (newNodeName == "") - { - // This is bad. We've been given an invalid node object. - // return false to indicate that an error occured. + // Get the name of the given object... since an MObject is not + // persistent. We'll use the name of the object to attach/re-attach + // callbacks when necessary. + if (newNodeName == "") { + // This is bad. We've been given an invalid node object. + // return false to indicate that an error occured. - return false; - } + return false; + } - fNodeName = newNodeName; - return attachCallbacks(); + fNodeName = newNodeName; + return attachCallbacks(); } void NodeMonitor::stopWatching() { - if (fNodeName != "") - { - // Clean up the callbacks - detachCallbacks(); - - fNodeName = ""; - fIsDirty = false; - } + if (fNodeName != "") { + // Clean up the callbacks + detachCallbacks(); + + fNodeName = ""; + fIsDirty = false; + } } bool NodeMonitor::dirty() { - return fIsDirty; + return fIsDirty; } void NodeMonitor::cleanIt() { - if (dirty()) - { - // We have to re-attach the callback. - attachCallbacks(); - } + if (dirty()) { + // We have to re-attach the callback. + attachCallbacks(); + } - fIsDirty = false; + fIsDirty = false; } - //---------------------------------------------------------------- // Private interface: //---------------------------------------------------------------- bool NodeMonitor::attachCallbacks() { - // Make sure that there are no callbacks currently enabled. - detachCallbacks(); - - MStatus stat; - MObject node = getObjFromName(fNodeName, stat); - if (!stat) - { - detachCallbacks(); - return false; - } - - fIsDirty = false; - - fDirtyCallbackId = MNodeMessage::addNodeDirtyCallback(node, watchedObjectDirtyCallback, this, &stat ); - if (stat) - { - fRenamedCallbackId = MNodeMessage::addNameChangedCallback (node, watchedObjectRenamedCallback, this, &stat); - } - - // If an error occured, detach any valid callback. - if (!stat) - { - detachCallbacks(); - return false; - } - - return true; + // Make sure that there are no callbacks currently enabled. + detachCallbacks(); + + MStatus stat; + MObject node = getObjFromName(fNodeName, stat); + if (!stat) { + detachCallbacks(); + return false; + } + + fIsDirty = false; + + fDirtyCallbackId = MNodeMessage::addNodeDirtyCallback(node, watchedObjectDirtyCallback, this, &stat); + if (stat) { + fRenamedCallbackId = MNodeMessage::addNameChangedCallback(node, watchedObjectRenamedCallback, this, &stat); + } + + // If an error occured, detach any valid callback. + if (!stat) { + detachCallbacks(); + return false; + } + + return true; } void NodeMonitor::detachCallbacks() { - MStatus stat; - - if (fDirtyCallbackId) - { - stat = MMessage::removeCallback(fDirtyCallbackId); - assert(stat); - } - - if (fRenamedCallbackId) - { - stat = MMessage::removeCallback(fRenamedCallbackId); - assert(stat); - } - - fRenamedCallbackId = 0; - fDirtyCallbackId = 0; + MStatus stat; + + if (fDirtyCallbackId) { + stat = MMessage::removeCallback(fDirtyCallbackId); + assert(stat); + } + + if (fRenamedCallbackId) { + stat = MMessage::removeCallback(fRenamedCallbackId); + assert(stat); + } + + fRenamedCallbackId = 0; + fDirtyCallbackId = 0; } void NodeMonitor::callbackOccured() { - fIsDirty = true; + fIsDirty = true; - // Detach the callback so that we don't get called needlessly. We'll - // re-attach when the dirty bit is read back. - detachCallbacks(); + // Detach the callback so that we don't get called needlessly. We'll + // re-attach when the dirty bit is read back. + detachCallbacks(); } // Callback functions. Those are called, respectively, when a node is dirty (has changed substantially), @@ -202,22 +189,21 @@ void NodeMonitor::callbackOccured() /*static*/ void NodeMonitor::watchedObjectDirtyCallback(void* clientData) { - NodeMonitor* pMon = (NodeMonitor*) clientData; + NodeMonitor* pMon = (NodeMonitor*)clientData; - pMon->callbackOccured(); + pMon->callbackOccured(); } -/*static*/ void NodeMonitor::watchedObjectRenamedCallback(MObject & node, void* clientData) +/*static*/ void NodeMonitor::watchedObjectRenamedCallback(MObject& node, void* clientData) { - NodeMonitor* pMon = (NodeMonitor*) clientData; + NodeMonitor* pMon = (NodeMonitor*)clientData; + + // Get the new name of the node, and use it from now on. + MString oldName = pMon->fNodeName; + pMon->fNodeName = getNameFromObj(node); - // Get the new name of the node, and use it from now on. - MString oldName = pMon->fNodeName; - pMon->fNodeName = getNameFromObj(node); - - // Call the manager, if there's one. - if (pMon->fManager != NULL) - pMon->fManager->onNodeRenamed(node, oldName, pMon->fNodeName); + // Call the manager, if there's one. + if (pMon->fManager != NULL) pMon->fManager->onNodeRenamed(node, oldName, pMon->fNodeName); - pMon->callbackOccured(); + pMon->callbackOccured(); } diff --git a/src/plugins/Maya/Material/NodeMonitor.h b/src/plugins/Maya/Material/NodeMonitor.h index c41da8cf5c4..7f625bdffff 100644 --- a/src/plugins/Maya/Material/NodeMonitor.h +++ b/src/plugins/Maya/Material/NodeMonitor.h @@ -11,11 +11,11 @@ #include #include -#include #include #include #include #include +#include MObject getObjFromName(MString name, MStatus& stat); @@ -27,50 +27,47 @@ MString getNameFromObj(MObject obj); class NodeMonitorManager { public: - virtual void onNodeRenamed(MObject& node, MString oldName, MString newName) = 0; + virtual void onNodeRenamed(MObject& node, MString oldName, MString newName) = 0; }; class NodeMonitor { public: - NodeMonitor(NodeMonitorManager* manager = NULL); - - ~NodeMonitor(); + NodeMonitor(NodeMonitorManager* manager = NULL); - bool watch(MString nodeName); - bool watch(MObject nodeObj); + ~NodeMonitor(); - void stopWatching(); + bool watch(MString nodeName); + bool watch(MObject nodeObj); - bool dirty(); + void stopWatching(); - void cleanIt(); + bool dirty(); - void setManager(NodeMonitorManager* manager) { fManager = manager; } + void cleanIt(); + void setManager(NodeMonitorManager* manager) { fManager = manager; } private: - bool attachCallbacks(); + bool attachCallbacks(); - void detachCallbacks(); + void detachCallbacks(); - void callbackOccured(); + void callbackOccured(); - // Callback functions. Those are called, respectively, when a node is dirty (has changed substantially), - // or when a node is renamed. - static void watchedObjectDirtyCallback(void* clientData); - - static void watchedObjectRenamedCallback(MObject & node, void* clientData); + // Callback functions. Those are called, respectively, when a node is dirty (has changed substantially), + // or when a node is renamed. + static void watchedObjectDirtyCallback(void* clientData); + static void watchedObjectRenamedCallback(MObject& node, void* clientData); private: - MString fNodeName; - bool fIsDirty; + MString fNodeName; + bool fIsDirty; - MCallbackId fRenamedCallbackId; - MCallbackId fDirtyCallbackId; + MCallbackId fRenamedCallbackId; + MCallbackId fDirtyCallbackId; - NodeMonitorManager* fManager; + NodeMonitorManager* fManager; }; - -#endif // MAYA_ShadingConnection \ No newline at end of file +#endif // MAYA_ShadingConnection \ No newline at end of file diff --git a/src/plugins/Maya/Material/ShadingConnection.cpp b/src/plugins/Maya/Material/ShadingConnection.cpp index 0779e749ac0..f38ba594ec8 100644 --- a/src/plugins/Maya/Material/ShadingConnection.cpp +++ b/src/plugins/Maya/Material/ShadingConnection.cpp @@ -12,180 +12,176 @@ ShadingConnection::ShadingConnection(MObject shaderObj, MString shapeName, MString attribute /* = "" */) { - // Store those input values for later use. - this->m_shaderObj = shaderObj; - this->m_shapeName = shapeName; + // Store those input values for later use. + this->m_shaderObj = shaderObj; + this->m_shapeName = shapeName; - // By default, the connection is direct until proven otherwise. - this->m_directConnection = true; + // By default, the connection is direct until proven otherwise. + this->m_directConnection = true; - if (attribute != "") - traverseAttribute(attribute); + if (attribute != "") traverseAttribute(attribute); } ShadingConnection::TYPE ShadingConnection::traverseAttribute(MString attributeName) { - // Get a plug to the attribute. - MStatus status; - MFnDependencyNode shaderNode(m_shaderObj); + // Get a plug to the attribute. + MStatus status; + MFnDependencyNode shaderNode(m_shaderObj); - MPlug plug = shaderNode.findPlug( attributeName, &status ); - assert(status); + MPlug plug = shaderNode.findPlug(attributeName, &status); + assert(status); - this->m_attributeName = attributeName; + this->m_attributeName = attributeName; - return analyzePlug(plug); + return analyzePlug(plug); } - + ShadingConnection::TYPE ShadingConnection::analyzePlug(MPlug plug) { - MStatus status; - - // Find all incoming connections. - MPlugArray connectedElements; - plug.connectedTo( connectedElements, true, false, &status ); - assert(status); - - if (connectedElements.length() == 0) - { - // It's a constant color... set it now and return. - unsigned int numChildren = plug.numChildren(); - assert(numChildren == 3); - - float red, green, blue; - plug.child(0).getValue(red); - plug.child(1).getValue(green); - plug.child(2).getValue(blue); - - return setConstantColor(MColor(red, green, blue, 1.0)); - } - - // The plug is actually connected on a different shading node. - MObject connectedObject = connectedElements[0].node(&status); - assert(status); - - // If this is a triple shading switch, go through it. - if (connectedObject.hasFn(MFn::kTripleShadingSwitch)) - { - return traverseTripleShadingSwitch(connectedObject); - } - - // Set the object and return the appropriate type. - return setTexture(connectedObject); + MStatus status; + + // Find all incoming connections. + MPlugArray connectedElements; + plug.connectedTo(connectedElements, true, false, &status); + assert(status); + + if (connectedElements.length() == 0) { + // It's a constant color... set it now and return. + unsigned int numChildren = plug.numChildren(); + assert(numChildren == 3); + + float red, green, blue; + plug.child(0).getValue(red); + plug.child(1).getValue(green); + plug.child(2).getValue(blue); + + return setConstantColor(MColor(red, green, blue, 1.0)); + } + + // The plug is actually connected on a different shading node. + MObject connectedObject = connectedElements[0].node(&status); + assert(status); + + // If this is a triple shading switch, go through it. + if (connectedObject.hasFn(MFn::kTripleShadingSwitch)) { + return traverseTripleShadingSwitch(connectedObject); + } + + // Set the object and return the appropriate type. + return setTexture(connectedObject); } ShadingConnection::TYPE ShadingConnection::traverseTripleShadingSwitch(MObject connectedObject) -{ - // The connection cannot be direct anymore. - m_directConnection = false; - - MFnDependencyNode node(connectedObject); - - MStatus status; - MPlug inputPlug = node.findPlug( "input" ); - - unsigned int numElements = inputPlug.numElements(); - unsigned int numChildren = inputPlug.numChildren(); - - // It is assumed that the first child of this input compound attribute is - // a "inTexture" attribute and the the second child is the inShape attribute. - // This assumption should always be safe, unless some drastic changes occured in the - // implementation of the shading switches... in which case this code won't work, so - // we would throw an exception. - assert( numChildren >= 2); // "Abnormal hierarchy in switching node." - - // Go through each row of the switch table. - for (unsigned int index = 0; index < numElements; index++) - { - MPlug inTexturePlug = inputPlug.elementByPhysicalIndex(index).child(0); - MPlug inShapePlug = inputPlug.elementByPhysicalIndex(index).child(1); - - MPlugArray inShapeConnections; - inShapePlug.connectedTo( inShapeConnections, true, false, &status ); - - // Check if one of the corresponding shapes matches the given shape name. - unsigned int numCorrespondingShapes = inShapeConnections.length(); - for (unsigned int shapeNum = 0; shapeNum < numCorrespondingShapes; shapeNum++) - { - MObject inShapeObj = inShapeConnections[0].node(&status); - assert(status); - - MFnDependencyNode inShape(inShapeObj); - MString inShapeName = inShape.name(); - - if (inShapeName == m_shapeName) - return analyzePlug(inTexturePlug); - } - } - - // If there was no special case in the switch for our shape, check the default. - MPlug defaultPlug = node.findPlug("default"); - return analyzePlug(defaultPlug); +{ + // The connection cannot be direct anymore. + m_directConnection = false; + + MFnDependencyNode node(connectedObject); + + MStatus status; + MPlug inputPlug = node.findPlug("input"); + + unsigned int numElements = inputPlug.numElements(); + unsigned int numChildren = inputPlug.numChildren(); + + // It is assumed that the first child of this input compound attribute is + // a "inTexture" attribute and the the second child is the inShape attribute. + // This assumption should always be safe, unless some drastic changes occured in the + // implementation of the shading switches... in which case this code won't work, so + // we would throw an exception. + assert(numChildren >= 2); // "Abnormal hierarchy in switching node." + + // Go through each row of the switch table. + for (unsigned int index = 0; index < numElements; index++) + { + MPlug inTexturePlug = inputPlug.elementByPhysicalIndex(index).child(0); + MPlug inShapePlug = inputPlug.elementByPhysicalIndex(index).child(1); + + MPlugArray inShapeConnections; + inShapePlug.connectedTo(inShapeConnections, true, false, &status); + + // Check if one of the corresponding shapes matches the given shape name. + unsigned int numCorrespondingShapes = inShapeConnections.length(); + for (unsigned int shapeNum = 0; shapeNum < numCorrespondingShapes; shapeNum++) + { + MObject inShapeObj = inShapeConnections[0].node(&status); + assert(status); + + MFnDependencyNode inShape(inShapeObj); + MString inShapeName = inShape.name(); + + if (inShapeName == m_shapeName) return analyzePlug(inTexturePlug); + } + } + + // If there was no special case in the switch for our shape, check the default. + MPlug defaultPlug = node.findPlug("default"); + return analyzePlug(defaultPlug); } ShadingConnection::TYPE ShadingConnection::type() { - return m_type; + return m_type; } MColor ShadingConnection::constantColor() { - assert(m_type == CONSTANT_COLOR); - return m_constantColor; + assert(m_type == CONSTANT_COLOR); + return m_constantColor; } MObject ShadingConnection::texture() { - assert(m_type == TEXTURE); - return m_texture; + assert(m_type == TEXTURE); + return m_texture; } MObject ShadingConnection::shaderObj() { - return m_shaderObj; + return m_shaderObj; } MString ShadingConnection::shaderName() { - MStatus stat; - MFnDependencyNode shaderNode(m_shaderObj, &stat); - assert(stat); - return shaderNode.name(); + MStatus stat; + MFnDependencyNode shaderNode(m_shaderObj, &stat); + assert(stat); + return shaderNode.name(); } MString ShadingConnection::attributeName() { - return m_attributeName; + return m_attributeName; } MString ShadingConnection::shapeName() { - return m_shapeName; + return m_shapeName; } ShadingConnection::TYPE ShadingConnection::setConstantColor(MColor col) { - m_constantColor = col; - m_type = CONSTANT_COLOR; + m_constantColor = col; + m_type = CONSTANT_COLOR; - // Reset m_texture to prevent misinterpretation. - m_texture = MObject(); + // Reset m_texture to prevent misinterpretation. + m_texture = MObject(); - return m_type; + return m_type; } ShadingConnection::TYPE ShadingConnection::setTexture(MObject texture) { - m_texture = texture; - m_type = TEXTURE; + m_texture = texture; + m_type = TEXTURE; - // Reset m_color to prevent misinterpretation. - m_constantColor = MColor(); + // Reset m_color to prevent misinterpretation. + m_constantColor = MColor(); - return m_type; + return m_type; } bool ShadingConnection::isDirectConnection() { - return m_directConnection; + return m_directConnection; } diff --git a/src/plugins/Maya/Material/ShadingConnection.h b/src/plugins/Maya/Material/ShadingConnection.h index 3c0f0fc3806..8ba5a7f56ea 100644 --- a/src/plugins/Maya/Material/ShadingConnection.h +++ b/src/plugins/Maya/Material/ShadingConnection.h @@ -6,18 +6,18 @@ // a shader's attribute, including what's connected upstream of it. // It also automatically passes through shader switches. // -// The ShadingConnection is a helper class that stores useful information +// The ShadingConnection is a helper class that stores useful information // about a shader's attribute, including what's connected upstream of it. // // It can: -// Traverse upstream until it finds if the connection is ultimately -// on a constant color, or a shading object. This process goes through +// Traverse upstream until it finds if the connection is ultimately +// on a constant color, or a shading object. This process goes through // shading switches if it encounters some. The object/color found is called // the "target". // // At the end of this process, the following information is stored: -// 1. Target type: whether or not the connection ends up on a shading -// object (for example: file texture), or a constant +// 1. Target type: whether or not the connection ends up on a shading +// object (for example: file texture), or a constant // color (ex: bright red). // 2. Target identity: either the color, or the target object itself. Note // that the caller is responsible to first check the type @@ -37,54 +37,50 @@ class ShadingConnection { public: - enum TYPE - { - CONSTANT_COLOR, - TEXTURE - }; + enum TYPE + { + CONSTANT_COLOR, + TEXTURE + }; - ShadingConnection(MObject shaderObj, MString shapeName, MString attribute = ""); + ShadingConnection(MObject shaderObj, MString shapeName, MString attribute = ""); - TYPE traverseAttribute(MString attributeName); - - TYPE analyzePlug(MPlug plug); - - TYPE traverseTripleShadingSwitch(MObject connectedObject); + TYPE traverseAttribute(MString attributeName); - TYPE type(); + TYPE analyzePlug(MPlug plug); - MColor constantColor(); + TYPE traverseTripleShadingSwitch(MObject connectedObject); - MObject texture(); + TYPE type(); - MObject shaderObj(); + MColor constantColor(); - MString shaderName(); + MObject texture(); - MString attributeName(); + MObject shaderObj(); - MString shapeName(); + MString shaderName(); - TYPE setConstantColor(MColor col); - TYPE setTexture(MObject texture); + MString attributeName(); - bool isDirectConnection(); + MString shapeName(); - -private: - // Input - MObject m_shaderObj; - MString m_attributeName; - MString m_shapeName; - - // Output - TYPE m_type; - MColor m_constantColor; - MObject m_texture; - bool m_directConnection; + TYPE setConstantColor(MColor col); + TYPE setTexture(MObject texture); + bool isDirectConnection(); +private: + // Input + MObject m_shaderObj; + MString m_attributeName; + MString m_shapeName; + + // Output + TYPE m_type; + MColor m_constantColor; + MObject m_texture; + bool m_directConnection; }; - -#endif // MAYA_ShadingConnection \ No newline at end of file +#endif // MAYA_ShadingConnection \ No newline at end of file diff --git a/src/plugins/Maya/Material/Stdafx.h b/src/plugins/Maya/Material/Stdafx.h index 5fb7ab59bf0..b7b2cc257cf 100644 --- a/src/plugins/Maya/Material/Stdafx.h +++ b/src/plugins/Maya/Material/Stdafx.h @@ -6,58 +6,58 @@ #pragma once -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0500 #include "xrCore/xrCore.h" #pragma comment(lib, "xrCore.lib") #include #pragma warning(push) -#pragma warning(disable:4995) +#pragma warning(disable : 4995) #define REQUIRE_IOSTREAM -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include +#include +#include #include +#include #include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -67,32 +67,52 @@ #define ENGINE_API #define ECORE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; #pragma warning(push) -#pragma warning(disable:4995) -#include "plugins/Shared/ELog.h" +#pragma warning(disable : 4995) #include -#include #include +#include +#include "plugins/Shared/ELog.h" #pragma warning(pop) #define AnsiString std::string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #define THROW R_ASSERT(0) #ifdef _MAYA_EXPORT - #define _EDITOR_FILE_NAME_ "maya_export" +#define _EDITOR_FILE_NAME_ "maya_export" #else - #ifdef _MAYA_MATERIAL - #define _EDITOR_FILE_NAME_ "maya_material" - #endif +#ifdef _MAYA_MATERIAL +#define _EDITOR_FILE_NAME_ "maya_material" +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" #endif /*_INCDEF_STDAFX_H_*/ \ No newline at end of file diff --git a/src/plugins/Maya/Material/crc16.cpp b/src/plugins/Maya/Material/crc16.cpp index 16c174b2b7d..087e1217f00 100644 --- a/src/plugins/Maya/Material/crc16.cpp +++ b/src/plugins/Maya/Material/crc16.cpp @@ -14,57 +14,56 @@ gen16(0) will create table for CRC16 gen16(1) for CCITT and start crc at -1 for SDLC */ -static BOOL crc16_ready = FALSE; -static int crc16_table [256]; // Lookup table array +static BOOL crc16_ready = FALSE; +static int crc16_table[256]; // Lookup table array -int gen_tab[2][8] = { - { 0xC0C1, 0xC181, 0xC301, 0xC601, 0xCC01, 0xD801, 0xF001, 0xA001 }, - { 0x1189, 0x2312, 0x4624, 0x8C48, 0x1081, 0x2102, 0x4204, 0x8408 } -}; +int gen_tab[2][8] = {{0xC0C1, 0xC181, 0xC301, 0xC601, 0xCC01, 0xD801, 0xF001, 0xA001}, + {0x1189, 0x2312, 0x4624, 0x8C48, 0x1081, 0x2102, 0x4204, 0x8408}}; -void crc16_init(unsigned p) +void crc16_init(unsigned p) { - int i, j, val; + int i, j, val; - for (i = 0; i < 256; i++) { - val = 0; - for (j = 0; j < 8; j++) - if (i & (1< 0 && argv[0][0] == '-') { - if (argv[0][1] == 'c') { - poly = 1; - init = 0; - } - if (argv[0][1] == 's') { - poly = 1; - init = -1; - } - argc--; argv++; - } - else { - poly = 0; - init = 0; - } - if (argc < 1) - usage(); - gen16(poly); - while (argc) { - while (findfile(fname, *argv, 0)) { - fd = open(fname, O_RDONLY | O_BINARY); - if (fd == -1) - break; - crc = init; - do { - n = read(fd, buffer[0], sizeof(buffer)); - crc = crc16(buffer[0], n, crc); - } while (n == sizeof(buffer)); - close(fd); - printf("crc of %s is %04X\n", fname, crc); - } - argc--; argv++; - } - return 0; + argc--; argv++; + if (argv > 0 && argv[0][0] == '-') { + if (argv[0][1] == 'c') { + poly = 1; + init = 0; + } + if (argv[0][1] == 's') { + poly = 1; + init = -1; + } + argc--; argv++; + } + else { + poly = 0; + init = 0; + } + if (argc < 1) + usage(); + gen16(poly); + while (argc) { + while (findfile(fname, *argv, 0)) { + fd = open(fname, O_RDONLY | O_BINARY); + if (fd == -1) + break; + crc = init; + do { + n = read(fd, buffer[0], sizeof(buffer)); + crc = crc16(buffer[0], n, crc); + } while (n == sizeof(buffer)); + close(fd); + printf("crc of %s is %04X\n", fname, crc); + } + argc--; argv++; + } + return 0; } */ \ No newline at end of file diff --git a/src/plugins/Maya/Material/hwUnlitShader.cpp b/src/plugins/Maya/Material/hwUnlitShader.cpp index c21a07e149d..af71b7c059b 100644 --- a/src/plugins/Maya/Material/hwUnlitShader.cpp +++ b/src/plugins/Maya/Material/hwUnlitShader.cpp @@ -8,7 +8,7 @@ // 2. Window->Setting/Preferences->Plug-in Manager. // Make sure that the CXRayMtl.mll plug-in is there // and click the "loaded" checkbox next to it to load it. -// 3. Create a new scene. +// 3. Create a new scene. // 4. Create a poly object (say, a polygon cube). // 5. Create a new CXRayMtl. You can use the hypershade, or // right-click on the cube and select Material->Create new Material->CXRayMtl. @@ -26,7 +26,7 @@ // and to set the transparency value to a color different than black. // This forces Maya to properly order geometry from farthest to closest. // This shader illustrates both the workaround (the transparency attributes -// illustrated in initialize() below) and the recommended way (overloading +// illustrated in initialize() below) and the recommended way (overloading // hasTransparency() to return true). If you do not need to support // earlier versions of Maya, or do not need transparency, then there is // no need to create the transparency attributes. @@ -38,260 +38,249 @@ using namespace std; #ifdef WIN32 -#pragma warning( disable : 4786 ) // Disable stupid STL warnings. +#pragma warning(disable : 4786) // Disable stupid STL warnings. #endif -#include "hwUnlitShader.h" #include "ShadingConnection.h" +#include "hwUnlitShader.h" #include "BlenderListLoader.h" - -// Plug-in ID and Attributes. +// Plug-in ID and Attributes. // This ID needs to be unique to prevent clashes. // -MTypeId CXRayMtl::id( 0x00105440 ); - -MObject CXRayMtl::color; -MObject CXRayMtl::colorR; -MObject CXRayMtl::colorG; -MObject CXRayMtl::colorB; - -MObject CXRayMtl::xrDoubleSide; -MObject CXRayMtl::xrEngineData; -MObject CXRayMtl::xrCompilerData; -MObject CXRayMtl::xrMaterialData; - -MObject CXRayMtl::transparency; -MObject CXRayMtl::transparencyR; -MObject CXRayMtl::transparencyG; -MObject CXRayMtl::transparencyB; - - -#define MAKE_INPUT(attr) \ - CHECK_MSTATUS ( attr.setKeyable(true) ); \ - CHECK_MSTATUS ( attr.setStorable(true) ); \ - CHECK_MSTATUS ( attr.setReadable(true) ); \ - CHECK_MSTATUS ( attr.setWritable(true) ); - -#define MAKE_OUTPUT(attr) \ - CHECK_MSTATUS ( attr.setKeyable(false) ) ; \ - CHECK_MSTATUS ( attr.setStorable(false) ); \ - CHECK_MSTATUS ( attr.setReadable(true) ) ; \ - CHECK_MSTATUS ( attr.setWritable(false) ); - -void CXRayMtl::postConstructor( ) +MTypeId CXRayMtl::id(0x00105440); + +MObject CXRayMtl::color; +MObject CXRayMtl::colorR; +MObject CXRayMtl::colorG; +MObject CXRayMtl::colorB; + +MObject CXRayMtl::xrDoubleSide; +MObject CXRayMtl::xrEngineData; +MObject CXRayMtl::xrCompilerData; +MObject CXRayMtl::xrMaterialData; + +MObject CXRayMtl::transparency; +MObject CXRayMtl::transparencyR; +MObject CXRayMtl::transparencyG; +MObject CXRayMtl::transparencyB; + +#define MAKE_INPUT(attr) \ + CHECK_MSTATUS(attr.setKeyable(true)); \ + CHECK_MSTATUS(attr.setStorable(true)); \ + CHECK_MSTATUS(attr.setReadable(true)); \ + CHECK_MSTATUS(attr.setWritable(true)); + +#define MAKE_OUTPUT(attr) \ + CHECK_MSTATUS(attr.setKeyable(false)); \ + CHECK_MSTATUS(attr.setStorable(false)); \ + CHECK_MSTATUS(attr.setReadable(true)); \ + CHECK_MSTATUS(attr.setWritable(false)); + +void CXRayMtl::postConstructor() { - setMPSafe(false); + setMPSafe(false); } CXRayMtl::CXRayMtl() { - m_pTextureCache = MTextureCache::instance(); + m_pTextureCache = MTextureCache::instance(); - attachSceneCallbacks(); + attachSceneCallbacks(); } CXRayMtl::~CXRayMtl() { - detachSceneCallbacks(); + detachSceneCallbacks(); } void CXRayMtl::releaseEverything() { - // Clean the texture cache, through refcounting. - m_pTextureCache->release(); + // Clean the texture cache, through refcounting. + m_pTextureCache->release(); } void CXRayMtl::attachSceneCallbacks() { - fBeforeNewCB = MSceneMessage::addCallback(MSceneMessage::kBeforeNew, releaseCallback, this); - fBeforeOpenCB = MSceneMessage::addCallback(MSceneMessage::kBeforeOpen, releaseCallback, this); - fBeforeRemoveReferenceCB = MSceneMessage::addCallback(MSceneMessage::kBeforeRemoveReference, - releaseCallback, this); - fMayaExitingCB = MSceneMessage::addCallback(MSceneMessage::kMayaExiting, releaseCallback, this); + fBeforeNewCB = MSceneMessage::addCallback(MSceneMessage::kBeforeNew, releaseCallback, this); + fBeforeOpenCB = MSceneMessage::addCallback(MSceneMessage::kBeforeOpen, releaseCallback, this); + fBeforeRemoveReferenceCB = MSceneMessage::addCallback(MSceneMessage::kBeforeRemoveReference, releaseCallback, this); + fMayaExitingCB = MSceneMessage::addCallback(MSceneMessage::kMayaExiting, releaseCallback, this); } /*static*/ void CXRayMtl::releaseCallback(void* clientData) { - CXRayMtl *pThis = (CXRayMtl*) clientData; - pThis->releaseEverything(); + CXRayMtl* pThis = (CXRayMtl*)clientData; + pThis->releaseEverything(); } void CXRayMtl::detachSceneCallbacks() { - if (fBeforeNewCB) - MMessage::removeCallback(fBeforeNewCB); - if (fBeforeOpenCB) - MMessage::removeCallback(fBeforeOpenCB); - if (fBeforeRemoveReferenceCB) - MMessage::removeCallback(fBeforeRemoveReferenceCB); - if (fMayaExitingCB) - MMessage::removeCallback(fMayaExitingCB); - - fBeforeNewCB = 0; - fBeforeOpenCB = 0; - fBeforeRemoveReferenceCB = 0; - fMayaExitingCB = 0; + if (fBeforeNewCB) MMessage::removeCallback(fBeforeNewCB); + if (fBeforeOpenCB) MMessage::removeCallback(fBeforeOpenCB); + if (fBeforeRemoveReferenceCB) MMessage::removeCallback(fBeforeRemoveReferenceCB); + if (fMayaExitingCB) MMessage::removeCallback(fMayaExitingCB); + + fBeforeNewCB = 0; + fBeforeOpenCB = 0; + fBeforeRemoveReferenceCB = 0; + fMayaExitingCB = 0; } - -void * CXRayMtl::creator() +void* CXRayMtl::creator() { - return xr_new(); + return xr_new(); } -MStatus initializePlugin( MObject obj ) -{ - MStatus status; - - const MString UserClassify( "shader/surface/utility" ); - - MFnPlugin plugin( obj, "GSC Game World", "1.0.0", "Any"); - status = plugin.registerNode( "XRayMtl", CXRayMtl::id, - CXRayMtl::creator, CXRayMtl::initialize, - MPxNode::kHwShaderNode, &UserClassify ); - if (!status) { - status.perror("registerNode"); - return status; - } - - return MS::kSuccess; +MStatus initializePlugin(MObject obj) +{ + MStatus status; + + const MString UserClassify("shader/surface/utility"); + + MFnPlugin plugin(obj, "GSC Game World", "1.0.0", "Any"); + status = plugin.registerNode( + "XRayMtl", CXRayMtl::id, CXRayMtl::creator, CXRayMtl::initialize, MPxNode::kHwShaderNode, &UserClassify); + if (!status) { + status.perror("registerNode"); + return status; + } + + return MS::kSuccess; } -MStatus uninitializePlugin( MObject obj ) +MStatus uninitializePlugin(MObject obj) { - MStatus status; - - MFnPlugin plugin( obj ); + MStatus status; - plugin.deregisterNode( CXRayMtl::id ); - if (!status) { - status.perror("deregisterNode"); - return status; - } + MFnPlugin plugin(obj); - return MS::kSuccess; + plugin.deregisterNode(CXRayMtl::id); + if (!status) { + status.perror("deregisterNode"); + return status; + } + + return MS::kSuccess; } -extern unsigned crc16_calc(unsigned char *data, unsigned count, unsigned old_crc=0); +extern unsigned crc16_calc(unsigned char* data, unsigned count, unsigned old_crc = 0); MStatus CXRayMtl::initialize() { - Core._initialize("XRayPlugin",ELogCallback,FALSE); - FS._initialize (CLocatorAPI::flScanAppRoot); + Core._initialize("XRayPlugin", ELogCallback, FALSE); + FS._initialize(CLocatorAPI::flScanAppRoot); - MFnNumericAttribute nAttr; - MStatus status; - MFnTypedAttribute sAttr; // For string attributes - MFnEnumAttribute eAttr; + MFnNumericAttribute nAttr; + MStatus status; + MFnTypedAttribute sAttr; // For string attributes + MFnEnumAttribute eAttr; - // Create COLOR input attributes - colorR = nAttr.create( "colorR", "cr",MFnNumericData::kFloat); + // Create COLOR input attributes + colorR = nAttr.create("colorR", "cr", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(1.0f); - colorG = nAttr.create( "colorG", "cg",MFnNumericData::kFloat); + colorG = nAttr.create("colorG", "cg", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(0.5f); - colorB = nAttr.create( "colorB", "cb",MFnNumericData::kFloat); + colorB = nAttr.create("colorB", "cb", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(0.5f); - color = nAttr.create( "color", "c", colorR, colorG, colorB); + color = nAttr.create("color", "c", colorR, colorG, colorB); nAttr.setStorable(true); nAttr.setKeyable(true); - nAttr.setDefault(1.0f, 0.5f, 0.5f); // ugly pink-salmon color. You can't miss it. + nAttr.setDefault(1.0f, 0.5f, 0.5f); // ugly pink-salmon color. You can't miss it. nAttr.setUsedAsColor(true); // Create TRANSPARENCY input attributes - transparencyR = nAttr.create( "transparencyR", "itr",MFnNumericData::kFloat); + transparencyR = nAttr.create("transparencyR", "itr", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(1.0f); - transparencyG = nAttr.create( "transparencyG", "itg",MFnNumericData::kFloat); + transparencyG = nAttr.create("transparencyG", "itg", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(0.5f); - transparencyB = nAttr.create( "transparencyB", "itb",MFnNumericData::kFloat); + transparencyB = nAttr.create("transparencyB", "itb", MFnNumericData::kFloat); nAttr.setStorable(true); nAttr.setKeyable(true); nAttr.setDefault(0.5f); - transparency = nAttr.create( "transparency", "it", transparencyR, transparencyG, transparencyB); + transparency = nAttr.create("transparency", "it", transparencyR, transparencyG, transparencyB); nAttr.setStorable(true); nAttr.setKeyable(true); - nAttr.setDefault(0.0001f, 0.0001f, 0.0001f); // very light gray. + nAttr.setDefault(0.0001f, 0.0001f, 0.0001f); // very light gray. nAttr.setUsedAsColor(true); - // Add the attributes here + // Add the attributes here addAttribute(color); addAttribute(transparency); - - // loading x-ray part - xrDoubleSide = eAttr.create( "xrayDoubleSide", "xrd"); - MAKE_INPUT(eAttr); - CHECK_MSTATUS (eAttr.addField("false",0)); - CHECK_MSTATUS (eAttr.addField("true",1)); - CHECK_MSTATUS (eAttr.setDefault(eAttr.fieldIndex("false"))); - - LPSTRVec lst; - LPSTRIt it; - xrEngineData = eAttr.create( "xrayEngineShader", "xre"); - MAKE_INPUT(eAttr); - LoadBlenderList(lst); - for (it=lst.begin(); it!=lst.end(); it++) - { - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); - ClearList(lst); - - xrCompilerData = eAttr.create( "xrayCompilerShader", "xrc"); - MAKE_INPUT(eAttr); - LoadShaderLCList(lst); - for (it=lst.begin(); it!=lst.end(); it++) - { - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); - ClearList(lst); - - xrMaterialData = eAttr.create( "xrayGameMaterial", " "); - MAKE_INPUT(eAttr); - LoadGameMtlList(lst); - for (it=lst.begin(); it!=lst.end(); it++) - { - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); - ClearList(lst); - - CHECK_MSTATUS ( addAttribute(xrDoubleSide) ); - CHECK_MSTATUS ( addAttribute(xrEngineData) ); - CHECK_MSTATUS ( addAttribute(xrCompilerData) ); - CHECK_MSTATUS ( addAttribute(xrMaterialData) ); - // end x-ray part -// create output attributes here - // outColor is the only output attribute and it is inherited - // so we do not need to create or add it. - // + // loading x-ray part + xrDoubleSide = eAttr.create("xrayDoubleSide", "xrd"); + MAKE_INPUT(eAttr); + CHECK_MSTATUS(eAttr.addField("false", 0)); + CHECK_MSTATUS(eAttr.addField("true", 1)); + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("false"))); + + LPSTRVec lst; + LPSTRIt it; + xrEngineData = eAttr.create("xrayEngineShader", "xre"); + MAKE_INPUT(eAttr); + LoadBlenderList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); + ClearList(lst); + + xrCompilerData = eAttr.create("xrayCompilerShader", "xrc"); + MAKE_INPUT(eAttr); + LoadShaderLCList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); + ClearList(lst); + + xrMaterialData = eAttr.create("xrayGameMaterial", " "); + MAKE_INPUT(eAttr); + LoadGameMtlList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); + ClearList(lst); + + CHECK_MSTATUS(addAttribute(xrDoubleSide)); + CHECK_MSTATUS(addAttribute(xrEngineData)); + CHECK_MSTATUS(addAttribute(xrCompilerData)); + CHECK_MSTATUS(addAttribute(xrMaterialData)); + // end x-ray part + // create output attributes here + // outColor is the only output attribute and it is inherited + // so we do not need to create or add it. + // return MS::kSuccess; } - /////////////////////////////////////////////////////// // DESCRIPTION: // This function gets called by Maya to evaluate the shader. @@ -301,257 +290,228 @@ MStatus CXRayMtl::initialize() // Put the result into the output plug. /////////////////////////////////////////////////////// -MStatus CXRayMtl::compute( -const MPlug& plug, - MDataBlock& block ) -{ - if((plug != outColor) && (plug != outColorR) && (plug != outColorG) && (plug != outColorB)) return MS::kUnknownParameter; -/* - bool k = false; - k |= (plug==outColor); - k |= (plug==outColorR); - k |= (plug==outColorG); - k |= (plug==outColorB); - if( !k ) return MS::kUnknownParameter; - // Always return black for now. - MFloatVector resultColor(0.0,0.0,0.0); - - // set ouput color attribute - MDataHandle outColorHandle = block.outputValue( outColor ); - MFloatVector& outColor = outColorHandle.asFloatVector(); - outColor = resultColor; - outColorHandle.setClean(); -*/ +MStatus CXRayMtl::compute(const MPlug& plug, MDataBlock& block) +{ + if ((plug != outColor) && (plug != outColorR) && (plug != outColorG) && (plug != outColorB)) + return MS::kUnknownParameter; + /* + bool k = false; + k |= (plug==outColor); + k |= (plug==outColorR); + k |= (plug==outColorG); + k |= (plug==outColorB); + if( !k ) return MS::kUnknownParameter; + // Always return black for now. + MFloatVector resultColor(0.0,0.0,0.0); + + // set ouput color attribute + MDataHandle outColorHandle = block.outputValue( outColor ); + MFloatVector& outColor = outColorHandle.asFloatVector(); + outColor = resultColor; + outColorHandle.setClean(); + */ return MS::kSuccess; } MStatus CXRayMtl::getFloat3(MObject attr, float value[3]) { - // Get the attr to use - // - MPlug plug(thisMObject(), attr); - - MObject object; - - MStatus status = plug.getValue(object); - if (!status) - { - status.perror("CXRayMtl::bind plug.getValue."); - return status; - } - - - MFnNumericData data(object, &status); - if (!status) - { - status.perror("CXRayMtl::bind construct data."); - return status; - } - - status = data.getData(value[0], value[1], value[2]); - if (!status) - { - status.perror("CXRayMtl::bind get values."); - return status; - } - - return MS::kSuccess; + // Get the attr to use + // + MPlug plug(thisMObject(), attr); + + MObject object; + + MStatus status = plug.getValue(object); + if (!status) { + status.perror("CXRayMtl::bind plug.getValue."); + return status; + } + + MFnNumericData data(object, &status); + if (!status) { + status.perror("CXRayMtl::bind construct data."); + return status; + } + + status = data.getData(value[0], value[1], value[2]); + if (!status) { + status.perror("CXRayMtl::bind get values."); + return status; + } + + return MS::kSuccess; } -MStatus CXRayMtl::getString(MObject attr, MString &str) +MStatus CXRayMtl::getString(MObject attr, MString& str) { - MPlug plug(thisMObject(), attr); - MStatus status = plug.getValue( str ); - return MS::kSuccess; + MPlug plug(thisMObject(), attr); + MStatus status = plug.getValue(str); + return MS::kSuccess; } - void CXRayMtl::updateTransparencyFlags(MString objectPath) { - // Update the transparency flags and values. - // Check if the transparency channel is mapped on a texture, or if - // it is constant. Textured transparency is not supported in this example, - // because it would involve multiplying alpha values of two texture maps... - MString transparencyName = ""; - ShadingConnection transparencyConnection(thisMObject(), objectPath, "transparency"); - if (transparencyConnection.type() == ShadingConnection::CONSTANT_COLOR) - { - // transparency = average of r,g,b transparency channels. - MColor tc = transparencyConnection.constantColor(); - fConstantTransparency = (tc.r + tc.g + tc.b) / 3.0f; - } - else - fConstantTransparency = 0.0f; // will result in alpha=1. + // Update the transparency flags and values. + // Check if the transparency channel is mapped on a texture, or if + // it is constant. Textured transparency is not supported in this example, + // because it would involve multiplying alpha values of two texture maps... + MString transparencyName = ""; + ShadingConnection transparencyConnection(thisMObject(), objectPath, "transparency"); + if (transparencyConnection.type() == ShadingConnection::CONSTANT_COLOR) { + // transparency = average of r,g,b transparency channels. + MColor tc = transparencyConnection.constantColor(); + fConstantTransparency = (tc.r + tc.g + tc.b) / 3.0f; + } + else + fConstantTransparency = 0.0f; // will result in alpha=1. } - /* virtual */ -MStatus CXRayMtl::bind(const MDrawRequest& request, - M3dView& view) +MStatus CXRayMtl::bind(const MDrawRequest& request, M3dView& view) { - MStatus status; - - // white, opaque. - float bgColor[4] = {1,1,1,1}; - - // Get path of current object in draw request - currentObjectPath = request.multiPath(); - MString currentPathName( currentObjectPath.partialPathName() ); - - updateTransparencyFlags(currentPathName); - - // Get decal texture name - MString decalName = ""; - ShadingConnection colorConnection(thisMObject(), currentPathName, "color"); - - // If the color attribute is ultimately connected to a file texture, find its filename. - // otherwise use the default color texture. - if (colorConnection.type() == ShadingConnection::TEXTURE && - colorConnection.texture().hasFn(MFn::kFileTexture)) - { - // Get the filename of the texture. - MFnDependencyNode textureNode(colorConnection.texture()); - MPlug filenamePlug( colorConnection.texture(), textureNode.attribute(MString("fileTextureName")) ); - filenamePlug.getValue(decalName); - if (decalName == "") - getFloat3(color, bgColor); - } - else - { - decalName = ""; - getFloat3(color, bgColor); - } - - assert(glGetError() == GL_NO_ERROR); - - view.beginGL(); - - glPushAttrib( GL_ALL_ATTRIB_BITS ); - glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); - - // Set the standard OpenGL blending mode. - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - // Change the constant alpha value. - float alpha = 1.0f - fConstantTransparency; - - // Set a color (with alpha). This color will be used directly if - // the shader is not textured. Otherwise, the texture will get modulated - // by the alpha. - glColor4f(bgColor[0], bgColor[1], bgColor[2], alpha); - - - // If the shader is textured... - if (decalName.length() != 0) - { - // Enable 2D texturing. - glEnable(GL_TEXTURE_2D); - - assert(glGetError() == GL_NO_ERROR); - - // Bind the 2D texture through the texture cache. The cache will keep - // the texture around, so that it will only be loaded in video - // memory once. In this example, the third parameter (mipmapping) is - // false, so no mipmaps are generated. Note that mipmaps only work if - // the texture has even dimensions. - m_pTextureCache->bind(colorConnection.texture(), MTexture::RGBA, false); - - // Set minification and magnification filtering to linear interpolation. - // For better quality, you could enable mipmapping while binding and - // use GL_MIPMAP_LINEAR_MIPMAP in for minification filtering. - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - } - - // Disable lighting. - glDisable(GL_LIGHTING); - - view.endGL(); - - return MS::kSuccess; -} + MStatus status; + + // white, opaque. + float bgColor[4] = {1, 1, 1, 1}; + + // Get path of current object in draw request + currentObjectPath = request.multiPath(); + MString currentPathName(currentObjectPath.partialPathName()); + + updateTransparencyFlags(currentPathName); + + // Get decal texture name + MString decalName = ""; + ShadingConnection colorConnection(thisMObject(), currentPathName, "color"); + + // If the color attribute is ultimately connected to a file texture, find its filename. + // otherwise use the default color texture. + if (colorConnection.type() == ShadingConnection::TEXTURE && colorConnection.texture().hasFn(MFn::kFileTexture)) { + // Get the filename of the texture. + MFnDependencyNode textureNode(colorConnection.texture()); + MPlug filenamePlug(colorConnection.texture(), textureNode.attribute(MString("fileTextureName"))); + filenamePlug.getValue(decalName); + if (decalName == "") getFloat3(color, bgColor); + } + else + { + decalName = ""; + getFloat3(color, bgColor); + } + + assert(glGetError() == GL_NO_ERROR); + + view.beginGL(); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); + + // Set the standard OpenGL blending mode. + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // Change the constant alpha value. + float alpha = 1.0f - fConstantTransparency; + + // Set a color (with alpha). This color will be used directly if + // the shader is not textured. Otherwise, the texture will get modulated + // by the alpha. + glColor4f(bgColor[0], bgColor[1], bgColor[2], alpha); + + // If the shader is textured... + if (decalName.length() != 0) { + // Enable 2D texturing. + glEnable(GL_TEXTURE_2D); + + assert(glGetError() == GL_NO_ERROR); + + // Bind the 2D texture through the texture cache. The cache will keep + // the texture around, so that it will only be loaded in video + // memory once. In this example, the third parameter (mipmapping) is + // false, so no mipmaps are generated. Note that mipmaps only work if + // the texture has even dimensions. + m_pTextureCache->bind(colorConnection.texture(), MTexture::RGBA, false); + + // Set minification and magnification filtering to linear interpolation. + // For better quality, you could enable mipmapping while binding and + // use GL_MIPMAP_LINEAR_MIPMAP in for minification filtering. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + + // Disable lighting. + glDisable(GL_LIGHTING); + + view.endGL(); + return MS::kSuccess; +} /* virtual */ -MStatus CXRayMtl::unbind(const MDrawRequest& request, - M3dView& view) +MStatus CXRayMtl::unbind(const MDrawRequest& request, M3dView& view) { - view.beginGL(); - glPopClientAttrib(); - glPopAttrib(); + view.beginGL(); + glPopClientAttrib(); + glPopAttrib(); - view.endGL(); + view.endGL(); - return MS::kSuccess; + return MS::kSuccess; } /* virtual */ -MStatus CXRayMtl::geometry( const MDrawRequest& request, - M3dView& view, - int prim, - unsigned int writable, - int indexCount, - const unsigned int * indexArray, - int vertexCount, - const int * vertexIDs, - const float * vertexArray, - int normalCount, - const float ** normalArrays, - int colorCount, - const float ** colorArrays, - int texCoordCount, - const float ** texCoordArrays) +MStatus CXRayMtl::geometry(const MDrawRequest& request, M3dView& view, int prim, unsigned int writable, int indexCount, + const unsigned int* indexArray, int vertexCount, const int* vertexIDs, const float* vertexArray, int normalCount, + const float** normalArrays, int colorCount, const float** colorArrays, int texCoordCount, + const float** texCoordArrays) { - view.beginGL(); + view.beginGL(); - glVertexPointer(3, GL_FLOAT, 0, vertexArray); - glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, vertexArray); + glEnableClientState(GL_VERTEX_ARRAY); - if (normalCount > 0) - { - // Technically, we don't need the normals for this example. But - // most of the 3rd party plug-ins will probably want the normal, - // which is why the following lines were kept. - glNormalPointer(GL_FLOAT, 0, normalArrays[0]); - glEnableClientState(GL_NORMAL_ARRAY); - } + if (normalCount > 0) { + // Technically, we don't need the normals for this example. But + // most of the 3rd party plug-ins will probably want the normal, + // which is why the following lines were kept. + glNormalPointer(GL_FLOAT, 0, normalArrays[0]); + glEnableClientState(GL_NORMAL_ARRAY); + } - if (texCoordCount > 0) - { - glTexCoordPointer(2, GL_FLOAT, 0, texCoordArrays[0]); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } + if (texCoordCount > 0) { + glTexCoordPointer(2, GL_FLOAT, 0, texCoordArrays[0]); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } - glDrawElements(prim, indexCount, GL_UNSIGNED_INT, indexArray); + glDrawElements(prim, indexCount, GL_UNSIGNED_INT, indexArray); - view.endGL(); + view.endGL(); - return MS::kSuccess; + return MS::kSuccess; } /* virtual */ -int CXRayMtl::normalsPerVertex() +int CXRayMtl::normalsPerVertex() { - // Want only normals - return 1; + // Want only normals + return 1; } /* virtual */ -int CXRayMtl::texCoordsPerVertex() +int CXRayMtl::texCoordsPerVertex() { - return 1; + return 1; } /* virtual */ -bool CXRayMtl::hasTransparency() +bool CXRayMtl::hasTransparency() { - // Performance note: if we knew that the texture - // is always opaque, we could return false here - // to avoid the computation cost associated with - // ordering objects from farthest to closest. - return true; + // Performance note: if we knew that the texture + // is always opaque, we could return false here + // to avoid the computation cost associated with + // ordering objects from farthest to closest. + return true; } diff --git a/src/plugins/Maya/Material/hwUnlitShader.h b/src/plugins/Maya/Material/hwUnlitShader.h index f6a3fe3c2cd..a8a0e5f00a0 100644 --- a/src/plugins/Maya/Material/hwUnlitShader.h +++ b/src/plugins/Maya/Material/hwUnlitShader.h @@ -10,13 +10,13 @@ // texturing and disables lighting. // // This sample demonstrates how to: -// - Specify a color attribute on your HW shader plug-in +// - Specify a color attribute on your HW shader plug-in // so that end-users can attach a file texture to it. -// - Traverse what's upstream of the color attribute, including +// - Traverse what's upstream of the color attribute, including // going through shading switches if required. -// - Using the MImage API class to load and uncompress a file +// - Using the MImage API class to load and uncompress a file // texture in any Maya-supported file format. -// - Setting up the graphics pipeline to display the +// - Setting up the graphics pipeline to display the // texture correctly. // // @@ -28,80 +28,67 @@ class CXRayMtl : public MPxHwShaderNode { public: - CXRayMtl(); - virtual ~CXRayMtl(); - void releaseEverything(); - - virtual MStatus compute( const MPlug&, MDataBlock& ); - virtual void postConstructor(); - - virtual MStatus bind(const MDrawRequest& request, - M3dView& view); - - virtual MStatus unbind(const MDrawRequest& request, - M3dView& view); - - virtual MStatus geometry( const MDrawRequest& request, - M3dView& view, - int prim, - unsigned int writable, - int indexCount, - const unsigned int * indexArray, - int vertexCount, - const int * vertexIDs, - const float * vertexArray, - int normalCount, - const float ** normalArrays, - int colorCount, - const float ** colorArrays, - int texCoordCount, - const float ** texCoordArrays); - - virtual int normalsPerVertex(); - virtual bool hasTransparency(); - virtual int texCoordsPerVertex(); - - static void * creator(); - static MStatus initialize(); - static MTypeId id; - - MTextureCache* m_pTextureCache; - - MStatus getFloat3(MObject colorAttr, float colorValue[3]); - MStatus getString(MObject attr, MString &str); - - void updateTransparencyFlags(MString objectPath); + CXRayMtl(); + virtual ~CXRayMtl(); + void releaseEverything(); + + virtual MStatus compute(const MPlug&, MDataBlock&); + virtual void postConstructor(); + + virtual MStatus bind(const MDrawRequest& request, M3dView& view); + + virtual MStatus unbind(const MDrawRequest& request, M3dView& view); + + virtual MStatus geometry(const MDrawRequest& request, M3dView& view, int prim, unsigned int writable, + int indexCount, const unsigned int* indexArray, int vertexCount, const int* vertexIDs, const float* vertexArray, + int normalCount, const float** normalArrays, int colorCount, const float** colorArrays, int texCoordCount, + const float** texCoordArrays); + + virtual int normalsPerVertex(); + virtual bool hasTransparency(); + virtual int texCoordsPerVertex(); + + static void* creator(); + static MStatus initialize(); + static MTypeId id; + + MTextureCache* m_pTextureCache; + + MStatus getFloat3(MObject colorAttr, float colorValue[3]); + MStatus getString(MObject attr, MString& str); + + void updateTransparencyFlags(MString objectPath); protected: - static MObject colorR; - static MObject colorG; - static MObject colorB; - static MObject color; - - static MObject xrEngineData; - static MObject xrCompilerData; - static MObject xrMaterialData; - static MObject xrDoubleSide; - - static MObject transparencyR; - static MObject transparencyG; - static MObject transparencyB; - static MObject transparency; - float fConstantTransparency; - - MDagPath currentObjectPath; - - // Callbacks that we monitor so we can release OpenGL-dependant resources before - // their context gets destroyed. - MCallbackId fBeforeNewCB; - MCallbackId fBeforeOpenCB; - MCallbackId fBeforeRemoveReferenceCB; - MCallbackId fMayaExitingCB; - - void attachSceneCallbacks(); - void detachSceneCallbacks(); - - static void releaseCallback(void* clientData); + static MObject colorR; + static MObject colorG; + static MObject colorB; + static MObject color; + + static MObject xrEngineData; + static MObject xrCompilerData; + static MObject xrMaterialData; + static MObject xrDoubleSide; + + static MObject transparencyR; + static MObject transparencyG; + static MObject transparencyB; + static MObject transparency; + float fConstantTransparency; + + MDagPath currentObjectPath; + + // Callbacks that we monitor so we can release OpenGL-dependant resources before + // their context gets destroyed. + MCallbackId fBeforeNewCB; + MCallbackId fBeforeOpenCB; + MCallbackId fBeforeRemoveReferenceCB; + MCallbackId fMayaExitingCB; + + void attachSceneCallbacks(); + void detachSceneCallbacks(); + + static void releaseCallback(void* clientData); }; #endif /* XRayMtlH */ diff --git a/src/plugins/Maya/Material/lambertShader.cpp b/src/plugins/Maya/Material/lambertShader.cpp index 65763f424a4..d75c5ce37db 100644 --- a/src/plugins/Maya/Material/lambertShader.cpp +++ b/src/plugins/Maya/Material/lambertShader.cpp @@ -29,15 +29,14 @@ #include "stdafx.h" #pragma hdrstop -#include #include +#include #include "plugins/Shared/BlenderListLoader.h" using namespace std; ///////////////////////////////// // Plugin Lambert Shader Class // ///////////////////////////////// - // This class will create a new shader. Shaders are custom dependency // graph objects so we will derive this class from the basic DG node // type MPxNode @@ -46,1006 +45,916 @@ using namespace std; class CXRayMtl : public MPxNode { public: - CXRayMtl(); - virtual ~CXRayMtl(); + CXRayMtl(); + virtual ~CXRayMtl(); - static void * creator(); - virtual MStatus compute( const MPlug&, MDataBlock& ); - static MStatus initialize (); + static void* creator(); + virtual MStatus compute(const MPlug&, MDataBlock&); + static MStatus initialize(); - // postConstructor: - // The postConstructor method allows us to call MPxNode member - // functions during initialization. Internally maya creates two - // objects when a user defined node is created, the internal MObject - // and the user derived object. The association between the these - // two objects is not made until after the MPxNode constructor is - // called. This implies that no MPxNode member function can be called - // from the MPxNode constructor. The postConstructor will get called - // immediately after the constructor when it is safe to call any - // MPxNode member function. - // + // postConstructor: + // The postConstructor method allows us to call MPxNode member + // functions during initialization. Internally maya creates two + // objects when a user defined node is created, the internal MObject + // and the user derived object. The association between the these + // two objects is not made until after the MPxNode constructor is + // called. This implies that no MPxNode member function can be called + // from the MPxNode constructor. The postConstructor will get called + // immediately after the constructor when it is safe to call any + // MPxNode member function. + // - virtual void postConstructor(); + virtual void postConstructor(); - static MTypeId id; // The IFF type id + static MTypeId id; // The IFF type id protected: + // Translucence coefficient + static MObject aTranslucenceCoeff; - // Translucence coefficient - static MObject aTranslucenceCoeff; + // Diffuse Reflectivity + static MObject aDiffuseReflectivity; - // Diffuse Reflectivity - static MObject aDiffuseReflectivity; + // Red component of surface color + static MObject aColorR; - // Red component of surface color - static MObject aColorR; + // Green component of surface color + static MObject aColorG; - // Green component of surface color - static MObject aColorG; + // Blue component of surface color + static MObject aColorB; - // Blue component of surface color - static MObject aColorB; + // Surface color + static MObject aColor; - // Surface color - static MObject aColor; + // Red component of incandescence + static MObject aIncandescenceR; - // Red component of incandescence - static MObject aIncandescenceR; + // Green component of incandescence + static MObject aIncandescenceG; - // Green component of incandescence - static MObject aIncandescenceG; + // Blue component of incandescence + static MObject aIncandescenceB; - // Blue component of incandescence - static MObject aIncandescenceB; + // Incandescence + static MObject aIncandescence; - // Incandescence - static MObject aIncandescence; + // Red component of surface transparency + static MObject aInTransR; - // Red component of surface transparency - static MObject aInTransR; + // Green component of surface transparency + static MObject aInTransG; - // Green component of surface transparency - static MObject aInTransG; + // Blue component of surface transparency + static MObject aInTransB; - // Blue component of surface transparency - static MObject aInTransB; + // Surface transparency + static MObject aInTransparency; - // Surface transparency - static MObject aInTransparency; + // Red component of output color + static MObject aOutColorR; - // Red component of output color - static MObject aOutColorR; + // Green component of output color + static MObject aOutColorG; - // Green component of output color - static MObject aOutColorG; + // Blue component of output color + static MObject aOutColorB; - // Blue component of output color - static MObject aOutColorB; + // Output color + static MObject aOutColor; - // Output color - static MObject aOutColor; + // Red component of output transparency + static MObject aOutTransR; - // Red component of output transparency - static MObject aOutTransR; + // Green component of output transparency + static MObject aOutTransG; - // Green component of output transparency - static MObject aOutTransG; + // Blue component of output transparency + static MObject aOutTransB; - // Blue component of output transparency - static MObject aOutTransB; + // Output transparency + static MObject aOutTransparency; - // Output transparency - static MObject aOutTransparency; + // X component of surface normal + static MObject aNormalCameraX; - // X component of surface normal - static MObject aNormalCameraX; + // Y component of surface normal + static MObject aNormalCameraY; - // Y component of surface normal - static MObject aNormalCameraY; + // Z component of surface normal + static MObject aNormalCameraZ; - // Z component of surface normal - static MObject aNormalCameraZ; + // Surface normal + static MObject aNormalCamera; - // Surface normal - static MObject aNormalCamera; + // X component of light direction vector + static MObject aLightDirectionX; - // X component of light direction vector - static MObject aLightDirectionX; + // Y component of light direction vector + static MObject aLightDirectionY; - // Y component of light direction vector - static MObject aLightDirectionY; + // Z component of light direction vector + static MObject aLightDirectionZ; - // Z component of light direction vector - static MObject aLightDirectionZ; + // Light direction vector + static MObject aLightDirection; - // Light direction vector - static MObject aLightDirection; + // Red component of light intensity + static MObject aLightIntensityR; - // Red component of light intensity - static MObject aLightIntensityR; + // Green component of light intensity + static MObject aLightIntensityG; - // Green component of light intensity - static MObject aLightIntensityG; + // Blue component of light intensity + static MObject aLightIntensityB; - // Blue component of light intensity - static MObject aLightIntensityB; + // Light Intensity vector + static MObject aLightIntensity; - // Light Intensity vector - static MObject aLightIntensity; + // Ambient flag + static MObject aLightAmbient; - // Ambient flag - static MObject aLightAmbient; + // Diffuse flag + static MObject aLightDiffuse; - // Diffuse flag - static MObject aLightDiffuse; + // Specular flag + static MObject aLightSpecular; - // Specular flag - static MObject aLightSpecular; + // Shadow Fraction flag + static MObject aLightShadowFraction; - // Shadow Fraction flag - static MObject aLightShadowFraction; + // Pre Shadow Intensity + static MObject aPreShadowIntensity; - // Pre Shadow Intensity - static MObject aPreShadowIntensity; + // Light blind data + static MObject aLightBlindData; - // Light blind data - static MObject aLightBlindData; + // Light data array + static MObject aLightData; - // Light data array - static MObject aLightData; - - // XRay data - static MObject xrEngineData; - static MObject xrCompilerData; - static MObject xrMaterialData; - static MObject xrDoubleSide; + // XRay data + static MObject xrEngineData; + static MObject xrCompilerData; + static MObject xrMaterialData; + static MObject xrDoubleSide; }; - // IFF type ID // Each node requires a unique identifier which is used by // MFnDependencyNode::create() to identify which node to create, and by -// the Maya file format. +// the Maya file format. // // For local testing of nodes you can use any identifier between // 0x00000000 and 0x0007ffff, but for any node that you plan to use for // more permanent purposes, you should get a universally unique id from // Alias Support. You will be assigned a unique range that you -// can manage on your own. +// can manage on your own. // -MTypeId CXRayMtl::id( 0x00105440 ); - +MTypeId CXRayMtl::id(0x00105440); // the postConstructor() function is called immediately after the objects // constructor. It is not safe to call MPxNode member functions from the // constructor, instead they should be called here. // -void CXRayMtl::postConstructor( ) +void CXRayMtl::postConstructor() { - // setMPSafe indicates that this shader can be used for multiprocessor - // rendering. For a shading node to be MP safe, it cannot access any - // shared global data and should only use attributes in the datablock - // to get input data and store output data. - // - setMPSafe( true ); + // setMPSafe indicates that this shader can be used for multiprocessor + // rendering. For a shading node to be MP safe, it cannot access any + // shared global data and should only use attributes in the datablock + // to get input data and store output data. + // + setMPSafe(true); } - /////////////////////////////////////////////////////// // DESCRIPTION: attribute information /////////////////////////////////////////////////////// // -MObject CXRayMtl::aTranslucenceCoeff; -MObject CXRayMtl::aDiffuseReflectivity; -MObject CXRayMtl::aInTransparency; -MObject CXRayMtl::aInTransR; -MObject CXRayMtl::aInTransG; -MObject CXRayMtl::aInTransB; -MObject CXRayMtl::aColor; -MObject CXRayMtl::aColorR; -MObject CXRayMtl::aColorG; -MObject CXRayMtl::aColorB; -MObject CXRayMtl::aIncandescence; -MObject CXRayMtl::aIncandescenceR; -MObject CXRayMtl::aIncandescenceG; -MObject CXRayMtl::aIncandescenceB; -MObject CXRayMtl::aOutColor; -MObject CXRayMtl::aOutColorR; -MObject CXRayMtl::aOutColorG; -MObject CXRayMtl::aOutColorB; -MObject CXRayMtl::aOutTransparency; -MObject CXRayMtl::aOutTransR; -MObject CXRayMtl::aOutTransG; -MObject CXRayMtl::aOutTransB; -MObject CXRayMtl::aNormalCamera; -MObject CXRayMtl::aNormalCameraX; -MObject CXRayMtl::aNormalCameraY; -MObject CXRayMtl::aNormalCameraZ; -MObject CXRayMtl::aLightData; -MObject CXRayMtl::aLightDirection; -MObject CXRayMtl::aLightDirectionX; -MObject CXRayMtl::aLightDirectionY; -MObject CXRayMtl::aLightDirectionZ; -MObject CXRayMtl::aLightIntensity; -MObject CXRayMtl::aLightIntensityR; -MObject CXRayMtl::aLightIntensityG; -MObject CXRayMtl::aLightIntensityB; -MObject CXRayMtl::aLightAmbient; -MObject CXRayMtl::aLightDiffuse; -MObject CXRayMtl::aLightSpecular; -MObject CXRayMtl::aLightShadowFraction; -MObject CXRayMtl::aPreShadowIntensity; -MObject CXRayMtl::aLightBlindData; +MObject CXRayMtl::aTranslucenceCoeff; +MObject CXRayMtl::aDiffuseReflectivity; +MObject CXRayMtl::aInTransparency; +MObject CXRayMtl::aInTransR; +MObject CXRayMtl::aInTransG; +MObject CXRayMtl::aInTransB; +MObject CXRayMtl::aColor; +MObject CXRayMtl::aColorR; +MObject CXRayMtl::aColorG; +MObject CXRayMtl::aColorB; +MObject CXRayMtl::aIncandescence; +MObject CXRayMtl::aIncandescenceR; +MObject CXRayMtl::aIncandescenceG; +MObject CXRayMtl::aIncandescenceB; +MObject CXRayMtl::aOutColor; +MObject CXRayMtl::aOutColorR; +MObject CXRayMtl::aOutColorG; +MObject CXRayMtl::aOutColorB; +MObject CXRayMtl::aOutTransparency; +MObject CXRayMtl::aOutTransR; +MObject CXRayMtl::aOutTransG; +MObject CXRayMtl::aOutTransB; +MObject CXRayMtl::aNormalCamera; +MObject CXRayMtl::aNormalCameraX; +MObject CXRayMtl::aNormalCameraY; +MObject CXRayMtl::aNormalCameraZ; +MObject CXRayMtl::aLightData; +MObject CXRayMtl::aLightDirection; +MObject CXRayMtl::aLightDirectionX; +MObject CXRayMtl::aLightDirectionY; +MObject CXRayMtl::aLightDirectionZ; +MObject CXRayMtl::aLightIntensity; +MObject CXRayMtl::aLightIntensityR; +MObject CXRayMtl::aLightIntensityG; +MObject CXRayMtl::aLightIntensityB; +MObject CXRayMtl::aLightAmbient; +MObject CXRayMtl::aLightDiffuse; +MObject CXRayMtl::aLightSpecular; +MObject CXRayMtl::aLightShadowFraction; +MObject CXRayMtl::aPreShadowIntensity; +MObject CXRayMtl::aLightBlindData; // XRya data -MObject CXRayMtl::xrDoubleSide; -MObject CXRayMtl::xrEngineData; -MObject CXRayMtl::xrCompilerData; -MObject CXRayMtl::xrMaterialData; - +MObject CXRayMtl::xrDoubleSide; +MObject CXRayMtl::xrEngineData; +MObject CXRayMtl::xrCompilerData; +MObject CXRayMtl::xrMaterialData; // This node does not need to perform any special actions on creation or // destruction // -CXRayMtl::CXRayMtl() {} -CXRayMtl::~CXRayMtl(){} - +CXRayMtl::CXRayMtl() +{ +} +CXRayMtl::~CXRayMtl() +{ +} // The creator() method allows Maya to instantiate instances of this node. // It is called every time a new instance of the node is requested by // either the createNode command or the MFnDependencyNode::create() -// method. +// method. // // In this case creator simply returns a new CXRayMtl object. // void* CXRayMtl::creator() { - return new CXRayMtl; + return new CXRayMtl; } - // The initialize method is called only once when the node is first // registered with Maya. In this method you define the attributes of the // node, what data comes in and goes out of the node that other nodes may -// want to connect to. +// want to connect to. // -#define MAKE_INPUT(attr) \ - CHECK_MSTATUS ( attr.setKeyable(true) ); \ - CHECK_MSTATUS ( attr.setStorable(true) ); \ - CHECK_MSTATUS ( attr.setReadable(true) ); \ - CHECK_MSTATUS ( attr.setWritable(true) ); +#define MAKE_INPUT(attr) \ + CHECK_MSTATUS(attr.setKeyable(true)); \ + CHECK_MSTATUS(attr.setStorable(true)); \ + CHECK_MSTATUS(attr.setReadable(true)); \ + CHECK_MSTATUS(attr.setWritable(true)); -extern unsigned crc16_calc(unsigned char *data, unsigned count, unsigned old_crc=0); +extern unsigned crc16_calc(unsigned char* data, unsigned count, unsigned old_crc = 0); MStatus CXRayMtl::initialize() { - MFnNumericAttribute nAttr; - MFnLightDataAttribute lAttr; - MFnEnumAttribute eAttr; - MFnTypedAttribute tAttr; - - MStatus status; // Status will be used to hold the MStatus value - // returned by each api function call. It is important - // to check the status returned by a call to aid in - // debugging. Failed API calls can result in subtle - // errors that can be difficult to track down, you may - // wish to use the CHECK_MSTATUS macro for any API - // call where you do not need to provide your own - // error handling. - // - - // Attribute Initialization: - // - // create - The create function creates a new attribute for the - // node, it takes a long name for the attribute, a short - // name for the attribute, the type of the attribute, - // and a status object to determine if the api call was - // successful. - // - // setKeyable - Sets whether this attribute should accept keyframe - // data, Attributes are not keyable by default. - // - // setStorable - Sets whether this attribute should be storable. If an - // attribute is storable, then it will be writen out - // when the node is stored to a file. Attributes are - // storable by default. - // - // setDefault - Sets the default value for this attribute. - // - // setUsedAsColor - Sets whether this attribute should be presented as - // a color in the UI. - // - // setHidden - Sets whether this attribute should be hidden from the - // UI. This is useful if the attribute is being used for - // blind data, or if it is being used as scratch space - // for a geometry calculation (should also be marked - // non-connectable in that case). Attributes are not - // hidden by default. - // - // setReadable - Sets whether this attribute should be readable. If an - // attribute is readable, then it can be used as the - // source in a dependency graph connection. Attributes - // are readable by default. - // - // setWritable - Sets whether this attribute should be readable. If an - // attribute is writable, then it can be used as the - // destination in a dependency graph connection. If an - // attribute is not writable then setAttr commands will - // fail to change the attribute. If both keyable and - // writable for an attribute are set to true it will be - // displayed in the channel box when the node is - // selected. Attributes are writable by default. - // - // setArray - Sets whether this attribute should have an array of - // data. This should be set to true if the attribute - // needs to accept multiple incoming connections. - // Attributes are single elements by default. - // - - - // Input Attributes - // - aTranslucenceCoeff = nAttr.create( "translucenceCoeff", "tc", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); - - aDiffuseReflectivity = nAttr.create( "diffuseReflectivity", "drfl", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.8f ) ); - - aColorR = nAttr.create( "colorR", "cr",MFnNumericData::kFloat, 0, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); - - aColorG = nAttr.create( "colorG", "cg", MFnNumericData::kFloat, 0, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.58824f ) ); - - aColorB = nAttr.create( "colorB", "cb",MFnNumericData::kFloat, 0, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.644f ) ); - - aColor = nAttr.create( "color", "c", aColorR, aColorG, aColorB, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.58824f, 0.644f ) ); - CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); - - aIncandescenceR = nAttr.create( "incandescenceR", "ir", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); - - aIncandescenceG = nAttr.create( "incandescenceG", "ig", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); - - aIncandescenceB = nAttr.create( "incandescenceB", "ib", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f ) ); - - aIncandescence = nAttr.create( "incandescence", "ic", aIncandescenceR, - aIncandescenceG, aIncandescenceB, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); - CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); - - aInTransR = nAttr.create( "transparencyR", "itr", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - - aInTransG = nAttr.create( "transparencyG", "itg", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - - aInTransB = nAttr.create( "transparencyB", "itb", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - - aInTransparency = nAttr.create( "transparency", "it", aInTransR, - aInTransG, aInTransB, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setKeyable( true ) ); - CHECK_MSTATUS( nAttr.setStorable( true ) ); - CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) ); - CHECK_MSTATUS( nAttr.setUsedAsColor( true ) ); - - - // Output Attributes - // - - // Color Output - // - aOutColorR = nAttr.create( "outColorR", "ocr", MFnNumericData::kFloat, - 0, &status ); - CHECK_MSTATUS( status ); - - aOutColorG = nAttr.create( "outColorG", "ocg", MFnNumericData::kFloat, - 0, &status ); - CHECK_MSTATUS( status ); - - aOutColorB = nAttr.create( "outColorB", "ocb", MFnNumericData::kFloat, - 0, &status ); - CHECK_MSTATUS( status ); - - aOutColor = nAttr.create( "outColor", "oc", aOutColorR, aOutColorG, - aOutColorB, &status ); - CHECK_MSTATUS( status ); - - CHECK_MSTATUS( nAttr.setHidden( false ) ); - CHECK_MSTATUS( nAttr.setReadable( true ) ); - CHECK_MSTATUS( nAttr.setWritable( false ) ); - - - // Transparency Output - // - aOutTransR = nAttr.create( "outTransparencyR", "otr", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - - aOutTransG = nAttr.create( "outTransparencyG", "otg", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - - aOutTransB = nAttr.create( "outTransparencyB", "otb", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - - aOutTransparency = nAttr.create( "outTransparency", "ot", - aOutTransR,aOutTransG,aOutTransB, &status ); - CHECK_MSTATUS( status ); - - CHECK_MSTATUS( nAttr.setHidden( false ) ); - CHECK_MSTATUS( nAttr.setReadable( true ) ); - CHECK_MSTATUS( nAttr.setWritable( false ) ); - - - // Camera Normals - // - aNormalCameraX = nAttr.create( "normalCameraX", "nx", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setStorable( false ) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aNormalCameraY = nAttr.create( "normalCameraY", "ny", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setStorable( false ) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aNormalCameraZ = nAttr.create( "normalCameraZ", "nz", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setStorable( false ) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aNormalCamera = nAttr.create( "normalCamera","n", aNormalCameraX, - aNormalCameraY, aNormalCameraZ, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( nAttr.setStorable( false ) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); - CHECK_MSTATUS( nAttr.setHidden( true ) ); - - - // Light Direction - // - aLightDirectionX = nAttr.create( "lightDirectionX", "ldx", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightDirectionY = nAttr.create( "lightDirectionY", "ldy", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightDirectionZ = nAttr.create( "lightDirectionZ", "ldz", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightDirection = nAttr.create( "lightDirection", "ld", - aLightDirectionX, aLightDirectionY, aLightDirectionZ, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); - - - // Light Intensity - // - aLightIntensityR = nAttr.create( "lightIntensityR", "lir", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightIntensityG = nAttr.create( "lightIntensityG", "lig", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightIntensityB = nAttr.create( "lightIntensityB", "lib", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightIntensity = nAttr.create( "lightIntensity", "li", - aLightIntensityR, aLightIntensityG, aLightIntensityB, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) ); - - - // Light - // - aLightAmbient = nAttr.create( "lightAmbient", "la", - MFnNumericData::kBoolean, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( true ) ); - - aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", - MFnNumericData::kBoolean, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( true ) ); - - aLightSpecular = nAttr.create( "lightSpecular", "ls", - MFnNumericData::kBoolean, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( false ) ); - - aLightShadowFraction = nAttr.create( "lightShadowFraction", "lsf", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aPreShadowIntensity = nAttr.create( "preShadowIntensity", "psi", - MFnNumericData::kFloat, 0, &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - CHECK_MSTATUS( nAttr.setDefault( 1.0f ) ); - - aLightBlindData = nAttr.createAddr( "lightBlindData", "lbld", - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(true) ); - CHECK_MSTATUS ( nAttr.setWritable(false) ); - - aLightData = lAttr.create( "lightDataArray", "ltd", aLightDirection, - aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular, - aLightShadowFraction, aPreShadowIntensity, aLightBlindData, - &status ); - CHECK_MSTATUS( status ); - CHECK_MSTATUS( lAttr.setArray( true ) ); - CHECK_MSTATUS( lAttr.setStorable( false ) ); - CHECK_MSTATUS( lAttr.setHidden( true ) ); - CHECK_MSTATUS( lAttr.setDefault( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - true, true, false, 1.0f, 1.0f, NULL ) ); - - - // Next we will add the attributes we have defined to the node - // - CHECK_MSTATUS( addAttribute( aTranslucenceCoeff ) ); - CHECK_MSTATUS( addAttribute( aDiffuseReflectivity ) ); - CHECK_MSTATUS( addAttribute( aColor ) ); - CHECK_MSTATUS( addAttribute( aIncandescence ) ); - CHECK_MSTATUS( addAttribute( aInTransparency ) ); - CHECK_MSTATUS( addAttribute( aOutColor ) ); - CHECK_MSTATUS( addAttribute( aOutTransparency ) ); - CHECK_MSTATUS( addAttribute( aNormalCamera ) ); - - // Only add the parent of the compound - CHECK_MSTATUS( addAttribute( aLightData ) ); - - // The attributeAffects() method is used to indicate when the input - // attribute affects the output attribute. This knowledge allows Maya - // to optimize dependencies in the graph in more complex nodes where - // there may be several inputs and outputs, but not all the inputs - // affect all the outputs. - // - CHECK_MSTATUS( attributeAffects( aTranslucenceCoeff, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aDiffuseReflectivity, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aColorR, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aColorG, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aColorB, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aColor, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aInTransR, aOutTransparency ) ); - CHECK_MSTATUS( attributeAffects( aInTransG, aOutTransparency ) ); - CHECK_MSTATUS( attributeAffects( aInTransB, aOutTransparency ) ); - CHECK_MSTATUS( attributeAffects( aInTransparency, aOutTransparency ) ); - CHECK_MSTATUS( attributeAffects( aInTransparency, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aIncandescenceR, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aIncandescenceG, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aIncandescenceB, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aIncandescence, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightIntensityR, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightIntensityB, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightIntensityG, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightIntensity, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aNormalCameraX, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aNormalCameraY, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aNormalCameraZ, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aNormalCamera, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightDirectionX, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightDirectionY, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightDirectionZ, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightDirection, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightAmbient, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightSpecular, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightDiffuse, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightShadowFraction, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aPreShadowIntensity, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightBlindData, aOutColor ) ); - CHECK_MSTATUS( attributeAffects( aLightData, aOutColor ) ); - - // loading x-ray part - xrDoubleSide = nAttr.create( "xrayDoubleSide", "xrd", MFnNumericData::kBoolean, 0, &status ); - MAKE_INPUT(nAttr); - - LPSTRVec lst; - LPSTRIt it; - - xrEngineData = eAttr.create( "xrayEngineShader", "xre"); - MAKE_INPUT(eAttr); - LoadBlenderList(lst); - for (it=lst.begin(); it!=lst.end(); it++) - { - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } + MFnNumericAttribute nAttr; + MFnLightDataAttribute lAttr; + MFnEnumAttribute eAttr; + MFnTypedAttribute tAttr; + + MStatus status; // Status will be used to hold the MStatus value + // returned by each api function call. It is important + // to check the status returned by a call to aid in + // debugging. Failed API calls can result in subtle + // errors that can be difficult to track down, you may + // wish to use the CHECK_MSTATUS macro for any API + // call where you do not need to provide your own + // error handling. + // + + // Attribute Initialization: + // + // create - The create function creates a new attribute for the + // node, it takes a long name for the attribute, a short + // name for the attribute, the type of the attribute, + // and a status object to determine if the api call was + // successful. + // + // setKeyable - Sets whether this attribute should accept keyframe + // data, Attributes are not keyable by default. + // + // setStorable - Sets whether this attribute should be storable. If an + // attribute is storable, then it will be writen out + // when the node is stored to a file. Attributes are + // storable by default. + // + // setDefault - Sets the default value for this attribute. + // + // setUsedAsColor - Sets whether this attribute should be presented as + // a color in the UI. + // + // setHidden - Sets whether this attribute should be hidden from the + // UI. This is useful if the attribute is being used for + // blind data, or if it is being used as scratch space + // for a geometry calculation (should also be marked + // non-connectable in that case). Attributes are not + // hidden by default. + // + // setReadable - Sets whether this attribute should be readable. If an + // attribute is readable, then it can be used as the + // source in a dependency graph connection. Attributes + // are readable by default. + // + // setWritable - Sets whether this attribute should be readable. If an + // attribute is writable, then it can be used as the + // destination in a dependency graph connection. If an + // attribute is not writable then setAttr commands will + // fail to change the attribute. If both keyable and + // writable for an attribute are set to true it will be + // displayed in the channel box when the node is + // selected. Attributes are writable by default. + // + // setArray - Sets whether this attribute should have an array of + // data. This should be set to true if the attribute + // needs to accept multiple incoming connections. + // Attributes are single elements by default. + // + + // Input Attributes + // + aTranslucenceCoeff = nAttr.create("translucenceCoeff", "tc", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f)); + + aDiffuseReflectivity = nAttr.create("diffuseReflectivity", "drfl", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.8f)); + + aColorR = nAttr.create("colorR", "cr", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f)); + + aColorG = nAttr.create("colorG", "cg", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.58824f)); + + aColorB = nAttr.create("colorB", "cb", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.644f)); + + aColor = nAttr.create("color", "c", aColorR, aColorG, aColorB, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f, 0.58824f, 0.644f)); + CHECK_MSTATUS(nAttr.setUsedAsColor(true)); + + aIncandescenceR = nAttr.create("incandescenceR", "ir", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f)); + + aIncandescenceG = nAttr.create("incandescenceG", "ig", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f)); + + aIncandescenceB = nAttr.create("incandescenceB", "ib", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f)); + + aIncandescence = nAttr.create("incandescence", "ic", aIncandescenceR, aIncandescenceG, aIncandescenceB, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f, 0.0f, 0.0f)); + CHECK_MSTATUS(nAttr.setUsedAsColor(true)); + + aInTransR = nAttr.create("transparencyR", "itr", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + + aInTransG = nAttr.create("transparencyG", "itg", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + + aInTransB = nAttr.create("transparencyB", "itb", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + + aInTransparency = nAttr.create("transparency", "it", aInTransR, aInTransG, aInTransB, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setKeyable(true)); + CHECK_MSTATUS(nAttr.setStorable(true)); + CHECK_MSTATUS(nAttr.setDefault(0.0f, 0.0f, 0.0f)); + CHECK_MSTATUS(nAttr.setUsedAsColor(true)); + + // Output Attributes + // + + // Color Output + // + aOutColorR = nAttr.create("outColorR", "ocr", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutColorG = nAttr.create("outColorG", "ocg", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutColorB = nAttr.create("outColorB", "ocb", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutColor = nAttr.create("outColor", "oc", aOutColorR, aOutColorG, aOutColorB, &status); + CHECK_MSTATUS(status); + + CHECK_MSTATUS(nAttr.setHidden(false)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + + // Transparency Output + // + aOutTransR = nAttr.create("outTransparencyR", "otr", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutTransG = nAttr.create("outTransparencyG", "otg", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutTransB = nAttr.create("outTransparencyB", "otb", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + + aOutTransparency = nAttr.create("outTransparency", "ot", aOutTransR, aOutTransG, aOutTransB, &status); + CHECK_MSTATUS(status); + + CHECK_MSTATUS(nAttr.setHidden(false)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + + // Camera Normals + // + aNormalCameraX = nAttr.create("normalCameraX", "nx", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aNormalCameraY = nAttr.create("normalCameraY", "ny", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aNormalCameraZ = nAttr.create("normalCameraZ", "nz", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aNormalCamera = nAttr.create("normalCamera", "n", aNormalCameraX, aNormalCameraY, aNormalCameraZ, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); + + // Light Direction + // + aLightDirectionX = nAttr.create("lightDirectionX", "ldx", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightDirectionY = nAttr.create("lightDirectionY", "ldy", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightDirectionZ = nAttr.create("lightDirectionZ", "ldz", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightDirection = + nAttr.create("lightDirection", "ld", aLightDirectionX, aLightDirectionY, aLightDirectionZ, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + + // Light Intensity + // + aLightIntensityR = nAttr.create("lightIntensityR", "lir", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightIntensityG = nAttr.create("lightIntensityG", "lig", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightIntensityB = nAttr.create("lightIntensityB", "lib", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightIntensity = + nAttr.create("lightIntensity", "li", aLightIntensityR, aLightIntensityG, aLightIntensityB, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + + // Light + // + aLightAmbient = nAttr.create("lightAmbient", "la", MFnNumericData::kBoolean, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(true)); + + aLightDiffuse = nAttr.create("lightDiffuse", "ldf", MFnNumericData::kBoolean, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(true)); + + aLightSpecular = nAttr.create("lightSpecular", "ls", MFnNumericData::kBoolean, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(false)); + + aLightShadowFraction = nAttr.create("lightShadowFraction", "lsf", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aPreShadowIntensity = nAttr.create("preShadowIntensity", "psi", MFnNumericData::kFloat, 0, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + CHECK_MSTATUS(nAttr.setDefault(1.0f)); + + aLightBlindData = nAttr.createAddr("lightBlindData", "lbld", &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(true)); + CHECK_MSTATUS(nAttr.setWritable(false)); + + aLightData = lAttr.create("lightDataArray", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, + aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData, &status); + CHECK_MSTATUS(status); + CHECK_MSTATUS(lAttr.setArray(true)); + CHECK_MSTATUS(lAttr.setStorable(false)); + CHECK_MSTATUS(lAttr.setHidden(true)); + CHECK_MSTATUS(lAttr.setDefault(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, false, 1.0f, 1.0f, NULL)); + + // Next we will add the attributes we have defined to the node + // + CHECK_MSTATUS(addAttribute(aTranslucenceCoeff)); + CHECK_MSTATUS(addAttribute(aDiffuseReflectivity)); + CHECK_MSTATUS(addAttribute(aColor)); + CHECK_MSTATUS(addAttribute(aIncandescence)); + CHECK_MSTATUS(addAttribute(aInTransparency)); + CHECK_MSTATUS(addAttribute(aOutColor)); + CHECK_MSTATUS(addAttribute(aOutTransparency)); + CHECK_MSTATUS(addAttribute(aNormalCamera)); + + // Only add the parent of the compound + CHECK_MSTATUS(addAttribute(aLightData)); + + // The attributeAffects() method is used to indicate when the input + // attribute affects the output attribute. This knowledge allows Maya + // to optimize dependencies in the graph in more complex nodes where + // there may be several inputs and outputs, but not all the inputs + // affect all the outputs. + // + CHECK_MSTATUS(attributeAffects(aTranslucenceCoeff, aOutColor)); + CHECK_MSTATUS(attributeAffects(aDiffuseReflectivity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aColorR, aOutColor)); + CHECK_MSTATUS(attributeAffects(aColorG, aOutColor)); + CHECK_MSTATUS(attributeAffects(aColorB, aOutColor)); + CHECK_MSTATUS(attributeAffects(aColor, aOutColor)); + CHECK_MSTATUS(attributeAffects(aInTransR, aOutTransparency)); + CHECK_MSTATUS(attributeAffects(aInTransG, aOutTransparency)); + CHECK_MSTATUS(attributeAffects(aInTransB, aOutTransparency)); + CHECK_MSTATUS(attributeAffects(aInTransparency, aOutTransparency)); + CHECK_MSTATUS(attributeAffects(aInTransparency, aOutColor)); + CHECK_MSTATUS(attributeAffects(aIncandescenceR, aOutColor)); + CHECK_MSTATUS(attributeAffects(aIncandescenceG, aOutColor)); + CHECK_MSTATUS(attributeAffects(aIncandescenceB, aOutColor)); + CHECK_MSTATUS(attributeAffects(aIncandescence, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightIntensityR, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightIntensityB, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightIntensityG, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightIntensity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aNormalCameraX, aOutColor)); + CHECK_MSTATUS(attributeAffects(aNormalCameraY, aOutColor)); + CHECK_MSTATUS(attributeAffects(aNormalCameraZ, aOutColor)); + CHECK_MSTATUS(attributeAffects(aNormalCamera, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDirectionX, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDirectionY, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDirectionZ, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDirection, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightAmbient, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightSpecular, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDiffuse, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightShadowFraction, aOutColor)); + CHECK_MSTATUS(attributeAffects(aPreShadowIntensity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightBlindData, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightData, aOutColor)); + + // loading x-ray part + xrDoubleSide = nAttr.create("xrayDoubleSide", "xrd", MFnNumericData::kBoolean, 0, &status); + MAKE_INPUT(nAttr); + + LPSTRVec lst; + LPSTRIt it; + + xrEngineData = eAttr.create("xrayEngineShader", "xre"); + MAKE_INPUT(eAttr); + LoadBlenderList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } #if MAYA_API_VERSION > 450 - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); -#else + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); +#else #endif - ClearList(lst); - - xrCompilerData = eAttr.create( "xrayCompilerShader", "xrc"); - MAKE_INPUT(eAttr); - LoadShaderLCList(lst); - for (it=lst.begin(); it!=lst.end(); it++){ - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } + ClearList(lst); + + xrCompilerData = eAttr.create("xrayCompilerShader", "xrc"); + MAKE_INPUT(eAttr); + LoadShaderLCList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } #if MAYA_API_VERSION > 450 - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); -#else + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); +#else #endif - ClearList(lst); - - xrMaterialData = eAttr.create( "xrayGameMaterial", " "); - MAKE_INPUT(eAttr); - LoadGameMtlList(lst); - for (it=lst.begin(); it!=lst.end(); it++) - { - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,crc16_calc((u8*)*it,xr_strlen(*it)))); - } + ClearList(lst); + + xrMaterialData = eAttr.create("xrayGameMaterial", " "); + MAKE_INPUT(eAttr); + LoadGameMtlList(lst); + for (it = lst.begin(); it != lst.end(); it++) + { + _ChangeSymbol(*it, '\\', '/'); + CHECK_MSTATUS(eAttr.addField(*it, crc16_calc((u8*)*it, xr_strlen(*it)))); + } #if MAYA_API_VERSION > 450 - CHECK_MSTATUS ( eAttr.setDefault(eAttr.fieldIndex("default"))); -#else + CHECK_MSTATUS(eAttr.setDefault(eAttr.fieldIndex("default"))); +#else #endif - ClearList(lst); + ClearList(lst); - CHECK_MSTATUS ( addAttribute(xrDoubleSide) ); - CHECK_MSTATUS ( addAttribute(xrEngineData) ); - CHECK_MSTATUS ( addAttribute(xrCompilerData) ); - CHECK_MSTATUS ( addAttribute(xrMaterialData) ); - // end x-ray part + CHECK_MSTATUS(addAttribute(xrDoubleSide)); + CHECK_MSTATUS(addAttribute(xrEngineData)); + CHECK_MSTATUS(addAttribute(xrCompilerData)); + CHECK_MSTATUS(addAttribute(xrMaterialData)); + // end x-ray part - return( MS::kSuccess ); + return (MS::kSuccess); } // The compute() method does the actual work of the node using the inputs -// of the node to generate its output. +// of the node to generate its output. // // Compute takes two parameters: plug and data. // - Plug is the the data value that needs to be recomputed // - Data provides handles to all of the nodes attributes, only these // handles should be used when performing computations. // -MStatus CXRayMtl::compute( const MPlug& plug, MDataBlock& block ) -{ - // The plug parameter will allow us to determine which output attribute - // needs to be calculated. - // - if( plug == aOutColor - || plug == aOutColorR - || plug == aOutColorG - || plug == aOutColorB - || plug == aOutTransparency - || plug == aOutTransR - || plug == aOutTransG - || plug == aOutTransB ) - { - MStatus status; - MFloatVector resultColor( 0.0, 0.0, 0.0 ); - - - // Get surface shading parameters from input block - // - MFloatVector& surfaceNormal = block.inputValue( aNormalCamera, - &status ).asFloatVector(); - CHECK_MSTATUS( status ); - - MFloatVector& surfaceColor = block.inputValue( aColor, - &status ).asFloatVector(); - CHECK_MSTATUS( status ); - - MFloatVector& incandescence = block.inputValue( aIncandescence, - &status ).asFloatVector(); - CHECK_MSTATUS( status ); - - float diffuseReflectivity = block.inputValue( - aDiffuseReflectivity, &status ).asFloat(); - CHECK_MSTATUS( status ); - -// float translucenceCoeff = block.inputValue( aTranslucenceCoeff, -// &status ).asFloat(); -// CHECK_MSTATUS( status ); - - - // Get light list - // - MArrayDataHandle lightData = block.inputArrayValue( aLightData, - &status ); - CHECK_MSTATUS( status ); - - int numLights = lightData.elementCount( &status ); - CHECK_MSTATUS( status ); - - - // Calculate the effect of the lights in the scene on the color - // - - // Iterate through light list and get ambient/diffuse values - // - for( int count=1; count <= numLights; count++ ) - { - // Get the current light out of the array - // - MDataHandle currentLight = lightData.inputValue( &status ); - CHECK_MSTATUS( status ); - - - // Get the intensity of that light - // - MFloatVector& lightIntensity = currentLight.child( - aLightIntensity ).asFloatVector(); - - - // Find ambient component - // - if ( currentLight.child( aLightAmbient ).asBool() ) - { - resultColor += lightIntensity; - } - - - // Find diffuse component - // - if ( currentLight.child( aLightDiffuse ).asBool() ) - { - MFloatVector& lightDirection = currentLight.child( - aLightDirection ).asFloatVector(); - float cosln = lightDirection * surfaceNormal; - - if ( cosln > 0.0f ) { - resultColor += lightIntensity - * ( cosln * diffuseReflectivity ); - } - } - - - // Advance to the next light. - // - if ( count < numLights ) { - status = lightData.next(); - CHECK_MSTATUS( status ); - } - } - - - // Factor incident light with surface color and add incandescence - // - resultColor[0] = resultColor[0] * surfaceColor[0] + incandescence[0]; - resultColor[1] = resultColor[1] * surfaceColor[1] + incandescence[1]; - resultColor[2] = resultColor[2] * surfaceColor[2] + incandescence[2]; - - - // Set ouput color attribute - // - if ( plug == aOutColor || plug == aOutColorR || plug == aOutColorG - || plug == aOutColorB) - { - // Get the handle to the attribute - // - MDataHandle outColorHandle = block.outputValue( aOutColor, - &status ); - CHECK_MSTATUS( status ); - MFloatVector& outColor = outColorHandle.asFloatVector(); - - outColor = resultColor; // Set the output value - outColorHandle.setClean(); // Mark the output value as clean - } - - - // Set ouput transparency - // - if ( plug == aOutTransparency || plug == aOutTransR - || plug == aOutTransG || plug == aOutTransB ) - { - MFloatVector& transparency = block.inputValue( - aInTransparency, &status ).asFloatVector(); - CHECK_MSTATUS( status ); - - - // Get the handle to the attribute - // - MDataHandle outTransHandle = block.outputValue( - aOutTransparency, &status ); - CHECK_MSTATUS( status ); - MFloatVector& outTrans = outTransHandle.asFloatVector(); - - outTrans = transparency; // Set the output value - outTransHandle.setClean(); // Mark the output value as clean - } - } - else - { - return( MS::kUnknownParameter ); // We got an unexpected plug - } - - return( MS::kSuccess ); +MStatus CXRayMtl::compute(const MPlug& plug, MDataBlock& block) +{ + // The plug parameter will allow us to determine which output attribute + // needs to be calculated. + // + if (plug == aOutColor || plug == aOutColorR || plug == aOutColorG || plug == aOutColorB || + plug == aOutTransparency || plug == aOutTransR || plug == aOutTransG || plug == aOutTransB) + { + MStatus status; + MFloatVector resultColor(0.0, 0.0, 0.0); + + // Get surface shading parameters from input block + // + MFloatVector& surfaceNormal = block.inputValue(aNormalCamera, &status).asFloatVector(); + CHECK_MSTATUS(status); + + MFloatVector& surfaceColor = block.inputValue(aColor, &status).asFloatVector(); + CHECK_MSTATUS(status); + + MFloatVector& incandescence = block.inputValue(aIncandescence, &status).asFloatVector(); + CHECK_MSTATUS(status); + + float diffuseReflectivity = block.inputValue(aDiffuseReflectivity, &status).asFloat(); + CHECK_MSTATUS(status); + + // float translucenceCoeff = block.inputValue( aTranslucenceCoeff, + // &status ).asFloat(); + // CHECK_MSTATUS( status ); + + // Get light list + // + MArrayDataHandle lightData = block.inputArrayValue(aLightData, &status); + CHECK_MSTATUS(status); + + int numLights = lightData.elementCount(&status); + CHECK_MSTATUS(status); + + // Calculate the effect of the lights in the scene on the color + // + + // Iterate through light list and get ambient/diffuse values + // + for (int count = 1; count <= numLights; count++) + { + // Get the current light out of the array + // + MDataHandle currentLight = lightData.inputValue(&status); + CHECK_MSTATUS(status); + + // Get the intensity of that light + // + MFloatVector& lightIntensity = currentLight.child(aLightIntensity).asFloatVector(); + + // Find ambient component + // + if (currentLight.child(aLightAmbient).asBool()) { + resultColor += lightIntensity; + } + + // Find diffuse component + // + if (currentLight.child(aLightDiffuse).asBool()) { + MFloatVector& lightDirection = currentLight.child(aLightDirection).asFloatVector(); + float cosln = lightDirection * surfaceNormal; + + if (cosln > 0.0f) { + resultColor += lightIntensity * (cosln * diffuseReflectivity); + } + } + + // Advance to the next light. + // + if (count < numLights) { + status = lightData.next(); + CHECK_MSTATUS(status); + } + } + + // Factor incident light with surface color and add incandescence + // + resultColor[0] = resultColor[0] * surfaceColor[0] + incandescence[0]; + resultColor[1] = resultColor[1] * surfaceColor[1] + incandescence[1]; + resultColor[2] = resultColor[2] * surfaceColor[2] + incandescence[2]; + + // Set ouput color attribute + // + if (plug == aOutColor || plug == aOutColorR || plug == aOutColorG || plug == aOutColorB) { + // Get the handle to the attribute + // + MDataHandle outColorHandle = block.outputValue(aOutColor, &status); + CHECK_MSTATUS(status); + MFloatVector& outColor = outColorHandle.asFloatVector(); + + outColor = resultColor; // Set the output value + outColorHandle.setClean(); // Mark the output value as clean + } + + // Set ouput transparency + // + if (plug == aOutTransparency || plug == aOutTransR || plug == aOutTransG || plug == aOutTransB) { + MFloatVector& transparency = block.inputValue(aInTransparency, &status).asFloatVector(); + CHECK_MSTATUS(status); + + // Get the handle to the attribute + // + MDataHandle outTransHandle = block.outputValue(aOutTransparency, &status); + CHECK_MSTATUS(status); + MFloatVector& outTrans = outTransHandle.asFloatVector(); + + outTrans = transparency; // Set the output value + outTransHandle.setClean(); // Mark the output value as clean + } + } + else + { + return (MS::kUnknownParameter); // We got an unexpected plug + } + + return (MS::kSuccess); } - -MStatus uninitializePlugin( MObject obj ) +MStatus uninitializePlugin(MObject obj) { - const MString UserClassify( "shader/surface" ); + const MString UserClassify("shader/surface"); - MString command( "if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\"" ); + MString command("if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\""); - MFnPlugin plugin( obj ); + MFnPlugin plugin(obj); - CHECK_MSTATUS( plugin.deregisterNode( CXRayMtl::id ) ); + CHECK_MSTATUS(plugin.deregisterNode(CXRayMtl::id)); - command += UserClassify; - command += "\");}\n"; + command += UserClassify; + command += "\");}\n"; - CHECK_MSTATUS( MGlobal::executeCommand( command ) ); + CHECK_MSTATUS(MGlobal::executeCommand(command)); - Core._destroy(); + Core._destroy(); - return MS::kSuccess; + return MS::kSuccess; } -static MObject INIT_OBJ=MObject::kNullObj; +static MObject INIT_OBJ = MObject::kNullObj; void uninitialize(void*) { - if (!INIT_OBJ.isNull()){ - uninitializePlugin(INIT_OBJ); - INIT_OBJ=MObject::kNullObj; - } - Core._destroy(); + if (!INIT_OBJ.isNull()) { + uninitializePlugin(INIT_OBJ); + INIT_OBJ = MObject::kNullObj; + } + Core._destroy(); } // These methods load and unload the plugin, registerNode registers the // new node type with maya // -MStatus initializePlugin( MObject obj ) -{ - INIT_OBJ = obj; - const MString UserClassify( "shader/surface" ); +MStatus initializePlugin(MObject obj) +{ + INIT_OBJ = obj; + const MString UserClassify("shader/surface"); - Core._initialize("XRayMayaPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); + Core._initialize("XRayMayaPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); - MString command( "if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\"" ); + MString command("if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\""); - MFnPlugin plugin( obj, "GSC Game World", "1.00", "Any"); + MFnPlugin plugin(obj, "GSC Game World", "1.00", "Any"); - CHECK_MSTATUS( plugin.registerNode( "XRayMtl", CXRayMtl::id, - CXRayMtl::creator, CXRayMtl::initialize, MPxNode::kDependNode, - &UserClassify ) ); + CHECK_MSTATUS(plugin.registerNode( + "XRayMtl", CXRayMtl::id, CXRayMtl::creator, CXRayMtl::initialize, MPxNode::kDependNode, &UserClassify)); - command += UserClassify; + command += UserClassify; - command += "\");}\n"; + command += "\");}\n"; - CHECK_MSTATUS( MGlobal::executeCommand( command ) ); + CHECK_MSTATUS(MGlobal::executeCommand(command)); - // add callbacks -// MSceneMessage::addCallback(MSceneMessage::kMayaExiting, uninitialize, 0); + // add callbacks + // MSceneMessage::addCallback(MSceneMessage::kMayaExiting, uninitialize, 0); - return( MS::kSuccess ); + return (MS::kSuccess); } - diff --git a/src/plugins/Maya/Material/phongShader.cpp b/src/plugins/Maya/Material/phongShader.cpp index 8c8b7c5c6ac..bbcaa0c66f2 100644 --- a/src/plugins/Maya/Material/phongShader.cpp +++ b/src/plugins/Maya/Material/phongShader.cpp @@ -1,22 +1,22 @@ #include "stdafx.h" using namespace std; -#include -#include -#include -#include +#include #include #include -#include -#include -#include -#include #include +#include +#include +#include #include +#include +#include +#include +#include // add for raytracing api enhancement -#include #include +#include #include "BlenderListLoader.h" // @@ -24,27 +24,27 @@ using namespace std; /////////////////////////////////////////////////////// class CXRayMtl : public MPxNode { - public: - CXRayMtl(); - virtual ~CXRayMtl(); +public: + CXRayMtl(); + virtual ~CXRayMtl(); - virtual MStatus compute( const MPlug&, MDataBlock& ); + virtual MStatus compute(const MPlug&, MDataBlock&); - virtual void postConstructor(); + virtual void postConstructor(); - static void * creator(); - static MStatus initialize(); - static MTypeId id; + static void* creator(); + static MStatus initialize(); + static MTypeId id; - private: - static MObject aColor; +private: + static MObject aColor; static MObject aTranslucenceCoeff; static MObject aDiffuseReflectivity; - static MObject aIncandescence; - static MObject aPointCamera; - static MObject aNormalCamera; - static MObject aLightDirection; - static MObject aLightIntensity; + static MObject aIncandescence; + static MObject aPointCamera; + static MObject aNormalCamera; + static MObject aLightDirection; + static MObject aLightIntensity; static MObject aPower; static MObject aSpecularity; static MObject aLightAmbient; @@ -54,10 +54,10 @@ class CXRayMtl : public MPxNode static MObject aPreShadowIntensity; static MObject aLightBlindData; static MObject aLightData; - - static MObject aXREngineData; - static MObject aXRCompilerData; - static MObject aXRMaterialData; + + static MObject aXREngineData; + static MObject aXRCompilerData; + static MObject aXRMaterialData; static MObject aRayOrigin; static MObject aRayDirection; @@ -68,16 +68,15 @@ class CXRayMtl : public MPxNode static MObject aReflectGain; - static MObject aTriangleNormalCamera; - - static MObject aOutColor; + static MObject aTriangleNormalCamera; + static MObject aOutColor; }; // Static data -MTypeId CXRayMtl::id( 0x81001 ); +MTypeId CXRayMtl::id(0x81001); -// Attributes +// Attributes MObject CXRayMtl::aColor; MObject CXRayMtl::aTranslucenceCoeff; MObject CXRayMtl::aDiffuseReflectivity; @@ -112,24 +111,24 @@ MObject CXRayMtl::aReflectGain; MObject CXRayMtl::aTriangleNormalCamera; -#define MAKE_INPUT(attr) \ - CHECK_MSTATUS ( attr.setKeyable(true) ); \ - CHECK_MSTATUS ( attr.setStorable(true) ); \ - CHECK_MSTATUS ( attr.setReadable(true) ); \ - CHECK_MSTATUS ( attr.setWritable(true) ); +#define MAKE_INPUT(attr) \ + CHECK_MSTATUS(attr.setKeyable(true)); \ + CHECK_MSTATUS(attr.setStorable(true)); \ + CHECK_MSTATUS(attr.setReadable(true)); \ + CHECK_MSTATUS(attr.setWritable(true)); -#define MAKE_OUTPUT(attr) \ - CHECK_MSTATUS ( attr.setKeyable(false) ) ; \ - CHECK_MSTATUS ( attr.setStorable(false) ); \ - CHECK_MSTATUS ( attr.setReadable(true) ) ; \ - CHECK_MSTATUS ( attr.setWritable(false) ); +#define MAKE_OUTPUT(attr) \ + CHECK_MSTATUS(attr.setKeyable(false)); \ + CHECK_MSTATUS(attr.setStorable(false)); \ + CHECK_MSTATUS(attr.setReadable(true)); \ + CHECK_MSTATUS(attr.setWritable(false)); // // DESCRIPTION: /////////////////////////////////////////////////////// -void CXRayMtl::postConstructor( ) +void CXRayMtl::postConstructor() { - setMPSafe(true); + setMPSafe(true); } // @@ -149,11 +148,11 @@ CXRayMtl::~CXRayMtl() // // DESCRIPTION: /////////////////////////////////////////////////////// -void * CXRayMtl::creator() +void* CXRayMtl::creator() { - Core._initialize("XRayPlugin",ELogCallback,"\\\\X-Ray\\stalker$\\"); - - return new CXRayMtl(); + Core._initialize("XRayPlugin", ELogCallback, "\\\\X-Ray\\stalker$\\"); + + return new CXRayMtl(); } // @@ -161,432 +160,410 @@ void * CXRayMtl::creator() /////////////////////////////////////////////////////// MStatus CXRayMtl::initialize() { - MFnNumericAttribute nAttr; + MFnNumericAttribute nAttr; MFnLightDataAttribute lAttr; - MFnEnumAttribute eAttr; -/* - // loading x-ray part - LPSTRVec lst; - LPSTRIt it; - int k=0; - aXREngineData = eAttr.create( "engineShader", "xre"); - MAKE_INPUT(eAttr); - LoadBlenderList(lst); - for (it=lst.begin(); it!=lst.end(); it++){ - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); - } - ClearList(lst); - - aXRCompilerData = eAttr.create( "compilerShader", "xrc"); - MAKE_INPUT(eAttr); - LoadShaderLCList(lst); - for (it=lst.begin(); it!=lst.end(); it++){ - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); - } - ClearList(lst); - - aXRMaterialData = eAttr.create( "gameMaterial", "xrm"); - MAKE_INPUT(eAttr); - LoadGameMtlList(lst); - for (it=lst.begin(); it!=lst.end(); it++){ - _ChangeSymbol(*it,'\\','/'); - CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); - } - ClearList(lst); - // end x-ray part -*/ - aTranslucenceCoeff = nAttr.create("translucenceCoeff", "tc", - MFnNumericData::kFloat); + MFnEnumAttribute eAttr; + /* + // loading x-ray part + LPSTRVec lst; + LPSTRIt it; + int k=0; + aXREngineData = eAttr.create( "engineShader", "xre"); + MAKE_INPUT(eAttr); + LoadBlenderList(lst); + for (it=lst.begin(); it!=lst.end(); it++){ + _ChangeSymbol(*it,'\\','/'); + CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); + } + ClearList(lst); + + aXRCompilerData = eAttr.create( "compilerShader", "xrc"); + MAKE_INPUT(eAttr); + LoadShaderLCList(lst); + for (it=lst.begin(); it!=lst.end(); it++){ + _ChangeSymbol(*it,'\\','/'); + CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); + } + ClearList(lst); + + aXRMaterialData = eAttr.create( "gameMaterial", "xrm"); + MAKE_INPUT(eAttr); + LoadGameMtlList(lst); + for (it=lst.begin(); it!=lst.end(); it++){ + _ChangeSymbol(*it,'\\','/'); + CHECK_MSTATUS (eAttr.addField(*it,it-lst.begin())); + } + ClearList(lst); + // end x-ray part + */ + aTranslucenceCoeff = nAttr.create("translucenceCoeff", "tc", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - aDiffuseReflectivity = nAttr.create("diffuseReflectivity", "drfl", - MFnNumericData::kFloat); + aDiffuseReflectivity = nAttr.create("diffuseReflectivity", "drfl", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(0.8f) ); + CHECK_MSTATUS(nAttr.setDefault(0.8f)); - aColor = nAttr.createColor( "color", "c" ); + aColor = nAttr.createColor("color", "c"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(0.0f, 0.58824f, 0.644f) ); + CHECK_MSTATUS(nAttr.setDefault(0.0f, 0.58824f, 0.644f)); - aIncandescence = nAttr.createColor( "incandescence", "ic" ); + aIncandescence = nAttr.createColor("incandescence", "ic"); MAKE_INPUT(nAttr); - aOutColor = nAttr.createColor( "outColor", "oc" ); + aOutColor = nAttr.createColor("outColor", "oc"); MAKE_OUTPUT(nAttr); - aPointCamera = nAttr.createPoint( "pointCamera", "pc" ); + aPointCamera = nAttr.createPoint("pointCamera", "pc"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); - aPower = nAttr.create( "power", "pow", MFnNumericData::kFloat); + aPower = nAttr.create("power", "pow", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setMin(0.0f) ); - CHECK_MSTATUS ( nAttr.setMax(200.0f) ); - CHECK_MSTATUS ( nAttr.setDefault(10.0f) ); + CHECK_MSTATUS(nAttr.setMin(0.0f)); + CHECK_MSTATUS(nAttr.setMax(200.0f)); + CHECK_MSTATUS(nAttr.setDefault(10.0f)); - aSpecularity = nAttr.create( "specularity", "spc", MFnNumericData::kFloat); + aSpecularity = nAttr.create("specularity", "spc", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setMin(0.0f) ); - CHECK_MSTATUS ( nAttr.setMax(1.0f) ) ; - CHECK_MSTATUS ( nAttr.setDefault(0.5f) ); + CHECK_MSTATUS(nAttr.setMin(0.0f)); + CHECK_MSTATUS(nAttr.setMax(1.0f)); + CHECK_MSTATUS(nAttr.setDefault(0.5f)); - aReflectGain = nAttr.create( "reflectionGain", "rg", MFnNumericData::kFloat); + aReflectGain = nAttr.create("reflectionGain", "rg", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setMin(0.0f) ); - CHECK_MSTATUS ( nAttr.setMax(1.0f) ); - CHECK_MSTATUS ( nAttr.setDefault(0.5f) ); + CHECK_MSTATUS(nAttr.setMin(0.0f)); + CHECK_MSTATUS(nAttr.setMax(1.0f)); + CHECK_MSTATUS(nAttr.setDefault(0.5f)); - aNormalCamera = nAttr.createPoint( "normalCamera", "n" ); + aNormalCamera = nAttr.createPoint("normalCamera", "n"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); - aTriangleNormalCamera = nAttr.createPoint( "triangleNormalCamera", "tn" ); + aTriangleNormalCamera = nAttr.createPoint("triangleNormalCamera", "tn"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f)); - CHECK_MSTATUS ( nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightDirection = nAttr.createPoint( "lightDirection", "ld" ); + aLightDirection = nAttr.createPoint("lightDirection", "ld"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightIntensity = nAttr.createColor( "lightIntensity", "li" ); + aLightIntensity = nAttr.createColor("lightIntensity", "li"); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setDefault(1.0f, 1.0f, 1.0f) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightAmbient = nAttr.create( "lightAmbient", "la", - MFnNumericData::kBoolean); + aLightAmbient = nAttr.create("lightAmbient", "la", MFnNumericData::kBoolean); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightDiffuse = nAttr.create( "lightDiffuse", "ldf", - MFnNumericData::kBoolean); + aLightDiffuse = nAttr.create("lightDiffuse", "ldf", MFnNumericData::kBoolean); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightSpecular = nAttr.create( "lightSpecular", "ls", - MFnNumericData::kBoolean); + aLightSpecular = nAttr.create("lightSpecular", "ls", MFnNumericData::kBoolean); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightShadowFraction = nAttr.create("lightShadowFraction", "lsf", - MFnNumericData::kFloat); + aLightShadowFraction = nAttr.create("lightShadowFraction", "lsf", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setHidden(true)); - aPreShadowIntensity = nAttr.create("preShadowIntensity", "psi", - MFnNumericData::kFloat); + aPreShadowIntensity = nAttr.create("preShadowIntensity", "psi", MFnNumericData::kFloat); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); + CHECK_MSTATUS(nAttr.setHidden(true)); - aLightBlindData = nAttr.create("lightBlindData", "lbld", - MFnNumericData::kLong); + aLightBlindData = nAttr.create("lightBlindData", "lbld", MFnNumericData::kLong); MAKE_INPUT(nAttr); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - - aLightData = lAttr.create( "lightDataArray", "ltd", - aLightDirection, aLightIntensity, aLightAmbient, - aLightDiffuse, aLightSpecular, - aLightShadowFraction, - aPreShadowIntensity, - aLightBlindData); - CHECK_MSTATUS ( lAttr.setArray(true) ); - CHECK_MSTATUS ( lAttr.setStorable(false) ); - CHECK_MSTATUS ( lAttr.setHidden(true) ); - CHECK_MSTATUS ( lAttr.setDefault(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, - false, 0.0f, 1.0f, 0) ); - - // rayOrigin - MObject RayX = nAttr.create( "rayOx", "rxo", MFnNumericData::kFloat, 0.0 ); - MObject RayY = nAttr.create( "rayOy", "ryo", MFnNumericData::kFloat, 0.0 ); - MObject RayZ = nAttr.create( "rayOz", "rzo", MFnNumericData::kFloat, 0.0 ); - aRayOrigin = nAttr.create( "rayOrigin", "rog", RayX, RayY, RayZ ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(false) ); - - // rayDirection - RayX = nAttr.create( "rayDirectionX", "rdx", MFnNumericData::kFloat, 1.0 ); - RayY = nAttr.create( "rayDirectionY", "rdy", MFnNumericData::kFloat, 0.0 ); - RayZ = nAttr.create( "rayDirectionZ", "rdz", MFnNumericData::kFloat, 0.0 ); - aRayDirection = nAttr.create( "rayDirection", "rad", RayX, RayY, RayZ ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(false) ); - - // objectId - aObjectId = nAttr.create( "objectId", "oi", MFnNumericData::kLong, 0.0 ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(false) ); - - // raySampler - aRaySampler = nAttr.create("raySampler", "rtr", MFnNumericData::kLong,0.0); - CHECK_MSTATUS ( nAttr.setStorable(false)); - CHECK_MSTATUS ( nAttr.setHidden(true) ); - CHECK_MSTATUS ( nAttr.setReadable(false) ); - - // rayDepth - aRayDepth = nAttr.create( "rayDepth", "rd", MFnNumericData::kShort, 0.0 ); - CHECK_MSTATUS ( nAttr.setStorable(false) ); - CHECK_MSTATUS (nAttr.setHidden(true) ) ; - CHECK_MSTATUS ( nAttr.setReadable(false) ); - - CHECK_MSTATUS ( addAttribute(aXREngineData) ); - CHECK_MSTATUS ( addAttribute(aXRCompilerData) ); - CHECK_MSTATUS ( addAttribute(aXRMaterialData) ); - - CHECK_MSTATUS ( addAttribute(aTranslucenceCoeff) ); - CHECK_MSTATUS ( addAttribute(aDiffuseReflectivity) ); - CHECK_MSTATUS ( addAttribute(aColor) ); - CHECK_MSTATUS ( addAttribute(aIncandescence) ); - CHECK_MSTATUS ( addAttribute(aPointCamera) ); - CHECK_MSTATUS ( addAttribute(aNormalCamera) ); - CHECK_MSTATUS ( addAttribute(aTriangleNormalCamera) ); - - CHECK_MSTATUS ( addAttribute(aLightData) ); - - CHECK_MSTATUS ( addAttribute(aPower) ); - CHECK_MSTATUS ( addAttribute(aSpecularity) ); - CHECK_MSTATUS ( addAttribute(aOutColor) ); - - CHECK_MSTATUS ( addAttribute(aRayOrigin) ); - CHECK_MSTATUS ( addAttribute(aRayDirection) ); - CHECK_MSTATUS ( addAttribute(aObjectId) ); - CHECK_MSTATUS ( addAttribute(aRaySampler) ); - CHECK_MSTATUS ( addAttribute(aRayDepth) ); - CHECK_MSTATUS ( addAttribute(aReflectGain) ); - - CHECK_MSTATUS ( attributeAffects (aXREngineData, aXREngineData)); - CHECK_MSTATUS ( attributeAffects (aXRCompilerData, aXRCompilerData)); - CHECK_MSTATUS ( attributeAffects (aXRMaterialData, aXRMaterialData)); - - CHECK_MSTATUS ( attributeAffects (aTranslucenceCoeff, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aDiffuseReflectivity, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightIntensity, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aIncandescence, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aPointCamera, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aNormalCamera, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aTriangleNormalCamera, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightData, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightAmbient, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightSpecular, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightDiffuse, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightDirection, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightShadowFraction, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aPreShadowIntensity, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aLightBlindData, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aPower, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aSpecularity, aOutColor)); - CHECK_MSTATUS ( attributeAffects (aColor, aOutColor)); - - CHECK_MSTATUS ( attributeAffects (aRayOrigin,aOutColor)); - CHECK_MSTATUS ( attributeAffects (aRayDirection,aOutColor)); - CHECK_MSTATUS ( attributeAffects (aObjectId,aOutColor)); - CHECK_MSTATUS ( attributeAffects (aRaySampler,aOutColor)); - CHECK_MSTATUS ( attributeAffects (aRayDepth,aOutColor)); - CHECK_MSTATUS ( attributeAffects (aReflectGain,aOutColor) ); + CHECK_MSTATUS(nAttr.setHidden(true)); + + aLightData = lAttr.create("lightDataArray", "ltd", aLightDirection, aLightIntensity, aLightAmbient, aLightDiffuse, + aLightSpecular, aLightShadowFraction, aPreShadowIntensity, aLightBlindData); + CHECK_MSTATUS(lAttr.setArray(true)); + CHECK_MSTATUS(lAttr.setStorable(false)); + CHECK_MSTATUS(lAttr.setHidden(true)); + CHECK_MSTATUS(lAttr.setDefault(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, true, true, false, 0.0f, 1.0f, 0)); + + // rayOrigin + MObject RayX = nAttr.create("rayOx", "rxo", MFnNumericData::kFloat, 0.0); + MObject RayY = nAttr.create("rayOy", "ryo", MFnNumericData::kFloat, 0.0); + MObject RayZ = nAttr.create("rayOz", "rzo", MFnNumericData::kFloat, 0.0); + aRayOrigin = nAttr.create("rayOrigin", "rog", RayX, RayY, RayZ); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(false)); + + // rayDirection + RayX = nAttr.create("rayDirectionX", "rdx", MFnNumericData::kFloat, 1.0); + RayY = nAttr.create("rayDirectionY", "rdy", MFnNumericData::kFloat, 0.0); + RayZ = nAttr.create("rayDirectionZ", "rdz", MFnNumericData::kFloat, 0.0); + aRayDirection = nAttr.create("rayDirection", "rad", RayX, RayY, RayZ); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(false)); + + // objectId + aObjectId = nAttr.create("objectId", "oi", MFnNumericData::kLong, 0.0); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(false)); + + // raySampler + aRaySampler = nAttr.create("raySampler", "rtr", MFnNumericData::kLong, 0.0); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(false)); + + // rayDepth + aRayDepth = nAttr.create("rayDepth", "rd", MFnNumericData::kShort, 0.0); + CHECK_MSTATUS(nAttr.setStorable(false)); + CHECK_MSTATUS(nAttr.setHidden(true)); + CHECK_MSTATUS(nAttr.setReadable(false)); + + CHECK_MSTATUS(addAttribute(aXREngineData)); + CHECK_MSTATUS(addAttribute(aXRCompilerData)); + CHECK_MSTATUS(addAttribute(aXRMaterialData)); + + CHECK_MSTATUS(addAttribute(aTranslucenceCoeff)); + CHECK_MSTATUS(addAttribute(aDiffuseReflectivity)); + CHECK_MSTATUS(addAttribute(aColor)); + CHECK_MSTATUS(addAttribute(aIncandescence)); + CHECK_MSTATUS(addAttribute(aPointCamera)); + CHECK_MSTATUS(addAttribute(aNormalCamera)); + CHECK_MSTATUS(addAttribute(aTriangleNormalCamera)); + + CHECK_MSTATUS(addAttribute(aLightData)); + + CHECK_MSTATUS(addAttribute(aPower)); + CHECK_MSTATUS(addAttribute(aSpecularity)); + CHECK_MSTATUS(addAttribute(aOutColor)); + + CHECK_MSTATUS(addAttribute(aRayOrigin)); + CHECK_MSTATUS(addAttribute(aRayDirection)); + CHECK_MSTATUS(addAttribute(aObjectId)); + CHECK_MSTATUS(addAttribute(aRaySampler)); + CHECK_MSTATUS(addAttribute(aRayDepth)); + CHECK_MSTATUS(addAttribute(aReflectGain)); + + CHECK_MSTATUS(attributeAffects(aXREngineData, aXREngineData)); + CHECK_MSTATUS(attributeAffects(aXRCompilerData, aXRCompilerData)); + CHECK_MSTATUS(attributeAffects(aXRMaterialData, aXRMaterialData)); + + CHECK_MSTATUS(attributeAffects(aTranslucenceCoeff, aOutColor)); + CHECK_MSTATUS(attributeAffects(aDiffuseReflectivity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightIntensity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aIncandescence, aOutColor)); + CHECK_MSTATUS(attributeAffects(aPointCamera, aOutColor)); + CHECK_MSTATUS(attributeAffects(aNormalCamera, aOutColor)); + CHECK_MSTATUS(attributeAffects(aTriangleNormalCamera, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightData, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightAmbient, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightSpecular, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDiffuse, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightDirection, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightShadowFraction, aOutColor)); + CHECK_MSTATUS(attributeAffects(aPreShadowIntensity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aLightBlindData, aOutColor)); + CHECK_MSTATUS(attributeAffects(aPower, aOutColor)); + CHECK_MSTATUS(attributeAffects(aSpecularity, aOutColor)); + CHECK_MSTATUS(attributeAffects(aColor, aOutColor)); + + CHECK_MSTATUS(attributeAffects(aRayOrigin, aOutColor)); + CHECK_MSTATUS(attributeAffects(aRayDirection, aOutColor)); + CHECK_MSTATUS(attributeAffects(aObjectId, aOutColor)); + CHECK_MSTATUS(attributeAffects(aRaySampler, aOutColor)); + CHECK_MSTATUS(attributeAffects(aRayDepth, aOutColor)); + CHECK_MSTATUS(attributeAffects(aReflectGain, aOutColor)); return MS::kSuccess; } - // // DESCRIPTION: /////////////////////////////////////////////////////// -MStatus CXRayMtl::compute( -const MPlug& plug, - MDataBlock& block ) -{ - if ((plug != aOutColor) && (plug.parent() != aOutColor)) - return MS::kUnknownParameter; +MStatus CXRayMtl::compute(const MPlug& plug, MDataBlock& block) +{ + if ((plug != aOutColor) && (plug.parent() != aOutColor)) return MS::kUnknownParameter; - MFloatVector resultColor(0.0,0.0,0.0); + MFloatVector resultColor(0.0, 0.0, 0.0); // get sample surface shading parameters - MFloatVector& surfaceNormal = block.inputValue( aNormalCamera ).asFloatVector(); - MFloatVector& cameraPosition = block.inputValue( aPointCamera ).asFloatVector(); + MFloatVector& surfaceNormal = block.inputValue(aNormalCamera).asFloatVector(); + MFloatVector& cameraPosition = block.inputValue(aPointCamera).asFloatVector(); - // use for raytracing api enhancement below - MFloatVector point = cameraPosition; - MFloatVector normal = surfaceNormal; + // use for raytracing api enhancement below + MFloatVector point = cameraPosition; + MFloatVector normal = surfaceNormal; - MFloatVector& surfaceColor = block.inputValue( aColor ).asFloatVector(); - MFloatVector& incandescence = block.inputValue( aIncandescence ).asFloatVector(); - float diffuseReflectivity = block.inputValue( aDiffuseReflectivity ).asFloat(); + MFloatVector& surfaceColor = block.inputValue(aColor).asFloatVector(); + MFloatVector& incandescence = block.inputValue(aIncandescence).asFloatVector(); + float diffuseReflectivity = block.inputValue(aDiffuseReflectivity).asFloat(); // float translucenceCoeff = block.inputValue( aTranslucenceCoeff ).asFloat(); - // User-defined Reflection Color Gain - float reflectGain = block.inputValue( aReflectGain ).asFloat(); - + // User-defined Reflection Color Gain + float reflectGain = block.inputValue(aReflectGain).asFloat(); + // Phong shading attributes - float power = block.inputValue( aPower ).asFloat(); - float spec = block.inputValue( aSpecularity ).asFloat(); + float power = block.inputValue(aPower).asFloat(); + float spec = block.inputValue(aSpecularity).asFloat(); float specularR, specularG, specularB; float diffuseR, diffuseG, diffuseB; diffuseR = diffuseG = diffuseB = specularR = specularG = specularB = 0.0; // get light list - MArrayDataHandle lightData = block.inputArrayValue( aLightData ); + MArrayDataHandle lightData = block.inputArrayValue(aLightData); int numLights = lightData.elementCount(); - + // iterate through light list and get ambient/diffuse values - for( int count=1; count <= numLights; count++ ) + for (int count = 1; count <= numLights; count++) { MDataHandle currentLight = lightData.inputValue(); MFloatVector& lightIntensity = currentLight.child(aLightIntensity).asFloatVector(); - + // Find the blind data - int& blindData = currentLight.child( aLightBlindData ).asInt(); - + int& blindData = currentLight.child(aLightBlindData).asInt(); + // find ambient component - if( currentLight.child(aLightAmbient).asBool() ) { + if (currentLight.child(aLightAmbient).asBool()) { diffuseR += lightIntensity[0]; diffuseG += lightIntensity[1]; diffuseB += lightIntensity[2]; } MFloatVector& lightDirection = currentLight.child(aLightDirection).asFloatVector(); - - if ( blindData == 0 ) - { - // find diffuse and specular component - if( currentLight.child(aLightDiffuse).asBool() ) - { - float cosln = lightDirection * surfaceNormal;; - if( cosln > 0.0f ) // calculate only if facing light - { - diffuseR += lightIntensity[0] * ( cosln * diffuseReflectivity ); - diffuseG += lightIntensity[1] * ( cosln * diffuseReflectivity ); - diffuseB += lightIntensity[2] * ( cosln * diffuseReflectivity ); - } - - CHECK_MSTATUS( cameraPosition.normalize() ); - - if( cosln > 0.0f ) // calculate only if facing light - { - float RV = ( ( (2*surfaceNormal) * cosln ) - lightDirection ) * cameraPosition; - if( RV > 0.0 ) RV = 0.0; - if( RV < 0.0 ) RV = -RV; - - if ( power < 0 ) power = -power; - - float s = spec * powf( RV, power ); - - specularR += lightIntensity[0] * s; - specularG += lightIntensity[1] * s; - specularB += lightIntensity[2] * s; - } - } + + if (blindData == 0) { + // find diffuse and specular component + if (currentLight.child(aLightDiffuse).asBool()) { + float cosln = lightDirection * surfaceNormal; + ; + if (cosln > 0.0f) // calculate only if facing light + { + diffuseR += lightIntensity[0] * (cosln * diffuseReflectivity); + diffuseG += lightIntensity[1] * (cosln * diffuseReflectivity); + diffuseB += lightIntensity[2] * (cosln * diffuseReflectivity); + } + + CHECK_MSTATUS(cameraPosition.normalize()); + + if (cosln > 0.0f) // calculate only if facing light + { + float RV = (((2 * surfaceNormal) * cosln) - lightDirection) * cameraPosition; + if (RV > 0.0) RV = 0.0; + if (RV < 0.0) RV = -RV; + + if (power < 0) power = -power; + + float s = spec * powf(RV, power); + + specularR += lightIntensity[0] * s; + specularG += lightIntensity[1] * s; + specularB += lightIntensity[2] * s; + } + } } else { - float cosln = MRenderUtil::diffuseReflectance( blindData, lightDirection, point, surfaceNormal, true ); - if( cosln > 0.0f ) // calculate only if facing light - { - diffuseR += lightIntensity[0] * ( cosln * diffuseReflectivity ); - diffuseG += lightIntensity[1] * ( cosln * diffuseReflectivity ); - diffuseB += lightIntensity[2] * ( cosln * diffuseReflectivity ); - } - - CHECK_MSTATUS ( cameraPosition.normalize() ); - - if ( currentLight.child(aLightSpecular).asBool() ) - { - MFloatVector specLightDirection = lightDirection; - MDataHandle directionH = block.inputValue( aRayDirection ); - MFloatVector direction = directionH.asFloatVector(); - float lightAttenuation = 1.0; - - specLightDirection = MRenderUtil::maximumSpecularReflection( blindData, - lightDirection, point, surfaceNormal, direction ); - lightAttenuation = MRenderUtil::lightAttenuation( blindData, point, surfaceNormal, false ); - - // Are we facing the light - if ( specLightDirection * surfaceNormal > 0.0f ) - { - float power = block.inputValue( aPower ).asFloat(); - MFloatVector rv = 2 * surfaceNormal * ( surfaceNormal * direction ) - direction; - float s = spec * powf( rv * specLightDirection, power ); - - specularR += lightIntensity[0] * s * lightAttenuation; - specularG += lightIntensity[1] * s * lightAttenuation; - specularB += lightIntensity[2] * s * lightAttenuation; - } - } - } - if( !lightData.next() ) break; + float cosln = MRenderUtil::diffuseReflectance(blindData, lightDirection, point, surfaceNormal, true); + if (cosln > 0.0f) // calculate only if facing light + { + diffuseR += lightIntensity[0] * (cosln * diffuseReflectivity); + diffuseG += lightIntensity[1] * (cosln * diffuseReflectivity); + diffuseB += lightIntensity[2] * (cosln * diffuseReflectivity); + } + + CHECK_MSTATUS(cameraPosition.normalize()); + + if (currentLight.child(aLightSpecular).asBool()) { + MFloatVector specLightDirection = lightDirection; + MDataHandle directionH = block.inputValue(aRayDirection); + MFloatVector direction = directionH.asFloatVector(); + float lightAttenuation = 1.0; + + specLightDirection = + MRenderUtil::maximumSpecularReflection(blindData, lightDirection, point, surfaceNormal, direction); + lightAttenuation = MRenderUtil::lightAttenuation(blindData, point, surfaceNormal, false); + + // Are we facing the light + if (specLightDirection * surfaceNormal > 0.0f) { + float power = block.inputValue(aPower).asFloat(); + MFloatVector rv = 2 * surfaceNormal * (surfaceNormal * direction) - direction; + float s = spec * powf(rv * specLightDirection, power); + + specularR += lightIntensity[0] * s * lightAttenuation; + specularG += lightIntensity[1] * s * lightAttenuation; + specularB += lightIntensity[2] * s * lightAttenuation; + } + } + } + if (!lightData.next()) break; } // factor incident light with surface color and add incandescence - resultColor[0] = ( diffuseR * surfaceColor[0] ) + specularR + incandescence[0]; - resultColor[1] = ( diffuseG * surfaceColor[1] ) + specularG + incandescence[1]; - resultColor[2] = ( diffuseB * surfaceColor[2] ) + specularB + incandescence[2]; - - // add the reflection color - if (reflectGain > 0.0) { - - MStatus status; - - // required attributes for using raytracer - // origin, direction, sampler, depth, and object id. - // - MDataHandle originH = block.inputValue( aRayOrigin, &status); - MFloatVector origin = originH.asFloatVector(); - - MDataHandle directionH = block.inputValue( aRayDirection, &status); - MFloatVector direction = directionH.asFloatVector(); - - MDataHandle samplerH = block.inputValue( aRaySampler, &status); - int samplerPtr = samplerH.asLong(); - - MDataHandle depthH = block.inputValue( aRayDepth, &status); - short depth = depthH.asShort(); - - MDataHandle objH = block.inputValue( aObjectId, &status); - int objId = objH.asLong(); - - MFloatVector reflectColor; - MFloatVector reflectTransparency; - - MFloatVector& triangleNormal = block.inputValue( aTriangleNormalCamera ).asFloatVector(); - - // compute reflected ray - MFloatVector l = -direction; - float dot = l * normal; - if( dot < 0.0 ) dot = -dot; - MFloatVector refVector = 2 * normal * dot - l; // reflection ray - float dotRef = refVector * triangleNormal; - if( dotRef < 0.0 ) { - const float s = 0.01f; - MFloatVector mVec = refVector - dotRef * triangleNormal; - mVec.normalize(); - refVector = mVec + s * triangleNormal; - } - CHECK_MSTATUS ( refVector.normalize() ); - - status = MRenderUtil::raytrace( - point, // origin - refVector, // direction - objId, // object id - samplerPtr, // sampler info - depth, // ray depth - reflectColor, // output color and transp - reflectTransparency); - - // add in the reflection color - resultColor[0] += reflectGain * (reflectColor[0]); - resultColor[1] += reflectGain * (reflectColor[1]); - resultColor[2] += reflectGain * (reflectColor[2]); - } + resultColor[0] = (diffuseR * surfaceColor[0]) + specularR + incandescence[0]; + resultColor[1] = (diffuseG * surfaceColor[1]) + specularG + incandescence[1]; + resultColor[2] = (diffuseB * surfaceColor[2]) + specularB + incandescence[2]; + + // add the reflection color + if (reflectGain > 0.0) { + MStatus status; + + // required attributes for using raytracer + // origin, direction, sampler, depth, and object id. + // + MDataHandle originH = block.inputValue(aRayOrigin, &status); + MFloatVector origin = originH.asFloatVector(); + + MDataHandle directionH = block.inputValue(aRayDirection, &status); + MFloatVector direction = directionH.asFloatVector(); + + MDataHandle samplerH = block.inputValue(aRaySampler, &status); + int samplerPtr = samplerH.asLong(); + + MDataHandle depthH = block.inputValue(aRayDepth, &status); + short depth = depthH.asShort(); + + MDataHandle objH = block.inputValue(aObjectId, &status); + int objId = objH.asLong(); + + MFloatVector reflectColor; + MFloatVector reflectTransparency; + + MFloatVector& triangleNormal = block.inputValue(aTriangleNormalCamera).asFloatVector(); + + // compute reflected ray + MFloatVector l = -direction; + float dot = l * normal; + if (dot < 0.0) dot = -dot; + MFloatVector refVector = 2 * normal * dot - l; // reflection ray + float dotRef = refVector * triangleNormal; + if (dotRef < 0.0) { + const float s = 0.01f; + MFloatVector mVec = refVector - dotRef * triangleNormal; + mVec.normalize(); + refVector = mVec + s * triangleNormal; + } + CHECK_MSTATUS(refVector.normalize()); + + status = MRenderUtil::raytrace(point, // origin + refVector, // direction + objId, // object id + samplerPtr, // sampler info + depth, // ray depth + reflectColor, // output color and transp + reflectTransparency); + + // add in the reflection color + resultColor[0] += reflectGain * (reflectColor[0]); + resultColor[1] += reflectGain * (reflectColor[1]); + resultColor[2] += reflectGain * (reflectColor[2]); + } // set ouput color attribute - MDataHandle outColorHandle = block.outputValue( aOutColor ); + MDataHandle outColorHandle = block.outputValue(aOutColor); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); @@ -596,25 +573,24 @@ const MPlug& plug, // // DESCRIPTION: /////////////////////////////////////////////////////// -MStatus initializePlugin( MObject obj ) +MStatus initializePlugin(MObject obj) { - const MString UserClassify( "shader/surface" ); + const MString UserClassify("shader/surface"); - MFnPlugin plugin( obj, "Alias|Wavefront - Example", "5.0", "Any"); - CHECK_MSTATUS ( plugin.registerNode( "XRayMtl", CXRayMtl::id, - CXRayMtl::creator, CXRayMtl::initialize, - MPxNode::kDependNode, &UserClassify ) ); + MFnPlugin plugin(obj, "Alias|Wavefront - Example", "5.0", "Any"); + CHECK_MSTATUS(plugin.registerNode( + "XRayMtl", CXRayMtl::id, CXRayMtl::creator, CXRayMtl::initialize, MPxNode::kDependNode, &UserClassify)); - return MS::kSuccess; + return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// -MStatus uninitializePlugin( MObject obj ) +MStatus uninitializePlugin(MObject obj) { - MFnPlugin plugin( obj ); - CHECK_MSTATUS ( plugin.deregisterNode( CXRayMtl::id ) ); + MFnPlugin plugin(obj); + CHECK_MSTATUS(plugin.deregisterNode(CXRayMtl::id)); - return MS::kSuccess; + return MS::kSuccess; } diff --git a/src/plugins/Maya/Material/stdafx.cpp b/src/plugins/Maya/Material/stdafx.cpp index 47ba185752c..d12030476ed 100644 --- a/src/plugins/Maya/Material/stdafx.cpp +++ b/src/plugins/Maya/Material/stdafx.cpp @@ -1,3 +1,2 @@ #include "stdafx.h" #pragma hdrstop - diff --git a/src/plugins/Shared/BlenderListLoader.cpp b/src/plugins/Shared/BlenderListLoader.cpp index 893810c37c4..03e6c78e678 100644 --- a/src/plugins/Shared/BlenderListLoader.cpp +++ b/src/plugins/Shared/BlenderListLoader.cpp @@ -7,67 +7,69 @@ IC bool str_pred(LPCSTR x, LPCSTR y) { - return xr_strcmp(x,y)<0; + return xr_strcmp(x, y) < 0; } void ClearList(LPSTRVec& lst) { - for (LPSTRIt it=lst.begin(); it!=lst.end(); it++) - xr_free (*it); + for (LPSTRIt it = lst.begin(); it != lst.end(); it++) + xr_free(*it); } int LoadBlenderList(LPSTRVec& lst) { - ClearList (lst); + ClearList(lst); - // Load blenders - string_path sh; - FS.update_path (sh,"$game_data$","shaders.xr"); - IReader* R = FS.r_open(sh); - R_ASSERT2 (R,sh); - IReader* fs = R->open_chunk(3); R_ASSERT(fs); + // Load blenders + string_path sh; + FS.update_path(sh, "$game_data$", "shaders.xr"); + IReader* R = FS.r_open(sh); + R_ASSERT2(R, sh); + IReader* fs = R->open_chunk(3); + R_ASSERT(fs); - xr_string buf; - lst.resize (fs->r_u32()); - for (LPSTRIt it=lst.begin(); it!=lst.end(); it++){ - fs->r_stringZ (buf); - *it=xr_strdup (buf.c_str()); - } - fs->close(); - std::sort (lst.begin(), lst.end(), str_pred); - return lst.size(); + xr_string buf; + lst.resize(fs->r_u32()); + for (LPSTRIt it = lst.begin(); it != lst.end(); it++) + { + fs->r_stringZ(buf); + *it = xr_strdup(buf.c_str()); + } + fs->close(); + std::sort(lst.begin(), lst.end(), str_pred); + return lst.size(); } int LoadShaderLCList(LPSTRVec& lst) { - Shader_xrLC_LIB LIB; + Shader_xrLC_LIB LIB; - ClearList (lst); + ClearList(lst); - string_path fn; - FS.update_path (fn,"$game_data$","shaders_xrlc.xr"); - LIB.Load (fn); + string_path fn; + FS.update_path(fn, "$game_data$", "shaders_xrlc.xr"); + LIB.Load(fn); - lst.resize (LIB.Library().size()); - LPSTRIt s_it = lst.begin(); - for (Shader_xrLCIt l_it=LIB.Library().begin(); l_it!=LIB.Library().end(); l_it++,s_it++) - *s_it = xr_strdup(l_it->Name); - LIB.Unload (); - std::sort (lst.begin(), lst.end(), str_pred); - return lst.size (); + lst.resize(LIB.Library().size()); + LPSTRIt s_it = lst.begin(); + for (Shader_xrLCIt l_it = LIB.Library().begin(); l_it != LIB.Library().end(); l_it++, s_it++) + *s_it = xr_strdup(l_it->Name); + LIB.Unload(); + std::sort(lst.begin(), lst.end(), str_pred); + return lst.size(); } int LoadGameMtlList(LPSTRVec& lst) { - ClearList (lst); + ClearList(lst); - GMLib.Load (); + GMLib.Load(); - lst.resize (GMLib.CountMaterial()); - LPSTRIt s_it = lst.begin(); - for (GameMtlIt gm_it=GMLib.FirstMaterial(); gm_it!=GMLib.LastMaterial(); gm_it++,s_it++) - *s_it = xr_strdup(*(*gm_it)->m_Name); - GMLib.Unload (); - std::sort (lst.begin(), lst.end(), str_pred); - return lst.size (); + lst.resize(GMLib.CountMaterial()); + LPSTRIt s_it = lst.begin(); + for (GameMtlIt gm_it = GMLib.FirstMaterial(); gm_it != GMLib.LastMaterial(); gm_it++, s_it++) + *s_it = xr_strdup(*(*gm_it)->m_Name); + GMLib.Unload(); + std::sort(lst.begin(), lst.end(), str_pred); + return lst.size(); } diff --git a/src/plugins/Shared/BoneDef.h b/src/plugins/Shared/BoneDef.h index 3cf000163e9..25a974d2b85 100644 --- a/src/plugins/Shared/BoneDef.h +++ b/src/plugins/Shared/BoneDef.h @@ -8,29 +8,32 @@ class CExporter; class CBoneDef { public: - CBoneDef* parent; - string name; - INode* pBone; + CBoneDef* parent; + string name; + INode* pBone; + + Fmatrix matInit; + Fmatrix matOffset; - Fmatrix matInit; - Fmatrix matOffset; public: - CBoneDef(INode* pNode); - IC BOOL isEqual(INode* pNode){ return pBone==pNode; } - LPCSTR GetParentName(); - BOOL SetInitTM(IPhysiqueExport* pExport, const Matrix3& matMesh); - void CalculateLocalMatrix(TimeValue tick, Fmatrix& mat) - { - Fmatrix m; - Helper::ConvertMatrix(pBone->GetNodeTM(tick),m); - if (parent){ - Fmatrix i_m; - Helper::ConvertMatrix(parent->pBone->GetNodeTM(tick),i_m); - i_m.invert(); - mat.mul(i_m,m); - }else{ - mat.set(m); - } - } + CBoneDef(INode* pNode); + IC BOOL isEqual(INode* pNode) { return pBone == pNode; } + LPCSTR GetParentName(); + BOOL SetInitTM(IPhysiqueExport* pExport, const Matrix3& matMesh); + void CalculateLocalMatrix(TimeValue tick, Fmatrix& mat) + { + Fmatrix m; + Helper::ConvertMatrix(pBone->GetNodeTM(tick), m); + if (parent) { + Fmatrix i_m; + Helper::ConvertMatrix(parent->pBone->GetNodeTM(tick), i_m); + i_m.invert(); + mat.mul(i_m, m); + } + else + { + mat.set(m); + } + } }; -DEFINE_VECTOR(CBoneDef*,BoneDefVec,BoneDefIt); \ No newline at end of file +DEFINE_VECTOR(CBoneDef*, BoneDefVec, BoneDefIt); \ No newline at end of file diff --git a/src/plugins/Shared/ELog.cpp b/src/plugins/Shared/ELog.cpp index be2bb5a8fc5..fc672ba5235 100644 --- a/src/plugins/Shared/ELog.cpp +++ b/src/plugins/Shared/ELog.cpp @@ -7,96 +7,108 @@ #include "ELog.h" #ifdef _EDITOR - #include "LogForm.h" - #include "ui_main.h" - void __stdcall ELogCallback(LPCSTR txt) - { - if (0==txt[0]) return; - bool bDlg = ('#'==txt[0])||((0!=txt[1])&&('#'==txt[1])); - TMsgDlgType mt = ('!'==txt[0])||((0!=txt[1])&&('!'==txt[1]))?mtError:mtInformation; - if (('!'==txt[0])||('#'==txt[0])) txt++; - if (('!'==txt[0])||('#'==txt[0])) txt++; - if (bDlg) TfrmLog::AddDlgMessage (mt,txt); - else TfrmLog::AddMessage (mt,txt); - } +#include "LogForm.h" +#include "ui_main.h" +void __stdcall ELogCallback(LPCSTR txt) +{ + if (0 == txt[0]) return; + bool bDlg = ('#' == txt[0]) || ((0 != txt[1]) && ('#' == txt[1])); + TMsgDlgType mt = ('!' == txt[0]) || ((0 != txt[1]) && ('!' == txt[1])) ? mtError : mtInformation; + if (('!' == txt[0]) || ('#' == txt[0])) txt++; + if (('!' == txt[0]) || ('#' == txt[0])) txt++; + if (bDlg) + TfrmLog::AddDlgMessage(mt, txt); + else + TfrmLog::AddMessage(mt, txt); +} #endif #ifdef _LW_EXPORT - #include - extern "C" LWMessageFuncs *g_msg; - void ELogCallback(void *context, LPCSTR txt) - { - if (0==txt[0]) return; - bool bDlg = ('#'==txt[0])||((0!=txt[1])&&('#'==txt[1])); - if (bDlg){ - int mt = ('!'==txt[0])||((0!=txt[1])&&('!'==txt[1]))?1:0; - if (('!'==txt[0])||('#'==txt[0])) txt++; - if (('!'==txt[0])||('#'==txt[0])) txt++; - if (mt==1) g_msg->error(txt,0); - else g_msg->info(txt,0); - } - } +#include +extern "C" LWMessageFuncs* g_msg; +void ELogCallback(void* context, LPCSTR txt) +{ + if (0 == txt[0]) return; + bool bDlg = ('#' == txt[0]) || ((0 != txt[1]) && ('#' == txt[1])); + if (bDlg) { + int mt = ('!' == txt[0]) || ((0 != txt[1]) && ('!' == txt[1])) ? 1 : 0; + if (('!' == txt[0]) || ('#' == txt[0])) txt++; + if (('!' == txt[0]) || ('#' == txt[0])) txt++; + if (mt == 1) + g_msg->error(txt, 0); + else + g_msg->info(txt, 0); + } +} #endif #ifdef _MAX_EXPORT - #include "plugins/Max/Export/NetDeviceLog.h" - void ELogCallback(void *context, LPCSTR txt) - { - if (0!=txt[0]){ - if (txt[0]=='!')EConsole.print(mtError,txt+1); - else EConsole.print(mtInformation,txt); - } - } +#include "plugins/Max/Export/NetDeviceLog.h" +void ELogCallback(void* context, LPCSTR txt) +{ + if (0 != txt[0]) { + if (txt[0] == '!') + EConsole.print(mtError, txt + 1); + else + EConsole.print(mtInformation, txt); + } +} #endif #ifdef _MAYA_PLUGIN - void ELogCallback(void *context, LPCSTR txt) - { - if (0!=txt[0]){ - if (txt[0]=='!')std::cerr << "XR-Error: " << txt+1 << "\n"; - else std::cerr << "XR-Info: " << txt << "\n"; - } -//. MStringArray res; -// MGlobal::executeCommand("confirmDialog -title \"Error\" -message \"Mesh have non-triangulated polygon.\" -button \"Ok\" -defaultButton \"Ok\"",res); - } +void ELogCallback(void* context, LPCSTR txt) +{ + if (0 != txt[0]) { + if (txt[0] == '!') + std::cerr << "XR-Error: " << txt + 1 << "\n"; + else + std::cerr << "XR-Info: " << txt << "\n"; + } + //. MStringArray res; + // MGlobal::executeCommand("confirmDialog -title \"Error\" -message \"Mesh have non-triangulated polygon.\" + //-button \"Ok\" -defaultButton \"Ok\"",res); +} #endif //---------------------------------------------------- CLog ELog; //---------------------------------------------------- -int CLog::DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) +int CLog::DlgMsg(TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) { in_use = true; - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); - int res=0; -#ifdef _EDITOR + int res = 0; +#ifdef _EDITOR ExecCommand(COMMAND_RENDER_FOCUS); - res=MessageDlg(buf, mt, btn, 0); - if (mtConfirmation==mt){ - switch (res){ - case mrYes: strcat(buf," - Yes."); break; - case mrNo: strcat(buf," - No."); break; - case mrCancel: strcat(buf," - Cancel."); break; - default: strcat(buf," - Something."); + res = MessageDlg(buf, mt, btn, 0); + if (mtConfirmation == mt) { + switch (res) + { + case mrYes: strcat(buf, " - Yes."); break; + case mrNo: strcat(buf, " - No."); break; + case mrCancel: strcat(buf, " - Cancel."); break; + default: strcat(buf, " - Something."); } } #endif #ifdef _LW_EXPORT - switch(mt){ - case mtError: g_msg->error(buf,0); break; - case mtInformation: g_msg->info(buf,0); break; - default: g_msg->info(buf,0); break; - } + switch (mt) + { + case mtError: g_msg->error(buf, 0); break; + case mtInformation: g_msg->info(buf, 0); break; + default: g_msg->info(buf, 0); break; + } #endif #ifdef _MAX_PLUGIN - switch(mt){ - case mtError: MessageBox(0,buf,"Error", MB_OK|MB_ICONERROR); break; - case mtInformation: MessageBox(0,buf,"Information", MB_OK|MB_ICONINFORMATION); break; - default: MessageBox(0,buf,"Information", MB_OK|MB_ICONINFORMATION); break; - } + switch (mt) + { + case mtError: MessageBox(0, buf, "Error", MB_OK | MB_ICONERROR); break; + case mtInformation: MessageBox(0, buf, "Information", MB_OK | MB_ICONINFORMATION); break; + default: MessageBox(0, buf, "Information", MB_OK | MB_ICONINFORMATION); break; + } #endif Msg(mt, buf); @@ -106,74 +118,79 @@ int CLog::DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...) return res; } - -int CLog::DlgMsg (TMsgDlgType mt, LPCSTR _Format, ...) +int CLog::DlgMsg(TMsgDlgType mt, LPCSTR _Format, ...) { in_use = true; - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); - int res=0; + int res = 0; #ifdef _EDITOR ExecCommand(COMMAND_RENDER_FOCUS); - if (mtConfirmation==mt) res=MessageDlg(buf, mt, TMsgDlgButtons() << mbYes << mbNo << mbCancel, 0); - else res=MessageDlg(buf, mt, TMsgDlgButtons() << mbOK, 0); - - if (mtConfirmation==mt){ - switch (res){ - case mrYes: strcat(buf," - Yes."); break; - case mrNo: strcat(buf," - No."); break; - case mrCancel: strcat(buf," - Cancel."); break; - default: strcat(buf," - Something."); + if (mtConfirmation == mt) + res = MessageDlg(buf, mt, TMsgDlgButtons() << mbYes << mbNo << mbCancel, 0); + else + res = MessageDlg(buf, mt, TMsgDlgButtons() << mbOK, 0); + + if (mtConfirmation == mt) { + switch (res) + { + case mrYes: strcat(buf, " - Yes."); break; + case mrNo: strcat(buf, " - No."); break; + case mrCancel: strcat(buf, " - Cancel."); break; + default: strcat(buf, " - Something."); } } #endif #ifdef _LW_EXPORT - switch(mt){ - case mtError: g_msg->error(buf,0); break; - case mtInformation: g_msg->info(buf,0); break; - default: g_msg->info(buf,0); break; - } + switch (mt) + { + case mtError: g_msg->error(buf, 0); break; + case mtInformation: g_msg->info(buf, 0); break; + default: g_msg->info(buf, 0); break; + } #endif #ifdef _MAX_PLUGIN - switch(mt){ - case mtError: MessageBox(0,buf,"Error", MB_OK|MB_ICONERROR); break; - case mtInformation: MessageBox(0,buf,"Information", MB_OK|MB_ICONINFORMATION); break; - default: MessageBox(0,buf,"Information", MB_OK|MB_ICONINFORMATION); break; - } + switch (mt) + { + case mtError: MessageBox(0, buf, "Error", MB_OK | MB_ICONERROR); break; + case mtInformation: MessageBox(0, buf, "Information", MB_OK | MB_ICONINFORMATION); break; + default: MessageBox(0, buf, "Information", MB_OK | MB_ICONINFORMATION); break; + } #endif - Msg(mt,buf); + Msg(mt, buf); in_use = false; - + return res; } void CLog::Msg(TMsgDlgType mt, LPCSTR _Format, ...) { - char buf[4096]; - va_list l; - va_start( l, _Format ); - vsprintf( buf, _Format, l ); + char buf[4096]; + va_list l; + va_start(l, _Format); + vsprintf(buf, _Format, l); #ifdef _EDITOR - TfrmLog::AddMessage(mt,AnsiString(buf)); + TfrmLog::AddMessage(mt, AnsiString(buf)); #endif #ifdef _MAX_EXPORT - EConsole.print(mt,buf); + EConsole.print(mt, buf); #endif #ifdef _LW_EXPORT - switch (mt){ - case mtError: g_msg->error(buf,0); break; - } + switch (mt) + { + case mtError: g_msg->error(buf, 0); break; + } #endif - ::LogExecCB = FALSE; - ::Msg (buf); - ::LogExecCB = TRUE; + ::LogExecCB = FALSE; + ::Msg(buf); + ::LogExecCB = TRUE; } //---------------------------------------------------- diff --git a/src/plugins/Shared/ELog.h b/src/plugins/Shared/ELog.h index bef7f68670f..1c2c09468a5 100644 --- a/src/plugins/Shared/ELog.h +++ b/src/plugins/Shared/ELog.h @@ -5,19 +5,20 @@ #ifndef ELogH #define ELogH -class ECORE_API CLog{ +class ECORE_API CLog +{ public: - bool in_use; + bool in_use; + public: - CLog (){in_use=false;} - void Msg (TMsgDlgType mt, LPCSTR _Format, ...); - int DlgMsg (TMsgDlgType mt, LPCSTR _Format, ...); - int DlgMsg (TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...); + CLog() { in_use = false; } + void Msg(TMsgDlgType mt, LPCSTR _Format, ...); + int DlgMsg(TMsgDlgType mt, LPCSTR _Format, ...); + int DlgMsg(TMsgDlgType mt, TMsgDlgButtons btn, LPCSTR _Format, ...); }; -void ECORE_API ELogCallback(void *context, LPCSTR txt); +void ECORE_API ELogCallback(void* context, LPCSTR txt); extern ECORE_API CLog ELog; #endif /*_INCDEF_NETDEVICELOG_H_*/ - diff --git a/src/plugins/Shared/Face.h b/src/plugins/Shared/Face.h index b3cebe2720c..56a9321b9a7 100644 --- a/src/plugins/Shared/Face.h +++ b/src/plugins/Shared/Face.h @@ -2,13 +2,14 @@ #include "vert.h" -struct st_FACE { - int v[3]; - u32 m_id; - u32 sm_group; +struct st_FACE +{ + int v[3]; + u32 m_id; + u32 sm_group; + public: - void _VSet(int id, int idx){v[id]=idx;} + void _VSet(int id, int idx) { v[id] = idx; } }; -DEFINE_VECTOR(st_FACE*,ExpFaceVec,ExpFaceIt); - +DEFINE_VECTOR(st_FACE*, ExpFaceVec, ExpFaceIt); diff --git a/src/plugins/Shared/GameMaterial.cpp b/src/plugins/Shared/GameMaterial.cpp index 1adc51e028d..566e83487bf 100644 --- a/src/plugins/Shared/GameMaterial.cpp +++ b/src/plugins/Shared/GameMaterial.cpp @@ -1,399 +1,362 @@ #include "stdafx.h" #pragma hdrstop -#include "GameMaterial.h" #include "BlenderListLoader.h" +#include "GameMaterial.h" #include "macrorec.h" -class XRayMtlClassDesc:public ClassDesc2 { +class XRayMtlClassDesc : public ClassDesc2 +{ public: - int IsPublic () { return 1; } - void * Create (BOOL loading) { return new XRayMtl(loading); } - const TCHAR * ClassName () { return GetString(IDS_CLASS_NAME); } - SClass_ID SuperClassID () { return MATERIAL_CLASS_ID; } - Class_ID ClassID () { return XRAYMTL_CLASS_ID; } - const TCHAR* Category () { return GetString(IDS_CATEGORY); } - // JBW: new descriptor data accessors added. Note that the - // internal name is hardwired since it must not be localized. - const TCHAR* InternalName () { return _T("S.T.A.L.K.E.R.Mtl"); } // returns fixed parsable name (scripter-visible name) - HINSTANCE HInstance () { return hInstance; } // returns owning module handle + int IsPublic() { return 1; } + void* Create(BOOL loading) { return new XRayMtl(loading); } + const TCHAR* ClassName() { return GetString(IDS_CLASS_NAME); } + SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; } + Class_ID ClassID() { return XRAYMTL_CLASS_ID; } + const TCHAR* Category() { return GetString(IDS_CATEGORY); } + // JBW: new descriptor data accessors added. Note that the + // internal name is hardwired since it must not be localized. + const TCHAR* InternalName() + { + return _T("S.T.A.L.K.E.R.Mtl"); + } // returns fixed parsable name (scripter-visible name) + HINSTANCE HInstance() { return hInstance; } // returns owning module handle }; static XRayMtlClassDesc stdmtl2CD; -ClassDesc2* GetXRayMtlDesc() { return &stdmtl2CD; } +ClassDesc2* GetXRayMtlDesc() +{ + return &stdmtl2CD; +} -ShaderParamDlg* XRayMtl::pShaderDlg; +ShaderParamDlg* XRayMtl::pShaderDlg; IAutoMParamDlg* XRayMtl::xrayDlg; IAutoMParamDlg* XRayMtl::masterDlg; IAutoMParamDlg* XRayMtl::texmapDlg; IAutoMParamDlg* XRayMtl::extendedDlg; IAutoMParamDlg* XRayMtl::samplingDlg; -HWND XRayMtl::curHwmEdit; -IMtlParams* XRayMtl::curImp; +HWND XRayMtl::curHwmEdit; +IMtlParams* XRayMtl::curImp; Tab XRayMtl::shaderList; Tab XRayMtl::samplerList; -LPSTRVec XRayMtl::EShaders; -LPSTRVec XRayMtl::CShaders; -LPSTRVec XRayMtl::GameMtls; +LPSTRVec XRayMtl::EShaders; +LPSTRVec XRayMtl::CShaders; +LPSTRVec XRayMtl::GameMtls; ///////////////////////////////////////////////////////////////////////// // utility function -IC float Min( float a, float b ) { return (a < b) ? a : b; } -IC float Min( float a, float b, float c ) { return (a < b) ? Min(a,c) : Min(b,c); } -IC float Min( Color& c ){ return Min( c.r, c.g, c.b ); } -IC float Max( float a, float b ) { return (a < b) ? b : a; } -IC float Max( float a, float b, float c ) { return (a < b) ? Max( b, c ) : Max(a,c); } -IC float Max( Color& c ){ return Max( c.r, c.g, c.b ); } - -IC float LBound( float x, float min = 0.0f ){ return x < min ? min : x; } -IC Color LBound( Color& c, float min = 0.0f ) -{ return Color( LBound(c.r, min), LBound(c.g, min), LBound(c.b, min) ); } -IC float UBound( float x, float max = 1.0f ){ return x > max ? max : x; } -IC Color UBound( Color& c, float max = 1.0f ) -{ return Color( UBound(c.r,max), UBound(c.g,max), UBound(c.b,max) ); } - -IC float Bound( float x, float min = 0.0f, float max = 1.0f ){ return x < min? min:( x > max? max : x); } -IC Color Bound( Color& c, float min = 0.0f, float max = 1.0f ){ - return Color( Bound(c.r,min,max), Bound(c.r,min,max), Bound(c.r,min,max) ); -} -IC void BoundInPlace( AColor& c , float min = 0.0f, float max = 1.0f ){ - if( c.r > max ) c.r = max; else if( c.r < min ) c.r = min; - if( c.g > max ) c.g = max; else if( c.g < min ) c.g = min; - if( c.b > max ) c.b = max; else if( c.b < min ) c.b = min; - if( c.a > max ) c.a = max; else if( c.a < min ) c.a = min; +IC float Min(float a, float b) +{ + return (a < b) ? a : b; +} +IC float Min(float a, float b, float c) +{ + return (a < b) ? Min(a, c) : Min(b, c); +} +IC float Min(Color& c) +{ + return Min(c.r, c.g, c.b); +} +IC float Max(float a, float b) +{ + return (a < b) ? b : a; +} +IC float Max(float a, float b, float c) +{ + return (a < b) ? Max(b, c) : Max(a, c); +} +IC float Max(Color& c) +{ + return Max(c.r, c.g, c.b); +} + +IC float LBound(float x, float min = 0.0f) +{ + return x < min ? min : x; +} +IC Color LBound(Color& c, float min = 0.0f) +{ + return Color(LBound(c.r, min), LBound(c.g, min), LBound(c.b, min)); +} +IC float UBound(float x, float max = 1.0f) +{ + return x > max ? max : x; +} +IC Color UBound(Color& c, float max = 1.0f) +{ + return Color(UBound(c.r, max), UBound(c.g, max), UBound(c.b, max)); +} + +IC float Bound(float x, float min = 0.0f, float max = 1.0f) +{ + return x < min ? min : (x > max ? max : x); +} +IC Color Bound(Color& c, float min = 0.0f, float max = 1.0f) +{ + return Color(Bound(c.r, min, max), Bound(c.r, min, max), Bound(c.r, min, max)); +} +IC void BoundInPlace(AColor& c, float min = 0.0f, float max = 1.0f) +{ + if (c.r > max) + c.r = max; + else if (c.r < min) + c.r = min; + if (c.g > max) + c.g = max; + else if (c.g < min) + c.g = min; + if (c.b > max) + c.b = max; + else if (c.b < min) + c.b = min; + if (c.a > max) + c.a = max; + else if (c.a < min) + c.a = min; } ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // Material Texture Channels // -#define MTL_NTEXMAPS 4 - +#define MTL_NTEXMAPS 4 // channels ids needed by shader -#define _BUMP 0 -#define _REFLECT 1 -#define _REFRACT 2 -#define _DISPLACE 3 +#define _BUMP 0 +#define _REFLECT 1 +#define _REFRACT 2 +#define _DISPLACE 3 // channel names static int mtlChannelNameIDS[] = { - IDS_DS_BU, IDS_DS_RL, IDS_DS_RR, IDS_DS_DP, -}; + IDS_DS_BU, IDS_DS_RL, IDS_DS_RR, IDS_DS_DP, +}; // what channel corresponds to the stdMat ID's -static int mtlStdIDToChannel[N_ID_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3 }; +static int mtlStdIDToChannel[N_ID_CHANNELS] = {-1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3}; // internal non-local parsable channel map names static TCHAR* mtlChannelInternalNames[STD2_NMAX_TEXMAPS] = { - _T("bumpMap"), _T("reflectionMap"), _T("refractionMap"), _T("displacementMap"), - _T(""), _T(""), _T(""), _T(""), + _T("bumpMap"), _T("reflectionMap"), _T("refractionMap"), _T("displacementMap"), _T(""), _T(""), _T(""), _T(""), - _T(""), _T(""), _T(""), _T(""), - _T(""), _T(""), _T(""), _T(""), + _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), - _T(""), _T(""), _T(""), _T(""), - _T(""), _T(""), _T(""), _T(""), -}; + _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), +}; // sized for nmax textures static int mtlChannelType[STD2_NMAX_TEXMAPS] = { - BUMP_CHANNEL, REFL_CHANNEL, REFR_CHANNEL, DISP_CHANNEL, - UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, - - UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, - UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, - UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, - UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, -}; + BUMP_CHANNEL, REFL_CHANNEL, REFR_CHANNEL, DISP_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, + UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, + UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, + UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, + UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, UNSUPPORTED_CHANNEL, + UNSUPPORTED_CHANNEL, +}; static IReshading::ReshadeRequirements chooseReshade[3][3] = { - { IReshading::RR_None, - IReshading::RR_NeedPreshade, - IReshading::RR_NeedReshade }, // RR_None - { IReshading::RR_NeedPreshade, - IReshading::RR_NeedPreshade, - IReshading::RR_NeedPreshade }, // RR_NeedPreshade - { IReshading::RR_NeedReshade, - IReshading::RR_NeedPreshade, - IReshading::RR_NeedReshade }, // RR_NeedReshade + {IReshading::RR_None, IReshading::RR_NeedPreshade, IReshading::RR_NeedReshade}, // RR_None + {IReshading::RR_NeedPreshade, IReshading::RR_NeedPreshade, IReshading::RR_NeedPreshade}, // RR_NeedPreshade + {IReshading::RR_NeedReshade, IReshading::RR_NeedPreshade, IReshading::RR_NeedReshade}, // RR_NeedReshade }; -#define NO_UPDATE -2 +#define NO_UPDATE -2 // parameter setter callback, reflect any ParamBlock-mediated param setting in instance data members. // Since standard2 keeps many parameters as instance data members, these setter callbacks -// are implemented to reduce changes to existing code +// are implemented to reduce changes to existing code class ShaderPBAccessor : public PBAccessor { public: - void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - // use item data to unscramble sorted lists - case std2_shader_type: { - ClassDesc* pCD = XRayMtl::GetShaderCD(v.i); - if (pCD && m->GetShaderIndx() != NO_UPDATE ) - { - m->SwitchShader(pCD); - m->shaderId = v.i; - } - } break; - case std2_shader_by_name: { - for (int i = 0; i < XRayMtl::NumShaders(); i++) - { - ClassDesc* pCD = XRayMtl::GetShaderCD(i); - if (_tcsicmp(pCD->ClassName(), v.s) == 0) - { - m->pb_shader->SetValue(std2_shader_type, 0, i); - break; - } - } - } break; - case std2_wire: - m->SetFlag(NEWSTDMTL_WIRE, v.i); break; - case std2_two_sided: - m->SetFlag(NEWSTDMTL_2SIDE, v.i); break; - case std2_face_map: - m->SetFlag(NEWSTDMTL_FACEMAP, v.i); break; - case std2_faceted: - m->SetFlag(NEWSTDMTL_FACETED, v.i); break; - } - } - - void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_shader_by_name: { - ClassDesc* pCD = XRayMtl::GetShaderCD(m->shaderId); - if (pCD) - v.s = (TCHAR*)pCD->ClassName(); - } break; - } - } + void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + // use item data to unscramble sorted lists + case std2_shader_type: + { + ClassDesc* pCD = XRayMtl::GetShaderCD(v.i); + if (pCD && m->GetShaderIndx() != NO_UPDATE) { + m->SwitchShader(pCD); + m->shaderId = v.i; + } + } + break; + case std2_shader_by_name: + { + for (int i = 0; i < XRayMtl::NumShaders(); i++) + { + ClassDesc* pCD = XRayMtl::GetShaderCD(i); + if (_tcsicmp(pCD->ClassName(), v.s) == 0) { + m->pb_shader->SetValue(std2_shader_type, 0, i); + break; + } + } + } + break; + case std2_wire: m->SetFlag(NEWSTDMTL_WIRE, v.i); break; + case std2_two_sided: m->SetFlag(NEWSTDMTL_2SIDE, v.i); break; + case std2_face_map: m->SetFlag(NEWSTDMTL_FACEMAP, v.i); break; + case std2_faceted: m->SetFlag(NEWSTDMTL_FACETED, v.i); break; + } + } + + void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_shader_by_name: + { + ClassDesc* pCD = XRayMtl::GetShaderCD(m->shaderId); + if (pCD) v.s = (TCHAR*)pCD->ClassName(); + } + break; + } + } }; static ShaderPBAccessor shaderPBAccessor; // shader rollout dialog proc -class ShaderDlgProc : public ParamMap2UserDlgProc +class ShaderDlgProc : public ParamMap2UserDlgProc { public: - BOOL DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) - { - case WM_INITDIALOG: - // load the shader dropdown - HWND hwndShader = GetDlgItem(hWnd, IDC_SHADER); - SendMessage(hwndShader, CB_RESETCONTENT, 0L, 0L); - for (int i = 0; i < XRayMtl::NumShaders(); i++) { - ClassDesc* pClassD = XRayMtl::GetShaderCD(i); - int n = SendMessage(hwndShader, CB_ADDSTRING, 0L, (LPARAM)(pClassD->ClassName()) ); - SendMessage(hwndShader, CB_SETITEMDATA, n, (LPARAM)pClassD ); - } - return TRUE; - } - return FALSE; - } - void DeleteThis() { } + BOOL DlgProc(TimeValue t, IParamMap2* map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + { + switch (msg) + { + case WM_INITDIALOG: + // load the shader dropdown + HWND hwndShader = GetDlgItem(hWnd, IDC_SHADER); + SendMessage(hwndShader, CB_RESETCONTENT, 0L, 0L); + for (int i = 0; i < XRayMtl::NumShaders(); i++) + { + ClassDesc* pClassD = XRayMtl::GetShaderCD(i); + int n = SendMessage(hwndShader, CB_ADDSTRING, 0L, (LPARAM)(pClassD->ClassName())); + SendMessage(hwndShader, CB_SETITEMDATA, n, (LPARAM)pClassD); + } + return TRUE; + } + return FALSE; + } + void DeleteThis() {} }; - static ShaderDlgProc shaderDlgProc; // shader parameters -static ParamBlockDesc2 std2_shader_blk ( std2_shader, _T("newShaderParameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, SHADER_PB_REF, - //rollout - IDD_DMTL_SHADER4, IDS_KE_SHADER, 0, 0, &shaderDlgProc, - // params - std2_shader_type, _T("shaderType"), TYPE_INT, 0, IDS_JW_SHADERTYPE, - p_default, 3, - p_ui, TYPE_INTLISTBOX, IDC_SHADER, 0, - p_accessor, &shaderPBAccessor, - end, - std2_wire, _T("wire"), TYPE_BOOL, 0, IDS_DS_WIREFRAME, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_WIRE, - p_accessor, &shaderPBAccessor, - end, - std2_two_sided, _T("twoSided"), TYPE_BOOL, 0, IDS_JW_TWOSIDED, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_2SIDE, - p_accessor, &shaderPBAccessor, - end, - std2_face_map, _T("faceMap"), TYPE_BOOL, 0, IDS_JW_FACEMAP, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_FACE_MAP, - p_accessor, &shaderPBAccessor, - end, - std2_faceted, _T("faceted"), TYPE_BOOL, 0, IDS_KE_FACETED, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_FACETED, - p_accessor, &shaderPBAccessor, - end, - std2_shader_by_name, _T("shaderByName"), TYPE_STRING, 0, IDS_JW_SHADERBYNAME, - p_accessor, &shaderPBAccessor, - end, - end - ); +static ParamBlockDesc2 std2_shader_blk(std2_shader, _T("newShaderParameters"), 0, &stdmtl2CD, + P_AUTO_CONSTRUCT + P_AUTO_UI, SHADER_PB_REF, + // rollout + IDD_DMTL_SHADER4, IDS_KE_SHADER, 0, 0, &shaderDlgProc, + // params + std2_shader_type, _T("shaderType"), TYPE_INT, 0, IDS_JW_SHADERTYPE, p_default, 3, p_ui, TYPE_INTLISTBOX, IDC_SHADER, + 0, p_accessor, &shaderPBAccessor, end, std2_wire, _T("wire"), TYPE_BOOL, 0, IDS_DS_WIREFRAME, p_default, FALSE, + p_ui, TYPE_SINGLECHEKBOX, IDC_WIRE, p_accessor, &shaderPBAccessor, end, std2_two_sided, _T("twoSided"), TYPE_BOOL, + 0, IDS_JW_TWOSIDED, p_default, FALSE, p_ui, TYPE_SINGLECHEKBOX, IDC_2SIDE, p_accessor, &shaderPBAccessor, end, + std2_face_map, _T("faceMap"), TYPE_BOOL, 0, IDS_JW_FACEMAP, p_default, FALSE, p_ui, TYPE_SINGLECHEKBOX, + IDC_FACE_MAP, p_accessor, &shaderPBAccessor, end, std2_faceted, _T("faceted"), TYPE_BOOL, 0, IDS_KE_FACETED, + p_default, FALSE, p_ui, TYPE_SINGLECHEKBOX, IDC_FACETED, p_accessor, &shaderPBAccessor, end, std2_shader_by_name, + _T("shaderByName"), TYPE_STRING, 0, IDS_JW_SHADERBYNAME, p_accessor, &shaderPBAccessor, end, end); //////////////////////// // Extended Rollout class ExtendedPBAccessor : public PBAccessor { public: - void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - IParamMap2* map = m->pb_extended ? m->pb_extended->GetMap() : NULL; - - switch (id) - { - case std2_opacity_type: - m->SetFlag(NEWSTDMTL_ADD_TRANSP, v.i == 2); - m->SetFlag(NEWSTDMTL_FILT_TRANSP, v.i == 0); - if (map != NULL) - { - map->Show(std2_filter_color, v.i == 0); - map->Show(std2_ep_filter_map, v.i == 0); - m->UpdateTexmaps(); - m->UpdateLockADTex(FALSE); - } - break; - case std2_opacity: - m->opacity = v.f; - if (m->pShader->GetParamDlg()) - m->pShader->GetParamDlg()->UpdateOpacity(); - break; - case std2_filter_color: - m->filter = *v.p; break; - case std2_falloff_type: - m->SetFlag(NEWSTDMTL_FALLOFF_OUT, v.i == 1); break; - case std2_falloff_amnt: - m->opfall = v.f; break; - case std2_ior: - m->ioRefract = v.f; break; - - case std2_wire_size: - m->wireSize = v.f; break; - case std2_wire_units: - m->SetFlag(NEWSTDMTL_WIRE_UNITS, v.i == 1); break; - - case std2_apply_refl_dimming: - m->dimReflect = v.i; break; - case std2_dim_lvl: - m->dimIntens = v.f; break; - case std2_refl_lvl: - m->dimMult = v.f; break; - } - } + void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + IParamMap2* map = m->pb_extended ? m->pb_extended->GetMap() : NULL; + + switch (id) + { + case std2_opacity_type: + m->SetFlag(NEWSTDMTL_ADD_TRANSP, v.i == 2); + m->SetFlag(NEWSTDMTL_FILT_TRANSP, v.i == 0); + if (map != NULL) { + map->Show(std2_filter_color, v.i == 0); + map->Show(std2_ep_filter_map, v.i == 0); + m->UpdateTexmaps(); + m->UpdateLockADTex(FALSE); + } + break; + case std2_opacity: + m->opacity = v.f; + if (m->pShader->GetParamDlg()) m->pShader->GetParamDlg()->UpdateOpacity(); + break; + case std2_filter_color: m->filter = *v.p; break; + case std2_falloff_type: m->SetFlag(NEWSTDMTL_FALLOFF_OUT, v.i == 1); break; + case std2_falloff_amnt: m->opfall = v.f; break; + case std2_ior: m->ioRefract = v.f; break; + + case std2_wire_size: m->wireSize = v.f; break; + case std2_wire_units: m->SetFlag(NEWSTDMTL_WIRE_UNITS, v.i == 1); break; + + case std2_apply_refl_dimming: m->dimReflect = v.i; break; + case std2_dim_lvl: m->dimIntens = v.f; break; + case std2_refl_lvl: m->dimMult = v.f; break; + } + } }; static ExtendedPBAccessor extendedPBAccessor; // extra rollout dialog proc -class ExtraDlgProc : public ParamMap2UserDlgProc +class ExtraDlgProc : public ParamMap2UserDlgProc { public: - BOOL DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) - { - case WM_INITDIALOG:{ - XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); - m->UpdateExtraParams( m->GetShader()->SupportStdParams() ); - return TRUE; - } - } - return FALSE; - } - void DeleteThis() { } + BOOL DlgProc(TimeValue t, IParamMap2* map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + { + switch (msg) + { + case WM_INITDIALOG: + { + XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); + m->UpdateExtraParams(m->GetShader()->SupportStdParams()); + return TRUE; + } + } + return FALSE; + } + void DeleteThis() {} }; static ExtraDlgProc extraDlgProc; // extended parameters -static ParamBlockDesc2 std2_extended_blk ( std2_extended, _T("extendedParameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, EXTENDED_PB_REF, - //rollout - IDD_DMTL_EXTRA6, IDS_DS_EXTRA, 0, APPENDROLL_CLOSED, &extraDlgProc, - // params - std2_opacity_type, _T("opacityType"), TYPE_INT, 0, IDS_JW_OPACITYTYPE, - p_default, 0, - p_range, 0, 2, - p_ui, TYPE_RADIO, 3, IDC_TR_SUB2, IDC_TR_SUB, IDC_TR_ADD, - p_accessor, &extendedPBAccessor, - end, - std2_opacity, _T("opacity"), TYPE_PCNT_FRAC, P_ANIMATABLE, IDS_DS_OPACITY, - p_default, 0.0, - p_range, 0.0, 100.0, // UI us in the shader rollout - p_accessor, &extendedPBAccessor, - end, - std2_filter_color, _T("filterColor"), TYPE_RGBA, P_ANIMATABLE, IDS_DS_FILTER, - p_default, Color(0, 0, 0), - p_ui, TYPE_COLORSWATCH, IDC_FILTER_CS, - p_accessor, &extendedPBAccessor, - end, - std2_ep_filter_map, _T("filterMap"), TYPE_TEXMAP, P_SUBTEX + P_NO_AUTO_LABELS, IDS_JW_FILTERMAP, - p_subtexno, ID_FI, - p_ui, TYPE_TEXMAPBUTTON, IDC_MAPON_FI, - p_accessor, &extendedPBAccessor, - end, - std2_falloff_type, _T("opacityFallOffType"), TYPE_INT, 0, IDS_JW_FALLOFFTYPE, - p_default, 0, - p_range, 0, 1, - p_ui, TYPE_RADIO, 2, IDC_TF_IN, IDC_TF_OUT, - p_accessor, &extendedPBAccessor, - end, - std2_falloff_amnt, _T("opacityFallOff"), TYPE_PCNT_FRAC, P_ANIMATABLE, IDS_DS_FALLOFF, - p_default, 0.0, - p_range, 0.0, 100.0, - p_ui, TYPE_SPINNER, EDITTYPE_INT, IDC_TF_EDIT, IDC_TF_SPIN, 0.1, - p_accessor, &extendedPBAccessor, - end, - std2_ior, _T("ior"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_IOR, - p_default, 1.5, - p_range, 0.0, 10.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_IOR_EDIT, IDC_IOR_SPIN, 0.01, - p_accessor, &extendedPBAccessor, - end, - std2_wire_size, _T("wireSize"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_WIRESZ, - p_default, 1.0, - p_range, 0.0, 100.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_WIRE_EDIT, IDC_WIRE_SPIN, 1.0, - p_accessor, &extendedPBAccessor, - end, - std2_wire_units, _T("wireUnits"), TYPE_INT, 0, IDS_JW_WIREUNITS, - p_default, 0, - p_range, 0, 1, - p_ui, TYPE_RADIO, 2, IDC_PIXELS, IDC_UNITS, - p_accessor, &extendedPBAccessor, - end, - std2_apply_refl_dimming, _T("applyReflectionDimming"), TYPE_BOOL, 0, IDS_JW_APPLYREFDIM, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_DIM_REFL, - p_accessor, &extendedPBAccessor, - end, - std2_dim_lvl, _T("dimLevel"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_DIMLEV, - p_default, 0.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_DIM_AMT, IDC_DIM_AMTSPIN, 0.01, - p_accessor, &extendedPBAccessor, - end, - std2_refl_lvl, _T("reflectionLevel"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_DIMMULT, - p_default, 1.0, - p_range, 0.1, 10.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_DIM_MULT, IDC_DIM_MULTSPIN, 0.01, - p_accessor, &extendedPBAccessor, - end, - end - ); +static ParamBlockDesc2 std2_extended_blk(std2_extended, _T("extendedParameters"), 0, &stdmtl2CD, + P_AUTO_CONSTRUCT + P_AUTO_UI, EXTENDED_PB_REF, + // rollout + IDD_DMTL_EXTRA6, IDS_DS_EXTRA, 0, APPENDROLL_CLOSED, &extraDlgProc, + // params + std2_opacity_type, _T("opacityType"), TYPE_INT, 0, IDS_JW_OPACITYTYPE, p_default, 0, p_range, 0, 2, p_ui, + TYPE_RADIO, 3, IDC_TR_SUB2, IDC_TR_SUB, IDC_TR_ADD, p_accessor, &extendedPBAccessor, end, std2_opacity, + _T("opacity"), TYPE_PCNT_FRAC, P_ANIMATABLE, IDS_DS_OPACITY, p_default, 0.0, p_range, 0.0, + 100.0, // UI us in the shader rollout + p_accessor, &extendedPBAccessor, end, std2_filter_color, _T("filterColor"), TYPE_RGBA, P_ANIMATABLE, IDS_DS_FILTER, + p_default, Color(0, 0, 0), p_ui, TYPE_COLORSWATCH, IDC_FILTER_CS, p_accessor, &extendedPBAccessor, end, + std2_ep_filter_map, _T("filterMap"), TYPE_TEXMAP, P_SUBTEX + P_NO_AUTO_LABELS, IDS_JW_FILTERMAP, p_subtexno, ID_FI, + p_ui, TYPE_TEXMAPBUTTON, IDC_MAPON_FI, p_accessor, &extendedPBAccessor, end, std2_falloff_type, + _T("opacityFallOffType"), TYPE_INT, 0, IDS_JW_FALLOFFTYPE, p_default, 0, p_range, 0, 1, p_ui, TYPE_RADIO, 2, + IDC_TF_IN, IDC_TF_OUT, p_accessor, &extendedPBAccessor, end, std2_falloff_amnt, _T("opacityFallOff"), + TYPE_PCNT_FRAC, P_ANIMATABLE, IDS_DS_FALLOFF, p_default, 0.0, p_range, 0.0, 100.0, p_ui, TYPE_SPINNER, EDITTYPE_INT, + IDC_TF_EDIT, IDC_TF_SPIN, 0.1, p_accessor, &extendedPBAccessor, end, std2_ior, _T("ior"), TYPE_FLOAT, P_ANIMATABLE, + IDS_DS_IOR, p_default, 1.5, p_range, 0.0, 10.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_IOR_EDIT, IDC_IOR_SPIN, + 0.01, p_accessor, &extendedPBAccessor, end, std2_wire_size, _T("wireSize"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_WIRESZ, + p_default, 1.0, p_range, 0.0, 100.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_WIRE_EDIT, IDC_WIRE_SPIN, 1.0, + p_accessor, &extendedPBAccessor, end, std2_wire_units, _T("wireUnits"), TYPE_INT, 0, IDS_JW_WIREUNITS, p_default, 0, + p_range, 0, 1, p_ui, TYPE_RADIO, 2, IDC_PIXELS, IDC_UNITS, p_accessor, &extendedPBAccessor, end, + std2_apply_refl_dimming, _T("applyReflectionDimming"), TYPE_BOOL, 0, IDS_JW_APPLYREFDIM, p_default, FALSE, p_ui, + TYPE_SINGLECHEKBOX, IDC_DIM_REFL, p_accessor, &extendedPBAccessor, end, std2_dim_lvl, _T("dimLevel"), TYPE_FLOAT, + P_ANIMATABLE, IDS_DS_DIMLEV, p_default, 0.0, p_range, 0.0, 1.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_DIM_AMT, + IDC_DIM_AMTSPIN, 0.01, p_accessor, &extendedPBAccessor, end, std2_refl_lvl, _T("reflectionLevel"), TYPE_FLOAT, + P_ANIMATABLE, IDS_DS_DIMMULT, p_default, 1.0, p_range, 0.1, 10.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_DIM_MULT, + IDC_DIM_MULTSPIN, 0.01, p_accessor, &extendedPBAccessor, end, end); /////////////////////////////////////////////////////////////////////////////////// // Sampling Rollout @@ -401,304 +364,256 @@ static ParamBlockDesc2 std2_extended_blk ( std2_extended, _T("extendedParameters class SamplingPBAccessor : public PBAccessor { public: - void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - macroRecorder->Disable(); - switch (id) - { - case std2_ssampler: { - ClassDesc* pCD = XRayMtl::GetSamplerCD(v.i); - if (pCD && m->GetSamplerIndx() != NO_UPDATE ) - { - m->SwitchSampler(pCD); - // m->samplerId = v.i; - } - } break; - case std2_ssampler_by_name: { - for (int i = 0; i < XRayMtl::NumSamplers(); i++) - { - ClassDesc* pCD = XRayMtl::GetSamplerCD(i); - if (_tcsicmp(pCD->ClassName(), v.s) == 0) - { - m->pb_sampling->SetValue(std2_ssampler, 0, i); - break; - } - } - } break; - case std2_ssampler_qual: - m->GetPixelSampler()->SetQuality( v.f ); break; - case std2_ssampler_enable: - m->GetPixelSampler()->SetEnable( v.i ); - m->SetFlag(NEWSTDMTL_SSAMP_ON, v.i); break; - - case std2_ssampler_adapt_threshold: - m->GetPixelSampler()->SetAdaptiveThreshold( v.f ); break; - case std2_ssampler_adapt_on:{ - m->GetPixelSampler()->SetAdaptiveOn( v.i ); - IParamMap2* map = m->pb_sampling ? m->pb_sampling->GetMap() : NULL; - if ( map ) { - map->Enable(std2_ssampler_adapt_threshold, v.i ); - } - } break; - case std2_ssampler_subsample_tex_on: - m->GetPixelSampler()->SetTextureSuperSampleOn( v.i ); break; - case std2_ssampler_advanced: { - IParamMap2* map = m->pb_sampling ? m->pb_sampling->GetMap() : NULL; - HWND hwnd = ( map ) ? map->GetHWnd() : NULL; - m->GetPixelSampler()->ExecuteParamDialog( hwnd, m ); - } break; - case std2_ssampler_param0: - m->GetPixelSampler()->SetOptionalParam( 0, v.f ); break; - case std2_ssampler_param1: - m->GetPixelSampler()->SetOptionalParam( 1, v.f ); break; - - } - macroRecorder->Enable(); - } - void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_ssampler_by_name: { - ClassDesc* pCD = XRayMtl::GetSamplerCD(m->samplerId); - if (pCD) - v.s = (TCHAR*)pCD->ClassName(); - } break; - } - } + void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + macroRecorder->Disable(); + switch (id) + { + case std2_ssampler: + { + ClassDesc* pCD = XRayMtl::GetSamplerCD(v.i); + if (pCD && m->GetSamplerIndx() != NO_UPDATE) { + m->SwitchSampler(pCD); + // m->samplerId = v.i; + } + } + break; + case std2_ssampler_by_name: + { + for (int i = 0; i < XRayMtl::NumSamplers(); i++) + { + ClassDesc* pCD = XRayMtl::GetSamplerCD(i); + if (_tcsicmp(pCD->ClassName(), v.s) == 0) { + m->pb_sampling->SetValue(std2_ssampler, 0, i); + break; + } + } + } + break; + case std2_ssampler_qual: m->GetPixelSampler()->SetQuality(v.f); break; + case std2_ssampler_enable: + m->GetPixelSampler()->SetEnable(v.i); + m->SetFlag(NEWSTDMTL_SSAMP_ON, v.i); + break; + + case std2_ssampler_adapt_threshold: m->GetPixelSampler()->SetAdaptiveThreshold(v.f); break; + case std2_ssampler_adapt_on: + { + m->GetPixelSampler()->SetAdaptiveOn(v.i); + IParamMap2* map = m->pb_sampling ? m->pb_sampling->GetMap() : NULL; + if (map) { + map->Enable(std2_ssampler_adapt_threshold, v.i); + } + } + break; + case std2_ssampler_subsample_tex_on: m->GetPixelSampler()->SetTextureSuperSampleOn(v.i); break; + case std2_ssampler_advanced: + { + IParamMap2* map = m->pb_sampling ? m->pb_sampling->GetMap() : NULL; + HWND hwnd = (map) ? map->GetHWnd() : NULL; + m->GetPixelSampler()->ExecuteParamDialog(hwnd, m); + } + break; + case std2_ssampler_param0: m->GetPixelSampler()->SetOptionalParam(0, v.f); break; + case std2_ssampler_param1: m->GetPixelSampler()->SetOptionalParam(1, v.f); break; + } + macroRecorder->Enable(); + } + void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_ssampler_by_name: + { + ClassDesc* pCD = XRayMtl::GetSamplerCD(m->samplerId); + if (pCD) v.s = (TCHAR*)pCD->ClassName(); + } + break; + } + } }; - static SamplingPBAccessor samplingPBAccessor; // sampling rollout dialog proc -class SamplingDlgProc : public ParamMap2UserDlgProc +class SamplingDlgProc : public ParamMap2UserDlgProc { public: - BOOL DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) - { - case WM_INITDIALOG: - // load the sampler dropdown - HWND hwndSamplerCombo = GetDlgItem(hWnd, IDC_PIX_SAMPLER); - SendMessage(hwndSamplerCombo, CB_RESETCONTENT, 0L, 0L); - for (int i = 0; i < XRayMtl::NumSamplers(); i++) { - ClassDesc* pClassD = XRayMtl::GetSamplerCD(i); - int n = SendMessage(hwndSamplerCombo, CB_ADDSTRING, 0L, (LPARAM)(pClassD->ClassName()) ); - SendMessage(hwndSamplerCombo, CB_SETITEMDATA, n, (LPARAM)pClassD ); - } - XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); - // Class_ID sampId = m->GetPixelSampler()->ClassID(); - - // JohnW: Are these still necessary? removed setindx 3/23/99 ke - macroRecorder->Disable(); - // m->SetSamplerIndx( m->FindSampler( sampId ) ); - m->UpdateSamplingParams(); - macroRecorder->Enable(); - return TRUE; - } - return FALSE; - } - void DeleteThis() { } + BOOL DlgProc(TimeValue t, IParamMap2* map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + { + switch (msg) + { + case WM_INITDIALOG: + // load the sampler dropdown + HWND hwndSamplerCombo = GetDlgItem(hWnd, IDC_PIX_SAMPLER); + SendMessage(hwndSamplerCombo, CB_RESETCONTENT, 0L, 0L); + for (int i = 0; i < XRayMtl::NumSamplers(); i++) + { + ClassDesc* pClassD = XRayMtl::GetSamplerCD(i); + int n = SendMessage(hwndSamplerCombo, CB_ADDSTRING, 0L, (LPARAM)(pClassD->ClassName())); + SendMessage(hwndSamplerCombo, CB_SETITEMDATA, n, (LPARAM)pClassD); + } + XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); + // Class_ID sampId = m->GetPixelSampler()->ClassID(); + + // JohnW: Are these still necessary? removed setindx 3/23/99 ke + macroRecorder->Disable(); + // m->SetSamplerIndx( m->FindSampler( sampId ) ); + m->UpdateSamplingParams(); + macroRecorder->Enable(); + return TRUE; + } + return FALSE; + } + void DeleteThis() {} }; static SamplingDlgProc samplingDlgProc; // supersampling parameters -static ParamBlockDesc2 std2_sampling_blk ( std2_sampling, _T("samplingParameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, SAMPLING_PB_REF, - //rollout - IDD_DMTL_SAMPLING3, IDS_KE_SAMPLING, 0, APPENDROLL_CLOSED, &samplingDlgProc, - // params - std2_ssampler, _T("sampler"), TYPE_INT, 0, IDS_JW_PIXELSAMPLER, - p_default, 0, - p_ui, TYPE_INTLISTBOX, IDC_PIX_SAMPLER, 0, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_qual, _T("samplerQuality"), TYPE_FLOAT, P_ANIMATABLE, IDS_JW_SAMPLERQUAL, - p_default, 0.5, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_SAMPLEQUALITY_EDIT, IDC_SAMPLEQUALITY_SPIN, 0.01, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_enable, _T("samplerEnable"), TYPE_BOOL, P_ANIMATABLE, IDS_JW_SAMPLERENABLE, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_SUPER_SAMP, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_adapt_threshold, _T("samplerAdaptThreshold"), TYPE_FLOAT, 0, IDS_KE_SAMPLERADAPTTHRESH, - p_default, 0.1, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_THRESHOLD_EDIT, IDC_THRESHOLD_SPIN, 0.001, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_adapt_on, _T("samplerAdaptOn"), TYPE_BOOL, 0, IDS_KE_SAMPLERADAPTON, - p_default, TRUE, - p_ui, TYPE_SINGLECHEKBOX, IDC_ADAPT_ON, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_subsample_tex_on, _T("subSampleTextureOn"), TYPE_BOOL, 0, IDS_KE_SUBSAMPLE_TEX_ON, - p_default, TRUE, - p_ui, TYPE_SINGLECHEKBOX, IDC_SAMPLE_TEX, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_advanced, _T("samplerAdvancedOptions"), TYPE_BOOL, 0, IDS_KE_SAMPLERADVANCED, - p_default, TRUE, - p_ui, TYPE_SINGLECHEKBOX, IDC_ADVANCED_BUTTON, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_by_name, _T("samplerByName"), TYPE_STRING, 0, IDS_JW_SAMPLERBYNAME, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_param0, _T("UserParam0"), TYPE_FLOAT, 0, IDS_KE_SAMPLER_PARAM0, - p_default, 0.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_PARAM0_EDIT, IDC_PARAM0_SPIN, 0.01, - p_accessor, &samplingPBAccessor, - end, - std2_ssampler_param1, _T("UserParam1"), TYPE_FLOAT, 0, IDS_KE_SAMPLER_PARAM1, - p_default, 0.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_PARAM1_EDIT, IDC_PARAM1_SPIN, 0.01, - p_accessor, &samplingPBAccessor, - end, - end - ); +static ParamBlockDesc2 std2_sampling_blk(std2_sampling, _T("samplingParameters"), 0, &stdmtl2CD, + P_AUTO_CONSTRUCT + P_AUTO_UI, SAMPLING_PB_REF, + // rollout + IDD_DMTL_SAMPLING3, IDS_KE_SAMPLING, 0, APPENDROLL_CLOSED, &samplingDlgProc, + // params + std2_ssampler, _T("sampler"), TYPE_INT, 0, IDS_JW_PIXELSAMPLER, p_default, 0, p_ui, TYPE_INTLISTBOX, + IDC_PIX_SAMPLER, 0, p_accessor, &samplingPBAccessor, end, std2_ssampler_qual, _T("samplerQuality"), TYPE_FLOAT, + P_ANIMATABLE, IDS_JW_SAMPLERQUAL, p_default, 0.5, p_range, 0.0, 1.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, + IDC_SAMPLEQUALITY_EDIT, IDC_SAMPLEQUALITY_SPIN, 0.01, p_accessor, &samplingPBAccessor, end, std2_ssampler_enable, + _T("samplerEnable"), TYPE_BOOL, P_ANIMATABLE, IDS_JW_SAMPLERENABLE, p_default, FALSE, p_ui, TYPE_SINGLECHEKBOX, + IDC_SUPER_SAMP, p_accessor, &samplingPBAccessor, end, std2_ssampler_adapt_threshold, _T("samplerAdaptThreshold"), + TYPE_FLOAT, 0, IDS_KE_SAMPLERADAPTTHRESH, p_default, 0.1, p_range, 0.0, 1.0, p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, + IDC_THRESHOLD_EDIT, IDC_THRESHOLD_SPIN, 0.001, p_accessor, &samplingPBAccessor, end, std2_ssampler_adapt_on, + _T("samplerAdaptOn"), TYPE_BOOL, 0, IDS_KE_SAMPLERADAPTON, p_default, TRUE, p_ui, TYPE_SINGLECHEKBOX, IDC_ADAPT_ON, + p_accessor, &samplingPBAccessor, end, std2_ssampler_subsample_tex_on, _T("subSampleTextureOn"), TYPE_BOOL, 0, + IDS_KE_SUBSAMPLE_TEX_ON, p_default, TRUE, p_ui, TYPE_SINGLECHEKBOX, IDC_SAMPLE_TEX, p_accessor, &samplingPBAccessor, + end, std2_ssampler_advanced, _T("samplerAdvancedOptions"), TYPE_BOOL, 0, IDS_KE_SAMPLERADVANCED, p_default, TRUE, + p_ui, TYPE_SINGLECHEKBOX, IDC_ADVANCED_BUTTON, p_accessor, &samplingPBAccessor, end, std2_ssampler_by_name, + _T("samplerByName"), TYPE_STRING, 0, IDS_JW_SAMPLERBYNAME, p_accessor, &samplingPBAccessor, end, + std2_ssampler_param0, _T("UserParam0"), TYPE_FLOAT, 0, IDS_KE_SAMPLER_PARAM0, p_default, 0.0, p_range, 0.0, 1.0, + p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_PARAM0_EDIT, IDC_PARAM0_SPIN, 0.01, p_accessor, &samplingPBAccessor, end, + std2_ssampler_param1, _T("UserParam1"), TYPE_FLOAT, 0, IDS_KE_SAMPLER_PARAM1, p_default, 0.0, p_range, 0.0, 1.0, + p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_PARAM1_EDIT, IDC_PARAM1_SPIN, 0.01, p_accessor, &samplingPBAccessor, end, + end); class XRayPBAccessor : public PBAccessor { public: - void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_eshader_type: - m->eshaderId = (m->GetEShader(v.i))?v.i:-1; - break; - case std2_cshader_type: - m->cshaderId = (m->GetCShader(v.i))?v.i:-1; - break; - case std2_gamemtl_type: - m->gamemtlId = (m->GetGameMtl(v.i))?v.i:-1; - break; - case std2_eshader_by_name: { - int idx = m->FindEShader(v.s); - if (idx>=0) m->pb_xray->SetValue(std2_eshader_type, 0, idx); - }break; - case std2_cshader_by_name: { - int idx = m->FindCShader(v.s); - if (idx>=0) m->pb_xray->SetValue(std2_cshader_type, 0, idx); - }break; - case std2_gamemtl_by_name: { - int idx = m->FindGameMtl(v.s); - if (idx>=0) m->pb_xray->SetValue(std2_gamemtl_type, 0, idx); - }break; - } - } - - void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_eshader_by_name:{ - v.s = m->GetEShader(m->eshaderId); - }break; - case std2_cshader_by_name:{ - v.s = m->GetCShader(m->cshaderId); - }break; - case std2_gamemtl_by_name:{ - v.s = m->GetGameMtl(m->gamemtlId); - }break; - } - } + void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_eshader_type: m->eshaderId = (m->GetEShader(v.i)) ? v.i : -1; break; + case std2_cshader_type: m->cshaderId = (m->GetCShader(v.i)) ? v.i : -1; break; + case std2_gamemtl_type: m->gamemtlId = (m->GetGameMtl(v.i)) ? v.i : -1; break; + case std2_eshader_by_name: + { + int idx = m->FindEShader(v.s); + if (idx >= 0) m->pb_xray->SetValue(std2_eshader_type, 0, idx); + } + break; + case std2_cshader_by_name: + { + int idx = m->FindCShader(v.s); + if (idx >= 0) m->pb_xray->SetValue(std2_cshader_type, 0, idx); + } + break; + case std2_gamemtl_by_name: + { + int idx = m->FindGameMtl(v.s); + if (idx >= 0) m->pb_xray->SetValue(std2_gamemtl_type, 0, idx); + } + break; + } + } + + void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // get into v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_eshader_by_name: { v.s = m->GetEShader(m->eshaderId); + } + break; + case std2_cshader_by_name: { v.s = m->GetCShader(m->cshaderId); + } + break; + case std2_gamemtl_by_name: { v.s = m->GetGameMtl(m->gamemtlId); + } + break; + } + } }; static XRayPBAccessor xrayPBAccessor; // shader rollout dialog proc -class XRayDlgProc : public ParamMap2UserDlgProc +class XRayDlgProc : public ParamMap2UserDlgProc { public: - BOOL DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) - { - case WM_INITDIALOG:{ - XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); - // load the shader dropdown - { - HWND hwndEShader = GetDlgItem(hWnd, IDC_ESHADER); - SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); - for (DWORD i = 0; i < XRayMtl::EShaders.size(); i++) - { - int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetEShader(i)); - SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); - } - } - { - HWND hwndEShader = GetDlgItem(hWnd, IDC_CSHADER); - SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); - for (DWORD i = 0; i < XRayMtl::CShaders.size(); i++) - { - int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetCShader(i)); - SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); - } - } - { - HWND hwndEShader = GetDlgItem(hWnd, IDC_GAMEMTL); - SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); - for (DWORD i = 0; i < XRayMtl::GameMtls.size(); i++) - { - int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetGameMtl(i)); - SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); - } - } - }return TRUE; - } - return FALSE; - } - void DeleteThis() { } + BOOL DlgProc(TimeValue t, IParamMap2* map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + { + switch (msg) + { + case WM_INITDIALOG: + { + XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); + // load the shader dropdown + { + HWND hwndEShader = GetDlgItem(hWnd, IDC_ESHADER); + SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); + for (DWORD i = 0; i < XRayMtl::EShaders.size(); i++) + { + int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetEShader(i)); + SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); + } + } + { + HWND hwndEShader = GetDlgItem(hWnd, IDC_CSHADER); + SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); + for (DWORD i = 0; i < XRayMtl::CShaders.size(); i++) + { + int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetCShader(i)); + SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); + } + } + { + HWND hwndEShader = GetDlgItem(hWnd, IDC_GAMEMTL); + SendMessage(hwndEShader, CB_RESETCONTENT, 0L, 0L); + for (DWORD i = 0; i < XRayMtl::GameMtls.size(); i++) + { + int n = SendMessage(hwndEShader, CB_ADDSTRING, 0L, (LPARAM)m->GetGameMtl(i)); + SendMessage(hwndEShader, CB_SETITEMDATA, n, (LPARAM)i); + } + } + } + return TRUE; + } + return FALSE; + } + void DeleteThis() {} }; - static XRayDlgProc xrayDlgProc; // shader parameters -static ParamBlockDesc2 std2_xray_blk ( std2_xray, _T("Parameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, XRAY_PB_REF, - //rollout - IDD_DMTL_XRAY, IDS_KE_XRAY, 0, APPENDROLL_CLOSED, &xrayDlgProc, - // params - std2_eshader_type, _T("EShaderType"), TYPE_INT, 0, IDS_JW_ESHADERTYPE, - p_default, 0, - p_ui, TYPE_INTLISTBOX, IDC_ESHADER, 0, - p_accessor, &xrayPBAccessor, - end, - std2_cshader_type, _T("CShaderType"), TYPE_INT, 0, IDS_JW_CSHADERTYPE, - p_default, 0, - p_ui, TYPE_INTLISTBOX, IDC_CSHADER, 0, - p_accessor, &xrayPBAccessor, - end, - std2_gamemtl_type, _T("GameMtlType"), TYPE_INT, 0, IDS_JW_GAMEMTLTYPE, - p_default, 0, - p_ui, TYPE_INTLISTBOX, IDC_GAMEMTL, 0, - p_accessor, &xrayPBAccessor, - end, - std2_eshader_by_name, _T("EShaderByName"),TYPE_STRING, 0, IDS_JW_ESHADERBYNAME, - p_accessor, &xrayPBAccessor, - end, - std2_cshader_by_name, _T("CShaderByName"),TYPE_STRING, 0, IDS_JW_CSHADERBYNAME, - p_accessor, &xrayPBAccessor, - end, - std2_gamemtl_by_name, _T("GameMtlByName"),TYPE_STRING, 0, IDS_JW_GAMEMTLBYNAME, - p_accessor, &xrayPBAccessor, - end, - end - ); +static ParamBlockDesc2 std2_xray_blk(std2_xray, _T("Parameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, + XRAY_PB_REF, + // rollout + IDD_DMTL_XRAY, IDS_KE_XRAY, 0, APPENDROLL_CLOSED, &xrayDlgProc, + // params + std2_eshader_type, _T("EShaderType"), TYPE_INT, 0, IDS_JW_ESHADERTYPE, p_default, 0, p_ui, TYPE_INTLISTBOX, + IDC_ESHADER, 0, p_accessor, &xrayPBAccessor, end, std2_cshader_type, _T("CShaderType"), TYPE_INT, 0, + IDS_JW_CSHADERTYPE, p_default, 0, p_ui, TYPE_INTLISTBOX, IDC_CSHADER, 0, p_accessor, &xrayPBAccessor, end, + std2_gamemtl_type, _T("GameMtlType"), TYPE_INT, 0, IDS_JW_GAMEMTLTYPE, p_default, 0, p_ui, TYPE_INTLISTBOX, + IDC_GAMEMTL, 0, p_accessor, &xrayPBAccessor, end, std2_eshader_by_name, _T("EShaderByName"), TYPE_STRING, 0, + IDS_JW_ESHADERBYNAME, p_accessor, &xrayPBAccessor, end, std2_cshader_by_name, _T("CShaderByName"), TYPE_STRING, 0, + IDS_JW_CSHADERBYNAME, p_accessor, &xrayPBAccessor, end, std2_gamemtl_by_name, _T("GameMtlByName"), TYPE_STRING, 0, + IDS_JW_GAMEMTLBYNAME, p_accessor, &xrayPBAccessor, end, end); //////////////////////////////////////////end, sampling static HIMAGELIST hLockButtons = NULL; @@ -707,83 +622,87 @@ static HIMAGELIST hLockButtons = NULL; class ResourceDelete { public: - ResourceDelete() {} - ~ResourceDelete() { if (hLockButtons) ImageList_Destroy(hLockButtons); } + ResourceDelete() {} + ~ResourceDelete() + { + if (hLockButtons) ImageList_Destroy(hLockButtons); + } }; static ResourceDelete theResourceDelete; // mjm - end -static void SetupPadLockButton(HWND hWnd, int id, BOOL check) +static void SetupPadLockButton(HWND hWnd, int id, BOOL check) { - ICustButton *iBut; - iBut = GetICustButton(GetDlgItem(hWnd, id)); - iBut->SetImage(hLockButtons, 2, 2, 2, 2, 16, 15); - iBut->SetType(CBT_CHECK); - ReleaseICustButton(iBut); + ICustButton* iBut; + iBut = GetICustButton(GetDlgItem(hWnd, id)); + iBut->SetImage(hLockButtons, 2, 2, 2, 2, 16, 15); + iBut->SetType(CBT_CHECK); + ReleaseICustButton(iBut); } static void LoadXRayMtlResources() { - static BOOL loaded=FALSE; - if (loaded) return; - loaded = TRUE; - HBITMAP hBitmap, hMask; - hLockButtons = ImageList_Create(16, 15, TRUE, 2, 0); - hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_DMTL_BUTTONS)); - hMask = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_DMTL_MASKBUTTONS)); - ImageList_Add(hLockButtons, hBitmap, hMask); - DeleteObject(hBitmap); - DeleteObject(hMask); -} - -class StdMapsDlgProc : public ParamMap2UserDlgProc + static BOOL loaded = FALSE; + if (loaded) return; + loaded = TRUE; + HBITMAP hBitmap, hMask; + hLockButtons = ImageList_Create(16, 15, TRUE, 2, 0); + hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_DMTL_BUTTONS)); + hMask = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_DMTL_MASKBUTTONS)); + ImageList_Add(hLockButtons, hBitmap, hMask); + DeleteObject(hBitmap); + DeleteObject(hMask); +} + +class StdMapsDlgProc : public ParamMap2UserDlgProc { public: - BOOL DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) - { - XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); - switch (msg) - { - case WM_INITDIALOG: - // conditionally set map amount spinner ranges and padlock button images - LoadXRayMtlResources(); - int bumpChan = m->stdIDToChannel[ ID_BU ]; - int dispChan = m->stdIDToChannel[ ID_DP ]; - int slevChan = m->stdIDToChannel[ ID_SS ]; - - for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) - { - if (i == bumpChan || i == dispChan || i == slevChan) - map->SetRange(std2_map_amnts, -999, 999, i); - else - map->SetRange(std2_map_amnts, 0, 100, i); - } - - SetupPadLockButton(hWnd, IDC_LOCK_TEX01, TRUE); - macroRecorder->Disable(); - { - KillRefmsg kill( m->killRefmsg ); - m->UpdateLockADTex(TRUE); - } - macroRecorder->Enable(); - return TRUE; - } - return FALSE; - } - - void DeleteThis() { } + BOOL DlgProc(TimeValue t, IParamMap2* map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + { + XRayMtl* m = (XRayMtl*)map->GetParamBlock()->GetOwner(); + switch (msg) + { + case WM_INITDIALOG: + // conditionally set map amount spinner ranges and padlock button images + LoadXRayMtlResources(); + int bumpChan = m->stdIDToChannel[ID_BU]; + int dispChan = m->stdIDToChannel[ID_DP]; + int slevChan = m->stdIDToChannel[ID_SS]; + + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + if (i == bumpChan || i == dispChan || i == slevChan) + map->SetRange(std2_map_amnts, -999, 999, i); + else + map->SetRange(std2_map_amnts, 0, 100, i); + } + + SetupPadLockButton(hWnd, IDC_LOCK_TEX01, TRUE); + macroRecorder->Disable(); + { + KillRefmsg kill(m->killRefmsg); + m->UpdateLockADTex(TRUE); + } + macroRecorder->Enable(); + return TRUE; + } + return FALSE; + } + + void DeleteThis() {} }; static StdMapsDlgProc stdMapsDlgProc; -static BOOL IsMultipleInstanced(XRayMtl *m, Texmap *t) { - int cnt=0; - for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) { - if (m->maps->txmap[i].map == t) - cnt++; - } - return (cnt>1)?TRUE:FALSE; +static BOOL IsMultipleInstanced(XRayMtl* m, Texmap* t) +{ + int cnt = 0; + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + if (m->maps->txmap[i].map == t) cnt++; + } + return (cnt > 1) ? TRUE : FALSE; } #define BUMP_DEF_AMT .30f @@ -791,345 +710,299 @@ static BOOL IsMultipleInstanced(XRayMtl *m, Texmap *t) { class MapsPBAccessor : public PBAccessor { public: - // the texture maps are stored, as before, in the Texmaps structure, so the parameters in the - // pb_map block act as 'views' onto this structure. Any setting of map info (say from the scripter) - // is reflected here in the Texmaps structure, and any getting of map info is extracted here from - // this structure. - - // I hope to be able to host the texmap stuff entirely in the paramblock when I get assignable subanim - // numbers supported in PB2's (so that the map, map enable and map amount Tab<>s are number in interleaved row order) - void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_map_enables: - m->maps->txmap[tabIndex].mapOn = v.i; - m->UpdateMapButtons(); - m->UpdateExtendedMapButtons(); - break; - - case std2_maps: - { - Texmap* tex = (Texmap*)v.r; - m->maps->ReplaceReference(2*tabIndex+1, tex); - if (tex != NULL) { - macroRecorder->Disable(); - m->EnableMap(tabIndex, TRUE); - macroRecorder->Enable(); - if (m->maps->txmap[tabIndex].amtCtrl == NULL) { - m->maps->ReplaceReference(2*tabIndex, NewDefaultFloatController()); - m->maps->txmap[tabIndex].amtCtrl->SetValue(TimeValue(0), &m->maps->txmap[tabIndex].amount); - } - } else { - if (m->maps->txmap[tabIndex].amtCtrl != NULL) - m->maps->DeleteReference(2*tabIndex); - macroRecorder->Disable(); - m->SetTexmapAmt(tabIndex, ((tabIndex == m->stdIDToChannel[ID_BU]) ? BUMP_DEF_AMT : 1.0f), TimeValue(0)); - m->EnableMap(tabIndex, FALSE); - macroRecorder->Enable(); - } - if (tex && (tabIndex == m->stdIDToChannel[ID_RL]|| tabIndex == m->stdIDToChannel[ID_RR]) ){ - if (!IsMultipleInstanced(m,tex)) { //DS 4/26/99: keep settings for instanced map - UVGen* uvg0 = tex->GetTheUVGen(); - if (uvg0 && uvg0->IsStdUVGen()) { - StdUVGen *uvg = (StdUVGen*)uvg0; - uvg->InitSlotType(MAPSLOT_ENVIRON); - uvg->SetCoordMapping(UVMAP_SPHERE_ENV); - } - } - } - m->UpdateMapButtons(); - m->UpdateExtendedMapButtons(); - - break; - } - - case std2_map_amnts: - { - // Kill the refmessage from the map, since it will - // be fixed later by the ref message for std2_map_amnts. - KillRefmsg kill(m->killRefmsg); - if (m->maps->txmap[tabIndex].amtCtrl) - m->maps->txmap[tabIndex].amtCtrl->SetValue(t, &v.f); - m->maps->txmap[tabIndex].amount = v.f; - if (tabIndex == m->stdIDToChannel[ID_BU]) - m->mInRQ = chooseReshade[m->mInRQ][IReshading::RR_NeedPreshade]; - } - break; - - case std2_mp_ad_texlock: - m->SetFlag(NEWSTDMTL_LOCK_ADTEX, v.i); - m->UpdateLockADTex(TRUE); - // removed to avoid multiple viewport redraws on change shader - // m->UpdateMtlDisplay(); - break; - } - } - - void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // set from v - { - XRayMtl* m = (XRayMtl*)owner; - switch (id) - { - case std2_map_enables: - v.i = m->maps->txmap[tabIndex].mapOn; break; - case std2_maps: - v.r = m->maps->txmap[tabIndex].map; break; - case std2_map_amnts: - if (m->maps->txmap[tabIndex].amtCtrl) - m->maps->txmap[tabIndex].amtCtrl->GetValue(t, &v.f, valid); - else - v.f = m->maps->txmap[tabIndex].amount; - break; - } - } - - // this allows 'virtual' parameters to refelect key state if in spinners and the underlying - // source parameter is animatable (map amount in this case) - BOOL KeyFrameAtTime(ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) - { - if (id == std2_map_amnts) - return ((XRayMtl*)owner)->AmtKeyAtTime(tabIndex, t); - else - return FALSE; - } - + // the texture maps are stored, as before, in the Texmaps structure, so the parameters in the + // pb_map block act as 'views' onto this structure. Any setting of map info (say from the scripter) + // is reflected here in the Texmaps structure, and any getting of map info is extracted here from + // this structure. + + // I hope to be able to host the texmap stuff entirely in the paramblock when I get assignable subanim + // numbers supported in PB2's (so that the map, map enable and map amount Tab<>s are number in interleaved row + // order) + void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_map_enables: + m->maps->txmap[tabIndex].mapOn = v.i; + m->UpdateMapButtons(); + m->UpdateExtendedMapButtons(); + break; + + case std2_maps: + { + Texmap* tex = (Texmap*)v.r; + m->maps->ReplaceReference(2 * tabIndex + 1, tex); + if (tex != NULL) { + macroRecorder->Disable(); + m->EnableMap(tabIndex, TRUE); + macroRecorder->Enable(); + if (m->maps->txmap[tabIndex].amtCtrl == NULL) { + m->maps->ReplaceReference(2 * tabIndex, NewDefaultFloatController()); + m->maps->txmap[tabIndex].amtCtrl->SetValue(TimeValue(0), &m->maps->txmap[tabIndex].amount); + } + } + else + { + if (m->maps->txmap[tabIndex].amtCtrl != NULL) m->maps->DeleteReference(2 * tabIndex); + macroRecorder->Disable(); + m->SetTexmapAmt(tabIndex, ((tabIndex == m->stdIDToChannel[ID_BU]) ? BUMP_DEF_AMT : 1.0f), TimeValue(0)); + m->EnableMap(tabIndex, FALSE); + macroRecorder->Enable(); + } + if (tex && (tabIndex == m->stdIDToChannel[ID_RL] || tabIndex == m->stdIDToChannel[ID_RR])) { + if (!IsMultipleInstanced(m, tex)) { // DS 4/26/99: keep settings for instanced map + UVGen* uvg0 = tex->GetTheUVGen(); + if (uvg0 && uvg0->IsStdUVGen()) { + StdUVGen* uvg = (StdUVGen*)uvg0; + uvg->InitSlotType(MAPSLOT_ENVIRON); + uvg->SetCoordMapping(UVMAP_SPHERE_ENV); + } + } + } + m->UpdateMapButtons(); + m->UpdateExtendedMapButtons(); + + break; + } + + case std2_map_amnts: + { + // Kill the refmessage from the map, since it will + // be fixed later by the ref message for std2_map_amnts. + KillRefmsg kill(m->killRefmsg); + if (m->maps->txmap[tabIndex].amtCtrl) m->maps->txmap[tabIndex].amtCtrl->SetValue(t, &v.f); + m->maps->txmap[tabIndex].amount = v.f; + if (tabIndex == m->stdIDToChannel[ID_BU]) m->mInRQ = chooseReshade[m->mInRQ][IReshading::RR_NeedPreshade]; + } + break; + + case std2_mp_ad_texlock: + m->SetFlag(NEWSTDMTL_LOCK_ADTEX, v.i); + m->UpdateLockADTex(TRUE); + // removed to avoid multiple viewport redraws on change shader + // m->UpdateMtlDisplay(); + break; + } + } + + void Get(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t, Interval& valid) // set from v + { + XRayMtl* m = (XRayMtl*)owner; + switch (id) + { + case std2_map_enables: v.i = m->maps->txmap[tabIndex].mapOn; break; + case std2_maps: v.r = m->maps->txmap[tabIndex].map; break; + case std2_map_amnts: + if (m->maps->txmap[tabIndex].amtCtrl) + m->maps->txmap[tabIndex].amtCtrl->GetValue(t, &v.f, valid); + else + v.f = m->maps->txmap[tabIndex].amount; + break; + } + } + + // this allows 'virtual' parameters to refelect key state if in spinners and the underlying + // source parameter is animatable (map amount in this case) + BOOL KeyFrameAtTime(ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t) + { + if (id == std2_map_amnts) + return ((XRayMtl*)owner)->AmtKeyAtTime(tabIndex, t); + else + return FALSE; + } }; static MapsPBAccessor mapsPBAccessor; - // std_maps parameters -static ParamBlockDesc2 std_maps_blk ( std_maps, _T("maps"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, MAPS_PB_REF, - //rollout - IDD_DMTL_TEXMAP4, IDS_DS_TEXMAP, 0, APPENDROLL_CLOSED, &stdMapsDlgProc, - // params - std2_map_enables, _T("mapEnables"), TYPE_BOOL_TAB, STD2_NMAX_TEXMAPS, 0, IDS_JW_MAPENABLES, - p_default, FALSE, - p_ui, TYPE_SINGLECHEKBOX, IDC_USEMAP_0, IDC_USEMAP_1, IDC_USEMAP_2, IDC_USEMAP_3, - IDC_USEMAP_4, IDC_USEMAP_5, IDC_USEMAP_6, IDC_USEMAP_7, - IDC_USEMAP_8, IDC_USEMAP_9, IDC_USEMAP_10, IDC_USEMAP_11, - IDC_USEMAP_12, IDC_USEMAP_13, IDC_USEMAP_14, IDC_USEMAP_15, - IDC_USEMAP_16, IDC_USEMAP_17, IDC_USEMAP_18, IDC_USEMAP_19, - IDC_USEMAP_20, IDC_USEMAP_21, IDC_USEMAP_22, IDC_USEMAP_23, - p_accessor, &mapsPBAccessor, - end, - std2_maps, _T("maps"), TYPE_TEXMAP_TAB, STD2_NMAX_TEXMAPS, P_NO_REF, IDS_JW_MAPS, - p_ui, TYPE_TEXMAPBUTTON, IDC_MAP_0, IDC_MAP_1, IDC_MAP_2, IDC_MAP_3, - IDC_MAP_4, IDC_MAP_5, IDC_MAP_6, IDC_MAP_7, - IDC_MAP_8, IDC_MAP_9, IDC_MAP_10, IDC_MAP_11, - IDC_MAP_12, IDC_MAP_13, IDC_MAP_14, IDC_MAP_15, - IDC_MAP_16, IDC_MAP_17, IDC_MAP_18, IDC_MAP_19, - IDC_MAP_20, IDC_MAP_21, IDC_MAP_22, IDC_MAP_23, - p_accessor, &mapsPBAccessor, - end, - std2_map_amnts, _T("mapAmounts"), TYPE_PCNT_FRAC_TAB, STD2_NMAX_TEXMAPS, 0, IDS_JW_MAPAMOUNTS, - p_default, 1.0, // default is given in internal units JBW 10.8.99 - p_range, 0.0, 100.0, - p_ui, TYPE_SPINNER, EDITTYPE_INT, IDC_AMTEDIT_0, IDC_AMTSPIN_0, IDC_AMTEDIT_1, IDC_AMTSPIN_1, - IDC_AMTEDIT_2, IDC_AMTSPIN_2, IDC_AMTEDIT_3, IDC_AMTSPIN_3, - IDC_AMTEDIT_4, IDC_AMTSPIN_4, IDC_AMTEDIT_5, IDC_AMTSPIN_5, - IDC_AMTEDIT_6, IDC_AMTSPIN_6, IDC_AMTEDIT_7, IDC_AMTSPIN_7, - IDC_AMTEDIT_8, IDC_AMTSPIN_8, IDC_AMTEDIT_9, IDC_AMTSPIN_9, - IDC_AMTEDIT_10, IDC_AMTSPIN_10, IDC_AMTEDIT_11, IDC_AMTSPIN_11, - IDC_AMTEDIT_12, IDC_AMTSPIN_12, IDC_AMTEDIT_13, IDC_AMTSPIN_13, - IDC_AMTEDIT_14, IDC_AMTSPIN_14, IDC_AMTEDIT_15, IDC_AMTSPIN_15, - IDC_AMTEDIT_16, IDC_AMTSPIN_16, IDC_AMTEDIT_17, IDC_AMTSPIN_17, - IDC_AMTEDIT_18, IDC_AMTSPIN_18, IDC_AMTEDIT_19, IDC_AMTSPIN_19, - IDC_AMTEDIT_20, IDC_AMTSPIN_20, IDC_AMTEDIT_21, IDC_AMTSPIN_21, - IDC_AMTEDIT_22, IDC_AMTSPIN_22, IDC_AMTEDIT_23, IDC_AMTSPIN_23, - 1.0, - p_accessor, &mapsPBAccessor, - end, - std2_mp_ad_texlock, _T("adTextureLock"), TYPE_BOOL, 0, IDS_JW_ADTEXLOCK, - p_default, TRUE, - p_ui, TYPE_CHECKBUTTON, IDC_LOCK_TEX01, - p_accessor, &mapsPBAccessor, - end, - end - ); +static ParamBlockDesc2 std_maps_blk(std_maps, _T("maps"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, MAPS_PB_REF, + // rollout + IDD_DMTL_TEXMAP4, IDS_DS_TEXMAP, 0, APPENDROLL_CLOSED, &stdMapsDlgProc, + // params + std2_map_enables, _T("mapEnables"), TYPE_BOOL_TAB, STD2_NMAX_TEXMAPS, 0, IDS_JW_MAPENABLES, p_default, FALSE, p_ui, + TYPE_SINGLECHEKBOX, IDC_USEMAP_0, IDC_USEMAP_1, IDC_USEMAP_2, IDC_USEMAP_3, IDC_USEMAP_4, IDC_USEMAP_5, + IDC_USEMAP_6, IDC_USEMAP_7, IDC_USEMAP_8, IDC_USEMAP_9, IDC_USEMAP_10, IDC_USEMAP_11, IDC_USEMAP_12, IDC_USEMAP_13, + IDC_USEMAP_14, IDC_USEMAP_15, IDC_USEMAP_16, IDC_USEMAP_17, IDC_USEMAP_18, IDC_USEMAP_19, IDC_USEMAP_20, + IDC_USEMAP_21, IDC_USEMAP_22, IDC_USEMAP_23, p_accessor, &mapsPBAccessor, end, std2_maps, _T("maps"), + TYPE_TEXMAP_TAB, STD2_NMAX_TEXMAPS, P_NO_REF, IDS_JW_MAPS, p_ui, TYPE_TEXMAPBUTTON, IDC_MAP_0, IDC_MAP_1, IDC_MAP_2, + IDC_MAP_3, IDC_MAP_4, IDC_MAP_5, IDC_MAP_6, IDC_MAP_7, IDC_MAP_8, IDC_MAP_9, IDC_MAP_10, IDC_MAP_11, IDC_MAP_12, + IDC_MAP_13, IDC_MAP_14, IDC_MAP_15, IDC_MAP_16, IDC_MAP_17, IDC_MAP_18, IDC_MAP_19, IDC_MAP_20, IDC_MAP_21, + IDC_MAP_22, IDC_MAP_23, p_accessor, &mapsPBAccessor, end, std2_map_amnts, _T("mapAmounts"), TYPE_PCNT_FRAC_TAB, + STD2_NMAX_TEXMAPS, 0, IDS_JW_MAPAMOUNTS, p_default, 1.0, // default is given in internal units JBW 10.8.99 + p_range, 0.0, 100.0, p_ui, TYPE_SPINNER, EDITTYPE_INT, IDC_AMTEDIT_0, IDC_AMTSPIN_0, IDC_AMTEDIT_1, IDC_AMTSPIN_1, + IDC_AMTEDIT_2, IDC_AMTSPIN_2, IDC_AMTEDIT_3, IDC_AMTSPIN_3, IDC_AMTEDIT_4, IDC_AMTSPIN_4, IDC_AMTEDIT_5, + IDC_AMTSPIN_5, IDC_AMTEDIT_6, IDC_AMTSPIN_6, IDC_AMTEDIT_7, IDC_AMTSPIN_7, IDC_AMTEDIT_8, IDC_AMTSPIN_8, + IDC_AMTEDIT_9, IDC_AMTSPIN_9, IDC_AMTEDIT_10, IDC_AMTSPIN_10, IDC_AMTEDIT_11, IDC_AMTSPIN_11, IDC_AMTEDIT_12, + IDC_AMTSPIN_12, IDC_AMTEDIT_13, IDC_AMTSPIN_13, IDC_AMTEDIT_14, IDC_AMTSPIN_14, IDC_AMTEDIT_15, IDC_AMTSPIN_15, + IDC_AMTEDIT_16, IDC_AMTSPIN_16, IDC_AMTEDIT_17, IDC_AMTSPIN_17, IDC_AMTEDIT_18, IDC_AMTSPIN_18, IDC_AMTEDIT_19, + IDC_AMTSPIN_19, IDC_AMTEDIT_20, IDC_AMTSPIN_20, IDC_AMTEDIT_21, IDC_AMTSPIN_21, IDC_AMTEDIT_22, IDC_AMTSPIN_22, + IDC_AMTEDIT_23, IDC_AMTSPIN_23, 1.0, p_accessor, &mapsPBAccessor, end, std2_mp_ad_texlock, _T("adTextureLock"), + TYPE_BOOL, 0, IDS_JW_ADTEXLOCK, p_default, TRUE, p_ui, TYPE_CHECKBUTTON, IDC_LOCK_TEX01, p_accessor, + &mapsPBAccessor, end, end); #ifndef DESIGN_VER // std2_dynamics parameters -static ParamBlockDesc2 std2_dynamics_blk ( std2_dynamics, _T("dynamicsParameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, DYNAMICS_PB_REF, - //rollout - IDD_DMTL_DYNAM, IDS_DS_DYNAMICS, 0, APPENDROLL_CLOSED, NULL, - // params - std2_bounce, _T("bounce"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_BOUNCE, - p_default, 1.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_BOUNCE_EDIT, IDC_BOUNCE_SPIN, 0.01, - end, - std2_static_friction, _T("staticFriction"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_STATFRIC, - p_default, 0.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_STATFRIC_EDIT, IDC_STATFRIC_SPIN, 0.01, - end, - std2_sliding_friction, _T("slidingFriction"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_SLIDFRIC, - p_default, 0.0, - p_range, 0.0, 1.0, - p_ui, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_SLIDFRIC_EDIT, IDC_SLIDFRIC_SPIN, 0.01, - end, - end - ); +static ParamBlockDesc2 std2_dynamics_blk(std2_dynamics, _T("dynamicsParameters"), 0, &stdmtl2CD, + P_AUTO_CONSTRUCT + P_AUTO_UI, DYNAMICS_PB_REF, + // rollout + IDD_DMTL_DYNAM, IDS_DS_DYNAMICS, 0, APPENDROLL_CLOSED, NULL, + // params + std2_bounce, _T("bounce"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_BOUNCE, p_default, 1.0, p_range, 0.0, 1.0, p_ui, + TYPE_SPINNER, EDITTYPE_FLOAT, IDC_BOUNCE_EDIT, IDC_BOUNCE_SPIN, 0.01, end, std2_static_friction, + _T("staticFriction"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_STATFRIC, p_default, 0.0, p_range, 0.0, 1.0, p_ui, + TYPE_SPINNER, EDITTYPE_FLOAT, IDC_STATFRIC_EDIT, IDC_STATFRIC_SPIN, 0.01, end, std2_sliding_friction, + _T("slidingFriction"), TYPE_FLOAT, P_ANIMATABLE, IDS_DS_SLIDFRIC, p_default, 0.0, p_range, 0.0, 1.0, p_ui, + TYPE_SPINNER, EDITTYPE_FLOAT, IDC_SLIDFRIC_EDIT, IDC_SLIDFRIC_SPIN, 0.01, end, end); #endif // Old Parameter block indices, kept around for old-version loading -#define PB_AMBIENT_O 0 -#define PB_DIFFUSE_O 1 -#define PB_SPECULAR_O 2 -#define PB_SHININESS_O 3 -#define PB_SHIN_STR_O 4 -#define PB_SELFI_O 5 -#define PB_OPAC_O 6 -#define PB_OPFALL_O 7 -#define PB_FILTER_O 8 -#define PB_WIRESZ_O 9 -#define PB_IOR_O 10 -#define PB_BOUNCE_O 11 -#define PB_STATFRIC_O 12 -#define PB_SLIDFRIC_O 13 -#define PB_DIMLEV_O 14 -#define PB_DIMMULT_O 15 -#define PB_SOFTEN_O 16 -#define PB_SELFILLUM_CLR_O 17 +#define PB_AMBIENT_O 0 +#define PB_DIFFUSE_O 1 +#define PB_SPECULAR_O 2 +#define PB_SHININESS_O 3 +#define PB_SHIN_STR_O 4 +#define PB_SELFI_O 5 +#define PB_OPAC_O 6 +#define PB_OPFALL_O 7 +#define PB_FILTER_O 8 +#define PB_WIRESZ_O 9 +#define PB_IOR_O 10 +#define PB_BOUNCE_O 11 +#define PB_STATFRIC_O 12 +#define PB_SLIDFRIC_O 13 +#define PB_DIMLEV_O 14 +#define PB_DIMMULT_O 15 +#define PB_SOFTEN_O 16 +#define PB_SELFILLUM_CLR_O 17 // Ver. 10 Parameter block indices -#define PB_OPAC 0 -#define PB_OPFALL 1 -#define PB_FILTER 2 -#define PB_WIRESZ 3 -#define PB_IOR 4 -#define PB_BOUNCE 5 -#define PB_STATFRIC 6 -#define PB_SLIDFRIC 7 -#define PB_DIMLEV 8 -#define PB_DIMMULT 9 +#define PB_OPAC 0 +#define PB_OPFALL 1 +#define PB_FILTER 2 +#define PB_WIRESZ 3 +#define PB_IOR 4 +#define PB_BOUNCE 5 +#define PB_STATFRIC 6 +#define PB_SLIDFRIC 7 +#define PB_DIMLEV 8 +#define PB_DIMMULT 9 #define CURRENT_NEWSTDMTL_VERSION 12 #define FINAL_PARAMBLOCK_v1_VERSION 10 #define NPARAMS 10 -#define XRAYMTL_PBVERSION 1 -#define NEWSTDMTL_PBVERSION 9 +#define XRAYMTL_PBVERSION 1 +#define NEWSTDMTL_PBVERSION 9 // conversion descriptors for old ParamBlocks to ParamBlock2s -// here we have two version descriptors, one for parameters going into +// here we have two version descriptors, one for parameters going into // new pb_extended pblock, the other for params going into the // new pb_dynamics block. The -1 ID's below indicate no copy, // so we use to update calls to distribute old params from one block // into two new blocks static ParamBlockDescID extVer10[] = { - { TYPE_FLOAT, NULL, TRUE, std2_opacity }, // opacity - { TYPE_FLOAT, NULL, TRUE, std2_falloff_amnt }, // opfalloff - { TYPE_RGBA, NULL, TRUE, std2_filter_color }, // filter - { TYPE_FLOAT, NULL, TRUE, std2_wire_size }, // wireSize - { TYPE_FLOAT, NULL, TRUE, std2_ior }, // index of refraction - { TYPE_FLOAT, NULL, TRUE, -1 }, // bounce - { TYPE_FLOAT, NULL, TRUE, -1 }, // static friction - { TYPE_FLOAT, NULL, TRUE, -1 }, // sliding friction - { TYPE_FLOAT, NULL, TRUE, std2_dim_lvl }, // reflect dim level - { TYPE_FLOAT, NULL, TRUE, std2_refl_lvl }, // reflect dim multiplier + {TYPE_FLOAT, NULL, TRUE, std2_opacity}, // opacity + {TYPE_FLOAT, NULL, TRUE, std2_falloff_amnt}, // opfalloff + {TYPE_RGBA, NULL, TRUE, std2_filter_color}, // filter + {TYPE_FLOAT, NULL, TRUE, std2_wire_size}, // wireSize + {TYPE_FLOAT, NULL, TRUE, std2_ior}, // index of refraction + {TYPE_FLOAT, NULL, TRUE, -1}, // bounce + {TYPE_FLOAT, NULL, TRUE, -1}, // static friction + {TYPE_FLOAT, NULL, TRUE, -1}, // sliding friction + {TYPE_FLOAT, NULL, TRUE, std2_dim_lvl}, // reflect dim level + {TYPE_FLOAT, NULL, TRUE, std2_refl_lvl}, // reflect dim multiplier }; static ParamBlockDescID dynVer10[] = { - { TYPE_FLOAT, NULL, TRUE, -1 }, // opacity - { TYPE_FLOAT, NULL, TRUE, -1 }, // opfalloff - { TYPE_RGBA, NULL, TRUE, -1 }, // filter - { TYPE_FLOAT, NULL, TRUE, -1 }, // wireSize - { TYPE_FLOAT, NULL, TRUE, -1 }, // index of refraction - { TYPE_FLOAT, NULL, TRUE, std2_bounce }, // bounce - { TYPE_FLOAT, NULL, TRUE, std2_static_friction }, // static friction - { TYPE_FLOAT, NULL, TRUE, std2_sliding_friction }, // sliding friction - { TYPE_FLOAT, NULL, TRUE, -1 }, // reflect dim level - { TYPE_FLOAT, NULL, TRUE, -1 }, // reflect dim multiplier + {TYPE_FLOAT, NULL, TRUE, -1}, // opacity + {TYPE_FLOAT, NULL, TRUE, -1}, // opfalloff + {TYPE_RGBA, NULL, TRUE, -1}, // filter + {TYPE_FLOAT, NULL, TRUE, -1}, // wireSize + {TYPE_FLOAT, NULL, TRUE, -1}, // index of refraction + {TYPE_FLOAT, NULL, TRUE, std2_bounce}, // bounce + {TYPE_FLOAT, NULL, TRUE, std2_static_friction}, // static friction + {TYPE_FLOAT, NULL, TRUE, std2_sliding_friction}, // sliding friction + {TYPE_FLOAT, NULL, TRUE, -1}, // reflect dim level + {TYPE_FLOAT, NULL, TRUE, -1}, // reflect dim multiplier }; // v10 Param Block Descriptor -static ParamBlockDescID stdmtl2PB[ NPARAMS ] = { - { TYPE_FLOAT, NULL, TRUE, 7 }, // opacity - { TYPE_FLOAT, NULL, TRUE, 8 }, // opfalloff - { TYPE_RGBA, NULL, TRUE, 9 }, // filter - { TYPE_FLOAT, NULL, TRUE, 10 }, // wireSize - { TYPE_FLOAT, NULL, TRUE, 11 }, // index of refraction - { TYPE_FLOAT, NULL, TRUE, 12 }, // bounce - { TYPE_FLOAT, NULL, TRUE, 13 }, // static friction - { TYPE_FLOAT, NULL, TRUE, 14 }, // sliding friction - { TYPE_FLOAT, NULL, TRUE, 15 }, // reflect dim level - { TYPE_FLOAT, NULL, TRUE, 16 }, // reflect dim multiplier -}; +static ParamBlockDescID stdmtl2PB[NPARAMS] = { + {TYPE_FLOAT, NULL, TRUE, 7}, // opacity + {TYPE_FLOAT, NULL, TRUE, 8}, // opfalloff + {TYPE_RGBA, NULL, TRUE, 9}, // filter + {TYPE_FLOAT, NULL, TRUE, 10}, // wireSize + {TYPE_FLOAT, NULL, TRUE, 11}, // index of refraction + {TYPE_FLOAT, NULL, TRUE, 12}, // bounce + {TYPE_FLOAT, NULL, TRUE, 13}, // static friction + {TYPE_FLOAT, NULL, TRUE, 14}, // sliding friction + {TYPE_FLOAT, NULL, TRUE, 15}, // reflect dim level + {TYPE_FLOAT, NULL, TRUE, 16}, // reflect dim multiplier +}; #define NPARAMS_O 17 -//Old (2.5 and before) Param Block Descriptor -static ParamBlockDescID stdmtlPB[ NPARAMS_O ] = { - { TYPE_RGBA, NULL, TRUE, 1 }, // ambient - { TYPE_RGBA, NULL, TRUE, 2 }, // diffuse - { TYPE_RGBA, NULL, TRUE, 3 }, // specular - { TYPE_FLOAT, NULL, TRUE, 4 }, // shininess - { TYPE_FLOAT, NULL, TRUE, 5 }, // shini_strength - { TYPE_FLOAT, NULL, TRUE, 6 }, // self-illum - { TYPE_FLOAT, NULL, TRUE, 7 }, // opacity - { TYPE_FLOAT, NULL, TRUE, 8 }, // opfalloff - { TYPE_RGBA, NULL, TRUE, 9 }, // filter - { TYPE_FLOAT, NULL, TRUE, 10 }, // wireSize - { TYPE_FLOAT, NULL, TRUE, 11 }, // index of refraction - { TYPE_FLOAT, NULL, TRUE, 12 }, // bounce - { TYPE_FLOAT, NULL, TRUE, 13 }, // static friction - { TYPE_FLOAT, NULL, TRUE, 14 }, // sliding friction - { TYPE_FLOAT, NULL, TRUE, 15 }, // reflect dim level - { TYPE_FLOAT, NULL, TRUE, 16 }, // reflect dim multiplier - { TYPE_FLOAT, NULL, TRUE, 17 } // soften -}; +// Old (2.5 and before) Param Block Descriptor +static ParamBlockDescID stdmtlPB[NPARAMS_O] = { + {TYPE_RGBA, NULL, TRUE, 1}, // ambient + {TYPE_RGBA, NULL, TRUE, 2}, // diffuse + {TYPE_RGBA, NULL, TRUE, 3}, // specular + {TYPE_FLOAT, NULL, TRUE, 4}, // shininess + {TYPE_FLOAT, NULL, TRUE, 5}, // shini_strength + {TYPE_FLOAT, NULL, TRUE, 6}, // self-illum + {TYPE_FLOAT, NULL, TRUE, 7}, // opacity + {TYPE_FLOAT, NULL, TRUE, 8}, // opfalloff + {TYPE_RGBA, NULL, TRUE, 9}, // filter + {TYPE_FLOAT, NULL, TRUE, 10}, // wireSize + {TYPE_FLOAT, NULL, TRUE, 11}, // index of refraction + {TYPE_FLOAT, NULL, TRUE, 12}, // bounce + {TYPE_FLOAT, NULL, TRUE, 13}, // static friction + {TYPE_FLOAT, NULL, TRUE, 14}, // sliding friction + {TYPE_FLOAT, NULL, TRUE, 15}, // reflect dim level + {TYPE_FLOAT, NULL, TRUE, 16}, // reflect dim multiplier + {TYPE_FLOAT, NULL, TRUE, 17} // soften +}; // Descriptor for mapping old (2.5 and before) shader parameters into new stdShader PB2's // Shader::ConvertParamBlock() uses this to extract old mtl shader params into new Shader -static ParamBlockDescID stdmtlPB2[ NPARAMS_O ] = { - { TYPE_RGBA, NULL, TRUE, shdr_ambient }, // ambient - { TYPE_RGBA, NULL, TRUE, shdr_diffuse }, // diffuse - { TYPE_RGBA, NULL, TRUE, shdr_specular }, // specular - { TYPE_FLOAT, NULL, TRUE, shdr_glossiness }, // shininess - { TYPE_FLOAT, NULL, TRUE, shdr_spec_lvl }, // shini_strength - { TYPE_FLOAT, NULL, TRUE, shdr_self_illum_amnt }, // self-illum - { TYPE_FLOAT, NULL, TRUE, -1 }, // opacity - { TYPE_FLOAT, NULL, TRUE, -1 }, // opfalloff - { TYPE_RGBA, NULL, TRUE, -1 }, // filter - { TYPE_FLOAT, NULL, TRUE, -1 }, // wireSize - { TYPE_FLOAT, NULL, TRUE, -1 }, // index of refraction - { TYPE_FLOAT, NULL, TRUE, -1 }, // bounce - { TYPE_FLOAT, NULL, TRUE, -1 }, // static friction - { TYPE_FLOAT, NULL, TRUE, -1 }, // sliding friction - { TYPE_FLOAT, NULL, TRUE, -1 }, // reflect dim level - { TYPE_FLOAT, NULL, TRUE, -1 }, // reflect dim multiplier - { TYPE_FLOAT, NULL, TRUE, shdr_soften } // soften -}; +static ParamBlockDescID stdmtlPB2[NPARAMS_O] = { + {TYPE_RGBA, NULL, TRUE, shdr_ambient}, // ambient + {TYPE_RGBA, NULL, TRUE, shdr_diffuse}, // diffuse + {TYPE_RGBA, NULL, TRUE, shdr_specular}, // specular + {TYPE_FLOAT, NULL, TRUE, shdr_glossiness}, // shininess + {TYPE_FLOAT, NULL, TRUE, shdr_spec_lvl}, // shini_strength + {TYPE_FLOAT, NULL, TRUE, shdr_self_illum_amnt}, // self-illum + {TYPE_FLOAT, NULL, TRUE, -1}, // opacity + {TYPE_FLOAT, NULL, TRUE, -1}, // opfalloff + {TYPE_RGBA, NULL, TRUE, -1}, // filter + {TYPE_FLOAT, NULL, TRUE, -1}, // wireSize + {TYPE_FLOAT, NULL, TRUE, -1}, // index of refraction + {TYPE_FLOAT, NULL, TRUE, -1}, // bounce + {TYPE_FLOAT, NULL, TRUE, -1}, // static friction + {TYPE_FLOAT, NULL, TRUE, -1}, // sliding friction + {TYPE_FLOAT, NULL, TRUE, -1}, // reflect dim level + {TYPE_FLOAT, NULL, TRUE, -1}, // reflect dim multiplier + {TYPE_FLOAT, NULL, TRUE, shdr_soften} // soften +}; #define NUMOLDVER 1 -static ParamVersionDesc oldXRayMtlVersions[ NUMOLDVER ] = { - ParamVersionDesc(stdmtl2PB, NPARAMS, 0), +static ParamVersionDesc oldXRayMtlVersions[NUMOLDVER] = { + ParamVersionDesc(stdmtl2PB, NPARAMS, 0), }; #define NEWSTDMTL_NUMOLDVER 9 -static ParamVersionDesc oldNewStdMtlVersions[ NEWSTDMTL_NUMOLDVER+1 ] = { - ParamVersionDesc(stdmtlPB, 8, 0), - ParamVersionDesc(stdmtlPB, 9, 1), - ParamVersionDesc(stdmtlPB, 9, 2), - ParamVersionDesc(stdmtlPB, 10, 3), - ParamVersionDesc(stdmtlPB, 11, 4), - ParamVersionDesc(stdmtlPB, 14, 5), - ParamVersionDesc(stdmtlPB, 15, 6), - ParamVersionDesc(stdmtlPB, 15, 7), - ParamVersionDesc(stdmtlPB, 16, 8), - ParamVersionDesc(stdmtlPB, 17, 9) -}; +static ParamVersionDesc oldNewStdMtlVersions[NEWSTDMTL_NUMOLDVER + 1] = {ParamVersionDesc(stdmtlPB, 8, 0), + ParamVersionDesc(stdmtlPB, 9, 1), ParamVersionDesc(stdmtlPB, 9, 2), ParamVersionDesc(stdmtlPB, 10, 3), + ParamVersionDesc(stdmtlPB, 11, 4), ParamVersionDesc(stdmtlPB, 14, 5), ParamVersionDesc(stdmtlPB, 15, 6), + ParamVersionDesc(stdmtlPB, 15, 7), ParamVersionDesc(stdmtlPB, 16, 8), ParamVersionDesc(stdmtlPB, 17, 9)}; static ParamVersionDesc curVersion(stdmtl2PB, NPARAMS, XRAYMTL_PBVERSION); static ParamVersionDesc stdMtlVersion(stdmtlPB, NPARAMS_O, NEWSTDMTL_PBVERSION); #define IDT_MYTIMER 1010 #define DRAGTHRESH 6 -#define DITHER_WHEN_INACTIVE // avoids palette conflict probs +#define DITHER_WHEN_INACTIVE // avoids palette conflict probs //----------------------------------------------------------------------------- // XRayMtl @@ -1137,1848 +1010,1895 @@ static ParamVersionDesc stdMtlVersion(stdmtlPB, NPARAMS_O, NEWSTDMTL_PBVERSION); /* TCHAR* XRayMtl::get_string(int i) { - return strings[i]; + return strings[i]; } int XRayMtl::n_strings() { - return strings.Count(); + return strings.Count(); } */ void* XRayMtl::GetInterface(ULONG id) { - if( id == IID_IReshading ) - return (IReshading*)( this ); - // else if ( id == IID_IValidityToken ) - // return (IValidityToken*)( this ); - else - return Mtl::GetInterface(id); + if (id == IID_IReshading) return (IReshading*)(this); + // else if ( id == IID_IValidityToken ) + // return (IValidityToken*)( this ); + else + return Mtl::GetInterface(id); } - -void XRayMtl::Reset() +void XRayMtl::Reset() { - ReplaceReference( TEXMAPS_REF, new Texmaps((MtlBase*)this)); - ivalid.SetEmpty(); - - SetShaderIndx( FindShader( Class_ID(DEFAULT_SHADER_CLASS_ID,0) )); - // back in 4.28, as it broke reset....fixed in shader.reset so only allocs pb if not there - pShader->Reset(); // mjm - 4.22.99 - fix mem leak (pblock already created through SetShaderIndx() above. - - SetSamplerIndx( FindSampler( Class_ID(DEFAULT_SAMPLER_CLASS_ID,0) ) ); + ReplaceReference(TEXMAPS_REF, new Texmaps((MtlBase*)this)); + ivalid.SetEmpty(); + + SetShaderIndx(FindShader(Class_ID(DEFAULT_SHADER_CLASS_ID, 0))); + // back in 4.28, as it broke reset....fixed in shader.reset so only allocs pb if not there + pShader->Reset(); // mjm - 4.22.99 - fix mem leak (pblock already created through SetShaderIndx() above. + + SetSamplerIndx(FindSampler(Class_ID(DEFAULT_SAMPLER_CLASS_ID, 0))); + + // HEY!! this should all be done automatically in ParamBlock init... + macroRecorder->Disable(); // don't want to see this parameter reset in macrorecorder + // ensure all map-related parameters are set up + UpdateMapButtons(); // calls updatetexmaps + UpdateExtendedMapButtons(); + + pb_shader->SetValue(std2_wire, 0, FALSE); + pb_shader->SetValue(std2_two_sided, 0, FALSE); + pb_shader->SetValue(std2_faceted, 0, FALSE); + pb_shader->SetValue(std2_face_map, 0, FALSE); + + SetDimIntens(0.0f, 0); + SetDimMult(3.0f, 0); + + pb_extended->SetValue(std2_opacity_type, 0, 0); + pb_extended->SetValue(std2_falloff_type, 0, 0); + pb_extended->SetValue(std2_wire_units, 0, 0); + pb_extended->SetValue(std2_apply_refl_dimming, 0, FALSE); + SetOpacity(1.0f, 0); + SetFilter(Color(.5f, .5f, .5f), 0); + SetIOR(1.5f, 0); + + // sampling + SetSamplingQuality(0.5f); + SetSamplingOn(FALSE); + pb_sampling->SetValue(std2_ssampler_subsample_tex_on, 0, TRUE); + pb_sampling->SetValue(std2_ssampler_adapt_threshold, 0, .1f); + pb_sampling->SetValue(std2_ssampler_adapt_on, 0, TRUE); + + SetOpacFalloff(0.0f, 0); + SetWireSize(1.0f, 0); + int bumpChan = stdIDToChannel[ID_BU]; + SetTexmapAmt(bumpChan, BUMP_DEF_AMT, 0); + SetDynamicsProperty(0, 0, DYN_BOUNCE, 1.0f); + SetDynamicsProperty(0, 0, DYN_STATIC_FRICTION, 0.0f); + SetDynamicsProperty(0, 0, DYN_SLIDING_FRICTION, 0.0f); + + SetEShaderIndx(FindEShader("default")); + SetCShaderIndx(FindCShader("default")); + SetGameMtlIndx(FindGameMtl("default")); + + macroRecorder->Enable(); +} + +XRayMtl::XRayMtl(BOOL loading) : mReshadeRQ(RR_None), mInRQ(RR_None) // mjm - 06.02.00 +{ + texHandle[0] = texHandle[1] = NULL; + texHandleValid.SetEmpty(); + + pixelSampler = NULL; + samplerId = -1; + + filterOverrideOn = FALSE; + filterSz = 1.0f; + ioRefract = 1.5f; + + old_pblock = NULL; + pb_xray = pb_shader = pb_extended = pb_sampling = pb_maps = pb_dynamics = NULL; + maps = NULL; + filter = Color(0.0f, 0.0f, 0.0f); + pShader = NULL; + shaderId = -1; + flags = NEWSTDMTL_FILT_TRANSP | NEWSTDMTL_ROLLUP1_OPEN; + + dimReflect = FALSE; + dimIntens = 0.0f; + dimMult = 2.0f; + wireSize = opacity = 1.0f; + opfall = 0.0f; + for (int i = 0; i < 12; ++i) + stdIDToChannel[i] = -1; + + for (int i = 0; i < STD2_NMAX_TEXMAPS; ++i) + channelTypes[i] = UNSUPPORTED_CHANNEL; + + ivalid.SetEmpty(); + + /* + if(strings.Count() == 0) + { + char path[MAX_PATH]; + sprintf(path, "%s/%s", GetCOREInterface()->GetDir(APP_PLUGCFG_DIR), "strings.txt"); + FILE* fstr = fopen(path, "r"); + if(fstr != NULL) + { + while(!feof(fstr)) + { + TCHAR str[100]; + + _fgetts(str, 100, fstr); + TCHAR* res_str = _tcsdup(str); + strings.Append(1, &res_str); + } + fclose(fstr); + } + } + */ + if (!loading) { + // ask the ClassDesc to make the P_AUTO_CONSTRUCT paramblocks + stdmtl2CD.MakeAutoParamBlocks(this); + Reset(); + } +} + +RefTargetHandle XRayMtl::Clone(RemapDir& remap) +{ + // DebugPrint(" Cloning NEWSTDMTL %d \n", ++numNewStdMtls); + macroRecorder->Disable(); + XRayMtl* mnew = new XRayMtl(TRUE); + *((MtlBase*)mnew) = *((MtlBase*)this); // copy superclass stuff + mnew->ReplaceReference(TEXMAPS_REF, remap.CloneRef(maps)); + mnew->ReplaceReference(SHADER_REF, remap.CloneRef(pShader)); + mnew->ReplaceReference(XRAY_PB_REF, remap.CloneRef(pb_xray)); + mnew->ReplaceReference(SHADER_PB_REF, remap.CloneRef(pb_shader)); + mnew->ReplaceReference(EXTENDED_PB_REF, remap.CloneRef(pb_extended)); + mnew->ReplaceReference(SAMPLING_PB_REF, remap.CloneRef(pb_sampling)); + mnew->ReplaceReference(MAPS_PB_REF, remap.CloneRef(pb_maps)); +#ifndef DESIGN_VER + mnew->ReplaceReference(DYNAMICS_PB_REF, remap.CloneRef(pb_dynamics)); +#endif + mnew->ReplaceReference(SAMPLER_REF, remap.CloneRef(pixelSampler)); - // HEY!! this should all be done automatically in ParamBlock init... - macroRecorder->Disable(); // don't want to see this parameter reset in macrorecorder - // ensure all map-related parameters are set up - UpdateMapButtons(); // calls updatetexmaps - UpdateExtendedMapButtons(); + mnew->ivalid.SetEmpty(); + mnew->flags = flags; - pb_shader->SetValue(std2_wire, 0, FALSE ); - pb_shader->SetValue(std2_two_sided, 0, FALSE ); - pb_shader->SetValue(std2_faceted, 0, FALSE ); - pb_shader->SetValue(std2_face_map, 0, FALSE ); + mnew->filterOverrideOn = filterOverrideOn; + mnew->filterSz = filterSz; - SetDimIntens( 0.0f, 0 ); - SetDimMult( 3.0f, 0 ); + mnew->ioRefract = ioRefract; + mnew->opacity = opacity; + mnew->filter = filter; + mnew->opfall = opfall; - pb_extended->SetValue(std2_opacity_type, 0, 0 ); - pb_extended->SetValue(std2_falloff_type, 0, 0 ); - pb_extended->SetValue(std2_wire_units, 0, 0 ); - pb_extended->SetValue(std2_apply_refl_dimming, 0, FALSE ); - SetOpacity(1.0f, 0); - SetFilter(Color(.5f, .5f, .5f), 0); - SetIOR(1.5f, 0); + mnew->wireSize = wireSize; + mnew->dimReflect = dimReflect; - // sampling - SetSamplingQuality( 0.5f ); - SetSamplingOn( FALSE ); - pb_sampling->SetValue(std2_ssampler_subsample_tex_on, 0, TRUE ); - pb_sampling->SetValue(std2_ssampler_adapt_threshold, 0, .1f ); - pb_sampling->SetValue(std2_ssampler_adapt_on, 0, TRUE ); + mnew->samplerId = samplerId; + mnew->shaderId = shaderId; - SetOpacFalloff(0.0f, 0); - SetWireSize(1.0f, 0); - int bumpChan = stdIDToChannel[ ID_BU ]; - SetTexmapAmt(bumpChan, BUMP_DEF_AMT, 0); - SetDynamicsProperty(0, 0, DYN_BOUNCE, 1.0f); - SetDynamicsProperty(0, 0, DYN_STATIC_FRICTION, 0.0f); - SetDynamicsProperty(0, 0, DYN_SLIDING_FRICTION, 0.0f); + mnew->eshaderId = eshaderId; + mnew->cshaderId = cshaderId; + mnew->gamemtlId = gamemtlId; - SetEShaderIndx(FindEShader("default")); - SetCShaderIndx(FindCShader("default")); - SetGameMtlIndx(FindGameMtl("default")); + for (int i = 0; i < 12; ++i) + mnew->stdIDToChannel[i] = stdIDToChannel[i]; - macroRecorder->Enable(); + for (int i = 0; i < STD2_NMAX_TEXMAPS; ++i) + mnew->channelTypes[i] = channelTypes[i]; + macroRecorder->Enable(); + BaseClone(this, mnew, remap); + return (RefTargetHandle)mnew; } -XRayMtl::XRayMtl(BOOL loading) : mReshadeRQ(RR_None), mInRQ(RR_None) // mjm - 06.02.00 +ParamDlg* XRayMtl::CreateParamDlg(HWND hwMtlEdit, IMtlParams* imp) { - texHandle[0] = texHandle[1] = NULL; - texHandleValid.SetEmpty(); - - pixelSampler = NULL; - samplerId = -1; - - filterOverrideOn = FALSE; - filterSz = 1.0f; - ioRefract = 1.5f; - - old_pblock = NULL; - pb_xray = pb_shader = pb_extended = pb_sampling = pb_maps = pb_dynamics = NULL; - maps = NULL; - filter = Color(0.0f, 0.0f, 0.0f); - pShader = NULL; - shaderId = -1; - flags = NEWSTDMTL_FILT_TRANSP | NEWSTDMTL_ROLLUP1_OPEN; - - dimReflect = FALSE; - dimIntens = 0.0f; - dimMult = 2.0f; - wireSize = opacity = 1.0f; - opfall = 0.0f; - for ( int i = 0; i < 12; ++i ) - stdIDToChannel[i] = -1; - - for (int i = 0; i < STD2_NMAX_TEXMAPS; ++i ) - channelTypes[i] = UNSUPPORTED_CHANNEL; - - ivalid.SetEmpty(); - -/* - if(strings.Count() == 0) - { - char path[MAX_PATH]; - sprintf(path, "%s/%s", GetCOREInterface()->GetDir(APP_PLUGCFG_DIR), "strings.txt"); - FILE* fstr = fopen(path, "r"); - if(fstr != NULL) - { - while(!feof(fstr)) - { - TCHAR str[100]; - - _fgetts(str, 100, fstr); - TCHAR* res_str = _tcsdup(str); - strings.Append(1, &res_str); - } - fclose(fstr); - } - } -*/ - if (!loading){ - // ask the ClassDesc to make the P_AUTO_CONSTRUCT paramblocks - stdmtl2CD.MakeAutoParamBlocks(this); - Reset(); - } -} - -RefTargetHandle XRayMtl::Clone(RemapDir &remap) { - //DebugPrint(" Cloning NEWSTDMTL %d \n", ++numNewStdMtls); - macroRecorder->Disable(); - XRayMtl *mnew = new XRayMtl(TRUE); - *((MtlBase*)mnew) = *((MtlBase*)this); // copy superclass stuff - mnew->ReplaceReference(TEXMAPS_REF, remap.CloneRef(maps)); - mnew->ReplaceReference(SHADER_REF, remap.CloneRef(pShader)); - mnew->ReplaceReference(XRAY_PB_REF, remap.CloneRef(pb_xray)); - mnew->ReplaceReference(SHADER_PB_REF, remap.CloneRef(pb_shader)); - mnew->ReplaceReference(EXTENDED_PB_REF, remap.CloneRef(pb_extended)); - mnew->ReplaceReference(SAMPLING_PB_REF, remap.CloneRef(pb_sampling)); - mnew->ReplaceReference(MAPS_PB_REF, remap.CloneRef(pb_maps)); -#ifndef DESIGN_VER - mnew->ReplaceReference(DYNAMICS_PB_REF, remap.CloneRef(pb_dynamics)); -#endif - mnew->ReplaceReference(SAMPLER_REF, remap.CloneRef(pixelSampler)); - - mnew->ivalid.SetEmpty(); - mnew->flags = flags; - - mnew->filterOverrideOn = filterOverrideOn; - mnew->filterSz = filterSz; - - mnew->ioRefract = ioRefract; - mnew->opacity = opacity; - mnew->filter = filter; - mnew->opfall = opfall; - - mnew->wireSize = wireSize; - mnew->dimReflect = dimReflect; - - mnew->samplerId = samplerId; - mnew->shaderId = shaderId; - - mnew->eshaderId = eshaderId; - mnew->cshaderId = cshaderId; - mnew->gamemtlId = gamemtlId; - - for ( int i = 0; i < 12; ++i ) - mnew->stdIDToChannel[i] = stdIDToChannel[i]; - - for (int i = 0; i < STD2_NMAX_TEXMAPS; ++i ) - mnew->channelTypes[i] = channelTypes[i]; - macroRecorder->Enable(); - BaseClone(this, mnew, remap); - return (RefTargetHandle)mnew; -} - -ParamDlg* XRayMtl::CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp) -{ - KillRefmsg kill( killRefmsg ); - - Interval v; - macroRecorder->Disable(); - Update(imp->GetTime(), v); - // save the creation context for possible later shader switching requiring a new CreateParamDialog - curHwmEdit = hwMtlEdit; - curImp = imp; - // create the rollouts, first the main shader dialog as master - // note, we can't use PB2 AUTO_UI here, since the shader's dialog is to be installed in the - // middle of the rollouts - masterDlg = stdmtl2CD.CreateParamDlg(std2_shader, hwMtlEdit, imp, this); - // then have the selected shader make its own - pShaderDlg = pShader->CreateParamDialog(NULL, hwMtlEdit, imp, this, - ((flags & NEWSTDMTL_ROLLUP1_OPEN) ? 0 : APPENDROLL_CLOSED)); - masterDlg->AddDlg(pShaderDlg); - // now make the rest (they are added to the master automatically) - - if( pShader->SupportStdParams() & STD_EXTRA_DLG ) - extendedDlg = stdmtl2CD.CreateParamDlg(std2_extended, hwMtlEdit, imp, this); - else - extendedDlg = NULL; - - samplingDlg = stdmtl2CD.CreateParamDlg(std2_sampling, hwMtlEdit, imp, this); - texmapDlg = stdmtl2CD.CreateParamDlg(std_maps, hwMtlEdit, imp, this); - xrayDlg = stdmtl2CD.CreateParamDlg(std2_xray, hwMtlEdit, imp, this); - UpdateTexmaps(); - if( pb_dynamics ) // not in the VIZ version - stdmtl2CD.CreateParamDlg(std2_dynamics, hwMtlEdit, imp, this); - // restore any saved rollout state - stdmtl2CD.RestoreRolloutState(); - UpdateMapButtons(); - UpdateExtendedMapButtons(); - - macroRecorder->Enable(); - return masterDlg; + KillRefmsg kill(killRefmsg); + + Interval v; + macroRecorder->Disable(); + Update(imp->GetTime(), v); + // save the creation context for possible later shader switching requiring a new CreateParamDialog + curHwmEdit = hwMtlEdit; + curImp = imp; + // create the rollouts, first the main shader dialog as master + // note, we can't use PB2 AUTO_UI here, since the shader's dialog is to be installed in the + // middle of the rollouts + masterDlg = stdmtl2CD.CreateParamDlg(std2_shader, hwMtlEdit, imp, this); + // then have the selected shader make its own + pShaderDlg = pShader->CreateParamDialog( + NULL, hwMtlEdit, imp, this, ((flags & NEWSTDMTL_ROLLUP1_OPEN) ? 0 : APPENDROLL_CLOSED)); + masterDlg->AddDlg(pShaderDlg); + // now make the rest (they are added to the master automatically) + + if (pShader->SupportStdParams() & STD_EXTRA_DLG) + extendedDlg = stdmtl2CD.CreateParamDlg(std2_extended, hwMtlEdit, imp, this); + else + extendedDlg = NULL; + + samplingDlg = stdmtl2CD.CreateParamDlg(std2_sampling, hwMtlEdit, imp, this); + texmapDlg = stdmtl2CD.CreateParamDlg(std_maps, hwMtlEdit, imp, this); + xrayDlg = stdmtl2CD.CreateParamDlg(std2_xray, hwMtlEdit, imp, this); + UpdateTexmaps(); + if (pb_dynamics) // not in the VIZ version + stdmtl2CD.CreateParamDlg(std2_dynamics, hwMtlEdit, imp, this); + // restore any saved rollout state + stdmtl2CD.RestoreRolloutState(); + UpdateMapButtons(); + UpdateExtendedMapButtons(); + + macroRecorder->Enable(); + return masterDlg; } BOOL XRayMtl::SetDlgThing(ParamDlg* dlg) { - KillRefmsg kill( killRefmsg ); - - // set the appropriate 'thing' sub-object for each secondary dialog - if (dlg == pShaderDlg) - { - // handle material switching in the shader dialog, incoming material is 'this' - assert (SuperClassID() == MATERIAL_CLASS_ID); - assert (ClassID() == XRAYMTL_CLASS_ID); - XRayMtl* oldMtl = (XRayMtl*)pShaderDlg->GetThing(); - ULONG oldParams, newParams; - Class_ID newClassId, oldClassId; - - if (oldMtl) { - Shader* oldShader = oldMtl->GetShader(); - oldParams = oldShader->SupportStdParams(); - oldClassId = oldShader->ClassID(); - } else oldParams = 0;; - - newParams = pShader->SupportStdParams(); - newClassId = pShader->ClassID(); - - if ( shaderId < 0 ) { - //it's the standin shader - int i = -1; - // DbgAssert(0); - // SetShaderIndx( FindShader( pShader->ClassID() ), FALSE ); - } - - // see if we need to change Shader basic params rollup - if ( (oldClassId == newClassId) || - ((newParams & STD_BASIC2_DLG) && (oldParams & STD_BASIC2_DLG)) ){ - assert( pShaderDlg ); - // update in case of partial stdParam support - pShaderDlg->SetThings(this, pShader); - pShader->SetParamDlg( pShaderDlg ); - pShaderDlg->ReloadDialog(); - UpdateMapButtons(); - } else { - // different shader in this Std2Mtl, toss out the old rollup - HWND oldPanel = pShaderDlg->GetHWnd(); - masterDlg->DeleteDlg(pShaderDlg); - pShaderDlg->DeleteThis(); - - // make a new one - pShaderDlg = pShader->CreateParamDialog(oldPanel, curHwmEdit, curImp, this, - (flags & NEWSTDMTL_ROLLUP1_OPEN ? 0 : APPENDROLL_CLOSED)); - pShader->SetParamDlg(pShaderDlg); - pShaderDlg->LoadDialog(TRUE); - masterDlg->AddDlg(pShaderDlg); - - UpdateMapButtons(); // calls update texmaps - } - } - else if (dlg == texmapDlg) - { - texmapDlg->SetThing(this); - UpdateTexmaps(); - UpdateLockADTex(TRUE); - } - else if (dlg == extendedDlg) - { - extendedDlg->SetThing(this); - UpdateExtraParams( pShader->SupportStdParams() ); - UpdateExtendedMapButtons(); - std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); - } - else if (dlg == samplingDlg) - { - samplingDlg->SetThing(this); - if ( samplerId < 0 ) { - DbgAssert(0); - // SetSamplerIndx( FindSampler( pixelSampler->ClassID() ) ); - } - UpdateSamplingParams(); - } - else if ( pb_dynamics == NULL ) - { - //maybe do something here for viz case of no pb_dynamics - int i = 9; - }else if ( pb_xray == NULL ) - { - //maybe do something here for viz case of no pb_dynamics - int i = 9; - } - else - return FALSE; - return TRUE; + KillRefmsg kill(killRefmsg); + + // set the appropriate 'thing' sub-object for each secondary dialog + if (dlg == pShaderDlg) { + // handle material switching in the shader dialog, incoming material is 'this' + assert(SuperClassID() == MATERIAL_CLASS_ID); + assert(ClassID() == XRAYMTL_CLASS_ID); + XRayMtl* oldMtl = (XRayMtl*)pShaderDlg->GetThing(); + ULONG oldParams, newParams; + Class_ID newClassId, oldClassId; + + if (oldMtl) { + Shader* oldShader = oldMtl->GetShader(); + oldParams = oldShader->SupportStdParams(); + oldClassId = oldShader->ClassID(); + } + else + oldParams = 0; + ; + + newParams = pShader->SupportStdParams(); + newClassId = pShader->ClassID(); + + if (shaderId < 0) { + // it's the standin shader + int i = -1; + // DbgAssert(0); + // SetShaderIndx( FindShader( pShader->ClassID() ), FALSE ); + } + + // see if we need to change Shader basic params rollup + if ((oldClassId == newClassId) || ((newParams & STD_BASIC2_DLG) && (oldParams & STD_BASIC2_DLG))) { + assert(pShaderDlg); + // update in case of partial stdParam support + pShaderDlg->SetThings(this, pShader); + pShader->SetParamDlg(pShaderDlg); + pShaderDlg->ReloadDialog(); + UpdateMapButtons(); + } + else + { + // different shader in this Std2Mtl, toss out the old rollup + HWND oldPanel = pShaderDlg->GetHWnd(); + masterDlg->DeleteDlg(pShaderDlg); + pShaderDlg->DeleteThis(); + + // make a new one + pShaderDlg = pShader->CreateParamDialog( + oldPanel, curHwmEdit, curImp, this, (flags & NEWSTDMTL_ROLLUP1_OPEN ? 0 : APPENDROLL_CLOSED)); + pShader->SetParamDlg(pShaderDlg); + pShaderDlg->LoadDialog(TRUE); + masterDlg->AddDlg(pShaderDlg); + + UpdateMapButtons(); // calls update texmaps + } + } + else if (dlg == texmapDlg) + { + texmapDlg->SetThing(this); + UpdateTexmaps(); + UpdateLockADTex(TRUE); + } + else if (dlg == extendedDlg) + { + extendedDlg->SetThing(this); + UpdateExtraParams(pShader->SupportStdParams()); + UpdateExtendedMapButtons(); + std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); + } + else if (dlg == samplingDlg) + { + samplingDlg->SetThing(this); + if (samplerId < 0) { + DbgAssert(0); + // SetSamplerIndx( FindSampler( pixelSampler->ClassID() ) ); + } + UpdateSamplingParams(); + } + else if (pb_dynamics == NULL) + { + // maybe do something here for viz case of no pb_dynamics + int i = 9; + } + else if (pb_xray == NULL) + { + // maybe do something here for viz case of no pb_dynamics + int i = 9; + } + else + return FALSE; + return TRUE; } // compare function for sorting Shader Tab<> -static int __cdecl classDescListCompare(const void *elem1, const void *elem2) +static int __cdecl classDescListCompare(const void* elem1, const void* elem2) { - ClassDesc* s1 = *(ClassDesc**)elem1; - ClassDesc* s2 = *(ClassDesc**)elem2; - TSTR sn1 = s1->ClassName(); // need to snap name string, since both use GetString() - TSTR sn2 = s2->ClassName(); - return _tcscmp(sn1.data(), sn2.data()); + ClassDesc* s1 = *(ClassDesc**)elem1; + ClassDesc* s2 = *(ClassDesc**)elem2; + TSTR sn1 = s1->ClassName(); // need to snap name string, since both use GetString() + TSTR sn2 = s2->ClassName(); + return _tcscmp(sn1.data(), sn2.data()); } void XRayMtl::LoadShaderList() { - // loads static shader list with name-sorted Shader ClassDesc*'s - shaderList.ZeroCount(); - SubClassList* scList = GetCOREInterface()->GetDllDir().ClassDir().GetClassList(SHADER_CLASS_ID); - for (long i = 0, j = 0; i < scList->Count(ACC_ALL); ++i) { - if ( (*scList)[ i ].IsPublic() ) { - ClassDesc* pClassD = (*scList)[ i ].CD(); - shaderList.Append(1, &pClassD); - } - } - shaderList.Sort(&classDescListCompare); + // loads static shader list with name-sorted Shader ClassDesc*'s + shaderList.ZeroCount(); + SubClassList* scList = GetCOREInterface()->GetDllDir().ClassDir().GetClassList(SHADER_CLASS_ID); + for (long i = 0, j = 0; i < scList->Count(ACC_ALL); ++i) + { + if ((*scList)[i].IsPublic()) { + ClassDesc* pClassD = (*scList)[i].CD(); + shaderList.Append(1, &pClassD); + } + } + shaderList.Sort(&classDescListCompare); } int XRayMtl::NumShaders() { - if (shaderList.Count() == 0) - LoadShaderList(); - return shaderList.Count(); + if (shaderList.Count() == 0) LoadShaderList(); + return shaderList.Count(); } ClassDesc* XRayMtl::GetShaderCD(int i) { - if (shaderList.Count() == 0) - LoadShaderList(); - return (i >= 0 && i < shaderList.Count()) ? shaderList[i] : NULL; + if (shaderList.Count() == 0) LoadShaderList(); + return (i >= 0 && i < shaderList.Count()) ? shaderList[i] : NULL; } void XRayMtl::LoadSamplerList() { - // loads static sampler list with name-sorted Sampler ClassDesc*'s - samplerList.ZeroCount(); - SubClassList* scList = GetCOREInterface()->GetDllDir().ClassDir().GetClassList(SAMPLER_CLASS_ID); - for (long i = 0, j = 0; i < scList->Count(ACC_ALL); ++i) { - if ( (*scList)[ i ].IsPublic() ) { - ClassDesc* pClassD = (*scList)[ i ].CD(); - samplerList.Append(1, &pClassD); - } - } - samplerList.Sort(&classDescListCompare); + // loads static sampler list with name-sorted Sampler ClassDesc*'s + samplerList.ZeroCount(); + SubClassList* scList = GetCOREInterface()->GetDllDir().ClassDir().GetClassList(SAMPLER_CLASS_ID); + for (long i = 0, j = 0; i < scList->Count(ACC_ALL); ++i) + { + if ((*scList)[i].IsPublic()) { + ClassDesc* pClassD = (*scList)[i].CD(); + samplerList.Append(1, &pClassD); + } + } + samplerList.Sort(&classDescListCompare); } int XRayMtl::NumSamplers() { - if (samplerList.Count() == 0) - LoadSamplerList(); - return samplerList.Count(); + if (samplerList.Count() == 0) LoadSamplerList(); + return samplerList.Count(); } ClassDesc* XRayMtl::GetSamplerCD(int i) { - if (samplerList.Count() == 0) - LoadSamplerList(); - return (i >= 0 && i < samplerList.Count()) ? samplerList[i] : NULL; + if (samplerList.Count() == 0) LoadSamplerList(); + return (i >= 0 && i < samplerList.Count()) ? samplerList[i] : NULL; } - //------------------------------------------------------------------- // DS: This class is handy for implementing UNDO - 10/31/00 -#if MAX_VERSION_MAJOR<=5 - #define SRM_CLASS_ID 0xB8073421 - class SingleRefMaker: public ReferenceMaker { - public: - RefTargetHandle rtarget; - SingleRefMaker() { rtarget = NULL; } - ~SingleRefMaker() { - DeleteAllRefsFromMe(); - } - void SetRef(RefTargetHandle rt) { - theHold.Suspend(); - ReplaceReference(0,rt); - theHold.Resume(); - } - RefTargetHandle GetRef() { return rtarget; } - // ReferenceMaker - RefResult NotifyRefChanged( Interval changeInt,RefTargetHandle hTarget, - PartID& partID, RefMessage message ) { - if (message==REFMSG_TARGET_DELETED) { - if (hTarget==rtarget) - rtarget = NULL; - } - return REF_SUCCEED; - } - void DeleteThis() { xr_delete((SingleRefMaker*)this); } - - SClass_ID SuperClassID() { return SRM_CLASS_ID; } - // From ref - int NumRefs() { return 1; } - RefTargetHandle GetReference(int i) { return rtarget; } - void SetReference(int i, RefTargetHandle rtarg) { rtarget = rtarg; } - BOOL CanTransferReference(int i) {return FALSE;} - }; +#if MAX_VERSION_MAJOR <= 5 +#define SRM_CLASS_ID 0xB8073421 +class SingleRefMaker : public ReferenceMaker +{ +public: + RefTargetHandle rtarget; + SingleRefMaker() { rtarget = NULL; } + ~SingleRefMaker() { DeleteAllRefsFromMe(); } + void SetRef(RefTargetHandle rt) + { + theHold.Suspend(); + ReplaceReference(0, rt); + theHold.Resume(); + } + RefTargetHandle GetRef() { return rtarget; } + // ReferenceMaker + RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message) + { + if (message == REFMSG_TARGET_DELETED) { + if (hTarget == rtarget) rtarget = NULL; + } + return REF_SUCCEED; + } + void DeleteThis() { xr_delete((SingleRefMaker*)this); } + SClass_ID SuperClassID() { return SRM_CLASS_ID; } + // From ref + int NumRefs() { return 1; } + RefTargetHandle GetReference(int i) { return rtarget; } + void SetReference(int i, RefTargetHandle rtarg) { rtarget = rtarg; } + BOOL CanTransferReference(int i) { return FALSE; } +}; #endif //------------------------------------------------------------------- // This handles Undo/Redo of SwitchShader -class SwitchShaderRestore: public RestoreObj { +class SwitchShaderRestore : public RestoreObj +{ public: - XRayMtl *mtl; - SingleRefMaker oldShader; - SingleRefMaker newShader; - SwitchShaderRestore() { mtl = NULL; } - SwitchShaderRestore( XRayMtl * m, Shader *olds, Shader *news) { - mtl = m; - oldShader.SetRef(olds); - newShader.SetRef(news); - } - void Restore(int isUndo) { - mtl->SwitchShader((Shader *)oldShader.GetRef()); - } - void Redo() { - mtl->SwitchShader((Shader *)newShader.GetRef()); - } - TSTR Description() { return(TSTR(_T("SwitchShaderRestore"))); } + XRayMtl* mtl; + SingleRefMaker oldShader; + SingleRefMaker newShader; + SwitchShaderRestore() { mtl = NULL; } + SwitchShaderRestore(XRayMtl* m, Shader* olds, Shader* news) + { + mtl = m; + oldShader.SetRef(olds); + newShader.SetRef(news); + } + void Restore(int isUndo) { mtl->SwitchShader((Shader*)oldShader.GetRef()); } + void Redo() { mtl->SwitchShader((Shader*)newShader.GetRef()); } + TSTR Description() { return (TSTR(_T("SwitchShaderRestore"))); } }; - //-------------------------------------------------------------------------- - -void XRayMtl::SwitchShader(Shader* newShader, BOOL loadDlg ) +void XRayMtl::SwitchShader(Shader* newShader, BOOL loadDlg) { - // switch to a different shader - SuspendAnimate(); - Class_ID oldShaderId = pShader? pShader->ClassID(): Class_ID(0,0); - Class_ID newShaderId = newShader->ClassID(); - Class_ID constShaderId( CONSTClassID, 0 ); - if ( newShaderId != oldShaderId ) - { - if ( pb_extended ) { - int n = pb_extended->IDtoIndex( std2_opacity ); - pb_extended->RemoveController( n, 0); - } - - theHold.Suspend(); //----------------------------------------------------- - - if (newShaderId == constShaderId ) { // constant - SetFlag( NEWSTDMTL_FACETED, TRUE ); - pb_shader->SetValue(std2_faceted, 0, TRUE ); - } else if ( oldShaderId == constShaderId ) { - SetFlag( NEWSTDMTL_FACETED, FALSE ); - pb_shader->SetValue(std2_faceted, 0, FALSE ); - } - - Shader * oldShader = GetShader(); - ULONG oldParams = oldShader ? oldShader->SupportStdParams() : 0; - ShaderParamDlg* oldShaderDlg = oldShader ? oldShader->GetParamDlg() : loadDlg? pShaderDlg:NULL; - - ULONG newParams = newShader->SupportStdParams(); - - // copy any params in common - if ( oldShader && newShader ){ - ShuffleShaderParams( newShader, oldShader ); - ShuffleTexMaps( newShader, oldShader ); - } - - theHold.Resume(); //----------------------------------------------------- - - if (theHold.Holding()) - theHold.Put(new SwitchShaderRestore(this,oldShader,newShader)); // this will make a ref to oldShader - - theHold.Suspend(); //----------------------------------------------------- - - // moved from below, or it crashes on reset - if( oldShader) oldShader->SetParamDlg(NULL); // DS 3/9/99 ( undo may bring oldShader back, have to clear invalid pointer) - if( oldShaderDlg ) oldShaderDlg->SetThings( this, NULL ); - - // NB: this deletes the oldShader ( unless it being ref'd by SwitchShaderRestore) - SetShader( newShader ); - - - UpdateTexmaps(); - std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); - - // update UI if open - if (oldShaderDlg != NULL ) - { - // enable or disable extra params - UpdateExtraParams( newParams ); - - // now update or replace the basic rollup - if ((newParams & STD_BASIC2_DLG) && (oldParams & STD_BASIC2_DLG)) { - // update in case of partial stdParam support - oldShaderDlg->SetThings( this, newShader ); - newShader->SetParamDlg( oldShaderDlg ); - oldShaderDlg->LoadDialog(TRUE); - pShaderDlg = oldShaderDlg; - - } else { - - HWND oldPanel = oldShaderDlg->GetHWnd(); - masterDlg->DeleteDlg(oldShaderDlg); - oldShaderDlg->DeleteThis(); - - // including oldPanel replaces it... - pShaderDlg = newShader->CreateParamDialog(oldPanel, - curHwmEdit, curImp, this, - ((flags & NEWSTDMTL_ROLLUP1_OPEN) ? 0 : APPENDROLL_CLOSED)); - newShader->SetParamDlg(pShaderDlg,0); - pShaderDlg->LoadDialog(TRUE); - masterDlg->AddDlg(pShaderDlg); - - } - newShader->SetParamDlg(pShaderDlg,0); - SyncADTexLock( newShader->GetLockADTex() ); - UpdateMapButtons(); - UpdateExtendedMapButtons(); - - UpdateMtlDisplay(); - - }// end, oldShaderDlg not NULL - - theHold.Resume(); //-------------------------------------------------- - - } - ResumeAnimate(); + // switch to a different shader + SuspendAnimate(); + Class_ID oldShaderId = pShader ? pShader->ClassID() : Class_ID(0, 0); + Class_ID newShaderId = newShader->ClassID(); + Class_ID constShaderId(CONSTClassID, 0); + if (newShaderId != oldShaderId) { + if (pb_extended) { + int n = pb_extended->IDtoIndex(std2_opacity); + pb_extended->RemoveController(n, 0); + } + + theHold.Suspend(); //----------------------------------------------------- + + if (newShaderId == constShaderId) { // constant + SetFlag(NEWSTDMTL_FACETED, TRUE); + pb_shader->SetValue(std2_faceted, 0, TRUE); + } + else if (oldShaderId == constShaderId) + { + SetFlag(NEWSTDMTL_FACETED, FALSE); + pb_shader->SetValue(std2_faceted, 0, FALSE); + } + + Shader* oldShader = GetShader(); + ULONG oldParams = oldShader ? oldShader->SupportStdParams() : 0; + ShaderParamDlg* oldShaderDlg = oldShader ? oldShader->GetParamDlg() : loadDlg ? pShaderDlg : NULL; + + ULONG newParams = newShader->SupportStdParams(); + + // copy any params in common + if (oldShader && newShader) { + ShuffleShaderParams(newShader, oldShader); + ShuffleTexMaps(newShader, oldShader); + } + + theHold.Resume(); //----------------------------------------------------- + + if (theHold.Holding()) + theHold.Put(new SwitchShaderRestore(this, oldShader, newShader)); // this will make a ref to oldShader + + theHold.Suspend(); //----------------------------------------------------- + + // moved from below, or it crashes on reset + if (oldShader) + oldShader->SetParamDlg(NULL); // DS 3/9/99 ( undo may bring oldShader back, have to clear invalid pointer) + if (oldShaderDlg) oldShaderDlg->SetThings(this, NULL); + + // NB: this deletes the oldShader ( unless it being ref'd by SwitchShaderRestore) + SetShader(newShader); + + UpdateTexmaps(); + std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); + + // update UI if open + if (oldShaderDlg != NULL) { + // enable or disable extra params + UpdateExtraParams(newParams); + + // now update or replace the basic rollup + if ((newParams & STD_BASIC2_DLG) && (oldParams & STD_BASIC2_DLG)) { + // update in case of partial stdParam support + oldShaderDlg->SetThings(this, newShader); + newShader->SetParamDlg(oldShaderDlg); + oldShaderDlg->LoadDialog(TRUE); + pShaderDlg = oldShaderDlg; + } + else + { + HWND oldPanel = oldShaderDlg->GetHWnd(); + masterDlg->DeleteDlg(oldShaderDlg); + oldShaderDlg->DeleteThis(); + + // including oldPanel replaces it... + pShaderDlg = newShader->CreateParamDialog( + oldPanel, curHwmEdit, curImp, this, ((flags & NEWSTDMTL_ROLLUP1_OPEN) ? 0 : APPENDROLL_CLOSED)); + newShader->SetParamDlg(pShaderDlg, 0); + pShaderDlg->LoadDialog(TRUE); + masterDlg->AddDlg(pShaderDlg); + } + newShader->SetParamDlg(pShaderDlg, 0); + SyncADTexLock(newShader->GetLockADTex()); + UpdateMapButtons(); + UpdateExtendedMapButtons(); + + UpdateMtlDisplay(); + + } // end, oldShaderDlg not NULL + + theHold.Resume(); //-------------------------------------------------- + } + ResumeAnimate(); } // this is exposed at stdmat2 level BOOL XRayMtl::SwitchShader(Class_ID shaderId) { - ClassDesc* pCD; - int n = FindShader( shaderId, &pCD ); - if ( pCD ){ - //SS 1/26/2000: fix suggested by Kells - //SwitchShader(pCD); - SetShaderIndx(n); // sets pb2 & set calls switchshader w/ a real shader - return TRUE; - } - return FALSE; + ClassDesc* pCD; + int n = FindShader(shaderId, &pCD); + if (pCD) { + // SS 1/26/2000: fix suggested by Kells + // SwitchShader(pCD); + SetShaderIndx(n); // sets pb2 & set calls switchshader w/ a real shader + return TRUE; + } + return FALSE; } - void XRayMtl::SwitchShader(ClassDesc* pNewCD) { - // create the new shader object - Shader * newShader = (Shader*)(pNewCD->Create(0)); - newShader->Reset(); // creates pblock + // create the new shader object + Shader* newShader = (Shader*)(pNewCD->Create(0)); + newShader->Reset(); // creates pblock - SwitchShader( newShader ); + SwitchShader(newShader); } - // these provide R 2.5 id access to the old shaders. void XRayMtl::SetShading(int s) { - long cid; - pb_shader->SetValue(std2_faceted,0,FALSE); - switch( s ) { -case 0: cid = PHONGClassID; - pb_shader->SetValue(std2_faceted,0,TRUE); - break; -case 1: cid = PHONGClassID; break; -case 2: cid = METALClassID; break; -case 3: cid = BLINNClassID; break; - } - long indx = FindShader( Class_ID(cid, 0) ); - - // this sets the new shader via pb2 accessor - SetShaderIndx( indx ); + long cid; + pb_shader->SetValue(std2_faceted, 0, FALSE); + switch (s) + { + case 0: + cid = PHONGClassID; + pb_shader->SetValue(std2_faceted, 0, TRUE); + break; + case 1: cid = PHONGClassID; break; + case 2: cid = METALClassID; break; + case 3: cid = BLINNClassID; break; + } + long indx = FindShader(Class_ID(cid, 0)); + + // this sets the new shader via pb2 accessor + SetShaderIndx(indx); } // all faceted shaders approximated by constant, all new shaders by blinn. -int XRayMtl::GetShading() { - if (IsFaceted()) return 0; - Class_ID id = pShader->ClassID(); - if ( id == Class_ID(PHONGClassID,0) ) return 1; - else if ( id == Class_ID(METALClassID,0) ) return 2; - return 3; +int XRayMtl::GetShading() +{ + if (IsFaceted()) return 0; + Class_ID id = pShader->ClassID(); + if (id == Class_ID(PHONGClassID, 0)) + return 1; + else if (id == Class_ID(METALClassID, 0)) + return 2; + return 3; } - //------------------------------------------------------------------- // This handles Undo/Redo of SwitchSampler -class SwitchSamplerRestore: public RestoreObj, public ReferenceMaker { +class SwitchSamplerRestore : public RestoreObj, public ReferenceMaker +{ public: - XRayMtl *mtl; - Sampler *saveSampler; - SwitchSamplerRestore() { saveSampler = NULL; mtl = NULL; } - SwitchSamplerRestore( XRayMtl * m, Sampler *s) { - mtl = m; - saveSampler = NULL; - theHold.Suspend(); - ReplaceReference(0,s); - theHold.Resume(); - } - ~SwitchSamplerRestore() { DeleteAllRefsFromMe(); } - void Switch() { - Sampler *samp = mtl->pixelSampler; - - samp->SetAFlag(A_LOCK_TARGET); // keeps sh from getting auto-deleted - mtl->SwitchSampler(saveSampler); - samp->ClearAFlag(A_LOCK_TARGET); - - ReplaceReference(0,samp); - } - void Restore(int isUndo) { Switch(); } - void Redo() { Switch(); } - TSTR Description() { return(TSTR(_T("SwitchSamplerRestore"))); } - - // ReferenceMaker - RefResult NotifyRefChanged( Interval changeInt,RefTargetHandle hTarget, - PartID& partID, RefMessage message ) { - if (message==REFMSG_TARGET_DELETED) { - if (hTarget==saveSampler) - saveSampler = NULL; - } - return REF_SUCCEED; - } - void DeleteThis() { SwitchSamplerRestore* ptr=this; xr_delete(ptr); } - - // From ref - int NumRefs() { return 1; } - RefTargetHandle GetReference(int i) { return saveSampler; } - void SetReference(int i, RefTargetHandle rtarg) { saveSampler = (Sampler*)rtarg; } - BOOL CanTransferReference(int i) {return FALSE;} + XRayMtl* mtl; + Sampler* saveSampler; + SwitchSamplerRestore() + { + saveSampler = NULL; + mtl = NULL; + } + SwitchSamplerRestore(XRayMtl* m, Sampler* s) + { + mtl = m; + saveSampler = NULL; + theHold.Suspend(); + ReplaceReference(0, s); + theHold.Resume(); + } + ~SwitchSamplerRestore() { DeleteAllRefsFromMe(); } + void Switch() + { + Sampler* samp = mtl->pixelSampler; + + samp->SetAFlag(A_LOCK_TARGET); // keeps sh from getting auto-deleted + mtl->SwitchSampler(saveSampler); + samp->ClearAFlag(A_LOCK_TARGET); + + ReplaceReference(0, samp); + } + void Restore(int isUndo) { Switch(); } + void Redo() { Switch(); } + TSTR Description() { return (TSTR(_T("SwitchSamplerRestore"))); } + // ReferenceMaker + RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message) + { + if (message == REFMSG_TARGET_DELETED) { + if (hTarget == saveSampler) saveSampler = NULL; + } + return REF_SUCCEED; + } + void DeleteThis() + { + SwitchSamplerRestore* ptr = this; + xr_delete(ptr); + } + + // From ref + int NumRefs() { return 1; } + RefTargetHandle GetReference(int i) { return saveSampler; } + void SetReference(int i, RefTargetHandle rtarg) { saveSampler = (Sampler*)rtarg; } + BOOL CanTransferReference(int i) { return FALSE; } }; - //-------------------------------------------------------------------------- // copy of classid of the default sampler -static Class_ID defaultSamplerID( DEFAULT_SAMPLER_CLASS_ID , 0); - - +static Class_ID defaultSamplerID(DEFAULT_SAMPLER_CLASS_ID, 0); -void XRayMtl::SwitchSampler( Sampler* newSampler ) +void XRayMtl::SwitchSampler(Sampler* newSampler) { - theHold.Suspend(); //----------------------------------------------------- + theHold.Suspend(); //----------------------------------------------------- - DbgAssert( newSampler ); - Class_ID oldSamplerId = pixelSampler? pixelSampler->ClassID(): Class_ID(0,0); - Class_ID newSamplerId = newSampler->ClassID(); + DbgAssert(newSampler); + Class_ID oldSamplerId = pixelSampler ? pixelSampler->ClassID() : Class_ID(0, 0); + Class_ID newSamplerId = newSampler->ClassID(); - if ( oldSamplerId != newSamplerId ) { + if (oldSamplerId != newSamplerId) { + theHold.Resume(); //----------------------------------------------------- + if (theHold.Holding()) + theHold.Put(new SwitchSamplerRestore(this, pixelSampler)); // this will make a ref to oldShader + theHold.Suspend(); //----------------------------------------------------- - theHold.Resume(); //----------------------------------------------------- - if (theHold.Holding()) - theHold.Put(new SwitchSamplerRestore(this, pixelSampler)); // this will make a ref to oldShader - theHold.Suspend(); //----------------------------------------------------- + SetPixelSampler(newSampler); + } - SetPixelSampler( newSampler ); - } + if (pb_sampling) UpdateSamplingParams(); - if ( pb_sampling ) - UpdateSamplingParams(); - - theHold.Resume(); //----------------------------------------------------- + theHold.Resume(); //----------------------------------------------------- } - void XRayMtl::SwitchSampler(ClassDesc* pNewCD) { - // if ( ! pNewCD ) { - // get default - // ClassDesc* pCD; - // int indx = FindSampler( defaultSamplerID, &pCD ); - // pNewCD = pCD; - // DbgAssert( pNewCD); - // } - DbgAssert( pNewCD); - Sampler * newSampler = (Sampler*)(pNewCD->Create(0)); - SwitchSampler( newSampler ); + // if ( ! pNewCD ) { + // get default + // ClassDesc* pCD; + // int indx = FindSampler( defaultSamplerID, &pCD ); + // pNewCD = pCD; + // DbgAssert( pNewCD); + // } + DbgAssert(pNewCD); + Sampler* newSampler = (Sampler*)(pNewCD->Create(0)); + SwitchSampler(newSampler); } // this is exposed at stdmat2 level -BOOL XRayMtl::SwitchSampler(Class_ID samplerId){ - // ClassDesc* pCD; - // int n = FindSampler( samplerId, &pCD ); - int n = FindSampler( samplerId ); - // if ( pCD ){ - if ( n >= 0 ){ - // SwitchSampler( (Sampler*)(pCD->Create(0)) ); - SetSamplerIndx( n ); - return TRUE; - } - return FALSE; -} - - - -void XRayMtl::SetPixelSampler( Sampler * sampler ) -{ - BOOL on = pixelSampler? pixelSampler->GetEnable() : FALSE; - BOOL superTex = pixelSampler? pixelSampler->GetTextureSuperSampleOn() : TRUE; - float quality = pixelSampler? pixelSampler->GetQuality() : 0.5f; - ReplaceReference( SAMPLER_REF, sampler ); - NotifyDependents(FOREVER, 0, REFMSG_SUBANIM_STRUCTURE_CHANGED); - if(pixelSampler) { - pixelSampler->SetEnable( on ); - pixelSampler->SetTextureSuperSampleOn( superTex ); - pixelSampler->SetQuality( quality ); - } -} +BOOL XRayMtl::SwitchSampler(Class_ID samplerId) +{ + // ClassDesc* pCD; + // int n = FindSampler( samplerId, &pCD ); + int n = FindSampler(samplerId); + // if ( pCD ){ + if (n >= 0) { + // SwitchSampler( (Sampler*)(pCD->Create(0)) ); + SetSamplerIndx(n); + return TRUE; + } + return FALSE; +} + +void XRayMtl::SetPixelSampler(Sampler* sampler) +{ + BOOL on = pixelSampler ? pixelSampler->GetEnable() : FALSE; + BOOL superTex = pixelSampler ? pixelSampler->GetTextureSuperSampleOn() : TRUE; + float quality = pixelSampler ? pixelSampler->GetQuality() : 0.5f; + ReplaceReference(SAMPLER_REF, sampler); + NotifyDependents(FOREVER, 0, REFMSG_SUBANIM_STRUCTURE_CHANGED); + if (pixelSampler) { + pixelSampler->SetEnable(on); + pixelSampler->SetTextureSuperSampleOn(superTex); + pixelSampler->SetQuality(quality); + } +} static TCHAR dots[] = _T(". . . . . . . . . . . . . . . . . . . . . . . ."); void XRayMtl::UpdateTexmaps() { - // if the UI is up for the maps paramblock, adjust button text and enables - // according to current shader's capabilities - // UI controls are updated indirectly via calls on the ParamMap2. - // further, a Param Alias table is set up for all the pmap Tab<> params for scripter access - IParamMap2* pmap = pb_maps->GetMap(); - Shader* pShader = GetShader(); - long nShaderMapChannels = pShader->nTexChannelsSupported(); - long nMtlMapChannels = MTL_NTEXMAPS; - pb_maps->ClearParamAliases(); - int slevChan = pShader->StdIDToChannel( ID_SS ); - - for ( long i = 0; i < STD2_NMAX_TEXMAPS; ++i ) - { - if ( i < nShaderMapChannels ) - { - BOOL isSupported = ! (pShader->ChannelType( i ) & UNSUPPORTED_CHANNEL); - if (pmap != NULL) - { - TSTR chanName = maps->txmap[i].name = pShader->GetTexChannelName(i); - // append dots - int n = chanName.length(); - chanName.append( _T(" " ) ); - chanName.append( &dots[ n+1 ] ); - pmap->SetText(std2_map_enables, chanName, i); - pmap->Enable(std2_map_enables, isSupported, i); - pmap->Enable(std2_map_amnts, isSupported, i); - pmap->Enable(std2_maps, isSupported, i); - - if ( i == slevChan || pShader->ChannelType( i ) == SLEV_CHANNEL ) - pmap->SetRange(std2_map_amnts, -999, 999, i); - else - pmap->SetRange(std2_map_amnts, 0, 100, i); - - } - // set up the Tab<> param aliases - TSTR chanIntName = pShader->GetTexChannelInternalName(i); - if (chanIntName.Length() > 0) - { - channelTypes[ i ] = pShader->ChannelType( i ); - pb_maps->DefineParamAlias(chanIntName, std2_maps, i); - pb_maps->DefineParamAlias(chanIntName + _T("Enable"), std2_map_enables, i); // JBW 5/24/99, made non-localizable (as names s/b internal) - pb_maps->DefineParamAlias(chanIntName + _T("Amount"), std2_map_amnts, i); - } - } - else - { // beyond the end of supported shader channels - if (pmap != NULL) - { - // add the mtls texture channels - if ( nMtlMapChannels > 0 ) { - TSTR chanName = maps->txmap[i].name = GetString( mtlChannelNameIDS[ i - nShaderMapChannels ] ); - // append dots - int n = chanName.length(); - chanName.append( _T(" " ) ); - chanName.append( &dots[ n+1 ] ); - pmap->SetText(std2_map_enables, chanName, i); - pmap->Enable(std2_map_enables, TRUE, i); - pmap->Enable(std2_map_amnts, TRUE, i); - pmap->Enable(std2_maps, TRUE, i); - // range, first channel is bumps, last is displacement - if ( nMtlMapChannels == MTL_NTEXMAPS || nMtlMapChannels == 1 ) - pmap->SetRange(std2_map_amnts, -999, 999, i); - else - pmap->SetRange(std2_map_amnts, 0, 100, i); - - --nMtlMapChannels; - - } else { - // channel is not used for this mtl/shader - pmap->SetText(std2_map_enables, dots, i); - macroRecorder->Disable(); - SetTexmapAmt(i, 0.0f, 0); - macroRecorder->Enable(); - pmap->Enable(std2_map_enables, FALSE, i); - pmap->Enable(std2_map_amnts, FALSE, i); - pmap->Enable(std2_maps, FALSE, i); - } - } - TSTR chanIntName = mtlChannelInternalNames[ i - nShaderMapChannels ] ; - if (chanIntName.Length() > 0) - { - channelTypes[ i ] = mtlChannelType[ i - nShaderMapChannels ]; - pb_maps->DefineParamAlias(chanIntName, std2_maps, i); - pb_maps->DefineParamAlias(chanIntName + GetString(IDS_JW_ENABLE), std2_map_enables, i); - pb_maps->DefineParamAlias(chanIntName + GetString(IDS_JW_AMOUNT), std2_map_amnts, i); - } - - } - } - - // last do the Channel Ids from stdMat - for (long i = 0; i < N_ID_CHANNELS; ++i ){ - int chan = pShader->StdIDToChannel(i); - if ( chan >= 0 ) { - stdIDToChannel[i] = chan; - } else if (mtlStdIDToChannel[ i ] >= 0){ - stdIDToChannel[i] = mtlStdIDToChannel[ i ] + pShader->nTexChannelsSupported(); - } else - stdIDToChannel[i] = -1; - } - - // disable for old metal - ULONG stdParms = pShader->SupportStdParams(); - if ( (stdParms & STD_BASIC2_DLG) && (stdParms & STD_PARAM_METAL) ){ - //metal std shader, turn off stuff - int n = stdIDToChannel[ ID_SP ]; - if ( pmap ) { - pmap->Enable(std2_map_amnts, FALSE, n ); - pmap->Enable(std2_maps, FALSE, n); - pmap->Enable(std2_map_enables, FALSE, n); - } - } - // disable filter on additive/subtractive - if ( (stdParms & STD_EXTRA_DLG) && TRANSP_FILTER != GetTransparencyType() ){ - //metal std shader, turn off stuff - int n = stdIDToChannel[ ID_FI ]; - if ( pmap ) { - pmap->Enable(std2_map_amnts, FALSE, n ); - pmap->Enable(std2_maps, FALSE, n); - pmap->Enable(std2_map_enables, FALSE, n); - } - } - -} - -static TCHAR* mapStates[] = { _T(" "), _T("m"), _T("M") }; - -void XRayMtl::UpdateMapButtons() -{ - UpdateTexmaps(); - if (IsShaderInUI()){ - pShader->GetParamDlg()->UpdateMapButtons(); - UpdateLockADTex(TRUE); - } - // UpdateExtendedMapButtons(); + // if the UI is up for the maps paramblock, adjust button text and enables + // according to current shader's capabilities + // UI controls are updated indirectly via calls on the ParamMap2. + // further, a Param Alias table is set up for all the pmap Tab<> params for scripter access + IParamMap2* pmap = pb_maps->GetMap(); + Shader* pShader = GetShader(); + long nShaderMapChannels = pShader->nTexChannelsSupported(); + long nMtlMapChannels = MTL_NTEXMAPS; + pb_maps->ClearParamAliases(); + int slevChan = pShader->StdIDToChannel(ID_SS); + + for (long i = 0; i < STD2_NMAX_TEXMAPS; ++i) + { + if (i < nShaderMapChannels) { + BOOL isSupported = !(pShader->ChannelType(i) & UNSUPPORTED_CHANNEL); + if (pmap != NULL) { + TSTR chanName = maps->txmap[i].name = pShader->GetTexChannelName(i); + // append dots + int n = chanName.length(); + chanName.append(_T(" " )); + chanName.append(&dots[n + 1]); + pmap->SetText(std2_map_enables, chanName, i); + pmap->Enable(std2_map_enables, isSupported, i); + pmap->Enable(std2_map_amnts, isSupported, i); + pmap->Enable(std2_maps, isSupported, i); + + if (i == slevChan || pShader->ChannelType(i) == SLEV_CHANNEL) + pmap->SetRange(std2_map_amnts, -999, 999, i); + else + pmap->SetRange(std2_map_amnts, 0, 100, i); + } + // set up the Tab<> param aliases + TSTR chanIntName = pShader->GetTexChannelInternalName(i); + if (chanIntName.Length() > 0) { + channelTypes[i] = pShader->ChannelType(i); + pb_maps->DefineParamAlias(chanIntName, std2_maps, i); + pb_maps->DefineParamAlias(chanIntName + _T("Enable"), std2_map_enables, + i); // JBW 5/24/99, made non-localizable (as names s/b internal) + pb_maps->DefineParamAlias(chanIntName + _T("Amount"), std2_map_amnts, i); + } + } + else + { // beyond the end of supported shader channels + if (pmap != NULL) { + // add the mtls texture channels + if (nMtlMapChannels > 0) { + TSTR chanName = maps->txmap[i].name = GetString(mtlChannelNameIDS[i - nShaderMapChannels]); + // append dots + int n = chanName.length(); + chanName.append(_T(" " )); + chanName.append(&dots[n + 1]); + pmap->SetText(std2_map_enables, chanName, i); + pmap->Enable(std2_map_enables, TRUE, i); + pmap->Enable(std2_map_amnts, TRUE, i); + pmap->Enable(std2_maps, TRUE, i); + // range, first channel is bumps, last is displacement + if (nMtlMapChannels == MTL_NTEXMAPS || nMtlMapChannels == 1) + pmap->SetRange(std2_map_amnts, -999, 999, i); + else + pmap->SetRange(std2_map_amnts, 0, 100, i); + + --nMtlMapChannels; + } + else + { + // channel is not used for this mtl/shader + pmap->SetText(std2_map_enables, dots, i); + macroRecorder->Disable(); + SetTexmapAmt(i, 0.0f, 0); + macroRecorder->Enable(); + pmap->Enable(std2_map_enables, FALSE, i); + pmap->Enable(std2_map_amnts, FALSE, i); + pmap->Enable(std2_maps, FALSE, i); + } + } + TSTR chanIntName = mtlChannelInternalNames[i - nShaderMapChannels]; + if (chanIntName.Length() > 0) { + channelTypes[i] = mtlChannelType[i - nShaderMapChannels]; + pb_maps->DefineParamAlias(chanIntName, std2_maps, i); + pb_maps->DefineParamAlias(chanIntName + GetString(IDS_JW_ENABLE), std2_map_enables, i); + pb_maps->DefineParamAlias(chanIntName + GetString(IDS_JW_AMOUNT), std2_map_amnts, i); + } + } + } + + // last do the Channel Ids from stdMat + for (long i = 0; i < N_ID_CHANNELS; ++i) + { + int chan = pShader->StdIDToChannel(i); + if (chan >= 0) { + stdIDToChannel[i] = chan; + } + else if (mtlStdIDToChannel[i] >= 0) + { + stdIDToChannel[i] = mtlStdIDToChannel[i] + pShader->nTexChannelsSupported(); + } + else + stdIDToChannel[i] = -1; + } + + // disable for old metal + ULONG stdParms = pShader->SupportStdParams(); + if ((stdParms & STD_BASIC2_DLG) && (stdParms & STD_PARAM_METAL)) { + // metal std shader, turn off stuff + int n = stdIDToChannel[ID_SP]; + if (pmap) { + pmap->Enable(std2_map_amnts, FALSE, n); + pmap->Enable(std2_maps, FALSE, n); + pmap->Enable(std2_map_enables, FALSE, n); + } + } + // disable filter on additive/subtractive + if ((stdParms & STD_EXTRA_DLG) && TRANSP_FILTER != GetTransparencyType()) { + // metal std shader, turn off stuff + int n = stdIDToChannel[ID_FI]; + if (pmap) { + pmap->Enable(std2_map_amnts, FALSE, n); + pmap->Enable(std2_maps, FALSE, n); + pmap->Enable(std2_map_enables, FALSE, n); + } + } +} + +static TCHAR* mapStates[] = {_T(" "), _T("m"), _T("M")}; + +void XRayMtl::UpdateMapButtons() +{ + UpdateTexmaps(); + if (IsShaderInUI()) { + pShader->GetParamDlg()->UpdateMapButtons(); + UpdateLockADTex(TRUE); + } + // UpdateExtendedMapButtons(); } void XRayMtl::UpdateExtendedMapButtons() { - IParamMap2* pmap = pb_extended->GetMap(); - if (pmap != NULL){ - int filtChan = stdIDToChannel[ID_FI]; - int state = GetMapState( filtChan ); - pmap->SetText(std2_ep_filter_map, mapStates[ state ]); + IParamMap2* pmap = pb_extended->GetMap(); + if (pmap != NULL) { + int filtChan = stdIDToChannel[ID_FI]; + int state = GetMapState(filtChan); + pmap->SetText(std2_ep_filter_map, mapStates[state]); - TSTR nm = GetMapName( filtChan ); - pmap->SetTooltip(std2_ep_filter_map, TRUE, nm); - } + TSTR nm = GetMapName(filtChan); + pmap->SetTooltip(std2_ep_filter_map, TRUE, nm); + } } void XRayMtl::UpdateSamplingParams() { - IParamMap2* map = pb_sampling->GetMap(); - if ( map ) { - HWND hwnd = map->GetHWnd(); - BOOL qualityOn = pixelSampler->SupportsQualityLevels()>0 ? TRUE:FALSE ; - map->Show(std2_ssampler_qual, qualityOn ); - HWND hwQual = GetDlgItem( hwnd, IDC_QUALITY_TEXT ); - ShowWindow( hwQual, qualityOn ); - - ULONG samplerParms = pixelSampler->SupportsStdParams(); - map->Show(std2_ssampler_adapt_on, samplerParms & ADAPTIVE_CHECK_BOX ); - map->Enable(std2_ssampler_adapt_threshold, pixelSampler->IsAdaptiveOn() ); - map->Show(std2_ssampler_adapt_threshold, samplerParms & ADAPTIVE_THRESHOLD ); - - map->Show(std2_ssampler_subsample_tex_on, samplerParms & SUPER_SAMPLE_TEX_CHECK_BOX ); - HWND hwThresh = GetDlgItem( hwnd, IDC_ADAPT_STATIC ); - ShowWindow( hwThresh, samplerParms & ADAPTIVE_THRESHOLD?TRUE:FALSE ); - map->Show(std2_ssampler_advanced, samplerParms & ADVANCED_DLG_BUTTON ); - SetDlgItemText( hwnd, IDC_COMMENT_TEXT, pixelSampler->GetDefaultComment() ); - - map->Show(std2_ssampler_param0, samplerParms & OPTIONAL_PARAM_0 ); - if( samplerParms & OPTIONAL_PARAM_0 ) - SetDlgItemText( hwnd, IDC_PARAM0_TEXT, pixelSampler->GetOptionalParamName(0) ); - ShowWindow( GetDlgItem( hwnd, IDC_PARAM0_TEXT ), samplerParms & OPTIONAL_PARAM_0 ); - - map->Show(std2_ssampler_param1, samplerParms & OPTIONAL_PARAM_1 ); - if( samplerParms & OPTIONAL_PARAM_1 ) - SetDlgItemText( hwnd, IDC_PARAM1_TEXT, pixelSampler->GetOptionalParamName(1) ); - ShowWindow( GetDlgItem( hwnd, IDC_PARAM1_TEXT ), samplerParms & OPTIONAL_PARAM_1 ); - } + IParamMap2* map = pb_sampling->GetMap(); + if (map) { + HWND hwnd = map->GetHWnd(); + BOOL qualityOn = pixelSampler->SupportsQualityLevels() > 0 ? TRUE : FALSE; + map->Show(std2_ssampler_qual, qualityOn); + HWND hwQual = GetDlgItem(hwnd, IDC_QUALITY_TEXT); + ShowWindow(hwQual, qualityOn); + + ULONG samplerParms = pixelSampler->SupportsStdParams(); + map->Show(std2_ssampler_adapt_on, samplerParms & ADAPTIVE_CHECK_BOX); + map->Enable(std2_ssampler_adapt_threshold, pixelSampler->IsAdaptiveOn()); + map->Show(std2_ssampler_adapt_threshold, samplerParms & ADAPTIVE_THRESHOLD); + + map->Show(std2_ssampler_subsample_tex_on, samplerParms & SUPER_SAMPLE_TEX_CHECK_BOX); + HWND hwThresh = GetDlgItem(hwnd, IDC_ADAPT_STATIC); + ShowWindow(hwThresh, samplerParms & ADAPTIVE_THRESHOLD ? TRUE : FALSE); + map->Show(std2_ssampler_advanced, samplerParms & ADVANCED_DLG_BUTTON); + SetDlgItemText(hwnd, IDC_COMMENT_TEXT, pixelSampler->GetDefaultComment()); + + map->Show(std2_ssampler_param0, samplerParms & OPTIONAL_PARAM_0); + if (samplerParms & OPTIONAL_PARAM_0) + SetDlgItemText(hwnd, IDC_PARAM0_TEXT, pixelSampler->GetOptionalParamName(0)); + ShowWindow(GetDlgItem(hwnd, IDC_PARAM0_TEXT), samplerParms & OPTIONAL_PARAM_0); + + map->Show(std2_ssampler_param1, samplerParms & OPTIONAL_PARAM_1); + if (samplerParms & OPTIONAL_PARAM_1) + SetDlgItemText(hwnd, IDC_PARAM1_TEXT, pixelSampler->GetOptionalParamName(1)); + ShowWindow(GetDlgItem(hwnd, IDC_PARAM1_TEXT), samplerParms & OPTIONAL_PARAM_1); + } } // enable & disable extra params possibly overridden by the shader -void XRayMtl::UpdateExtraParams( ULONG stdParams ) -{ - // update shader dlg map buttons - IParamMap2* pmap = pb_extended->GetMap(); - if (pmap != NULL) - { - HWND hRollup = pmap->GetHWnd(); - BOOL opacOn = ( stdParams & STD_EXTRA_OPACITY ) ? TRUE : FALSE; - pmap->Show( std2_opacity_type, opacOn ); - pmap->Show( std2_falloff_type, opacOn ); - pmap->Show( std2_falloff_amnt, opacOn ); - ShowWindow( GetDlgItem(hRollup, IDC_OPAC_TEXT1), opacOn ); - ShowWindow( GetDlgItem(hRollup, IDC_OPAC_TEXT2), opacOn ); - ShowWindow( GetDlgItem(hRollup, IDC_OPAC_TEXT3), opacOn ); - ShowWindow( GetDlgItem(hRollup, IDC_FILTER_OVERLAY), !opacOn ); - - BOOL reflOn = ( stdParams & STD_EXTRA_REFLECTION) ? TRUE : FALSE; - pmap->Show( std2_apply_refl_dimming, reflOn ); - pmap->Show( std2_dim_lvl, reflOn ); - pmap->Show( std2_refl_lvl, reflOn ); - ShowWindow( GetDlgItem(hRollup, IDC_REFL_TEXT1), reflOn ); - ShowWindow( GetDlgItem(hRollup, IDC_REFL_TEXT2), reflOn ); - ShowWindow( GetDlgItem(hRollup, IDC_REFL_BOX), reflOn ); - // EnableWindow( GetDlgItem(hRollup, IDC_REFL_BOX), reflOn ); - - BOOL refrOn = ( stdParams & STD_EXTRA_REFRACTION ) ? TRUE : FALSE; - pmap->Show( std2_ior, refrOn ); - ShowWindow( GetDlgItem(hRollup, IDC_REFR_TEXT1), refrOn ); - - // BOOL filterOn = (refrOn || opacOn) && GetTransparencyType() == TRANSP_FILTER; - BOOL filterOn = (refrOn && !opacOn) || (opacOn && GetTransparencyType() == TRANSP_FILTER); - pmap->Show( std2_filter_color, filterOn ); - pmap->Show( std2_ep_filter_map, filterOn ); - EnableWindow( GetDlgItem(hRollup, IDC_OPAC_BOX), (refrOn || opacOn) ); - } -} - -int XRayMtl::GetMapState( int nMap ) -{ - Texmap *t = (*maps)[nMap].map; - if ( t == NULL ) return 0; - return (*maps)[nMap].mapOn ? 2 :1; -} - - -TSTR XRayMtl::GetMapName( int nMap ) -{ - Texmap *t = (*maps)[nMap].map; - if ( t == NULL ) - return TSTR( GetString( IDS_KE_NONE ) ); - return t->GetFullName(); -} - - -void XRayMtl::SyncADTexLock( BOOL lockOn ) -{ - pb_maps->SetValue(std2_mp_ad_texlock, 0, lockOn ); - UpdateLockADTex(FALSE); - // SetFlag( NEWSTDMTL_LOCK_ADTEX, lockOn ); - // force an update - // if (masterDlg) - // masterDlg->ReloadDialog(); -} - -void XRayMtl::UpdateLockADTex( BOOL passOn ) -{ - IParamMap2* pmap = pb_maps->GetMap(); - int lock = GetFlag(NEWSTDMTL_LOCK_ADTEX)!=0; - if ( pShader->SupportStdParams() & STD_PARAM_LOCKADTEX ) { - if ( passOn ){ - pShader->SetLockADTex( lock ); - if (pmap != NULL && pShader->GetParamDlg()) - pShader->GetParamDlg()->LoadDialog(TRUE); - } - if (pmap != NULL) - { - pmap->Show(std2_mp_ad_texlock, TRUE); - pmap->Enable(std2_maps, !lock, 0); - } - } else { - // no std params, so no amb/diff lock - if (pmap != NULL) - { - pmap->Show(std2_mp_ad_texlock, FALSE); - pmap->Enable(std2_maps, TRUE, 0); - } - } - -} - -void XRayMtl::UpdateMtlDisplay() -{ - IParamMap2* map = pb_maps->GetMap(); - if (map != NULL) - { - // removed to avoid multiple viewport redraws on change shader - // map->RedrawViews(GetCOREInterface()->GetTime()); - map->Invalidate(); - } -} - -#define LIMIT0_1(x) if (x<0.0f) x = 0.0f; else if (x>1.0f) x = 1.0f; -#define LIMIT1(x) if (x > 1.0f) x = 1.0f; -#define LIMITMINMAX(x, min, max) if (xmax) x = max; - -static Color LimitColor(Color c) { - LIMIT0_1(c.r); - LIMIT0_1(c.g); - LIMIT0_1(c.b); - return c; -} +void XRayMtl::UpdateExtraParams(ULONG stdParams) +{ + // update shader dlg map buttons + IParamMap2* pmap = pb_extended->GetMap(); + if (pmap != NULL) { + HWND hRollup = pmap->GetHWnd(); + BOOL opacOn = (stdParams & STD_EXTRA_OPACITY) ? TRUE : FALSE; + pmap->Show(std2_opacity_type, opacOn); + pmap->Show(std2_falloff_type, opacOn); + pmap->Show(std2_falloff_amnt, opacOn); + ShowWindow(GetDlgItem(hRollup, IDC_OPAC_TEXT1), opacOn); + ShowWindow(GetDlgItem(hRollup, IDC_OPAC_TEXT2), opacOn); + ShowWindow(GetDlgItem(hRollup, IDC_OPAC_TEXT3), opacOn); + ShowWindow(GetDlgItem(hRollup, IDC_FILTER_OVERLAY), !opacOn); + + BOOL reflOn = (stdParams & STD_EXTRA_REFLECTION) ? TRUE : FALSE; + pmap->Show(std2_apply_refl_dimming, reflOn); + pmap->Show(std2_dim_lvl, reflOn); + pmap->Show(std2_refl_lvl, reflOn); + ShowWindow(GetDlgItem(hRollup, IDC_REFL_TEXT1), reflOn); + ShowWindow(GetDlgItem(hRollup, IDC_REFL_TEXT2), reflOn); + ShowWindow(GetDlgItem(hRollup, IDC_REFL_BOX), reflOn); + // EnableWindow( GetDlgItem(hRollup, IDC_REFL_BOX), reflOn ); + + BOOL refrOn = (stdParams & STD_EXTRA_REFRACTION) ? TRUE : FALSE; + pmap->Show(std2_ior, refrOn); + ShowWindow(GetDlgItem(hRollup, IDC_REFR_TEXT1), refrOn); + + // BOOL filterOn = (refrOn || opacOn) && GetTransparencyType() == TRANSP_FILTER; + BOOL filterOn = (refrOn && !opacOn) || (opacOn && GetTransparencyType() == TRANSP_FILTER); + pmap->Show(std2_filter_color, filterOn); + pmap->Show(std2_ep_filter_map, filterOn); + EnableWindow(GetDlgItem(hRollup, IDC_OPAC_BOX), (refrOn || opacOn)); + } +} + +int XRayMtl::GetMapState(int nMap) +{ + Texmap* t = (*maps)[nMap].map; + if (t == NULL) return 0; + return (*maps)[nMap].mapOn ? 2 : 1; +} + +TSTR XRayMtl::GetMapName(int nMap) +{ + Texmap* t = (*maps)[nMap].map; + if (t == NULL) return TSTR(GetString(IDS_KE_NONE)); + return t->GetFullName(); +} -void XRayMtl::Update(TimeValue t, Interval &valid) { - Point3 p; - if (!ivalid.InInterval(t)) { - ivalid.SetInfinite(); +void XRayMtl::SyncADTexLock(BOOL lockOn) +{ + pb_maps->SetValue(std2_mp_ad_texlock, 0, lockOn); + UpdateLockADTex(FALSE); + // SetFlag( NEWSTDMTL_LOCK_ADTEX, lockOn ); + // force an update + // if (masterDlg) + // masterDlg->ReloadDialog(); +} + +void XRayMtl::UpdateLockADTex(BOOL passOn) +{ + IParamMap2* pmap = pb_maps->GetMap(); + int lock = GetFlag(NEWSTDMTL_LOCK_ADTEX) != 0; + if (pShader->SupportStdParams() & STD_PARAM_LOCKADTEX) { + if (passOn) { + pShader->SetLockADTex(lock); + if (pmap != NULL && pShader->GetParamDlg()) pShader->GetParamDlg()->LoadDialog(TRUE); + } + if (pmap != NULL) { + pmap->Show(std2_mp_ad_texlock, TRUE); + pmap->Enable(std2_maps, !lock, 0); + } + } + else + { + // no std params, so no amb/diff lock + if (pmap != NULL) { + pmap->Show(std2_mp_ad_texlock, FALSE); + pmap->Enable(std2_maps, TRUE, 0); + } + } +} + +void XRayMtl::UpdateMtlDisplay() +{ + IParamMap2* map = pb_maps->GetMap(); + if (map != NULL) { + // removed to avoid multiple viewport redraws on change shader + // map->RedrawViews(GetCOREInterface()->GetTime()); + map->Invalidate(); + } +} + +#define LIMIT0_1(x) \ + if (x < 0.0f) \ + x = 0.0f; \ + else if (x > 1.0f) \ + x = 1.0f; +#define LIMIT1(x) \ + if (x > 1.0f) x = 1.0f; +#define LIMITMINMAX(x, min, max) \ + if (x < min) \ + x = min; \ + else if (x > max) \ + x = max; + +static Color LimitColor(Color c) +{ + LIMIT0_1(c.r); + LIMIT0_1(c.g); + LIMIT0_1(c.b); + return c; +} - pb_extended->GetValue(std2_filter_color, t, p, ivalid ); - filter = LimitColor(Color(p.x, p.y, p.z)); - pb_extended->GetValue(std2_ior, t, ioRefract, ivalid ); - pb_extended->GetValue(std2_opacity, t, opacity, ivalid ); - LIMIT0_1(opacity); +void XRayMtl::Update(TimeValue t, Interval& valid) +{ + Point3 p; + if (!ivalid.InInterval(t)) { + ivalid.SetInfinite(); - if (IsShaderInUI()) - pShader->GetParamDlg()->UpdateOpacity(); + pb_extended->GetValue(std2_filter_color, t, p, ivalid); + filter = LimitColor(Color(p.x, p.y, p.z)); + pb_extended->GetValue(std2_ior, t, ioRefract, ivalid); + pb_extended->GetValue(std2_opacity, t, opacity, ivalid); + LIMIT0_1(opacity); - pb_extended->GetValue(std2_falloff_amnt, t, opfall, ivalid ); - LIMIT0_1(opfall); + if (IsShaderInUI()) pShader->GetParamDlg()->UpdateOpacity(); - pb_extended->GetValue(std2_wire_size, t, wireSize, ivalid ); - pb_extended->GetValue(std2_dim_lvl, t, dimIntens, ivalid ); - LIMIT0_1(dimIntens); - pb_extended->GetValue(std2_refl_lvl, t, dimMult, ivalid ); + pb_extended->GetValue(std2_falloff_amnt, t, opfall, ivalid); + LIMIT0_1(opfall); - SetFlag(NEWSTDMTL_WIRE, pb_shader->GetInt(std2_wire, t)); - SetFlag(NEWSTDMTL_2SIDE, pb_shader->GetInt(std2_two_sided, t)); - SetFlag(NEWSTDMTL_FACEMAP, pb_shader->GetInt(std2_face_map, t)); - SetFlag(NEWSTDMTL_FACETED, pb_shader->GetInt(std2_faceted, t)); + pb_extended->GetValue(std2_wire_size, t, wireSize, ivalid); + pb_extended->GetValue(std2_dim_lvl, t, dimIntens, ivalid); + LIMIT0_1(dimIntens); + pb_extended->GetValue(std2_refl_lvl, t, dimMult, ivalid); - SetFlag(NEWSTDMTL_ADD_TRANSP, pb_extended->GetInt(std2_opacity_type, t) == 2); - SetFlag(NEWSTDMTL_FILT_TRANSP, pb_extended->GetInt(std2_opacity_type, t) == 0); - SetFlag(NEWSTDMTL_FALLOFF_OUT, pb_extended->GetInt(std2_falloff_type, t) == 1); - SetFlag(NEWSTDMTL_WIRE_UNITS, pb_extended->GetInt(std2_wire_units, t) == 1); - SetFlag(NEWSTDMTL_LOCK_ADTEX, pb_maps->GetInt(std2_mp_ad_texlock, t) == 1); - dimReflect = pb_extended->GetInt(std2_apply_refl_dimming, t); - - if (pShader) - pShader->Update( t, ivalid ); - - for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) - if (MAPACTIVE(i)) - maps->txmap[i].Update(t, ivalid); - - } - valid &= ivalid; -} - -BOOL XRayMtl::AmtKeyAtTime(int i, TimeValue t) { - if (maps->txmap[i].amtCtrl) - return maps->txmap[i].amtCtrl->IsKeyAtTime(t,0); - else - return FALSE; -} - -typedef struct { - float amount; - Control *amtCtrl; - Texmap *map; - BOOL mapOn; - TSTR name; -} saveChan; + SetFlag(NEWSTDMTL_WIRE, pb_shader->GetInt(std2_wire, t)); + SetFlag(NEWSTDMTL_2SIDE, pb_shader->GetInt(std2_two_sided, t)); + SetFlag(NEWSTDMTL_FACEMAP, pb_shader->GetInt(std2_face_map, t)); + SetFlag(NEWSTDMTL_FACETED, pb_shader->GetInt(std2_faceted, t)); -void XRayMtl::ShuffleTexMaps( Shader* newShader, Shader* oldShader ) + SetFlag(NEWSTDMTL_ADD_TRANSP, pb_extended->GetInt(std2_opacity_type, t) == 2); + SetFlag(NEWSTDMTL_FILT_TRANSP, pb_extended->GetInt(std2_opacity_type, t) == 0); + SetFlag(NEWSTDMTL_FALLOFF_OUT, pb_extended->GetInt(std2_falloff_type, t) == 1); + SetFlag(NEWSTDMTL_WIRE_UNITS, pb_extended->GetInt(std2_wire_units, t) == 1); + SetFlag(NEWSTDMTL_LOCK_ADTEX, pb_maps->GetInt(std2_mp_ad_texlock, t) == 1); + dimReflect = pb_extended->GetInt(std2_apply_refl_dimming, t); + + if (pShader) pShader->Update(t, ivalid); + + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + if (MAPACTIVE(i)) maps->txmap[i].Update(t, ivalid); + } + valid &= ivalid; +} + +BOOL XRayMtl::AmtKeyAtTime(int i, TimeValue t) { - saveChan oldMaps[STD2_NMAX_TEXMAPS]; + if (maps->txmap[i].amtCtrl) + return maps->txmap[i].amtCtrl->IsKeyAtTime(t, 0); + else + return FALSE; +} - for( long i = 0; i < STD2_NMAX_TEXMAPS; ++i ){ - oldMaps[i].amtCtrl = maps->txmap[i].amtCtrl; maps->txmap[i].amtCtrl = NULL; - oldMaps[i].amount = maps->txmap[i].amount; maps->txmap[i].amount = 1.0f; - oldMaps[i].map = maps->txmap[i].map; maps->txmap[i].map = NULL; - oldMaps[i].mapOn = maps->txmap[i].mapOn; maps->txmap[i].mapOn = FALSE; - oldMaps[i].name = maps->txmap[i].name; maps->txmap[i].name = _T(""); - } - int nOldShadeMaps = oldShader->nTexChannelsSupported(); - int nNewShadeMaps = newShader->nTexChannelsSupported(); +typedef struct +{ + float amount; + Control* amtCtrl; + Texmap* map; + BOOL mapOn; + TSTR name; +} saveChan; - // for each new shader map +void XRayMtl::ShuffleTexMaps(Shader* newShader, Shader* oldShader) +{ + saveChan oldMaps[STD2_NMAX_TEXMAPS]; + + for (long i = 0; i < STD2_NMAX_TEXMAPS; ++i) + { + oldMaps[i].amtCtrl = maps->txmap[i].amtCtrl; + maps->txmap[i].amtCtrl = NULL; + oldMaps[i].amount = maps->txmap[i].amount; + maps->txmap[i].amount = 1.0f; + oldMaps[i].map = maps->txmap[i].map; + maps->txmap[i].map = NULL; + oldMaps[i].mapOn = maps->txmap[i].mapOn; + maps->txmap[i].mapOn = FALSE; + oldMaps[i].name = maps->txmap[i].name; + maps->txmap[i].name = _T(""); + } + int nOldShadeMaps = oldShader->nTexChannelsSupported(); + int nNewShadeMaps = newShader->nTexChannelsSupported(); + + // for each new shader map int oldChan, newChan = 0; - for(; newChan < nNewShadeMaps; ++newChan ){ - - TSTR newName = newShader->GetTexChannelInternalName(newChan); - - // look for match in each old map - for ( oldChan = 0; oldChan < nOldShadeMaps; ++oldChan ) { - if ( newName == oldShader->GetTexChannelInternalName(oldChan) ) - break; - } - - if( oldChan < nOldShadeMaps ) { // found it - maps->txmap[newChan].amtCtrl = oldMaps[oldChan].amtCtrl; - maps->txmap[newChan].amount = oldMaps[oldChan].amount; - maps->txmap[newChan].map = oldMaps[oldChan].map; - maps->txmap[newChan].mapOn = oldMaps[oldChan].mapOn; - maps->txmap[newChan].name = oldMaps[oldChan].name; - } - - }// end, for each new map - - // now do the mtl maps - for ( int n = 0; n < MTL_NTEXMAPS; ++n ){ - newChan = n + nNewShadeMaps; - oldChan = n + nOldShadeMaps; - maps->txmap[newChan].amtCtrl = oldMaps[oldChan].amtCtrl; - maps->txmap[newChan].amount = oldMaps[oldChan].amount; - maps->txmap[newChan].map = oldMaps[oldChan].map; - maps->txmap[newChan].mapOn = oldMaps[oldChan].mapOn; - maps->txmap[newChan].name = oldMaps[oldChan].name; - } -} - -void XRayMtl::ShuffleShaderParams( Shader* newShader, Shader* oldShader ) -{ - ClassDesc2 *oldCD2 = NULL, *newCD2 = NULL; - - ClassDesc * newCD; - FindShader( newShader->ClassID(), &newCD ); - - ClassDesc * oldCD; - FindShader( oldShader->ClassID(), &oldCD ); - - // check if we have a ParamBlock2-based shaders - if (oldCD != NULL && oldCD->InternalName() != NULL) - oldCD2 = (ClassDesc2*)oldCD; - if (newCD != NULL && newCD->InternalName() != NULL) - newCD2 = (ClassDesc2*)newCD; - - // loop over destination shaders PB2-based parameters - if (oldCD2 != NULL && newCD2 != NULL){ - // loop over each block in the new shader - for (int i = 0; i < newCD2->NumParamBlockDescs(); i++){ - // get block descriptor and source paramblock - ParamBlockDesc2* newPBdesc = newCD2->GetParamBlockDesc(i); - IParamBlock2* newPB2 = newShader->GetParamBlockByID(newPBdesc->ID); - // loop over each new param and copy from old if there's a match - for (int j = 0; j < newPBdesc->count; j++){ - ParamDef& paramDef = newPBdesc->paramdefs[j]; - - // Now search the old shaders blocks - for (int i = 0; i < oldCD2->NumParamBlockDescs(); i++){ - ParamBlockDesc2* oldPBdesc = oldCD2->GetParamBlockDesc(i); - int j = oldPBdesc->NameToIndex(paramDef.int_name); - if (j >= 0){ - // found an internal name match, get the dest pblock and param def - ParamDef& srcParamDef = oldPBdesc->paramdefs[j]; - // copy only if types match - if (srcParamDef.type == paramDef.type){ - IParamBlock2* oldPB2 = oldShader->GetParamBlockByID(oldPBdesc->ID); - newPB2->Assign(paramDef.ID, oldPB2, srcParamDef.ID); - goto nextParam; // found it, outta here... - } - - } - } -nextParam: ; - }// end, dest param loop - }// end, desk block loop - Interval v; - v.SetInfinite(); - newShader->Update(0, v); - - // end, pb2 copying - } else { - - // StdParam based copy - newShader->CopyStdParams( oldShader ); - } -} - -float XRayMtl::GetXParency(int mtlNum, BOOL backFace) { - int opacChan = stdIDToChannel[ ID_OP ]; - - // When the mtl has "Show Map in Viewport" turned on, and has an opacity map, - // the opacity map over-rides the opacity. DS 6/16/00 - // (Actually, when the hardward doesn't support enough texture channels to do - // the opacity map, the overide is only true for NON-decal maps). - // - if (((*maps)[opacChan].map&&MAPACTIVE(opacChan)&&Active())) { - return 0.0f; - } - - // The following statement looks dubious -- what is it trying to do? -- DS 6/16/00 - if(opacity>0.9f && opfall>0.0f) - return 0.1f; - else - return 1.0f-opacity; -} - -ULONG XRayMtl::Requirements(int subMtlNum) { - ULONG req; - - assert( pShader ); - req = pShader->GetRequirements(subMtlNum); - - int opacChan = stdIDToChannel[ ID_OP ]; - int bumpChan = stdIDToChannel[ ID_BU ]; - int dispChan = stdIDToChannel[ ID_DP ]; - - if (opacity!=1.0f||MAPACTIVE(opacChan)||opfall>0.0f) { - req |= MTLREQ_TRANSP; - } - - if (opacity!=1.0f|| ((*maps)[opacChan].map&&MAPACTIVE(opacChan)&&Active())) - req |= MTLREQ_TRANSP_IN_VP; - - for (int i=0; iRequirements(subMtlNum); - } - if (MAPACTIVE(bumpChan)) { - ULONG bmpreq = (*maps)[bumpChan].map->Requirements(subMtlNum); - if (bmpreq&MTLREQ_UV) - req |= MTLREQ_BUMPUV; - if (bmpreq&MTLREQ_UV2) - req |= MTLREQ_BUMPUV2; - } - if (flags&NEWSTDMTL_WIRE) req|= MTLREQ_WIRE; - if (flags&NEWSTDMTL_2SIDE) req|= MTLREQ_2SIDE; - // if (pixelSampler && pixelSampler->GetEnable() ) - if ( flags&NEWSTDMTL_SSAMP_ON ) - req|= MTLREQ_SUPERSAMPLE; - if (flags&NEWSTDMTL_WIRE_UNITS) req|= MTLREQ_WIRE_ABS; - if (flags&NEWSTDMTL_FACEMAP) req |= MTLREQ_FACEMAP; - if (flags&NEWSTDMTL_ADD_TRANSP) req |= MTLREQ_ADDITIVE_TRANSP; - if (flags&NEWSTDMTL_FACETED) req |= MTLREQ_FACETED; - if (MAPACTIVE(dispChan)) req |= MTLREQ_DISPLACEMAP; - return req; -} - -int XRayMtl::MapSlotType(int i) -{ - if (i==stdIDToChannel[ID_DP]) return MAPSLOT_DISPLACEMENT; // DS 4/12/99 - return (i==stdIDToChannel[ID_RL] || i==stdIDToChannel[ID_RR])? -MAPSLOT_ENVIRON : MAPSLOT_TEXTURE; -} - -void XRayMtl::MappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq) { - int bumpChan = stdIDToChannel[ ID_BU ]; - for (int i=0; iMappingsRequired(subMtlNum,bumpreq,bumpreq); - else - (*maps)[i].map->MappingsRequired(subMtlNum,mapreq,bumpreq); - } - } -} - -Interval XRayMtl::Validity(TimeValue t) { - Interval v; - Update(t, v); - return ivalid; -} - -void XRayMtl::NotifyChanged() { - NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); -} - -void XRayMtl::SetFlag(ULONG f, ULONG val) { - if (val) flags|=f; - else flags &= ~f; -} - -void XRayMtl::SetTransparencyType(int type) { - switch (type) { -case TRANSP_SUBTRACTIVE: - SetFlag(NEWSTDMTL_ADD_TRANSP, 0); - SetFlag(NEWSTDMTL_FILT_TRANSP, 0); - pb_extended->SetValue(std2_opacity_type, 0, 1); - break; -case TRANSP_ADDITIVE: - SetFlag(NEWSTDMTL_ADD_TRANSP, 1); - SetFlag(NEWSTDMTL_FILT_TRANSP, 0); - pb_extended->SetValue(std2_opacity_type, 0, 2); - break; -case TRANSP_FILTER: - SetFlag(NEWSTDMTL_ADD_TRANSP, 0); - SetFlag(NEWSTDMTL_FILT_TRANSP, 1); - pb_extended->SetValue(std2_opacity_type, 0, 0); - break; - } -} - -void XRayMtl::DeleteThis() -{ - xr_delete((XRayMtl*)this); -} - - -TSTR XRayMtl::SubAnimName(int i) { - switch(i){ -case TEXMAPS_SUB: return TSTR(GetString( IDS_DS_TEXMAPS )); -case SHADER_SUB: return TSTR(GetString( IDS_KE_SHADER )); -case EXTRA_PB_SUB: return TSTR(GetString( IDS_DS_EXTRA )); -case SAMPLING_PB_SUB: return TSTR(GetString( IDS_KE_SAMPLING )); -case DYNAMICS_PB_SUB: return TSTR(GetString( IDS_DS_DYNAMICS )); - } - return TSTR(""); -} - -Animatable* XRayMtl::SubAnim(int i) { - switch(i) { -case TEXMAPS_SUB: return maps; -case SHADER_SUB: return pShader; -case EXTRA_PB_SUB: return pb_extended; -case SAMPLING_PB_SUB: return pb_sampling; -case DYNAMICS_PB_SUB: return pb_dynamics; -default: DbgAssert(0); return NULL; - } -} - -int XRayMtl::SubNumToRefNum(int subNum) -{ - switch (subNum) - { - case TEXMAPS_SUB: return TEXMAPS_REF; - case SHADER_SUB: return SHADER_REF; - case EXTRA_PB_SUB: return EXTENDED_PB_REF; - case SAMPLING_PB_SUB: return SAMPLING_PB_REF; - case DYNAMICS_PB_SUB: return DYNAMICS_PB_REF; - default: DbgAssert(0); return 0; - } -} - -IParamBlock2* -XRayMtl::GetParamBlock(int i) -{ - switch (i) - { - case 0: return pb_shader; - case 1: return pb_extended; - case 2: return pb_sampling; - case 3: return pb_maps; - case 4: return pb_dynamics; - case 5: return pb_xray; - } - return NULL; -} - -IParamBlock2* -XRayMtl::GetParamBlockByID(BlockID id) -{ - // return id'd ParamBlock - switch (id) - { - case std2_shader: return pb_shader; - case std2_extended: return pb_extended; - case std2_sampling: return pb_sampling; - case std_maps: return pb_maps; - case std2_dynamics: return pb_dynamics; - case std2_xray: return pb_xray; - } - return NULL; -} - -RefTargetHandle XRayMtl::GetReference(int i) { - switch(i) { -case OLD_PBLOCK_REF: return old_pblock; // old pblock, replaced by the 6 new pb2's -case TEXMAPS_REF: return maps; -case SHADER_REF: return pShader; -case SHADER_PB_REF: return pb_shader; -case EXTENDED_PB_REF: return pb_extended; -case SAMPLING_PB_REF: return pb_sampling; -case MAPS_PB_REF: return pb_maps; + for (; newChan < nNewShadeMaps; ++newChan) + { + TSTR newName = newShader->GetTexChannelInternalName(newChan); + + // look for match in each old map + for (oldChan = 0; oldChan < nOldShadeMaps; ++oldChan) + { + if (newName == oldShader->GetTexChannelInternalName(oldChan)) break; + } + + if (oldChan < nOldShadeMaps) { // found it + maps->txmap[newChan].amtCtrl = oldMaps[oldChan].amtCtrl; + maps->txmap[newChan].amount = oldMaps[oldChan].amount; + maps->txmap[newChan].map = oldMaps[oldChan].map; + maps->txmap[newChan].mapOn = oldMaps[oldChan].mapOn; + maps->txmap[newChan].name = oldMaps[oldChan].name; + } + + } // end, for each new map + + // now do the mtl maps + for (int n = 0; n < MTL_NTEXMAPS; ++n) + { + newChan = n + nNewShadeMaps; + oldChan = n + nOldShadeMaps; + maps->txmap[newChan].amtCtrl = oldMaps[oldChan].amtCtrl; + maps->txmap[newChan].amount = oldMaps[oldChan].amount; + maps->txmap[newChan].map = oldMaps[oldChan].map; + maps->txmap[newChan].mapOn = oldMaps[oldChan].mapOn; + maps->txmap[newChan].name = oldMaps[oldChan].name; + } +} + +void XRayMtl::ShuffleShaderParams(Shader* newShader, Shader* oldShader) +{ + ClassDesc2 *oldCD2 = NULL, *newCD2 = NULL; + + ClassDesc* newCD; + FindShader(newShader->ClassID(), &newCD); + + ClassDesc* oldCD; + FindShader(oldShader->ClassID(), &oldCD); + + // check if we have a ParamBlock2-based shaders + if (oldCD != NULL && oldCD->InternalName() != NULL) oldCD2 = (ClassDesc2*)oldCD; + if (newCD != NULL && newCD->InternalName() != NULL) newCD2 = (ClassDesc2*)newCD; + + // loop over destination shaders PB2-based parameters + if (oldCD2 != NULL && newCD2 != NULL) { + // loop over each block in the new shader + for (int i = 0; i < newCD2->NumParamBlockDescs(); i++) + { + // get block descriptor and source paramblock + ParamBlockDesc2* newPBdesc = newCD2->GetParamBlockDesc(i); + IParamBlock2* newPB2 = newShader->GetParamBlockByID(newPBdesc->ID); + // loop over each new param and copy from old if there's a match + for (int j = 0; j < newPBdesc->count; j++) + { + ParamDef& paramDef = newPBdesc->paramdefs[j]; + + // Now search the old shaders blocks + for (int i = 0; i < oldCD2->NumParamBlockDescs(); i++) + { + ParamBlockDesc2* oldPBdesc = oldCD2->GetParamBlockDesc(i); + int j = oldPBdesc->NameToIndex(paramDef.int_name); + if (j >= 0) { + // found an internal name match, get the dest pblock and param def + ParamDef& srcParamDef = oldPBdesc->paramdefs[j]; + // copy only if types match + if (srcParamDef.type == paramDef.type) { + IParamBlock2* oldPB2 = oldShader->GetParamBlockByID(oldPBdesc->ID); + newPB2->Assign(paramDef.ID, oldPB2, srcParamDef.ID); + goto nextParam; // found it, outta here... + } + } + } + nextParam:; + } // end, dest param loop + } // end, desk block loop + Interval v; + v.SetInfinite(); + newShader->Update(0, v); + + // end, pb2 copying + } + else + { + // StdParam based copy + newShader->CopyStdParams(oldShader); + } +} + +float XRayMtl::GetXParency(int mtlNum, BOOL backFace) +{ + int opacChan = stdIDToChannel[ID_OP]; + + // When the mtl has "Show Map in Viewport" turned on, and has an opacity map, + // the opacity map over-rides the opacity. DS 6/16/00 + // (Actually, when the hardward doesn't support enough texture channels to do + // the opacity map, the overide is only true for NON-decal maps). + // + if (((*maps)[opacChan].map && MAPACTIVE(opacChan) && Active())) { + return 0.0f; + } + + // The following statement looks dubious -- what is it trying to do? -- DS 6/16/00 + if (opacity > 0.9f && opfall > 0.0f) + return 0.1f; + else + return 1.0f - opacity; +} + +ULONG XRayMtl::Requirements(int subMtlNum) +{ + ULONG req; + + assert(pShader); + req = pShader->GetRequirements(subMtlNum); + + int opacChan = stdIDToChannel[ID_OP]; + int bumpChan = stdIDToChannel[ID_BU]; + int dispChan = stdIDToChannel[ID_DP]; + + if (opacity != 1.0f || MAPACTIVE(opacChan) || opfall > 0.0f) { + req |= MTLREQ_TRANSP; + } + + if (opacity != 1.0f || ((*maps)[opacChan].map && MAPACTIVE(opacChan) && Active())) req |= MTLREQ_TRANSP_IN_VP; + + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + if (MAPACTIVE(i)) req |= (*maps)[i].map->Requirements(subMtlNum); + } + if (MAPACTIVE(bumpChan)) { + ULONG bmpreq = (*maps)[bumpChan].map->Requirements(subMtlNum); + if (bmpreq & MTLREQ_UV) req |= MTLREQ_BUMPUV; + if (bmpreq & MTLREQ_UV2) req |= MTLREQ_BUMPUV2; + } + if (flags & NEWSTDMTL_WIRE) req |= MTLREQ_WIRE; + if (flags & NEWSTDMTL_2SIDE) req |= MTLREQ_2SIDE; + // if (pixelSampler && pixelSampler->GetEnable() ) + if (flags & NEWSTDMTL_SSAMP_ON) req |= MTLREQ_SUPERSAMPLE; + if (flags & NEWSTDMTL_WIRE_UNITS) req |= MTLREQ_WIRE_ABS; + if (flags & NEWSTDMTL_FACEMAP) req |= MTLREQ_FACEMAP; + if (flags & NEWSTDMTL_ADD_TRANSP) req |= MTLREQ_ADDITIVE_TRANSP; + if (flags & NEWSTDMTL_FACETED) req |= MTLREQ_FACETED; + if (MAPACTIVE(dispChan)) req |= MTLREQ_DISPLACEMAP; + return req; +} + +int XRayMtl::MapSlotType(int i) +{ + if (i == stdIDToChannel[ID_DP]) return MAPSLOT_DISPLACEMENT; // DS 4/12/99 + return (i == stdIDToChannel[ID_RL] || i == stdIDToChannel[ID_RR]) ? MAPSLOT_ENVIRON : MAPSLOT_TEXTURE; +} + +void XRayMtl::MappingsRequired(int subMtlNum, BitArray& mapreq, BitArray& bumpreq) +{ + int bumpChan = stdIDToChannel[ID_BU]; + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + if (MAPACTIVE(i)) { + if (i == bumpChan) + (*maps)[i].map->MappingsRequired(subMtlNum, bumpreq, bumpreq); + else + (*maps)[i].map->MappingsRequired(subMtlNum, mapreq, bumpreq); + } + } +} + +Interval XRayMtl::Validity(TimeValue t) +{ + Interval v; + Update(t, v); + return ivalid; +} + +void XRayMtl::NotifyChanged() +{ + NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); +} + +void XRayMtl::SetFlag(ULONG f, ULONG val) +{ + if (val) + flags |= f; + else + flags &= ~f; +} + +void XRayMtl::SetTransparencyType(int type) +{ + switch (type) + { + case TRANSP_SUBTRACTIVE: + SetFlag(NEWSTDMTL_ADD_TRANSP, 0); + SetFlag(NEWSTDMTL_FILT_TRANSP, 0); + pb_extended->SetValue(std2_opacity_type, 0, 1); + break; + case TRANSP_ADDITIVE: + SetFlag(NEWSTDMTL_ADD_TRANSP, 1); + SetFlag(NEWSTDMTL_FILT_TRANSP, 0); + pb_extended->SetValue(std2_opacity_type, 0, 2); + break; + case TRANSP_FILTER: + SetFlag(NEWSTDMTL_ADD_TRANSP, 0); + SetFlag(NEWSTDMTL_FILT_TRANSP, 1); + pb_extended->SetValue(std2_opacity_type, 0, 0); + break; + } +} + +void XRayMtl::DeleteThis() +{ + xr_delete((XRayMtl*)this); +} + +TSTR XRayMtl::SubAnimName(int i) +{ + switch (i) + { + case TEXMAPS_SUB: return TSTR(GetString(IDS_DS_TEXMAPS)); + case SHADER_SUB: return TSTR(GetString(IDS_KE_SHADER)); + case EXTRA_PB_SUB: return TSTR(GetString(IDS_DS_EXTRA)); + case SAMPLING_PB_SUB: return TSTR(GetString(IDS_KE_SAMPLING)); + case DYNAMICS_PB_SUB: return TSTR(GetString(IDS_DS_DYNAMICS)); + } + return TSTR(""); +} + +Animatable* XRayMtl::SubAnim(int i) +{ + switch (i) + { + case TEXMAPS_SUB: return maps; + case SHADER_SUB: return pShader; + case EXTRA_PB_SUB: return pb_extended; + case SAMPLING_PB_SUB: return pb_sampling; + case DYNAMICS_PB_SUB: return pb_dynamics; + default: DbgAssert(0); return NULL; + } +} + +int XRayMtl::SubNumToRefNum(int subNum) +{ + switch (subNum) + { + case TEXMAPS_SUB: return TEXMAPS_REF; + case SHADER_SUB: return SHADER_REF; + case EXTRA_PB_SUB: return EXTENDED_PB_REF; + case SAMPLING_PB_SUB: return SAMPLING_PB_REF; + case DYNAMICS_PB_SUB: return DYNAMICS_PB_REF; + default: DbgAssert(0); return 0; + } +} + +IParamBlock2* XRayMtl::GetParamBlock(int i) +{ + switch (i) + { + case 0: return pb_shader; + case 1: return pb_extended; + case 2: return pb_sampling; + case 3: return pb_maps; + case 4: return pb_dynamics; + case 5: return pb_xray; + } + return NULL; +} + +IParamBlock2* XRayMtl::GetParamBlockByID(BlockID id) +{ + // return id'd ParamBlock + switch (id) + { + case std2_shader: return pb_shader; + case std2_extended: return pb_extended; + case std2_sampling: return pb_sampling; + case std_maps: return pb_maps; + case std2_dynamics: return pb_dynamics; + case std2_xray: return pb_xray; + } + return NULL; +} + +RefTargetHandle XRayMtl::GetReference(int i) +{ + switch (i) + { + case OLD_PBLOCK_REF: + return old_pblock; // old pblock, replaced by the 6 new pb2's + case TEXMAPS_REF: return maps; + case SHADER_REF: return pShader; + case SHADER_PB_REF: return pb_shader; + case EXTENDED_PB_REF: return pb_extended; + case SAMPLING_PB_REF: return pb_sampling; + case MAPS_PB_REF: return pb_maps; #ifndef DESIGN_VER -case DYNAMICS_PB_REF: return pb_dynamics; + case DYNAMICS_PB_REF: return pb_dynamics; #else -case DYNAMICS_PB_REF: return NULL; + case DYNAMICS_PB_REF: return NULL; #endif -case XRAY_PB_REF: return pb_xray; -case SAMPLER_REF: return pixelSampler; -default: assert(0); return NULL; - } -} - -void XRayMtl::SetReference(int i, RefTargetHandle rtarg) { - switch(i) { -case OLD_PBLOCK_REF: old_pblock = (IParamBlock*)rtarg; return; -case TEXMAPS_REF: { - maps = (Texmaps*)rtarg; - if (maps != NULL) - maps->client = this; - return; - } -case SHADER_REF: - if (IsShaderInUI()){ - pShader->GetParamDlg()->SetThings(this, NULL); - pShader->SetParamDlg(NULL); - } - pShader = (Shader*)rtarg; - - return; -case SHADER_PB_REF: pb_shader = (IParamBlock2*)rtarg; return; -case EXTENDED_PB_REF: pb_extended = (IParamBlock2*)rtarg; return; -case SAMPLING_PB_REF: pb_sampling = (IParamBlock2*)rtarg; return; -case MAPS_PB_REF: pb_maps = (IParamBlock2*)rtarg; return; -case DYNAMICS_PB_REF: pb_dynamics = (IParamBlock2*)rtarg; return; -case XRAY_PB_REF: pb_xray = (IParamBlock2*)rtarg; return; -case SAMPLER_REF: pixelSampler = (Sampler*)rtarg; return; -default: assert(0); - } -} - -void XRayMtl::SetSubTexmap(int i, Texmap *m) -{ - assert(i < STD2_NMAX_TEXMAPS); - pb_maps->SetValue(std2_maps, TimeValue(0), m, i); + case XRAY_PB_REF: return pb_xray; + case SAMPLER_REF: return pixelSampler; + default: assert(0); return NULL; + } +} + +void XRayMtl::SetReference(int i, RefTargetHandle rtarg) +{ + switch (i) + { + case OLD_PBLOCK_REF: old_pblock = (IParamBlock*)rtarg; return; + case TEXMAPS_REF: + { + maps = (Texmaps*)rtarg; + if (maps != NULL) maps->client = this; + return; + } + case SHADER_REF: + if (IsShaderInUI()) { + pShader->GetParamDlg()->SetThings(this, NULL); + pShader->SetParamDlg(NULL); + } + pShader = (Shader*)rtarg; + + return; + case SHADER_PB_REF: pb_shader = (IParamBlock2*)rtarg; return; + case EXTENDED_PB_REF: pb_extended = (IParamBlock2*)rtarg; return; + case SAMPLING_PB_REF: pb_sampling = (IParamBlock2*)rtarg; return; + case MAPS_PB_REF: pb_maps = (IParamBlock2*)rtarg; return; + case DYNAMICS_PB_REF: pb_dynamics = (IParamBlock2*)rtarg; return; + case XRAY_PB_REF: pb_xray = (IParamBlock2*)rtarg; return; + case SAMPLER_REF: pixelSampler = (Sampler*)rtarg; return; + default: assert(0); + } +} + +void XRayMtl::SetSubTexmap(int i, Texmap* m) +{ + assert(i < STD2_NMAX_TEXMAPS); + pb_maps->SetValue(std2_maps, TimeValue(0), m, i); } // mjm - begin - 06.02.00 void XRayMtl::UpdateReshadeRequirements(RefTargetHandle hTarget, PartID partID) { - if (!killRefmsg.DistributeRefmsg()) - { - mReshadeRQ = RR_None; - } - else if (hTarget == maps) - { - mReshadeRQ = RR_NeedPreshade; - } - else if (hTarget == pShader) - { - mReshadeRQ = RR_NeedReshade; - } - else if (hTarget == pb_xray) - { - mReshadeRQ = RR_None; - } - else if (hTarget == pb_shader) - { - mReshadeRQ = RR_NeedReshade; - } - else if (hTarget == pb_extended) - { - mReshadeRQ = RR_NeedReshade; - } - else if (hTarget == pb_sampling) - { - mReshadeRQ = RR_None; - } - else if (hTarget == pb_maps) - { - if ( pb_maps->LastNotifyParamID() == std2_map_amnts) - mReshadeRQ = RR_NeedReshade; - else - mReshadeRQ = RR_NeedPreshade; - } - else if (hTarget == pb_dynamics) - { - mReshadeRQ = RR_None; - } - else if (hTarget == pixelSampler) - { - mReshadeRQ = RR_None; - } - - mReshadeRQ = chooseReshade[mReshadeRQ][mInRQ]; - mInRQ = RR_None; + if (!killRefmsg.DistributeRefmsg()) { + mReshadeRQ = RR_None; + } + else if (hTarget == maps) + { + mReshadeRQ = RR_NeedPreshade; + } + else if (hTarget == pShader) + { + mReshadeRQ = RR_NeedReshade; + } + else if (hTarget == pb_xray) + { + mReshadeRQ = RR_None; + } + else if (hTarget == pb_shader) + { + mReshadeRQ = RR_NeedReshade; + } + else if (hTarget == pb_extended) + { + mReshadeRQ = RR_NeedReshade; + } + else if (hTarget == pb_sampling) + { + mReshadeRQ = RR_None; + } + else if (hTarget == pb_maps) + { + if (pb_maps->LastNotifyParamID() == std2_map_amnts) + mReshadeRQ = RR_NeedReshade; + else + mReshadeRQ = RR_NeedPreshade; + } + else if (hTarget == pb_dynamics) + { + mReshadeRQ = RR_None; + } + else if (hTarget == pixelSampler) + { + mReshadeRQ = RR_None; + } + + mReshadeRQ = chooseReshade[mReshadeRQ][mInRQ]; + mInRQ = RR_None; } // mjm - end // invaldate for the viewport -RefResult XRayMtl::NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget, - PartID& partID, RefMessage message ) -{ - switch (message) { -case REFMSG_WANT_SHOWPARAMLEVEL: - { - BOOL *pb = (BOOL *)(partID); - *pb = TRUE; - return REF_STOP; - } -case REFMSG_CHANGE: - UpdateReshadeRequirements(hTarget, partID); // mjm - 06.02.00 - - ivalid.SetEmpty(); - // ask ClassDesc if any paramblock change caused the notify - // if not and changing ref was one of the pblocks, inval all PB2 UI - // else inval indicated param UI - IParamBlock2* cpb; - ParamID changing_param = stdmtl2CD.LastNotifyParamID(this, cpb); - if (hTarget != pShader) // && hTarget != maps) - { - if (changing_param != -1) - { - // DS 10/13/00: I needed to add code to check of the dialog for this map was actualy active because - // on during the creation of new materials, messages were getting routed to the current - // medit material, causing problems for undo of sub-object mtl assignment. - // DS 10/24/31: Removed the test because it isn't quite right, and was causing some problems ( #264662) - // and no longer seems necessary. (we need a better test for whether a mtl is in medit or not) - //if (cpb->GetMap()&&cpb->GetMap()->DlgActive())) - cpb->GetDesc()->InvalidateUI(changing_param); - if (changing_param == std2_opacity && - cpb == pb_extended && pShader && - pShader->GetParamDlg()) - pShader->GetParamDlg()->UpdateOpacity(); - } - else - { - stdmtl2CD.InvalidateUI(); - if (hTarget == pb_extended && pShader && - pShader->GetParamDlg()) - pShader->GetParamDlg()->UpdateOpacity(); - if (texHandle[0]||texHandle[1]) { - if (curImp) - curImp->MtlChanged(); - } - } - DiscardTexHandles(); // DS 5/22/00 - } - break; - } - - return REF_SUCCEED; -} - -Class_ID XRayMtl::ClassID() { return XRAYMTL_CLASS_ID; } - -TSTR XRayMtl::GetSubTexmapSlotName(int i) { - if ( pShader ){ - long nShaderChan = pShader->nTexChannelsSupported(); - if ( i < nShaderChan ) - return pShader->GetTexChannelName( i ); - else - return GetString( mtlChannelNameIDS[i - nShaderChan] ); - } else return TSTR(""); -} - - -void XRayMtl::EnableMap(int i, BOOL onoff) { - pb_maps->SetValue(std2_map_enables, TimeValue(0), onoff, i); -} - -void XRayMtl::SetFilter(Color c, TimeValue t) { - filter = c; - pb_extended->SetValue( std2_filter_color, t, Point3(c.r, c.g, c.b)); - int opacChan = stdIDToChannel[ ID_OP ]; - if (opacity!=1.0f||opfall!=0.0f||MAPACTIVE(opacChan)) - NotifyChanged(); -} - -void XRayMtl::SetIOR(float v, TimeValue t) { - ioRefract = v; - pb_extended->SetValue(std2_ior, t, v); -} - -void XRayMtl::SetOpacity(float v, TimeValue t) { - opacity = v; - pb_extended->SetValue(std2_opacity, t, v); -} - -void XRayMtl::SetOpacFalloff(float v, TimeValue t) { - opfall = v; - pb_extended->SetValue(std2_falloff_amnt, t, v); - int opacChan = stdIDToChannel[ ID_OP ]; - if (opacity!=1.0f||opfall!=0.0f||MAPACTIVE(opacChan)) - NotifyChanged(); -} - -void XRayMtl::SetWireSize(float v, TimeValue t) { - wireSize = v; - pb_extended->SetValue(std2_wire_size, t, v); - if (flags&NEWSTDMTL_WIRE) - NotifyChanged(); -} - -void XRayMtl::SetDimIntens(float v, TimeValue t) { - dimIntens = v; - pb_extended->SetValue(std2_dim_lvl, t, v); -} - -void XRayMtl::SetDimMult(float v, TimeValue t) { - dimMult = v; - pb_extended->SetValue(std2_refl_lvl, t, v); -} - -void XRayMtl::SetTexmapAmt(int imap, float amt, TimeValue t) { - pb_maps->SetValue(std2_map_amnts, t, amt, imap); +RefResult XRayMtl::NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message) +{ + switch (message) + { + case REFMSG_WANT_SHOWPARAMLEVEL: + { + BOOL* pb = (BOOL*)(partID); + *pb = TRUE; + return REF_STOP; + } + case REFMSG_CHANGE: + UpdateReshadeRequirements(hTarget, partID); // mjm - 06.02.00 + + ivalid.SetEmpty(); + // ask ClassDesc if any paramblock change caused the notify + // if not and changing ref was one of the pblocks, inval all PB2 UI + // else inval indicated param UI + IParamBlock2* cpb; + ParamID changing_param = stdmtl2CD.LastNotifyParamID(this, cpb); + if (hTarget != pShader) // && hTarget != maps) + { + if (changing_param != -1) { + // DS 10/13/00: I needed to add code to check of the dialog for this map was actualy active because + // on during the creation of new materials, messages were getting routed to the current + // medit material, causing problems for undo of sub-object mtl assignment. + // DS 10/24/31: Removed the test because it isn't quite right, and was causing some problems ( #264662) + // and no longer seems necessary. (we need a better test for whether a mtl is in medit or not) + // if (cpb->GetMap()&&cpb->GetMap()->DlgActive())) + cpb->GetDesc()->InvalidateUI(changing_param); + if (changing_param == std2_opacity && cpb == pb_extended && pShader && pShader->GetParamDlg()) + pShader->GetParamDlg()->UpdateOpacity(); + } + else + { + stdmtl2CD.InvalidateUI(); + if (hTarget == pb_extended && pShader && pShader->GetParamDlg()) + pShader->GetParamDlg()->UpdateOpacity(); + if (texHandle[0] || texHandle[1]) { + if (curImp) curImp->MtlChanged(); + } + } + DiscardTexHandles(); // DS 5/22/00 + } + break; + } + + return REF_SUCCEED; +} + +Class_ID XRayMtl::ClassID() +{ + return XRAYMTL_CLASS_ID; } -///////////////////////////////////////////////////////////////////// -// shaders -void XRayMtl::SetShaderIndx( long indx, BOOL update ) +TSTR XRayMtl::GetSubTexmapSlotName(int i) +{ + if (pShader) { + long nShaderChan = pShader->nTexChannelsSupported(); + if (i < nShaderChan) + return pShader->GetTexChannelName(i); + else + return GetString(mtlChannelNameIDS[i - nShaderChan]); + } + else + return TSTR(""); +} + +void XRayMtl::EnableMap(int i, BOOL onoff) { - if( !update ) shaderId = NO_UPDATE; - pb_shader->SetValue(std2_shader_type, 0, indx<0 ? 0 : indx ); - shaderId = indx; + pb_maps->SetValue(std2_map_enables, TimeValue(0), onoff, i); } -void XRayMtl::SetSamplerIndx( long indx, BOOL update ) +void XRayMtl::SetFilter(Color c, TimeValue t) { - if( !update ) samplerId = NO_UPDATE; - pb_sampling->SetValue(std2_ssampler, 0, indx<0 ? 0 : indx ); - samplerId = indx; + filter = c; + pb_extended->SetValue(std2_filter_color, t, Point3(c.r, c.g, c.b)); + int opacChan = stdIDToChannel[ID_OP]; + if (opacity != 1.0f || opfall != 0.0f || MAPACTIVE(opacChan)) NotifyChanged(); } +void XRayMtl::SetIOR(float v, TimeValue t) +{ + ioRefract = v; + pb_extended->SetValue(std2_ior, t, v); +} -static Class_ID ClassID0(0, 0); -static Class_ID ClassID1(1, 0); +void XRayMtl::SetOpacity(float v, TimeValue t) +{ + opacity = v; + pb_extended->SetValue(std2_opacity, t, v); +} -void XRayMtl::SetShader( Shader* pNewShader ) +void XRayMtl::SetOpacFalloff(float v, TimeValue t) { - // if ( (pShader?pShader->ClassID():ClassID0) != (pNewShader?pNewShader->ClassID():ClassID1) ){ - ReplaceReference( SHADER_REF, pNewShader ); - NotifyChanged(); - NotifyDependents(FOREVER, 0, REFMSG_SUBANIM_STRUCTURE_CHANGED); - // } + opfall = v; + pb_extended->SetValue(std2_falloff_amnt, t, v); + int opacChan = stdIDToChannel[ID_OP]; + if (opacity != 1.0f || opfall != 0.0f || MAPACTIVE(opacChan)) NotifyChanged(); } -// the shader Gets & Sets -BOOL XRayMtl::IsSelfIllumColorOn() -{ if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR){ - return pShader->IsSelfIllumClrOn(); +void XRayMtl::SetWireSize(float v, TimeValue t) +{ + wireSize = v; + pb_extended->SetValue(std2_wire_size, t, v); + if (flags & NEWSTDMTL_WIRE) NotifyChanged(); } -return FALSE; + +void XRayMtl::SetDimIntens(float v, TimeValue t) +{ + dimIntens = v; + pb_extended->SetValue(std2_dim_lvl, t, v); } -void XRayMtl::SetSelfIllumColorOn( BOOL on ) -{ if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR){ - pShader->SetSelfIllumClrOn( on ); +void XRayMtl::SetDimMult(float v, TimeValue t) +{ + dimMult = v; + pb_extended->SetValue(std2_refl_lvl, t, v); } + +void XRayMtl::SetTexmapAmt(int imap, float amt, TimeValue t) +{ + pb_maps->SetValue(std2_map_amnts, t, amt, imap); } -void XRayMtl::SetAmbient(Color c, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_AMBIENT_CLR){ - pShader->SetAmbientClr( c, t ); +///////////////////////////////////////////////////////////////////// +// shaders +void XRayMtl::SetShaderIndx(long indx, BOOL update) +{ + if (!update) shaderId = NO_UPDATE; + pb_shader->SetValue(std2_shader_type, 0, indx < 0 ? 0 : indx); + shaderId = indx; } + +void XRayMtl::SetSamplerIndx(long indx, BOOL update) +{ + if (!update) samplerId = NO_UPDATE; + pb_sampling->SetValue(std2_ssampler, 0, indx < 0 ? 0 : indx); + samplerId = indx; } -void XRayMtl::SetDiffuse(Color c, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_DIFFUSE_CLR){ - pShader->SetDiffuseClr( c, t ); +static Class_ID ClassID0(0, 0); +static Class_ID ClassID1(1, 0); + +void XRayMtl::SetShader(Shader* pNewShader) +{ + // if ( (pShader?pShader->ClassID():ClassID0) != (pNewShader?pNewShader->ClassID():ClassID1) ){ + ReplaceReference(SHADER_REF, pNewShader); + NotifyChanged(); + NotifyDependents(FOREVER, 0, REFMSG_SUBANIM_STRUCTURE_CHANGED); + // } } + +// the shader Gets & Sets +BOOL XRayMtl::IsSelfIllumColorOn() +{ + if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR) { + return pShader->IsSelfIllumClrOn(); + } + return FALSE; } -void XRayMtl::SetSpecular(Color c, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_SPECULAR_CLR){ - pShader->SetSpecularClr( c, t ); +void XRayMtl::SetSelfIllumColorOn(BOOL on) +{ + if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR) { + pShader->SetSelfIllumClrOn(on); + } } + +void XRayMtl::SetAmbient(Color c, TimeValue t) +{ + if (pShader->SupportStdParams() & STD_PARAM_AMBIENT_CLR) { + pShader->SetAmbientClr(c, t); + } } -void XRayMtl::SetShininess(float v, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_GLOSSINESS ){ - pShader->SetGlossiness( v, t ); +void XRayMtl::SetDiffuse(Color c, TimeValue t) +{ + if (pShader->SupportStdParams() & STD_PARAM_DIFFUSE_CLR) { + pShader->SetDiffuseClr(c, t); + } } + +void XRayMtl::SetSpecular(Color c, TimeValue t) +{ + if (pShader->SupportStdParams() & STD_PARAM_SPECULAR_CLR) { + pShader->SetSpecularClr(c, t); + } } -void XRayMtl::SetShinStr(float v, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_SPECULAR_LEV ){ - pShader->SetSpecularLevel( v, t ); +void XRayMtl::SetShininess(float v, TimeValue t) +{ + if (pShader->SupportStdParams() & STD_PARAM_GLOSSINESS) { + pShader->SetGlossiness(v, t); + } } + +void XRayMtl::SetShinStr(float v, TimeValue t) +{ + if (pShader->SupportStdParams() & STD_PARAM_SPECULAR_LEV) { + pShader->SetSpecularLevel(v, t); + } } void XRayMtl::SetSelfIllum(float v, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM ){ - pShader->SetSelfIllum( v, t ); -} +{ + if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM) { + pShader->SetSelfIllum(v, t); + } } - void XRayMtl::SetSelfIllumColor(Color c, TimeValue t) -{ if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR){ - pShader->SetSelfIllumClr( c, t ); -} +{ + if (pShader->SupportStdParams() & STD_PARAM_SELFILLUM_CLR) { + pShader->SetSelfIllumClr(c, t); + } } -static Color blackClr( 0.0, 0.0, 0.0 ); +static Color blackClr(0.0, 0.0, 0.0); -Color XRayMtl::GetAmbient(int mtlNum, BOOL backFace) +Color XRayMtl::GetAmbient(int mtlNum, BOOL backFace) { - return pShader->GetAmbientClr( mtlNum, backFace ); + return pShader->GetAmbientClr(mtlNum, backFace); } Color XRayMtl::GetDiffuse(int mtlNum, BOOL backFace) -{ - return pShader->GetDiffuseClr( mtlNum, backFace ); +{ + return pShader->GetDiffuseClr(mtlNum, backFace); } -Color XRayMtl::GetSpecular(int mtlNum, BOOL backFace) -{ - return pShader->GetSpecularClr( mtlNum, backFace ); +Color XRayMtl::GetSpecular(int mtlNum, BOOL backFace) +{ + return pShader->GetSpecularClr(mtlNum, backFace); } -Color XRayMtl::GetSelfIllumColor(int mtlNum, BOOL backFace) -{ - return pShader->GetSelfIllumClr( mtlNum, backFace ); +Color XRayMtl::GetSelfIllumColor(int mtlNum, BOOL backFace) +{ + return pShader->GetSelfIllumClr(mtlNum, backFace); } - -float XRayMtl::GetShininess(int mtlNum, BOOL backFace) -{ - float g = pShader->GetGlossiness( mtlNum, backFace ); - return Bound( g, 0.01f, 1.0f ); +float XRayMtl::GetShininess(int mtlNum, BOOL backFace) +{ + float g = pShader->GetGlossiness(mtlNum, backFace); + return Bound(g, 0.01f, 1.0f); } -float XRayMtl::GetShinStr(int mtlNum, BOOL backFace) -{ - return pShader->GetSpecularLevel( mtlNum, backFace ); +float XRayMtl::GetShinStr(int mtlNum, BOOL backFace) +{ + return pShader->GetSpecularLevel(mtlNum, backFace); } -float XRayMtl::GetSelfIllum(int mtlNum, BOOL backFace) -{ - return pShader->GetSelfIllum( mtlNum, backFace ); +float XRayMtl::GetSelfIllum(int mtlNum, BOOL backFace) +{ + return pShader->GetSelfIllum(mtlNum, backFace); } -float XRayMtl::GetShininess(TimeValue t) -{ - return pShader->GetGlossiness( t ); +float XRayMtl::GetShininess(TimeValue t) +{ + return pShader->GetGlossiness(t); } -float XRayMtl::GetShinStr(TimeValue t) -{ - return pShader->GetSpecularLevel( t ); +float XRayMtl::GetShinStr(TimeValue t) +{ + return pShader->GetSpecularLevel(t); } -float XRayMtl::GetSelfIllum(TimeValue t) -{ - return pShader->GetSelfIllum(t); +float XRayMtl::GetSelfIllum(TimeValue t) +{ + return pShader->GetSelfIllum(t); } - -BOOL XRayMtl::GetSelfIllumColorOn(int mtlNum, BOOL backFace) -{ - return pShader->IsSelfIllumClrOn(); +BOOL XRayMtl::GetSelfIllumColorOn(int mtlNum, BOOL backFace) +{ + return pShader->IsSelfIllumClrOn(); } -Color XRayMtl::GetAmbient(TimeValue t) -{ - return pShader->GetAmbientClr( t ); +Color XRayMtl::GetAmbient(TimeValue t) +{ + return pShader->GetAmbientClr(t); } -Color XRayMtl::GetDiffuse(TimeValue t) -{ - return pShader->GetDiffuseClr(t); +Color XRayMtl::GetDiffuse(TimeValue t) +{ + return pShader->GetDiffuseClr(t); } -Color XRayMtl::GetSpecular(TimeValue t) +Color XRayMtl::GetSpecular(TimeValue t) { - return pShader->GetSpecularClr( t ); + return pShader->GetSpecularClr(t); } -Color XRayMtl::GetSelfIllumColor(TimeValue t) +Color XRayMtl::GetSelfIllumColor(TimeValue t) { - return pShader->GetSelfIllumClr(t ); + return pShader->GetSelfIllumClr(t); } -float XRayMtl::GetSoftenLevel( TimeValue t) -{ - return pShader->GetSoftenLevel(t); +float XRayMtl::GetSoftenLevel(TimeValue t) +{ + return pShader->GetSoftenLevel(t); } -Color XRayMtl::GetFilter() { return filter; } -float XRayMtl::GetTexmapAmt(int imap) { return maps->txmap[imap].amount; } -float XRayMtl::GetTexmapAmt(int imap, TimeValue t) { return maps->txmap[imap].GetAmount(t); } - -Color XRayMtl::GetFilter(TimeValue t) { return pb_extended->GetColor(std2_filter_color, t); } -float XRayMtl::GetOpacity( TimeValue t) { return pb_extended->GetFloat(std2_opacity, t); } -float XRayMtl::GetOpacFalloff(TimeValue t){ return pb_extended->GetFloat(std2_falloff_amnt, t);} -float XRayMtl::GetWireSize(TimeValue t) { return pb_extended->GetFloat(std2_wire_size, t);} -float XRayMtl::GetIOR( TimeValue t) { return pb_extended->GetFloat(std2_ior, t);} -float XRayMtl::GetDimIntens( TimeValue t) { return pb_extended->GetFloat(std2_dim_lvl, t); } -float XRayMtl::GetDimMult( TimeValue t) { return pb_extended->GetFloat(std2_refl_lvl, t); } -BOOL XRayMtl::MapEnabled(int i) { return maps->txmap[i].mapOn;} - +Color XRayMtl::GetFilter() +{ + return filter; +} +float XRayMtl::GetTexmapAmt(int imap) +{ + return maps->txmap[imap].amount; +} +float XRayMtl::GetTexmapAmt(int imap, TimeValue t) +{ + return maps->txmap[imap].GetAmount(t); +} -float XRayMtl::GetDynamicsProperty(TimeValue t, int mtlNum, int propID) { - float val; - Interval ivalid; - switch(propID) { -case DYN_BOUNCE: - pb_dynamics->GetValue(std2_bounce, t, val, ivalid); - return val; -case DYN_STATIC_FRICTION: - pb_dynamics->GetValue(std2_static_friction, t, val, ivalid); - return val; -case DYN_SLIDING_FRICTION: - pb_dynamics->GetValue(std2_sliding_friction, t, val, ivalid); - return val; -default: - assert(0); - return 0.0f; - } +Color XRayMtl::GetFilter(TimeValue t) +{ + return pb_extended->GetColor(std2_filter_color, t); +} +float XRayMtl::GetOpacity(TimeValue t) +{ + return pb_extended->GetFloat(std2_opacity, t); +} +float XRayMtl::GetOpacFalloff(TimeValue t) +{ + return pb_extended->GetFloat(std2_falloff_amnt, t); +} +float XRayMtl::GetWireSize(TimeValue t) +{ + return pb_extended->GetFloat(std2_wire_size, t); +} +float XRayMtl::GetIOR(TimeValue t) +{ + return pb_extended->GetFloat(std2_ior, t); +} +float XRayMtl::GetDimIntens(TimeValue t) +{ + return pb_extended->GetFloat(std2_dim_lvl, t); +} +float XRayMtl::GetDimMult(TimeValue t) +{ + return pb_extended->GetFloat(std2_refl_lvl, t); +} +BOOL XRayMtl::MapEnabled(int i) +{ + return maps->txmap[i].mapOn; } -void XRayMtl::SetDynamicsProperty(TimeValue t, int mtlNum, int propID, float value){ +float XRayMtl::GetDynamicsProperty(TimeValue t, int mtlNum, int propID) +{ + float val; + Interval ivalid; + switch (propID) + { + case DYN_BOUNCE: pb_dynamics->GetValue(std2_bounce, t, val, ivalid); return val; + case DYN_STATIC_FRICTION: pb_dynamics->GetValue(std2_static_friction, t, val, ivalid); return val; + case DYN_SLIDING_FRICTION: pb_dynamics->GetValue(std2_sliding_friction, t, val, ivalid); return val; + default: assert(0); return 0.0f; + } +} + +void XRayMtl::SetDynamicsProperty(TimeValue t, int mtlNum, int propID, float value) +{ #ifndef DESIGN_VER - switch(propID) { -case DYN_BOUNCE: - pb_dynamics->SetValue( std2_bounce, t, value); - break; -case DYN_STATIC_FRICTION: - pb_dynamics->SetValue( std2_static_friction, t, value); - break; -case DYN_SLIDING_FRICTION: - pb_dynamics->SetValue( std2_sliding_friction, t, value); - break; -default: - assert(0); - break; - } + switch (propID) + { + case DYN_BOUNCE: pb_dynamics->SetValue(std2_bounce, t, value); break; + case DYN_STATIC_FRICTION: pb_dynamics->SetValue(std2_static_friction, t, value); break; + case DYN_SLIDING_FRICTION: pb_dynamics->SetValue(std2_sliding_friction, t, value); break; + default: assert(0); break; + } #endif } // returns the index of the shader in the list -int XRayMtl::FindShader( Class_ID& findId, ClassDesc** ppCD ) +int XRayMtl::FindShader(Class_ID& findId, ClassDesc** ppCD) { - for (int i = 0; i < XRayMtl::NumShaders(); i++) { - ClassDesc* pCD = XRayMtl::GetShaderCD(i); - if ( findId == pCD->ClassID() ){ - if (ppCD) *ppCD = pCD; - return i; - } - } - if (ppCD) *ppCD = NULL; // not found - return -1; -} - -int XRayMtl::FindSampler( Class_ID findId, ClassDesc** ppCD ) + for (int i = 0; i < XRayMtl::NumShaders(); i++) + { + ClassDesc* pCD = XRayMtl::GetShaderCD(i); + if (findId == pCD->ClassID()) { + if (ppCD) *ppCD = pCD; + return i; + } + } + if (ppCD) *ppCD = NULL; // not found + return -1; +} + +int XRayMtl::FindSampler(Class_ID findId, ClassDesc** ppCD) { - for (int i = 0; i < XRayMtl::NumSamplers(); i++) { - ClassDesc* pCD = XRayMtl::GetSamplerCD(i); - if ( findId == pCD->ClassID() ){ - if (ppCD) *ppCD = pCD; - return i; - } - } - if (ppCD) *ppCD = NULL; // not found - return -1; + for (int i = 0; i < XRayMtl::NumSamplers(); i++) + { + ClassDesc* pCD = XRayMtl::GetSamplerCD(i); + if (findId == pCD->ClassID()) { + if (ppCD) *ppCD = pCD; + return i; + } + } + if (ppCD) *ppCD = NULL; // not found + return -1; } /*** @@ -2998,8 +2918,6 @@ return (*scList)[ 1 ].CD(); } ***/ - - ///////////////////////////////////////////////////////////////////////// // Filing // @@ -3019,7 +2937,7 @@ return (*scList)[ 1 ].CD(); #define NEWSTDMTL_TEX_AMT9 0x5109 #define NEWSTDMTL_TEX_AMTA 0x510A -//xray part +// xray part #define NEWSTDMTL_XRAY_ESHADER_CHUNK 0x5200 #define NEWSTDMTL_XRAY_CSHADER_CHUNK 0x5201 #define NEWSTDMTL_XRAY_GAMEMTL_CHUNK 0x5202 @@ -3029,69 +2947,67 @@ return (*scList)[ 1 ].CD(); #define NEWSTDMTL_DIM_REFLECT 0x5400 #define NEWSTDMTL_SELFILLUM_CLR_ON 0x5500 -#define NEWSTDMTL_SAMPLING_ON 0x5510 -#define NEWSTDMTL_SAMPLING_QUALITY 0x5511 +#define NEWSTDMTL_SAMPLING_ON 0x5510 +#define NEWSTDMTL_SAMPLING_QUALITY 0x5511 // IO -IOResult XRayMtl::Save(ISave *isave) -{ - ULONG nb; - IOResult res; - isave->BeginChunk(MTL_HDR_CHUNK); - res = MtlBase::Save(isave); - if (res!=IO_OK) return res; - isave->EndChunk(); - - isave->BeginChunk(NEWSTDMTL_VERS_CHUNK); - int version = CURRENT_NEWSTDMTL_VERSION; - isave->Write(&version, sizeof(version), &nb); - isave->EndChunk(); - - // xray params - isave->BeginChunk(NEWSTDMTL_XRAY_ESHADER_CHUNK); - isave->WriteCString(GetEShader(eshaderId)); - isave->EndChunk(); +IOResult XRayMtl::Save(ISave* isave) +{ + ULONG nb; + IOResult res; + isave->BeginChunk(MTL_HDR_CHUNK); + res = MtlBase::Save(isave); + if (res != IO_OK) return res; + isave->EndChunk(); - isave->BeginChunk(NEWSTDMTL_XRAY_CSHADER_CHUNK); - isave->WriteCString(GetCShader(cshaderId)); - isave->EndChunk(); + isave->BeginChunk(NEWSTDMTL_VERS_CHUNK); + int version = CURRENT_NEWSTDMTL_VERSION; + isave->Write(&version, sizeof(version), &nb); + isave->EndChunk(); - isave->BeginChunk(NEWSTDMTL_XRAY_GAMEMTL_CHUNK); - isave->WriteCString(GetGameMtl(gamemtlId)); - isave->EndChunk(); + // xray params + isave->BeginChunk(NEWSTDMTL_XRAY_ESHADER_CHUNK); + isave->WriteCString(GetEShader(eshaderId)); + isave->EndChunk(); - return IO_OK; -} + isave->BeginChunk(NEWSTDMTL_XRAY_CSHADER_CHUNK); + isave->WriteCString(GetCShader(cshaderId)); + isave->EndChunk(); + isave->BeginChunk(NEWSTDMTL_XRAY_GAMEMTL_CHUNK); + isave->WriteCString(GetGameMtl(gamemtlId)); + isave->EndChunk(); -static INode* FindNodeRef(ReferenceTarget *rt) { - DependentIterator di(rt); - ReferenceMaker *rm; - INode *nd = NULL; - while (rm=di.Next()) { - if (rm->SuperClassID()==BASENODE_CLASS_ID) return (INode *)rm; - nd = FindNodeRef((ReferenceTarget *)rm); - if (nd) return nd; - } - return NULL; + return IO_OK; } - - -static float GetNodeScaling(Mtl *m) { - INode *n = FindNodeRef(m); - if (n==NULL) - return 1.0f; - Interval v; - Matrix3 tm = n->GetNodeTM(0, &v); - float f = float( _abs(Length(tm.GetRow(0))) +_abs(Length(tm.GetRow(1))) + _abs(Length(tm.GetRow(2))) )/3.0f; - return f; +static INode* FindNodeRef(ReferenceTarget* rt) +{ + DependentIterator di(rt); + ReferenceMaker* rm; + INode* nd = NULL; + while (rm = di.Next()) + { + if (rm->SuperClassID() == BASENODE_CLASS_ID) return (INode*)rm; + nd = FindNodeRef((ReferenceTarget*)rm); + if (nd) return nd; + } + return NULL; +} + +static float GetNodeScaling(Mtl* m) +{ + INode* n = FindNodeRef(m); + if (n == NULL) return 1.0f; + Interval v; + Matrix3 tm = n->GetNodeTM(0, &v); + float f = float(_abs(Length(tm.GetRow(0))) + _abs(Length(tm.GetRow(1))) + _abs(Length(tm.GetRow(2)))) / 3.0f; + return f; } - //----------------------------------------------------------------------- // DS - 4/7/97: Changed Opacity, Self-illumination, SHininess, Shininess strengh -// so that the map amount blends between the corresponding slider +// so that the map amount blends between the corresponding slider // setting and the map value. This code fixes up old files so they // will render the same way. This does not correctly handle animated values // for the amount or parameter sliders. @@ -3100,358 +3016,364 @@ static float GetNodeScaling(Mtl *m) { // JBW - 11/19/98 updated to convert old stdmtls and v.10 stdmtl2's to ParamBlock2-based XRayMtl's //----------------------------------------------------------------------- -void XRayMtl::OldVerFix(int loadVer) -{ - ULONG stdParams; - - macroRecorder->Disable(); - - // ask the ClassDesc to make the P_AUTO_CONSTRUCT paramblock2s - stdmtl2CD.MakeAutoParamBlocks(this); - - if (loadVer < 10) { - // create a shader, note: always a stdshader as it's an old version - if ( shaderId < 0 || shaderId > 3 ) shaderId = 1; // v1 files - long cid; - switch( shaderId ) { -case 0: cid = PHONGClassID; - pb_shader->SetValue(std2_faceted,0,TRUE); - break; -case 1: cid = PHONGClassID; break; -case 2: cid = METALClassID; break; -case 3: cid = BLINNClassID; break; - } - long indx = FindShader( Class_ID(cid, 0) ); - - if ( indx < 0 ) return; - - // this sets the new shader via pb2 accessor - SetShaderIndx( indx ); - - pShader->SetSelfIllumClrOn( FALSE ); - stdParams = pShader->SupportStdParams(); - - // convert param blocks - IParamBlock* oldPB = old_pblock; - IParamBlock* newParamBlk = UpdateParameterBlock(stdmtlPB, NPARAMS_O, oldPB, - stdmtl2PB, NPARAMS, NEWSTDMTL_PBVERSION); - - // if shader is PB2-based, give it the PB2 remapping descriptor - if (pShader->NumParamBlocks() > 0) - pShader->ConvertParamBlk(stdmtlPB2, NPARAMS_O, oldPB); - else - pShader->ConvertParamBlk(stdmtlPB, NPARAMS_O, oldPB); - - ReplaceReference( OLD_PBLOCK_REF, newParamBlk ); - UpdateTexmaps(); - std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); - - SetSamplerIndx( FindSampler( Class_ID(DEFAULT_SAMPLER_CLASS_ID,0) ) ); - if (flags & NEWSTDMTL_SSAMP_ON) { - pb_sampling->SetValue( std2_ssampler_enable,0, TRUE ); - } - - // gloss & strength are swapped from old versions - TexmapSlot tmSlot = maps->txmap[ID_SH]; - maps->txmap[ID_SH] = maps->txmap[ID_SS]; - maps->txmap[ID_SS] = tmSlot; - - - } - - // now set values that were previously stored outside the PB, prior to update - pb_shader->SetValue(std2_wire, 0, GetFlag(NEWSTDMTL_WIRE)!=0); - pb_shader->SetValue(std2_two_sided, 0, GetFlag(NEWSTDMTL_2SIDE)!=0); - pb_shader->SetValue(std2_face_map, 0, GetFlag(NEWSTDMTL_FACEMAP)!=0); - pb_shader->SetValue(std2_faceted, 0, GetFlag(NEWSTDMTL_FACETED)!=0); - - pb_extended->SetValue(std2_opacity_type, 0, (GetFlag(NEWSTDMTL_ADD_TRANSP) ? 2 : GetFlag(NEWSTDMTL_FILT_TRANSP) ? 0 : 1)); - pb_extended->SetValue(std2_falloff_type, 0, GetFlag(NEWSTDMTL_FALLOFF_OUT) ? 1 : 0); - pb_extended->SetValue(std2_wire_units, 0, GetFlag(NEWSTDMTL_WIRE_UNITS) ? 1 : 0); - pb_extended->SetValue(std2_apply_refl_dimming, 0, dimReflect); - - pShader->SetLockAD( GetFlag(NEWSTDMTL_LOCK_AD)?TRUE:FALSE ); - pShader->SetLockDS( GetFlag(NEWSTDMTL_LOCK_DS)?TRUE:FALSE ); - pShader->SetLockADTex( GetFlag(NEWSTDMTL_LOCK_ADTEX)!=0 ); - pb_maps->SetValue(std2_mp_ad_texlock, 0, GetFlag(NEWSTDMTL_LOCK_ADTEX)!=0 ); - - if (loadVer < 8) { - Interval v; - Update(0, v); - // In old versions, the ID's & the channel numbers correspond - if (MAPACTIVE(ID_OP)) { - if (maps->txmap[ID_OP].amount != 1.0f) - SetOpacity(0.0f, 0); - } - - if ( stdParams & STD_PARAM_SELFILLUM ) - if (MAPACTIVE(ID_SI)) { - if (maps->txmap[ID_SI].amount != 1.0f) - pShader->SetSelfIllum(0.0f, 0); - } - - if ( stdParams & STD_PARAM_SPECULAR_LEV ) - if (MAPACTIVE(ID_SS)) { - float amt = maps->txmap[ID_SS].amount; - SetTexmapAmt(ID_SS, amt * pShader->GetSpecularLevel(0, 0), 0); - pShader->SetSpecularLevel(0.0f, 0); - } - - if ( stdParams & STD_PARAM_GLOSSINESS ) - if (MAPACTIVE(ID_SH)) { - float amt = maps->txmap[ID_SH].amount; - SetTexmapAmt(ID_SH, amt* pShader->GetGlossiness(0, 0), 0); - pShader->SetGlossiness(0.0f, 0); - } - - } - if (loadVer < 9) { - if ( stdParams & STD_PARAM_SOFTEN_LEV ) - if (flags&NEWSTDMTL_SOFTEN) - pShader->SetSoftenLevel(.6f, 0); - else - pShader->SetSoftenLevel(0.0f, 0); - } - - // at this point we have a v10 Stdmtl2, convert to PB2-based - // distribute old pblock values to new pb2 blocks - UpdateParameterBlock2(extVer10, NPARAMS, old_pblock, &std2_extended_blk, pb_extended); +void XRayMtl::OldVerFix(int loadVer) +{ + ULONG stdParams; + + macroRecorder->Disable(); + + // ask the ClassDesc to make the P_AUTO_CONSTRUCT paramblock2s + stdmtl2CD.MakeAutoParamBlocks(this); + + if (loadVer < 10) { + // create a shader, note: always a stdshader as it's an old version + if (shaderId < 0 || shaderId > 3) shaderId = 1; // v1 files + long cid; + switch (shaderId) + { + case 0: + cid = PHONGClassID; + pb_shader->SetValue(std2_faceted, 0, TRUE); + break; + case 1: cid = PHONGClassID; break; + case 2: cid = METALClassID; break; + case 3: cid = BLINNClassID; break; + } + long indx = FindShader(Class_ID(cid, 0)); + + if (indx < 0) return; + + // this sets the new shader via pb2 accessor + SetShaderIndx(indx); + + pShader->SetSelfIllumClrOn(FALSE); + stdParams = pShader->SupportStdParams(); + + // convert param blocks + IParamBlock* oldPB = old_pblock; + IParamBlock* newParamBlk = + UpdateParameterBlock(stdmtlPB, NPARAMS_O, oldPB, stdmtl2PB, NPARAMS, NEWSTDMTL_PBVERSION); + + // if shader is PB2-based, give it the PB2 remapping descriptor + if (pShader->NumParamBlocks() > 0) + pShader->ConvertParamBlk(stdmtlPB2, NPARAMS_O, oldPB); + else + pShader->ConvertParamBlk(stdmtlPB, NPARAMS_O, oldPB); + + ReplaceReference(OLD_PBLOCK_REF, newParamBlk); + UpdateTexmaps(); + std2_extended_blk.SetSubTexNo(std2_ep_filter_map, stdIDToChannel[ID_FI]); + + SetSamplerIndx(FindSampler(Class_ID(DEFAULT_SAMPLER_CLASS_ID, 0))); + if (flags & NEWSTDMTL_SSAMP_ON) { + pb_sampling->SetValue(std2_ssampler_enable, 0, TRUE); + } + + // gloss & strength are swapped from old versions + TexmapSlot tmSlot = maps->txmap[ID_SH]; + maps->txmap[ID_SH] = maps->txmap[ID_SS]; + maps->txmap[ID_SS] = tmSlot; + } + + // now set values that were previously stored outside the PB, prior to update + pb_shader->SetValue(std2_wire, 0, GetFlag(NEWSTDMTL_WIRE) != 0); + pb_shader->SetValue(std2_two_sided, 0, GetFlag(NEWSTDMTL_2SIDE) != 0); + pb_shader->SetValue(std2_face_map, 0, GetFlag(NEWSTDMTL_FACEMAP) != 0); + pb_shader->SetValue(std2_faceted, 0, GetFlag(NEWSTDMTL_FACETED) != 0); + + pb_extended->SetValue( + std2_opacity_type, 0, (GetFlag(NEWSTDMTL_ADD_TRANSP) ? 2 : GetFlag(NEWSTDMTL_FILT_TRANSP) ? 0 : 1)); + pb_extended->SetValue(std2_falloff_type, 0, GetFlag(NEWSTDMTL_FALLOFF_OUT) ? 1 : 0); + pb_extended->SetValue(std2_wire_units, 0, GetFlag(NEWSTDMTL_WIRE_UNITS) ? 1 : 0); + pb_extended->SetValue(std2_apply_refl_dimming, 0, dimReflect); + + pShader->SetLockAD(GetFlag(NEWSTDMTL_LOCK_AD) ? TRUE : FALSE); + pShader->SetLockDS(GetFlag(NEWSTDMTL_LOCK_DS) ? TRUE : FALSE); + pShader->SetLockADTex(GetFlag(NEWSTDMTL_LOCK_ADTEX) != 0); + pb_maps->SetValue(std2_mp_ad_texlock, 0, GetFlag(NEWSTDMTL_LOCK_ADTEX) != 0); + + if (loadVer < 8) { + Interval v; + Update(0, v); + // In old versions, the ID's & the channel numbers correspond + if (MAPACTIVE(ID_OP)) { + if (maps->txmap[ID_OP].amount != 1.0f) SetOpacity(0.0f, 0); + } + + if (stdParams & STD_PARAM_SELFILLUM) + if (MAPACTIVE(ID_SI)) { + if (maps->txmap[ID_SI].amount != 1.0f) pShader->SetSelfIllum(0.0f, 0); + } + + if (stdParams & STD_PARAM_SPECULAR_LEV) + if (MAPACTIVE(ID_SS)) { + float amt = maps->txmap[ID_SS].amount; + SetTexmapAmt(ID_SS, amt * pShader->GetSpecularLevel(0, 0), 0); + pShader->SetSpecularLevel(0.0f, 0); + } + + if (stdParams & STD_PARAM_GLOSSINESS) + if (MAPACTIVE(ID_SH)) { + float amt = maps->txmap[ID_SH].amount; + SetTexmapAmt(ID_SH, amt * pShader->GetGlossiness(0, 0), 0); + pShader->SetGlossiness(0.0f, 0); + } + } + if (loadVer < 9) { + if (stdParams & STD_PARAM_SOFTEN_LEV) + if (flags & NEWSTDMTL_SOFTEN) + pShader->SetSoftenLevel(.6f, 0); + else + pShader->SetSoftenLevel(0.0f, 0); + } + + // at this point we have a v10 Stdmtl2, convert to PB2-based + // distribute old pblock values to new pb2 blocks + UpdateParameterBlock2(extVer10, NPARAMS, old_pblock, &std2_extended_blk, pb_extended); #ifndef DESIGN_VER - UpdateParameterBlock2(dynVer10, NPARAMS, old_pblock, &std2_dynamics_blk, pb_dynamics); + UpdateParameterBlock2(dynVer10, NPARAMS, old_pblock, &std2_dynamics_blk, pb_dynamics); #endif - // mask off rollup flags - flags &= ~NEWSTDMTL_ROLLUP_FLAGS; - flags |= NEWSTDMTL_ROLLUP1_OPEN; - // pb_shader->SetRolloutOpen( flags & NEWSTDMTL_ROLLUP1_OPEN ); - - macroRecorder->Enable(); + // mask off rollup flags + flags &= ~NEWSTDMTL_ROLLUP_FLAGS; + flags |= NEWSTDMTL_ROLLUP1_OPEN; + // pb_shader->SetRolloutOpen( flags & NEWSTDMTL_ROLLUP1_OPEN ); - // delete old pblock - ReplaceReference(OLD_PBLOCK_REF, NULL); + macroRecorder->Enable(); + // delete old pblock + ReplaceReference(OLD_PBLOCK_REF, NULL); } - // versin update post-load call back -class NewStdMtl2UpdateCB: public PostLoadCallback { +class NewStdMtl2UpdateCB : public PostLoadCallback +{ public: - // create shader & new pblock - XRayMtl *m; - int loadVersion; - - NewStdMtl2UpdateCB( XRayMtl *s, int loadVers ){ m = s; loadVersion = loadVers; } - void proc(ILoad *iload) { - m->OldVerFix( loadVersion ); - xr_delete((NewStdMtl2UpdateCB*)this); - } + // create shader & new pblock + XRayMtl* m; + int loadVersion; + + NewStdMtl2UpdateCB(XRayMtl* s, int loadVers) + { + m = s; + loadVersion = loadVers; + } + void proc(ILoad* iload) + { + m->OldVerFix(loadVersion); + xr_delete((NewStdMtl2UpdateCB*)this); + } }; -void XRayMtl::BumpFix( ) { - // Fix up bump map amount on old files if the node is scaled. DS 4/16/99 - int bumpChannel = stdIDToChannel[ID_BU]; - if ((*maps)[ bumpChannel].IsActive()) { - float s = GetNodeScaling(this); - if (s!=1.0f) { - float am = GetTexmapAmt(bumpChannel); - SetTexmapAmt(bumpChannel, s*am, 0); - } - } +void XRayMtl::BumpFix() +{ + // Fix up bump map amount on old files if the node is scaled. DS 4/16/99 + int bumpChannel = stdIDToChannel[ID_BU]; + if ((*maps)[bumpChannel].IsActive()) { + float s = GetNodeScaling(this); + if (s != 1.0f) { + float am = GetTexmapAmt(bumpChannel); + SetTexmapAmt(bumpChannel, s * am, 0); + } + } } - // Bumpp map amount fix post-load call back -class NewStdMtl2BumpFixCB: public PostLoadCallback { +class NewStdMtl2BumpFixCB : public PostLoadCallback +{ public: - // create shader & new pblock - XRayMtl *m; - - NewStdMtl2BumpFixCB( XRayMtl *s ){ m = s; } - int Priority() { return 7; } // run at lower priority after normal PLCB's are all finished - void proc(ILoad *iload) { - m->BumpFix( ); - xr_delete((NewStdMtl2BumpFixCB*)this); - } + // create shader & new pblock + XRayMtl* m; + + NewStdMtl2BumpFixCB(XRayMtl* s) { m = s; } + int Priority() { return 7; } // run at lower priority after normal PLCB's are all finished + void proc(ILoad* iload) + { + m->BumpFix(); + xr_delete((NewStdMtl2BumpFixCB*)this); + } }; // post-load finalize callback -class NewStdMtl2CB: public PostLoadCallback { +class NewStdMtl2CB : public PostLoadCallback +{ public: - XRayMtl *m; - - NewStdMtl2CB(XRayMtl *s){ m = s; } - void proc(ILoad *iload) - { - // ensure all map-related parameters are set up - m->UpdateTexmaps(); - - // make sure the right indx is selected for shaders & samplers - m->SetShaderIndx( m->FindShader( m->pShader->ClassID() ), FALSE ); - if( m->pixelSampler == NULL ) // for some alpha files! - m->SetSamplerIndx( m->FindSampler( Class_ID(DEFAULT_SAMPLER_CLASS_ID,0) ) ); - - m->SetSamplerIndx( m->FindSampler( m->pixelSampler->ClassID() ), FALSE ); - m->SetFlag(NEWSTDMTL_SSAMP_ON, m->pixelSampler->GetEnable() ); - -#ifndef DESIGN_VER - if( m->pb_dynamics == NULL ) - //create the parameter block - CreateParameterBlock2(&std2_dynamics_blk, m); -#endif - if( m->pb_xray == NULL ) - //create the parameter block - CreateParameterBlock2(&std2_xray_blk, m); + XRayMtl* m; - m->SetEShaderIndx( m->eshaderId ); - m->SetCShaderIndx( m->cshaderId ); - m->SetGameMtlIndx( m->gamemtlId ); + NewStdMtl2CB(XRayMtl* s) { m = s; } + void proc(ILoad* iload) + { + // ensure all map-related parameters are set up + m->UpdateTexmaps(); + // make sure the right indx is selected for shaders & samplers + m->SetShaderIndx(m->FindShader(m->pShader->ClassID()), FALSE); + if (m->pixelSampler == NULL) // for some alpha files! + m->SetSamplerIndx(m->FindSampler(Class_ID(DEFAULT_SAMPLER_CLASS_ID, 0))); - // DS - 2/11/99 This Update should not be here: it causes all - // submaps to be loaded when loading, which makes loading matlibs very slow. - // Interval i; - // i.SetInfinite(); - // m->Update(0, i); + m->SetSamplerIndx(m->FindSampler(m->pixelSampler->ClassID()), FALSE); + m->SetFlag(NEWSTDMTL_SSAMP_ON, m->pixelSampler->GetEnable()); - xr_delete((NewStdMtl2CB*)this); - } +#ifndef DESIGN_VER + if (m->pb_dynamics == NULL) + // create the parameter block + CreateParameterBlock2(&std2_dynamics_blk, m); +#endif + if (m->pb_xray == NULL) + // create the parameter block + CreateParameterBlock2(&std2_xray_blk, m); + + m->SetEShaderIndx(m->eshaderId); + m->SetCShaderIndx(m->cshaderId); + m->SetGameMtlIndx(m->gamemtlId); + + // DS - 2/11/99 This Update should not be here: it causes all + // submaps to be loaded when loading, which makes loading matlibs very slow. + // Interval i; + // i.SetInfinite(); + // m->Update(0, i); + + xr_delete((NewStdMtl2CB*)this); + } }; -IOResult XRayMtl::Load(ILoad *iload) { - ULONG nb; - int id; - int version = 0; - dimReflect = FALSE; - - // fix old ver - gamemtlId = -1; - - IOResult res; - while (IO_OK==(res=iload->OpenChunk())) { - switch(id = iload->CurChunkID()) { -case MTL_HDR_CHUNK: - res = MtlBase::Load(iload); - ivalid.SetEmpty(); - break; -case NEWSTDMTL_FLAGS_CHUNK: - res = iload->Read(&flags, sizeof(flags), &nb); - break; -case NEWSTDMTL_SHADING_CHUNK: - res = iload->Read(&shaderId, sizeof(shaderId), &nb); - break; -case NEWSTDMTL_XRAY_ESHADER_CHUNK:{ - LPSTR es_name; - res = iload->ReadCStringChunk(&es_name); - if (res==IO_OK) eshaderId = XRayMtl::FindEShader(es_name); - }break; -case NEWSTDMTL_XRAY_CSHADER_CHUNK:{ - LPSTR cs_name; - res = iload->ReadCStringChunk(&cs_name); - if (res==IO_OK) cshaderId = XRayMtl::FindCShader(cs_name); - }break; -case NEWSTDMTL_XRAY_GAMEMTL_CHUNK:{ - LPSTR gm_name; - res = iload->ReadCStringChunk(&gm_name); - if (res==IO_OK) gamemtlId = XRayMtl::FindGameMtl(gm_name); - }break; -case NEWSTDMTL_VERS_CHUNK: - res = iload->Read(&version, sizeof(version), &nb); - break; -case NEWSTDMTL_TEX_ONOFF_CHUNK: - { - ULONG f; - res = iload->Read(&f, sizeof(f), &nb); - for (int i=0; itxmap[i].mapOn = (f&(1<CloseChunk(); - if (res!=IO_OK) - return res; - } - - // register version updaters - if (version <= FINAL_PARAMBLOCK_v1_VERSION) { - iload->RegisterPostLoadCallback(new ParamBlockPLCB((ParamVersionDesc*)oldNewStdMtlVersions, NEWSTDMTL_NUMOLDVER, &stdMtlVersion, this, 0)); - iload->RegisterPostLoadCallback(new NewStdMtl2UpdateCB(this, version)); - if (version<12) - iload->RegisterPostLoadCallback(new NewStdMtl2BumpFixCB(this)); - iload->SetObsolete(); - } - - if (TextureDisplayEnabled()) { - IncrActive(); - } - - if (gamemtlId==-1) gamemtlId = XRayMtl::FindGameMtl("default"); - - // register plcb to finalize setup - iload->RegisterPostLoadCallback(new NewStdMtl2CB(this)); - - return IO_OK; -} - - -#define TRANSP_SUB 0 -#define TRANSP_ADD 1 -#define TRANSP_FILTER 2 - +IOResult XRayMtl::Load(ILoad* iload) +{ + ULONG nb; + int id; + int version = 0; + dimReflect = FALSE; + + // fix old ver + gamemtlId = -1; + + IOResult res; + while (IO_OK == (res = iload->OpenChunk())) + { + switch (id = iload->CurChunkID()) + { + case MTL_HDR_CHUNK: + res = MtlBase::Load(iload); + ivalid.SetEmpty(); + break; + case NEWSTDMTL_FLAGS_CHUNK: res = iload->Read(&flags, sizeof(flags), &nb); break; + case NEWSTDMTL_SHADING_CHUNK: res = iload->Read(&shaderId, sizeof(shaderId), &nb); break; + case NEWSTDMTL_XRAY_ESHADER_CHUNK: + { + LPSTR es_name; + res = iload->ReadCStringChunk(&es_name); + if (res == IO_OK) eshaderId = XRayMtl::FindEShader(es_name); + } + break; + case NEWSTDMTL_XRAY_CSHADER_CHUNK: + { + LPSTR cs_name; + res = iload->ReadCStringChunk(&cs_name); + if (res == IO_OK) cshaderId = XRayMtl::FindCShader(cs_name); + } + break; + case NEWSTDMTL_XRAY_GAMEMTL_CHUNK: + { + LPSTR gm_name; + res = iload->ReadCStringChunk(&gm_name); + if (res == IO_OK) gamemtlId = XRayMtl::FindGameMtl(gm_name); + } + break; + case NEWSTDMTL_VERS_CHUNK: res = iload->Read(&version, sizeof(version), &nb); break; + case NEWSTDMTL_TEX_ONOFF_CHUNK: + { + ULONG f; + res = iload->Read(&f, sizeof(f), &nb); + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + maps->txmap[i].mapOn = (f & (1 << i)) ? 1 : 0; + } + break; + case NEWSTDMTL_DIM_REFLECT: dimReflect = TRUE; break; + } + iload->CloseChunk(); + if (res != IO_OK) return res; + } + + // register version updaters + if (version <= FINAL_PARAMBLOCK_v1_VERSION) { + iload->RegisterPostLoadCallback( + new ParamBlockPLCB((ParamVersionDesc*)oldNewStdMtlVersions, NEWSTDMTL_NUMOLDVER, &stdMtlVersion, this, 0)); + iload->RegisterPostLoadCallback(new NewStdMtl2UpdateCB(this, version)); + if (version < 12) iload->RegisterPostLoadCallback(new NewStdMtl2BumpFixCB(this)); + iload->SetObsolete(); + } + + if (TextureDisplayEnabled()) { + IncrActive(); + } + + if (gamemtlId == -1) gamemtlId = XRayMtl::FindGameMtl("default"); + + // register plcb to finalize setup + iload->RegisterPostLoadCallback(new NewStdMtl2CB(this)); + + return IO_OK; +} + +#define TRANSP_SUB 0 +#define TRANSP_ADD 1 +#define TRANSP_FILTER 2 // Composite c_over on top of c. Assume c_over has pre-multiplied alpha. -IC void AlphaCompCol(Color& c, RGBA c_over) { - float ia = 1.0f - _abs(c_over.a); - ia = LBound( ia ); - c.r = c.r * ia + c_over.r; - c.g = c.g * ia + c_over.g; - c.b = c.b * ia + c_over.b; -} +IC void AlphaCompCol(Color& c, RGBA c_over) +{ + float ia = 1.0f - _abs(c_over.a); + ia = LBound(ia); + c.r = c.r * ia + c_over.r; + c.g = c.g * ia + c_over.g; + c.b = c.b * ia + c_over.b; +} ////////////////////////////////////////////////////////////////////////////// // // transpColor utility, same as in shaders/shaderUtil // -Color XRayMtl::TranspColor( float opac, Color filt, Color diff ) -{ - // Compute the color of the transparent filter color - if (flags & NEWSTDMTL_ADD_TRANSP) { - float f = 1.0f - opac; - return Color(f, f, f); - - } else if ( flags & NEWSTDMTL_FILT_TRANSP ){ - // Transparent Filter color mapping - if (opac>0.5f) { - // darken as opac goes ( 0.5--> 1.0) - // so that max component reaches 0.0f when opac reaches 1.0 - // find max component of filt - float m = Max(filt); - float d = 2.0f*(opac-.5f)*m; - Color fc = filt-d; - fc = LBound( fc ); - return fc; - } else { - // lighten as opac goes ( 0.5--> 0.0) - // so that min component reaches 1.0f when opac reaches 1.0 - // find min component of filt - float m = Min(filt); - float d = (1.0f-2.0f*opac)*(1.0f-m); - Color fc = filt+d; - fc = UBound( fc ); - return fc; - } - - } else { - // original 3DS transparency, subtractive using diff color - Color f = (1.0f-diff); - return (1.0f-opac)*f; - } -} - - -#define DOMAP(n) ((n>=0) && sc.doMaps&&(*maps)[ n ].IsActive()) +Color XRayMtl::TranspColor(float opac, Color filt, Color diff) +{ + // Compute the color of the transparent filter color + if (flags & NEWSTDMTL_ADD_TRANSP) { + float f = 1.0f - opac; + return Color(f, f, f); + } + else if (flags & NEWSTDMTL_FILT_TRANSP) + { + // Transparent Filter color mapping + if (opac > 0.5f) { + // darken as opac goes ( 0.5--> 1.0) + // so that max component reaches 0.0f when opac reaches 1.0 + // find max component of filt + float m = Max(filt); + float d = 2.0f * (opac - .5f) * m; + Color fc = filt - d; + fc = LBound(fc); + return fc; + } + else + { + // lighten as opac goes ( 0.5--> 0.0) + // so that min component reaches 1.0f when opac reaches 1.0 + // find min component of filt + float m = Min(filt); + float d = (1.0f - 2.0f * opac) * (1.0f - m); + Color fc = filt + d; + fc = UBound(fc); + return fc; + } + } + else + { + // original 3DS transparency, subtractive using diff color + Color f = (1.0f - diff); + return (1.0f - opac) * f; + } +} + +#define DOMAP(n) ((n >= 0) && sc.doMaps && (*maps)[n].IsActive()) #ifdef _DEBUG static long xStop = -1; @@ -3459,576 +3381,586 @@ static long yStop = -1; #endif // begin - ke/mjm - 03.16.00 - merge reshading code -//BOOL XRayMtl::SupportsReShading(ShadeContext& sc) { return TRUE; } +// BOOL XRayMtl::SupportsReShading(ShadeContext& sc) { return TRUE; } -void XRayMtl::PreShade(ShadeContext& sc, IReshadeFragment* pFrag ) +void XRayMtl::PreShade(ShadeContext& sc, IReshadeFragment* pFrag) { - RGBA mval; - Point3 N, N0, P; + RGBA mval; + Point3 N, N0, P; #ifdef _DEBUG - IPoint2 sPt = sc.ScreenCoord(); - if( sPt.x == xStop && sPt.y == yStop ) - long junk = -1; + IPoint2 sPt = sc.ScreenCoord(); + if (sPt.x == xStop && sPt.y == yStop) long junk = -1; #endif - BOOL bumped = FALSE; - N = sc.Normal(); - - int ambChan = stdIDToChannel[ ID_AM ]; - int diffChan = stdIDToChannel[ ID_DI ]; - int trChan = stdIDToChannel[ ID_OP ]; - int filtChan = stdIDToChannel[ ID_FI ]; - ULONG trType = (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : - (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; - - - // Do texture mapping - sc.SetIOR(ioRefract); - - // Bump mapping: Do this FIRST so other maps can use the perturbed normal - int bumpChannel = stdIDToChannel[ID_BU]; - if (DOMAP(bumpChannel)) { - Point3 dn = (*maps)[bumpChannel].EvalNormalPerturb(sc); - bumped = TRUE; - N = Normalize( N + (sc.backFace?-dn:dn)); - // NB: shadeContext has perturbed normal - sc.SetNormal(N); - pFrag->AddUnitVecChannel( N ); - } - - // All normal color & scalar maps are handled here - long t0 = pShader->ChannelType(0); - RGBA c; - for ( long i = 0; i < STD2_NMAX_TEXMAPS; ++i ) { - if ( sc.doMaps && (*maps)[ i ].IsActive()) { - long t = pShader->ChannelType(i); - // composite the channel - if ( (t & SKIP_CHANNELS)==0 ){ - if ( t & MONO_CHANNEL ) { - // note: r always holds channel data for mono channels - float m = (*maps)[i].map->EvalMono(sc); - pFrag->AddFloatChannel( m ); - } else { - if ( i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX)==0 ) { - c = (*maps)[i].map->EvalColor(sc); - if ((*maps)[i].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - - lc = c; - pFrag->AddIntChannel(lc.value); - pFrag->AddFloatChannel(c.a); - } - else { - BoundInPlace( c ); - pFrag->AddColorChannel(c); - } - } - } - } - } - } - - // Evaluate reflection map. - int reflChan = stdIDToChannel[ ID_RL ]; - if (DOMAP(reflChan)) { - AColor rcol; - Texmap *reflmap = (*maps)[reflChan].map; - if (reflmap->HandleOwnViewPerturb()) { - sc.TossCache(reflmap); - rcol = reflmap->EvalColor(sc); - } else - rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); - - if ((*maps)[reflChan].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - - lc = rcol; - pFrag->AddIntChannel(lc.value); - pFrag->AddFloatChannel(rcol.a); - } - else { - pFrag->AddColorChannel(rcol); - } - } - - // do refraction map - int refrChan = stdIDToChannel[ ID_RR ]; - if (DOMAP(refrChan)) { - // Evaluate refraction map, as yet unfiltered by filter color. - Texmap *refrmap = (*maps)[refrChan].map; - AColor rcol; - if (refrmap->HandleOwnViewPerturb()) - rcol = refrmap->EvalColor( sc ); - else - rcol = sc.EvalEnvironMap( refrmap, sc.RefractVector(ioRefract) ); - - if ((*maps)[refrChan].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - - lc = rcol; - pFrag->AddIntChannel(lc.value); - } - else { - pFrag->AddColorChannel(rcol); - } - } - - // see if the shader wants to save anything - IReshading* pReshading; - if((pReshading = (IReshading*)pShader->GetInterface(IID_IReshading)) != NULL ){ - pReshading->PreShade( sc, pFrag ); - } - if( bumped ) - sc.SetNormal( sc.OrigNormal() ); -} - -void XRayMtl::PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams*) -{ - IllumParams ip(0, NULL); - Color lightCol, rescol, diffIllum0; - float opac; - RGBA mval; - Point3 P; - BOOL bumped = FALSE; + BOOL bumped = FALSE; + N = sc.Normal(); + + int ambChan = stdIDToChannel[ID_AM]; + int diffChan = stdIDToChannel[ID_DI]; + int trChan = stdIDToChannel[ID_OP]; + int filtChan = stdIDToChannel[ID_FI]; + ULONG trType = + (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; + + // Do texture mapping + sc.SetIOR(ioRefract); + + // Bump mapping: Do this FIRST so other maps can use the perturbed normal + int bumpChannel = stdIDToChannel[ID_BU]; + if (DOMAP(bumpChannel)) { + Point3 dn = (*maps)[bumpChannel].EvalNormalPerturb(sc); + bumped = TRUE; + N = Normalize(N + (sc.backFace ? -dn : dn)); + // NB: shadeContext has perturbed normal + sc.SetNormal(N); + pFrag->AddUnitVecChannel(N); + } + + // All normal color & scalar maps are handled here + long t0 = pShader->ChannelType(0); + RGBA c; + for (long i = 0; i < STD2_NMAX_TEXMAPS; ++i) + { + if (sc.doMaps && (*maps)[i].IsActive()) { + long t = pShader->ChannelType(i); + // composite the channel + if ((t & SKIP_CHANNELS) == 0) { + if (t & MONO_CHANNEL) { + // note: r always holds channel data for mono channels + float m = (*maps)[i].map->EvalMono(sc); + pFrag->AddFloatChannel(m); + } + else + { + if (i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX) == 0) { + c = (*maps)[i].map->EvalColor(sc); + if ((*maps)[i].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + + lc = c; + pFrag->AddIntChannel(lc.value); + pFrag->AddFloatChannel(c.a); + } + else + { + BoundInPlace(c); + pFrag->AddColorChannel(c); + } + } + } + } + } + } + + // Evaluate reflection map. + int reflChan = stdIDToChannel[ID_RL]; + if (DOMAP(reflChan)) { + AColor rcol; + Texmap* reflmap = (*maps)[reflChan].map; + if (reflmap->HandleOwnViewPerturb()) { + sc.TossCache(reflmap); + rcol = reflmap->EvalColor(sc); + } + else + rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); + + if ((*maps)[reflChan].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + + lc = rcol; + pFrag->AddIntChannel(lc.value); + pFrag->AddFloatChannel(rcol.a); + } + else + { + pFrag->AddColorChannel(rcol); + } + } + + // do refraction map + int refrChan = stdIDToChannel[ID_RR]; + if (DOMAP(refrChan)) { + // Evaluate refraction map, as yet unfiltered by filter color. + Texmap* refrmap = (*maps)[refrChan].map; + AColor rcol; + if (refrmap->HandleOwnViewPerturb()) + rcol = refrmap->EvalColor(sc); + else + rcol = sc.EvalEnvironMap(refrmap, sc.RefractVector(ioRefract)); + + if ((*maps)[refrChan].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + + lc = rcol; + pFrag->AddIntChannel(lc.value); + } + else + { + pFrag->AddColorChannel(rcol); + } + } + + // see if the shader wants to save anything + IReshading* pReshading; + if ((pReshading = (IReshading*)pShader->GetInterface(IID_IReshading)) != NULL) { + pReshading->PreShade(sc, pFrag); + } + if (bumped) sc.SetNormal(sc.OrigNormal()); +} + +void XRayMtl::PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams*) +{ + IllumParams ip(0, NULL); + Color lightCol, rescol, diffIllum0; + float opac; + RGBA mval; + Point3 P; + BOOL bumped = FALSE; #ifdef _DEBUG - IPoint2 sPt = sc.ScreenCoord(); - if( sPt.x == xStop && sPt.y == yStop ) - long junk = -1; + IPoint2 sPt = sc.ScreenCoord(); + if (sPt.x == xStop && sPt.y == yStop) long junk = -1; #endif - pShader->Update( sc.CurTime(), FOREVER ); // mjm - 12.17.99 - pShader->GetIllumParams( sc, ip ); - ip.ClearOutputs(); - ip.pShader = pShader; - ip.pMtl = this; - - opac = opacity; - - int ambChan = stdIDToChannel[ ID_AM ]; - int diffChan = stdIDToChannel[ ID_DI ]; - int trChan = stdIDToChannel[ ID_OP ]; - int filtChan = stdIDToChannel[ ID_FI ]; - int reflChan = stdIDToChannel[ ID_RL ]; - int refrChan = stdIDToChannel[ ID_RR ]; - - if ( filtChan >= 0 )ip.channels[filtChan] = filter; - if ( trChan >= 0 ) ip.channels[trChan].r = opac; - ULONG trType = (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : - (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; - - P = sc.P(); // position - - ip.stdParams = pShader->SupportStdParams(); - - // Do texture mapping - ip.hasComponents = 0; - ip.stdIDToChannel = stdIDToChannel; - // sc.SetIOR(ioRefract); - - // All normal color & scalar maps are handled here - if (pFrag->NChannels() > 0) { - - // bump mapping - if( DOMAP( stdIDToChannel[ ID_BU ] ) ) { - bumped = TRUE; - // NB: shadeContext has perturbed normal - sc.SetNormal( pFrag->GetUnitVecChannel( nextTexIndex++ ) ); - } - - RGBA c; - for ( long i = 0; i < STD2_NMAX_TEXMAPS; ++i ) { - if ( sc.doMaps && (*maps)[ i ].IsActive()) { - long t = pShader->ChannelType(i); - // composite the channel - if ( (t & SKIP_CHANNELS)==0 ){ - if ( t & MONO_CHANNEL ) { - // note: r always holds channel data for mono channels - ip.channels[ i ].r = (*maps)[i].LerpMono( ip.channels[ i ].r, pFrag->GetFloatChannel(nextTexIndex++)); // mjm - 1.17.00 - } else { - if ( i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX)==0 ) { - if ((*maps)[ i ].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - lc.value = pFrag->GetIntChannel(nextTexIndex++); - lc.GetRGB(c); - c.a = pFrag->GetFloatChannel(nextTexIndex++); - } - else { - c = pFrag->GetColorChannel(nextTexIndex++); - } - c *= (*maps)[i].amount; // mjm - 1.17.00 - AlphaCompCol( ip.channels[ i ], c); - } - } - // lock adtex, really channels 0 & 1 - if ( i == diffChan && (flags & NEWSTDMTL_LOCK_ADTEX) && ambChan >= 0 ) { - AlphaCompCol( ip.channels[ ambChan ], c ); - } - }// end, don't skip - } // end, is active - }// end, for each possible map - - // Evaluate reflection map. - if ( (*maps)[ reflChan ].map ) - ip.hasComponents |= HAS_REFLECT_MAP; - - if (DOMAP(reflChan) ) { - ip.hasComponents |= HAS_REFLECT; - AColor rcol; // mjm - 1.17.00 - if ((*maps)[ reflChan ].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - lc.value = pFrag->GetIntChannel(nextTexIndex++); - lc.GetRGB(rcol); - rcol.a = pFrag->GetFloatChannel(nextTexIndex++); - } - else { - rcol = pFrag->GetColorChannel( nextTexIndex++ ); // mjm - 1.17.00 - } - Color rc(rcol.r, rcol.g, rcol.b); - ip.channels[reflChan] = rc; - ip.reflectAmt = rcol.a * (*maps)[reflChan].amount; - } - - // do refraction map - if ( (*maps)[ refrChan ].map ) - ip.hasComponents |= HAS_REFRACT_MAP; - - if (DOMAP(refrChan) ) { - // Evaluate refraction map, as yet unfiltered by filter color. - ip.refractAmt = (*maps)[refrChan].amount; - AColor rcol; // mjm - 1.17.00 - if ((*maps)[ refrChan ].map->IsHighDynamicRange()) { - LogLUV32Pixel lc; - lc.value = pFrag->GetIntChannel(nextTexIndex++); - lc.GetRGB(rcol); - } - else { - rcol = pFrag->GetColorChannel( nextTexIndex++ ); // mjm - 1.17.00 - } - Color rc( rcol.r, rcol.g, rcol.b ); - ip.channels[refrChan] = rc; - ip.hasComponents |= HAS_REFRACT; - } - } // end, at least one map - - // get falloff opacity for possible use by shader or compositor - opac = ip.channels[trChan].r; // get (perhaps) textured opacity - - ip.finalOpac = GetEffOpacity( sc, opac ); - if( ip.finalOpac < 1.0f ) - ip.hasComponents |= HAS_OPACITY; - - // init the global ambient - ip.ambIllumOut = sc.ambientLight; - - // mapping done, illuminate... - IReshading* pReshading; - if((pReshading = (IReshading*)pShader->GetInterface(IID_IReshading)) != NULL ){ - pReshading->PostShade( sc, pFrag, nextTexIndex, &ip ); - } - - // return color in sc, not the frag itself - sc.out.c = ip.finalC; - sc.out.t = ip.finalT; - - if( bumped ) - sc.SetNormal( sc.OrigNormal() ); + pShader->Update(sc.CurTime(), FOREVER); // mjm - 12.17.99 + pShader->GetIllumParams(sc, ip); + ip.ClearOutputs(); + ip.pShader = pShader; + ip.pMtl = this; + + opac = opacity; + + int ambChan = stdIDToChannel[ID_AM]; + int diffChan = stdIDToChannel[ID_DI]; + int trChan = stdIDToChannel[ID_OP]; + int filtChan = stdIDToChannel[ID_FI]; + int reflChan = stdIDToChannel[ID_RL]; + int refrChan = stdIDToChannel[ID_RR]; + + if (filtChan >= 0) ip.channels[filtChan] = filter; + if (trChan >= 0) ip.channels[trChan].r = opac; + ULONG trType = + (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; + + P = sc.P(); // position + + ip.stdParams = pShader->SupportStdParams(); + + // Do texture mapping + ip.hasComponents = 0; + ip.stdIDToChannel = stdIDToChannel; + // sc.SetIOR(ioRefract); + + // All normal color & scalar maps are handled here + if (pFrag->NChannels() > 0) { + // bump mapping + if (DOMAP(stdIDToChannel[ID_BU])) { + bumped = TRUE; + // NB: shadeContext has perturbed normal + sc.SetNormal(pFrag->GetUnitVecChannel(nextTexIndex++)); + } + + RGBA c; + for (long i = 0; i < STD2_NMAX_TEXMAPS; ++i) + { + if (sc.doMaps && (*maps)[i].IsActive()) { + long t = pShader->ChannelType(i); + // composite the channel + if ((t & SKIP_CHANNELS) == 0) { + if (t & MONO_CHANNEL) { + // note: r always holds channel data for mono channels + ip.channels[i].r = (*maps)[i].LerpMono( + ip.channels[i].r, pFrag->GetFloatChannel(nextTexIndex++)); // mjm - 1.17.00 + } + else + { + if (i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX) == 0) { + if ((*maps)[i].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + lc.value = pFrag->GetIntChannel(nextTexIndex++); + lc.GetRGB(c); + c.a = pFrag->GetFloatChannel(nextTexIndex++); + } + else + { + c = pFrag->GetColorChannel(nextTexIndex++); + } + c *= (*maps)[i].amount; // mjm - 1.17.00 + AlphaCompCol(ip.channels[i], c); + } + } + // lock adtex, really channels 0 & 1 + if (i == diffChan && (flags & NEWSTDMTL_LOCK_ADTEX) && ambChan >= 0) { + AlphaCompCol(ip.channels[ambChan], c); + } + } // end, don't skip + } // end, is active + } // end, for each possible map + + // Evaluate reflection map. + if ((*maps)[reflChan].map) ip.hasComponents |= HAS_REFLECT_MAP; + + if (DOMAP(reflChan)) { + ip.hasComponents |= HAS_REFLECT; + AColor rcol; // mjm - 1.17.00 + if ((*maps)[reflChan].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + lc.value = pFrag->GetIntChannel(nextTexIndex++); + lc.GetRGB(rcol); + rcol.a = pFrag->GetFloatChannel(nextTexIndex++); + } + else + { + rcol = pFrag->GetColorChannel(nextTexIndex++); // mjm - 1.17.00 + } + Color rc(rcol.r, rcol.g, rcol.b); + ip.channels[reflChan] = rc; + ip.reflectAmt = rcol.a * (*maps)[reflChan].amount; + } + + // do refraction map + if ((*maps)[refrChan].map) ip.hasComponents |= HAS_REFRACT_MAP; + + if (DOMAP(refrChan)) { + // Evaluate refraction map, as yet unfiltered by filter color. + ip.refractAmt = (*maps)[refrChan].amount; + AColor rcol; // mjm - 1.17.00 + if ((*maps)[refrChan].map->IsHighDynamicRange()) { + LogLUV32Pixel lc; + lc.value = pFrag->GetIntChannel(nextTexIndex++); + lc.GetRGB(rcol); + } + else + { + rcol = pFrag->GetColorChannel(nextTexIndex++); // mjm - 1.17.00 + } + Color rc(rcol.r, rcol.g, rcol.b); + ip.channels[refrChan] = rc; + ip.hasComponents |= HAS_REFRACT; + } + } // end, at least one map + + // get falloff opacity for possible use by shader or compositor + opac = ip.channels[trChan].r; // get (perhaps) textured opacity + + ip.finalOpac = GetEffOpacity(sc, opac); + if (ip.finalOpac < 1.0f) ip.hasComponents |= HAS_OPACITY; + + // init the global ambient + ip.ambIllumOut = sc.ambientLight; + + // mapping done, illuminate... + IReshading* pReshading; + if ((pReshading = (IReshading*)pShader->GetInterface(IID_IReshading)) != NULL) { + pReshading->PostShade(sc, pFrag, nextTexIndex, &ip); + } + + // return color in sc, not the frag itself + sc.out.c = ip.finalC; + sc.out.t = ip.finalT; + + if (bumped) sc.SetNormal(sc.OrigNormal()); } // too late for sdk, eco in progress -IllumParams* CloneIp( IllumParams& ip ) -{ - IllumParams* pClone = new IllumParams( ip.nUserIllumOut, ip.userIllumNames ); - pClone->finalC = ip.finalC; - pClone->finalT = ip.finalT; - pClone->finalOpac = ip.finalOpac; - pClone->finalAttenuation = ip.finalAttenuation; - pClone->ambIllumOut = ip.ambIllumOut; - pClone->diffIllumOut = ip.diffIllumOut; - pClone->transIllumOut = ip.transIllumOut; - pClone->selfIllumOut = ip.selfIllumOut; - pClone->specIllumOut = ip.specIllumOut; - pClone->reflIllumOut = ip.reflIllumOut; - pClone->transIllumOut = ip.transIllumOut; - pClone->diffIllumIntens = ip.diffIllumIntens; - for( int i=0; i < ip.nUserIllumOut; ++i ) - pClone->userIllumOut[i] = ip.userIllumOut[i]; - - pClone->stdParams = ip.stdParams; - pClone->hasComponents = ip.hasComponents; - pClone->pShader = ip.pShader; - pClone->pMtl = ip.pMtl; - pClone->stdIDToChannel = ip.stdIDToChannel; - pClone->refractAmt = ip.refractAmt; - pClone->reflectAmt = ip.reflectAmt; - - for(int i=0; i < STD2_NMAX_TEXMAPS; ++i ) - pClone->channels[ i ] = ip.channels[ i ]; - - return pClone; +IllumParams* CloneIp(IllumParams& ip) +{ + IllumParams* pClone = new IllumParams(ip.nUserIllumOut, ip.userIllumNames); + pClone->finalC = ip.finalC; + pClone->finalT = ip.finalT; + pClone->finalOpac = ip.finalOpac; + pClone->finalAttenuation = ip.finalAttenuation; + pClone->ambIllumOut = ip.ambIllumOut; + pClone->diffIllumOut = ip.diffIllumOut; + pClone->transIllumOut = ip.transIllumOut; + pClone->selfIllumOut = ip.selfIllumOut; + pClone->specIllumOut = ip.specIllumOut; + pClone->reflIllumOut = ip.reflIllumOut; + pClone->transIllumOut = ip.transIllumOut; + pClone->diffIllumIntens = ip.diffIllumIntens; + for (int i = 0; i < ip.nUserIllumOut; ++i) + pClone->userIllumOut[i] = ip.userIllumOut[i]; + + pClone->stdParams = ip.stdParams; + pClone->hasComponents = ip.hasComponents; + pClone->pShader = ip.pShader; + pClone->pMtl = ip.pMtl; + pClone->stdIDToChannel = ip.stdIDToChannel; + pClone->refractAmt = ip.refractAmt; + pClone->reflectAmt = ip.reflectAmt; + + for (int i = 0; i < STD2_NMAX_TEXMAPS; ++i) + pClone->channels[i] = ip.channels[i]; + + return pClone; } - // if this function changes, please also check SupportsReShading, PreShade, PostShade // end - ke/mjm - 03.16.00 - merge reshading code // [attilas|24.5.2000] if this function changes, please also check EvalColorStdChannel -void XRayMtl::Shade(ShadeContext& sc) +void XRayMtl::Shade(ShadeContext& sc) { - IllumParams ip( pShader->nUserIllumOut(), pShader->UserIllumNameArray() ); - Color lightCol, rescol, diffIllum0; - float opac; - RGBA mval; - Point3 N0, P; + IllumParams ip(pShader->nUserIllumOut(), pShader->UserIllumNameArray()); + Color lightCol, rescol, diffIllum0; + float opac; + RGBA mval; + Point3 N0, P; #ifdef _DEBUG - IPoint2 sPt = sc.ScreenCoord(); - if( sPt.x == xStop && sPt.y == yStop ) - long junk = -1; + IPoint2 sPt = sc.ScreenCoord(); + if (sPt.x == xStop && sPt.y == yStop) long junk = -1; #endif - BOOL bumped = FALSE; - if (gbufID) sc.SetGBufferID(gbufID); - // ip.mtlFlags = flags; - - pShader->GetIllumParams( sc, ip ); - ip.ClearOutputs(); - ip.pShader = pShader; - ip.pMtl = this; - - // N0 = ip.N = sc.Normal(); - N0 = sc.Normal(); - opac = opacity; - - int ambChan = stdIDToChannel[ ID_AM ]; - int diffChan = stdIDToChannel[ ID_DI ]; - int trChan = stdIDToChannel[ ID_OP ]; - int filtChan = stdIDToChannel[ ID_FI ]; - if ( filtChan >= 0 )ip.channels[filtChan] = filter; - if ( trChan >= 0 ) ip.channels[trChan].r = opac; - ULONG trType = (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : - (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; - - if (sc.mode==SCMODE_SHADOW) { - // Opacity mapping; - if (DOMAP(trChan)) - opac = (*maps)[trChan].LerpEvalMono(sc, opac); - - // "Shadow mode": This just computes the transparency, which is all - // you need for shadowing. - if (opac!=1.0f || opfall!=0.0f) { - - if (opfall != 0.0f) { - opac = GetEffOpacity(sc, opac); - } - - // Transparency may use diffuse color mapping, check for orig 3ds transp - if ((flags & (NEWSTDMTL_ADD_TRANSP|NEWSTDMTL_FILT_TRANSP))==0) { - if (DOMAP(diffChan)) { - mval = (*maps)[diffChan].Eval(sc); - AlphaCompCol(ip.channels[diffChan], mval); - } - } - // Transparency may also use filter color mapping - if ( flags & NEWSTDMTL_FILT_TRANSP ){ - if (DOMAP(filtChan)) { - mval = (*maps)[filtChan].Eval(sc); - AlphaCompCol(ip.channels[filtChan], mval); - } - } - // Compute the transpareny color - sc.out.t = TranspColor( opac, ip.channels[filtChan], ip.channels[diffChan]); - } else - sc.out.t.Black(); - return; - } // end, shadow mode - - // any shader can be faceted...& bumpmapped as well - if ( flags & NEWSTDMTL_FACETED ){ - Point3 N = sc.GNormal(); - bumped = TRUE; - sc.SetNormal(N); - } - - P = sc.P(); // position - - ip.stdParams = pShader->SupportStdParams(); - - // Do texture mapping - ip.hasComponents = 0; - ip.stdIDToChannel = stdIDToChannel; - sc.SetIOR(ioRefract); - - // Bump mapping: Do this FIRST so other maps can use the perturbed normal - int bumpChannel = stdIDToChannel[ID_BU]; - if (DOMAP(bumpChannel)) { - ip.hasComponents |= HAS_BUMPS; - Point3 dn = (*maps)[bumpChannel].EvalNormalPerturb(sc); - Point3 N = Normalize( sc.Normal() + (sc.backFace?-dn:dn) ); - sc.SetNormal(N); - bumped = TRUE; - } - - // All normal color & scalar maps are handled here - long t0 = pShader->ChannelType(0); - RGBA c; - for ( long i = 0; i < STD2_NMAX_TEXMAPS; ++i ) { - if ( sc.doMaps && (*maps)[ i ].IsActive()) { - long t = pShader->ChannelType(i); - // composite the channel - if ( (t & SKIP_CHANNELS)==0 ){ - if ( t & MONO_CHANNEL ) { - // note: x always holds channel data for mono channels - ip.channels[ i ].r = (*maps)[i].LerpEvalMono(sc, ip.channels[ i ].r ); - } else { - if ( i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX)==0 ) { - c = (*maps)[i].Eval(sc); - AlphaCompCol( ip.channels[ i ], c); - } - } - // lock adtex, really channels 0 & 1 - if ( i == diffChan && ambChan >= 0 && (flags & NEWSTDMTL_LOCK_ADTEX) ) { - if ( t0 & MONO_CHANNEL ) { - ip.channels[ ambChan ].r = (*maps)[diffChan].LerpEvalMono(sc, ip.channels[diffChan].r ); - } else { - AlphaCompCol( ip.channels[ ambChan ], c ); - } - - } - } - } - } - - // Evaluate reflection map. - int reflChan = stdIDToChannel[ ID_RL ]; - if ( (*maps)[ reflChan ].map ) - ip.hasComponents |= HAS_REFLECT_MAP; - - if (DOMAP(reflChan)) { - ip.hasComponents |= HAS_REFLECT; - AColor rcol; - Texmap *reflmap = (*maps)[reflChan].map; - if (reflmap->HandleOwnViewPerturb()) { - sc.TossCache(reflmap); - rcol = reflmap->EvalColor(sc); - } else - rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); - Color rc(rcol.r, rcol.g, rcol.b); - ip.channels[reflChan] = rc; - ip.reflectAmt = rcol.a * (*maps)[reflChan].amount; - } - - // do refraction map - int refrChan = stdIDToChannel[ ID_RR ]; - if ( (*maps)[ reflChan ].map ) - ip.hasComponents |= HAS_REFRACT_MAP; - - if (DOMAP(refrChan)) { - // Evaluate refraction map, as yet unfiltered by filter color. - ip.refractAmt = (*maps)[refrChan].amount; - Texmap *refrmap = (*maps)[refrChan].map; - AColor rcol; - if (refrmap->HandleOwnViewPerturb()) - rcol = refrmap->EvalColor( sc ); - else - rcol = sc.EvalEnvironMap( refrmap, sc.RefractVector(ioRefract) ); - - Color rc( rcol.r, rcol.g, rcol.b ); - ip.channels[refrChan] = rc; - ip.hasComponents |= HAS_REFRACT; - } - - // get falloff opacity for possible use by shader or compositor - opac = ip.channels[trChan].r; // get (perhaps) textured opacity - - ip.finalOpac = GetEffOpacity(sc, opac); - if(ip.finalOpac < 1.0f) - ip.hasComponents |= HAS_OPACITY; - - // init the global ambient - ip.ambIllumOut = sc.ambientLight; - - // mapping done, illuminate... - pShader->Illum(sc, ip); - - // return color in sc, not the frag itself - sc.out.c = ip.finalC; - sc.out.t = ip.finalT; - - // Render Elements - // note: shadow must be on for any shadows to work. no ele's will get shadows - // with shadows off - int nEles = sc.NRenderElements(); - if( nEles != 0 ){ - IllumParams* pIp2 = CloneIp( ip ); // too late for sdk, eco in progress - if( sc.shadow ){ - // get unshadowed ip - sc.shadow = FALSE; - pIp2->ClearOutputs(); - pShader->Illum(sc, *pIp2); - sc.shadow = TRUE; - } - for( int i=0; i < nEles; ++i ){ - IRenderElement* pEle = sc.GetRenderElement(i); - if( pEle->IsEnabled() ){ - MaxRenderElement* pMaxEle = (MaxRenderElement*)pEle->GetInterface( MaxRenderElement::IID ); - if( pEle->ShadowsApplied() ) - pMaxEle->PostIllum( sc, ip ); - else - pMaxEle->PostIllum( sc, *pIp2 ); - } - } - xr_delete(pIp2); - } - - if (bumped) sc.SetNormal(N0); // restore normal -} - - -float XRayMtl::EvalDisplacement(ShadeContext& sc) { - int dispChan = stdIDToChannel[ ID_DP ]; - if (DOMAP(dispChan)) - return (*maps)[dispChan].EvalMono(sc); - else return 0.0f; -} - - -Interval XRayMtl::DisplacementValidity(TimeValue t) { - int dispChan = stdIDToChannel[ ID_DP ]; - if (MAPACTIVE(dispChan)) { - Interval iv; - iv.SetInfinite(); - maps->txmap[dispChan].Update(t, iv); - return iv; - } - else - return FOREVER; -} - -void XRayMtl::DiscardTexHandles() { - for (int i=0; i<2; i++) { - if (texHandle[i]) { - texHandle[i]->DeleteThis(); - texHandle[i] = NULL; - } - } - texHandleValid.SetEmpty(); + BOOL bumped = FALSE; + if (gbufID) sc.SetGBufferID(gbufID); + // ip.mtlFlags = flags; + + pShader->GetIllumParams(sc, ip); + ip.ClearOutputs(); + ip.pShader = pShader; + ip.pMtl = this; + + // N0 = ip.N = sc.Normal(); + N0 = sc.Normal(); + opac = opacity; + + int ambChan = stdIDToChannel[ID_AM]; + int diffChan = stdIDToChannel[ID_DI]; + int trChan = stdIDToChannel[ID_OP]; + int filtChan = stdIDToChannel[ID_FI]; + if (filtChan >= 0) ip.channels[filtChan] = filter; + if (trChan >= 0) ip.channels[trChan].r = opac; + ULONG trType = + (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : (flags & NEWSTDMTL_ADD_TRANSP) ? TRANSP_ADD : TRANSP_SUB; + + if (sc.mode == SCMODE_SHADOW) { + // Opacity mapping; + if (DOMAP(trChan)) opac = (*maps)[trChan].LerpEvalMono(sc, opac); + + // "Shadow mode": This just computes the transparency, which is all + // you need for shadowing. + if (opac != 1.0f || opfall != 0.0f) { + if (opfall != 0.0f) { + opac = GetEffOpacity(sc, opac); + } + + // Transparency may use diffuse color mapping, check for orig 3ds transp + if ((flags & (NEWSTDMTL_ADD_TRANSP | NEWSTDMTL_FILT_TRANSP)) == 0) { + if (DOMAP(diffChan)) { + mval = (*maps)[diffChan].Eval(sc); + AlphaCompCol(ip.channels[diffChan], mval); + } + } + // Transparency may also use filter color mapping + if (flags & NEWSTDMTL_FILT_TRANSP) { + if (DOMAP(filtChan)) { + mval = (*maps)[filtChan].Eval(sc); + AlphaCompCol(ip.channels[filtChan], mval); + } + } + // Compute the transpareny color + sc.out.t = TranspColor(opac, ip.channels[filtChan], ip.channels[diffChan]); + } + else + sc.out.t.Black(); + return; + } // end, shadow mode + + // any shader can be faceted...& bumpmapped as well + if (flags & NEWSTDMTL_FACETED) { + Point3 N = sc.GNormal(); + bumped = TRUE; + sc.SetNormal(N); + } + + P = sc.P(); // position + + ip.stdParams = pShader->SupportStdParams(); + + // Do texture mapping + ip.hasComponents = 0; + ip.stdIDToChannel = stdIDToChannel; + sc.SetIOR(ioRefract); + + // Bump mapping: Do this FIRST so other maps can use the perturbed normal + int bumpChannel = stdIDToChannel[ID_BU]; + if (DOMAP(bumpChannel)) { + ip.hasComponents |= HAS_BUMPS; + Point3 dn = (*maps)[bumpChannel].EvalNormalPerturb(sc); + Point3 N = Normalize(sc.Normal() + (sc.backFace ? -dn : dn)); + sc.SetNormal(N); + bumped = TRUE; + } + + // All normal color & scalar maps are handled here + long t0 = pShader->ChannelType(0); + RGBA c; + for (long i = 0; i < STD2_NMAX_TEXMAPS; ++i) + { + if (sc.doMaps && (*maps)[i].IsActive()) { + long t = pShader->ChannelType(i); + // composite the channel + if ((t & SKIP_CHANNELS) == 0) { + if (t & MONO_CHANNEL) { + // note: x always holds channel data for mono channels + ip.channels[i].r = (*maps)[i].LerpEvalMono(sc, ip.channels[i].r); + } + else + { + if (i != ambChan || (flags & NEWSTDMTL_LOCK_ADTEX) == 0) { + c = (*maps)[i].Eval(sc); + AlphaCompCol(ip.channels[i], c); + } + } + // lock adtex, really channels 0 & 1 + if (i == diffChan && ambChan >= 0 && (flags & NEWSTDMTL_LOCK_ADTEX)) { + if (t0 & MONO_CHANNEL) { + ip.channels[ambChan].r = (*maps)[diffChan].LerpEvalMono(sc, ip.channels[diffChan].r); + } + else + { + AlphaCompCol(ip.channels[ambChan], c); + } + } + } + } + } + + // Evaluate reflection map. + int reflChan = stdIDToChannel[ID_RL]; + if ((*maps)[reflChan].map) ip.hasComponents |= HAS_REFLECT_MAP; + + if (DOMAP(reflChan)) { + ip.hasComponents |= HAS_REFLECT; + AColor rcol; + Texmap* reflmap = (*maps)[reflChan].map; + if (reflmap->HandleOwnViewPerturb()) { + sc.TossCache(reflmap); + rcol = reflmap->EvalColor(sc); + } + else + rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); + Color rc(rcol.r, rcol.g, rcol.b); + ip.channels[reflChan] = rc; + ip.reflectAmt = rcol.a * (*maps)[reflChan].amount; + } + + // do refraction map + int refrChan = stdIDToChannel[ID_RR]; + if ((*maps)[reflChan].map) ip.hasComponents |= HAS_REFRACT_MAP; + + if (DOMAP(refrChan)) { + // Evaluate refraction map, as yet unfiltered by filter color. + ip.refractAmt = (*maps)[refrChan].amount; + Texmap* refrmap = (*maps)[refrChan].map; + AColor rcol; + if (refrmap->HandleOwnViewPerturb()) + rcol = refrmap->EvalColor(sc); + else + rcol = sc.EvalEnvironMap(refrmap, sc.RefractVector(ioRefract)); + + Color rc(rcol.r, rcol.g, rcol.b); + ip.channels[refrChan] = rc; + ip.hasComponents |= HAS_REFRACT; + } + + // get falloff opacity for possible use by shader or compositor + opac = ip.channels[trChan].r; // get (perhaps) textured opacity + + ip.finalOpac = GetEffOpacity(sc, opac); + if (ip.finalOpac < 1.0f) ip.hasComponents |= HAS_OPACITY; + + // init the global ambient + ip.ambIllumOut = sc.ambientLight; + + // mapping done, illuminate... + pShader->Illum(sc, ip); + + // return color in sc, not the frag itself + sc.out.c = ip.finalC; + sc.out.t = ip.finalT; + + // Render Elements + // note: shadow must be on for any shadows to work. no ele's will get shadows + // with shadows off + int nEles = sc.NRenderElements(); + if (nEles != 0) { + IllumParams* pIp2 = CloneIp(ip); // too late for sdk, eco in progress + if (sc.shadow) { + // get unshadowed ip + sc.shadow = FALSE; + pIp2->ClearOutputs(); + pShader->Illum(sc, *pIp2); + sc.shadow = TRUE; + } + for (int i = 0; i < nEles; ++i) + { + IRenderElement* pEle = sc.GetRenderElement(i); + if (pEle->IsEnabled()) { + MaxRenderElement* pMaxEle = (MaxRenderElement*)pEle->GetInterface(MaxRenderElement::IID); + if (pEle->ShadowsApplied()) + pMaxEle->PostIllum(sc, ip); + else + pMaxEle->PostIllum(sc, *pIp2); + } + } + xr_delete(pIp2); + } + + if (bumped) sc.SetNormal(N0); // restore normal +} + +float XRayMtl::EvalDisplacement(ShadeContext& sc) +{ + int dispChan = stdIDToChannel[ID_DP]; + if (DOMAP(dispChan)) + return (*maps)[dispChan].EvalMono(sc); + else + return 0.0f; +} + +Interval XRayMtl::DisplacementValidity(TimeValue t) +{ + int dispChan = stdIDToChannel[ID_DP]; + if (MAPACTIVE(dispChan)) { + Interval iv; + iv.SetInfinite(); + maps->txmap[dispChan].Update(t, iv); + return iv; + } + else + return FOREVER; +} + +void XRayMtl::DiscardTexHandles() +{ + for (int i = 0; i < 2; i++) + { + if (texHandle[i]) { + texHandle[i]->DeleteThis(); + texHandle[i] = NULL; + } + } + texHandleValid.SetEmpty(); } // begin - dds- 04.27.00 - multiple map display support -void XRayMtl::ActivateTexDisplay(BOOL onoff) { - if (!onoff) { - DiscardTexHandles(); - } -} - -struct TextOps { - UBYTE colorOp; - UBYTE colorAlphaSource; - UBYTE colorScale; - UBYTE alphaOp; - UBYTE alphaAlphaSource; - UBYTE alphaScale; +void XRayMtl::ActivateTexDisplay(BOOL onoff) +{ + if (!onoff) { + DiscardTexHandles(); + } +} + +struct TextOps +{ + UBYTE colorOp; + UBYTE colorAlphaSource; + UBYTE colorScale; + UBYTE alphaOp; + UBYTE alphaAlphaSource; + UBYTE alphaScale; }; // TBD: these values have to be corrected. @@ -4036,78 +3968,86 @@ struct TextOps { #define TXOP_ALPHABLEND 1 #define TXOP_OPACITY 2 static TextOps txops[] = { - { GW_TEX_MODULATE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X }, - { GW_TEX_ALPHA_BLEND, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X }, - { GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_REPLACE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X }, + {GW_TEX_MODULATE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X}, + {GW_TEX_ALPHA_BLEND, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X}, + {GW_TEX_LEAVE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X, GW_TEX_REPLACE, GW_TEX_TEXTURE, GW_TEX_SCALE_1X}, }; -void XRayMtl::SetTexOps(Material *mtl, int i, int type) { - TextureInfo *ti = &mtl->texture[i]; - ti->colorOp = txops[type].colorOp; - ti->colorAlphaSource = txops[type].colorAlphaSource; - ti->colorScale = txops[type].colorScale; - ti->alphaOp = txops[type].alphaOp; - ti->alphaAlphaSource = txops[type].alphaAlphaSource; - ti->alphaScale = txops[type].alphaScale; - texOpsType[i] = type; -} - -#define BMIDATA(x) ((UBYTE *)((BYTE *)(x) + sizeof(BITMAPINFOHEADER))) - -static void StuffAlpha(BITMAPINFO *bi, float amt, float opac, Color fill) { - int w = bi->bmiHeader.biWidth; - int h = bi->bmiHeader.biHeight; - int npix = w*h; - UBYTE *a = BMIDATA(bi); - Color24 col; - col.r = (int)(fill.r*255.0f); - col.g = (int)(fill.g*255.0f); - col.b = (int)(fill.b*255.0f); - if (amt<1.0f) { - int ia = int(amt*255.0f); - int ic = int( (1.0f-amt)*opac*255.0f); - for (int j=0; j>8) + ic; - a[0] = col.b; - a[1] = col.g; - a[2] = col.r; - a += 4; - } - } - else { - for (int j=0; jbmiHeader.biWidth; - int h = bi->bmiHeader.biHeight; - int npix = w*h; - UBYTE *a = BMIDATA(bia); - UBYTE *b = BMIDATA(bi); - if (amt<1.0f) { - int ia = int(amt*255.0f); - int ic = int( (1.0f-amt)*opac*255.0f); - for (int j=0; j>8) + ic; - a += 4; - b += 4; - } - } - else { - for (int j=0; jtexture[i]; + ti->colorOp = txops[type].colorOp; + ti->colorAlphaSource = txops[type].colorAlphaSource; + ti->colorScale = txops[type].colorScale; + ti->alphaOp = txops[type].alphaOp; + ti->alphaAlphaSource = txops[type].alphaAlphaSource; + ti->alphaScale = txops[type].alphaScale; + texOpsType[i] = type; +} + +#define BMIDATA(x) ((UBYTE*)((BYTE*)(x) + sizeof(BITMAPINFOHEADER))) + +static void StuffAlpha(BITMAPINFO* bi, float amt, float opac, Color fill) +{ + int w = bi->bmiHeader.biWidth; + int h = bi->bmiHeader.biHeight; + int npix = w * h; + UBYTE* a = BMIDATA(bi); + Color24 col; + col.r = (int)(fill.r * 255.0f); + col.g = (int)(fill.g * 255.0f); + col.b = (int)(fill.b * 255.0f); + if (amt < 1.0f) { + int ia = int(amt * 255.0f); + int ic = int((1.0f - amt) * opac * 255.0f); + for (int j = 0; j < npix; j++) + { + a[3] = ((((a[0] + a[1] + a[2]) / 3) * ia) >> 8) + ic; + a[0] = col.b; + a[1] = col.g; + a[2] = col.r; + a += 4; + } + } + else + { + for (int j = 0; j < npix; j++) + { + a[3] = (a[0] + a[1] + a[2]) / 3; + a[0] = col.b; + a[1] = col.g; + a[2] = col.r; + a += 4; + } + } +} + +static void StuffAlphaInto(BITMAPINFO* bia, BITMAPINFO* bi, float amt, float opac) +{ + int w = bi->bmiHeader.biWidth; + int h = bi->bmiHeader.biHeight; + int npix = w * h; + UBYTE* a = BMIDATA(bia); + UBYTE* b = BMIDATA(bi); + if (amt < 1.0f) { + int ia = int(amt * 255.0f); + int ic = int((1.0f - amt) * opac * 255.0f); + for (int j = 0; j < npix; j++) + { + b[3] = ((((a[0] + a[1] + a[2]) / 3) * ia) >> 8) + ic; + a += 4; + b += 4; + } + } + else + { + for (int j = 0; j < npix; j++) + { + b[3] = (a[0] + a[1] + a[2]) / 3; + a += 4; + b += 4; + } + } } #if 0 @@ -4125,273 +4065,262 @@ static BOOL SameUV(TextureInfo &ta, TextureInfo &tb) { static Color whiteCol(1.0f, 1.0f, 1.0f); -void XRayMtl::SetupGfxMultiMaps(TimeValue t, Material *mtl, MtlMakerCallback &cb) { - if (texHandleValid.InInterval(t)) { - mtl->texture.SetCount(numTexHandlesUsed); - for (int i=0; itexture[i].textHandle = texHandle[i]->GetHandle(); - Texmap *tx = (*maps)[useSubForTex[i]].map; - cb.GetGfxTexInfoFromTexmap(t, mtl->texture[i], tx ); - SetTexOps(mtl,i,texOpsType[i]); - } - } - return; - } - - Texmap *tx[2]; - int diffChan = stdIDToChannel[ ID_DI ]; - int opacChan = stdIDToChannel[ ID_OP ]; - tx[0] = (*maps)[diffChan].IsActive()?(*maps)[diffChan].map:NULL; - tx[1] = (*maps)[opacChan].IsActive()?(*maps)[opacChan].map:NULL; - - int nsupport = cb.NumberTexturesSupported(); - - BITMAPINFO *bmi[NTEXHANDLES]; - - int nmaps=0; - for (int i=0; itexture.SetCount(nmaps); - if (nmaps==0) - return; - for (int i=0; itexture[i].textHandle = NULL; - texHandleValid.SetInfinite(); - Interval valid; - BOOL needDecal = FALSE; - int ntx = 0; - int op; - - int forceW = 0; - int forceH = 0; - if (tx[0]) { - cb.GetGfxTexInfoFromTexmap(t, mtl->texture[0], tx[0]); - TextureInfo &ti = mtl->texture[0]; - if (ti.tiling[0]==GW_TEX_NO_TILING||ti.tiling[1]==GW_TEX_NO_TILING) - needDecal = TRUE; - op = needDecal?TXOP_ALPHABLEND:TXOP_MODULATE; - bmi[0] = tx[0]->GetVPDisplayDIB(t,cb,valid,FALSE); - if (bmi[0]) { - texHandleValid &= valid; - useSubForTex[0] = diffChan; - ntx = 1; - forceW = bmi[0]->bmiHeader.biWidth; - forceH = bmi[0]->bmiHeader.biHeight; - } - } - if (tx[1]) { - cb.GetGfxTexInfoFromTexmap(t, mtl->texture[ntx], tx[1]); - if (nsupport>ntx) { - bmi[1] = tx[1]->GetVPDisplayDIB(t,cb,valid,TRUE); - if (bmi[1]) { - texHandleValid &= valid; - StuffAlpha(bmi[1], (*maps)[opacChan].amount, GetOpacity(t),ntx?whiteCol:pShader->GetDiffuseClr(t)); - texHandle[ntx] = cb.MakeHandle(bmi[1]); - bmi[1] = NULL; - mtl->texture[ntx].textHandle = texHandle[ntx]->GetHandle(); - SetTexOps(mtl,ntx,TXOP_OPACITY); - useSubForTex[ntx] = opacChan; - ntx++; - } - } - else { - if (!needDecal) { - TextureInfo ti; - // if (SameUV(mtl->texture[0],mtl->texture[1])) { - // Not really correct to combine channels for different UV's but what the heck. - bmi[1] = tx[1]->GetVPDisplayDIB(t,cb,valid,TRUE, forceW, forceH); - if (bmi[1]) { - texHandleValid &= valid; - StuffAlphaInto(bmi[1], bmi[0], (*maps)[opacChan].amount, GetOpacity(t)); - op = TXOP_OPACITY; - xr_free(bmi[1]); - bmi[1] = NULL; - } - // } - } - } - } - if (bmi[0]) { - texHandle[0] = cb.MakeHandle(bmi[0]); - bmi[0] = NULL; - mtl->texture[0].textHandle = texHandle[0]->GetHandle(); - SetTexOps(mtl,0,op); - } - mtl->texture.SetCount(ntx); - numTexHandlesUsed = ntx; +void XRayMtl::SetupGfxMultiMaps(TimeValue t, Material* mtl, MtlMakerCallback& cb) +{ + if (texHandleValid.InInterval(t)) { + mtl->texture.SetCount(numTexHandlesUsed); + for (int i = 0; i < numTexHandlesUsed; i++) + { + if (texHandle[i]) { + mtl->texture[i].textHandle = texHandle[i]->GetHandle(); + Texmap* tx = (*maps)[useSubForTex[i]].map; + cb.GetGfxTexInfoFromTexmap(t, mtl->texture[i], tx); + SetTexOps(mtl, i, texOpsType[i]); + } + } + return; + } + + Texmap* tx[2]; + int diffChan = stdIDToChannel[ID_DI]; + int opacChan = stdIDToChannel[ID_OP]; + tx[0] = (*maps)[diffChan].IsActive() ? (*maps)[diffChan].map : NULL; + tx[1] = (*maps)[opacChan].IsActive() ? (*maps)[opacChan].map : NULL; + + int nsupport = cb.NumberTexturesSupported(); + + BITMAPINFO* bmi[NTEXHANDLES]; + + int nmaps = 0; + for (int i = 0; i < NTEXHANDLES; i++) + { + if (tx[i]) nmaps++; + bmi[i] = NULL; + } + mtl->texture.SetCount(nmaps); + if (nmaps == 0) return; + for (int i = 0; i < nmaps; i++) + mtl->texture[i].textHandle = NULL; + texHandleValid.SetInfinite(); + Interval valid; + BOOL needDecal = FALSE; + int ntx = 0; + int op; + + int forceW = 0; + int forceH = 0; + if (tx[0]) { + cb.GetGfxTexInfoFromTexmap(t, mtl->texture[0], tx[0]); + TextureInfo& ti = mtl->texture[0]; + if (ti.tiling[0] == GW_TEX_NO_TILING || ti.tiling[1] == GW_TEX_NO_TILING) needDecal = TRUE; + op = needDecal ? TXOP_ALPHABLEND : TXOP_MODULATE; + bmi[0] = tx[0]->GetVPDisplayDIB(t, cb, valid, FALSE); + if (bmi[0]) { + texHandleValid &= valid; + useSubForTex[0] = diffChan; + ntx = 1; + forceW = bmi[0]->bmiHeader.biWidth; + forceH = bmi[0]->bmiHeader.biHeight; + } + } + if (tx[1]) { + cb.GetGfxTexInfoFromTexmap(t, mtl->texture[ntx], tx[1]); + if (nsupport > ntx) { + bmi[1] = tx[1]->GetVPDisplayDIB(t, cb, valid, TRUE); + if (bmi[1]) { + texHandleValid &= valid; + StuffAlpha(bmi[1], (*maps)[opacChan].amount, GetOpacity(t), ntx ? whiteCol : pShader->GetDiffuseClr(t)); + texHandle[ntx] = cb.MakeHandle(bmi[1]); + bmi[1] = NULL; + mtl->texture[ntx].textHandle = texHandle[ntx]->GetHandle(); + SetTexOps(mtl, ntx, TXOP_OPACITY); + useSubForTex[ntx] = opacChan; + ntx++; + } + } + else + { + if (!needDecal) { + TextureInfo ti; + // if (SameUV(mtl->texture[0],mtl->texture[1])) { + // Not really correct to combine channels for different UV's but what the heck. + bmi[1] = tx[1]->GetVPDisplayDIB(t, cb, valid, TRUE, forceW, forceH); + if (bmi[1]) { + texHandleValid &= valid; + StuffAlphaInto(bmi[1], bmi[0], (*maps)[opacChan].amount, GetOpacity(t)); + op = TXOP_OPACITY; + xr_free(bmi[1]); + bmi[1] = NULL; + } + // } + } + } + } + if (bmi[0]) { + texHandle[0] = cb.MakeHandle(bmi[0]); + bmi[0] = NULL; + mtl->texture[0].textHandle = texHandle[0]->GetHandle(); + SetTexOps(mtl, 0, op); + } + mtl->texture.SetCount(ntx); + numTexHandlesUsed = ntx; } // end - dds- 04.27.00 - multiple map display support //������������������������������������������������������������������������ -// Returns true if the evaluated color\value (output) is constant over all -// possible inputs. This means all points of a face and all faces the +// Returns true if the evaluated color\value (output) is constant over all +// possible inputs. This means all points of a face and all faces the // material is assigned to. // If it cannot determine the correct answer, it returns false // -bool XRayMtl::IsOutputConst -( - ShadeContext& sc, // describes context of evaluation - int stdID // must be ID_AM, ect - ) -{ - int channelID = StdIDToChannel( stdID ); - DbgAssert( 0 <= channelID && channelID < NumSubTexmaps() ); - if ( channelID < 0 || channelID >= NumSubTexmaps() ) - return false; - - if ( SubTexmapOn( channelID ) ) - { - Texmap* texMap = GetSubTexmap( channelID ); - DbgAssert( texMap != NULL ); - if ( texMap != NULL && texMap->IsOutputMeaningful( sc ) ) - // TODO: The texmap can be meaningful but constant - return false; - } - return true; +bool XRayMtl::IsOutputConst(ShadeContext& sc, // describes context of evaluation + int stdID // must be ID_AM, ect + ) +{ + int channelID = StdIDToChannel(stdID); + DbgAssert(0 <= channelID && channelID < NumSubTexmaps()); + if (channelID < 0 || channelID >= NumSubTexmaps()) return false; + + if (SubTexmapOn(channelID)) { + Texmap* texMap = GetSubTexmap(channelID); + DbgAssert(texMap != NULL); + if (texMap != NULL && texMap->IsOutputMeaningful(sc)) + // TODO: The texmap can be meaningful but constant + return false; + } + return true; } //������������������������������������������������������������������������ -// Evaluates the material on a single texmap channel. -// For a mono channel, the value is copied in all 3 components of the +// Evaluates the material on a single texmap channel. +// For a mono channel, the value is copied in all 3 components of the // output color. // -bool XRayMtl::EvalColorStdChannel -( - ShadeContext& sc, // describes context of evaluation - int stdID, // must be ID_AM, ect - Color& outClr // output var - ) -{ - switch ( stdID ) - { - case ID_BU: // Bump (value 8) - { - return EvalBump( sc, outClr ); - } - break; - - case ID_RL: // Reflection (value 9) - { - return EvalReflection( sc, outClr ); - } - break; - - case ID_RR: // Refraction (value 10) - { - return EvalRefraction( sc, outClr ); - } - break; - - case ID_DP: // Displacement (value 11) - { - float outVal; - bool bRes = EvalDisplacement( sc, outVal ); - if ( bRes ) - { - outClr.r = outClr.g = outClr.b = outVal; - } - return bRes; - } - break; - - // For everything else, there's a smart method - case ID_AM: // Ambient (value 0) - case ID_DI: // Diffuse (value 1) - case ID_SP: // Specular (value 2) - case ID_SH: // Shininess (value 3). In R3 and later this is called Glossiness. - case ID_SS: // Shininess strength (value 4). In R3 and later this is called Specular Level. - case ID_SI: // Self-illumination (value 5) - case ID_OP: // Opacity (value 6) - case ID_FI: // Filter color (value 7) - { - int id = StdIDToChannel( stdID ); - if ( id < 0 || id >= NumSubTexmaps() ) - return false; - return EvalChannel( sc, id, outClr ); - } - break; - - default: - // Should never happen - //DbgAssert( false ); - return false; - break; - } - return true; +bool XRayMtl::EvalColorStdChannel(ShadeContext& sc, // describes context of evaluation + int stdID, // must be ID_AM, ect + Color& outClr // output var + ) +{ + switch (stdID) + { + case ID_BU: // Bump (value 8) + { + return EvalBump(sc, outClr); + } + break; + + case ID_RL: // Reflection (value 9) + { + return EvalReflection(sc, outClr); + } + break; + + case ID_RR: // Refraction (value 10) + { + return EvalRefraction(sc, outClr); + } + break; + + case ID_DP: // Displacement (value 11) + { + float outVal; + bool bRes = EvalDisplacement(sc, outVal); + if (bRes) { + outClr.r = outClr.g = outClr.b = outVal; + } + return bRes; + } + break; + + // For everything else, there's a smart method + case ID_AM: // Ambient (value 0) + case ID_DI: // Diffuse (value 1) + case ID_SP: // Specular (value 2) + case ID_SH: // Shininess (value 3). In R3 and later this is called Glossiness. + case ID_SS: // Shininess strength (value 4). In R3 and later this is called Specular Level. + case ID_SI: // Self-illumination (value 5) + case ID_OP: // Opacity (value 6) + case ID_FI: // Filter color (value 7) + { + int id = StdIDToChannel(stdID); + if (id < 0 || id >= NumSubTexmaps()) return false; + return EvalChannel(sc, id, outClr); + } + break; + + default: + // Should never happen + // DbgAssert( false ); + return false; + break; + } + return true; } //������������������������������������������������������������������������ -// Evaluates the material on a single texmap channel. +// Evaluates the material on a single texmap channel. // -bool XRayMtl::EvalMonoStdChannel -( - ShadeContext& sc, // describes context of evaluation - int stdID, // must be ID_AM, ect - float& outVal // output var - ) -{ - switch ( stdID ) - { - case ID_BU: // Bump (value 8) - { - Color outClr; - bool bRes = EvalBump( sc, outClr ); - if ( bRes ) - outVal = Intens( outClr ); - return bRes; - } - break; - - case ID_RL: // Reflection (value 9) - { - return EvalReflection( sc, outVal ); - } - break; - - case ID_RR: // Refraction (value 10) - { - return EvalRefraction( sc, outVal ); - } - break; - - case ID_DP: // Displacement (value 11) - { - return EvalDisplacement( sc, outVal ); - } - break; - - // For everything else, there's a smart method - case ID_AM: // Ambient (value 0) - case ID_DI: // Diffuse (value 1) - case ID_SP: // Specular (value 2) - case ID_SH: // Shininess (value 3). In R3 and later this is called Glossiness. - case ID_SS: // Shininess strength (value 4). In R3 and later this is called Specular Level. - case ID_SI: // Self-illumination (value 5) - case ID_OP: // Opacity (value 6) - case ID_FI: // Filter color (value 7) - { - int id = StdIDToChannel( stdID ); - if ( id < 0 || id >= NumSubTexmaps() ) - return false; - Color outClr; - bool bRes = EvalChannel( sc, id, outClr ); - if ( bRes ) - outVal = Intens( outClr ); - return bRes; - } - break; - - default: - // Should never happen - //DbgAssert( false ); - return false; - break; - } - return true; +bool XRayMtl::EvalMonoStdChannel(ShadeContext& sc, // describes context of evaluation + int stdID, // must be ID_AM, ect + float& outVal // output var + ) +{ + switch (stdID) + { + case ID_BU: // Bump (value 8) + { + Color outClr; + bool bRes = EvalBump(sc, outClr); + if (bRes) outVal = Intens(outClr); + return bRes; + } + break; + + case ID_RL: // Reflection (value 9) + { + return EvalReflection(sc, outVal); + } + break; + + case ID_RR: // Refraction (value 10) + { + return EvalRefraction(sc, outVal); + } + break; + + case ID_DP: // Displacement (value 11) + { + return EvalDisplacement(sc, outVal); + } + break; + + // For everything else, there's a smart method + case ID_AM: // Ambient (value 0) + case ID_DI: // Diffuse (value 1) + case ID_SP: // Specular (value 2) + case ID_SH: // Shininess (value 3). In R3 and later this is called Glossiness. + case ID_SS: // Shininess strength (value 4). In R3 and later this is called Specular Level. + case ID_SI: // Self-illumination (value 5) + case ID_OP: // Opacity (value 6) + case ID_FI: // Filter color (value 7) + { + int id = StdIDToChannel(stdID); + if (id < 0 || id >= NumSubTexmaps()) return false; + Color outClr; + bool bRes = EvalChannel(sc, id, outClr); + if (bRes) outVal = Intens(outClr); + return bRes; + } + break; + + default: + // Should never happen + // DbgAssert( false ); + return false; + break; + } + return true; } //������������������������������������������������������������������������ @@ -4399,350 +4328,321 @@ bool XRayMtl::EvalMonoStdChannel // bool XRayMtl::EvalChannel(ShadeContext& sc, int channelID, Color& outClr) { - // For exmple, the Strauss shader doesn't support the ID_AM channel - DbgAssert( 0 <= channelID && channelID < NumSubTexmaps() ); - - // Check if the mtl has or not a shader - Shader* pShad = GetShader(); - DbgAssert( pShader != NULL ); - if ( pShad == NULL ) - { - // Filter color and opacity values are managed by the stdmtl2? - if ( channelID == StdIDToChannel(ID_FI) ) - { - outClr = filter; - return true; - } - else if ( channelID == StdIDToChannel(ID_FI) ) - { - outClr.r = outClr.g = outClr.b = opacity; - return true; - } - return false; - } - - // Get raw color\value from the shader - IllumParams ip(0, NULL); - memset(static_cast(&ip), 0, sizeof(IllumParams) ); - // ip.mtlFlags = flags; - pShad->GetIllumParams( sc, ip ); - - // Filter color and opacity values are managed by the stdmtl2? - if ( channelID == StdIDToChannel(ID_FI) ) - ip.channels[channelID] = filter; - else if ( channelID == StdIDToChannel(ID_OP) ) - { - ip.channels[channelID].r = opacity; - ip.channels[channelID].g = opacity; - ip.channels[channelID].b = opacity; - } - long channelType = pShad->ChannelType( channelID ); - - // Evaluate the texture map - if ( sc.doMaps ) - { - if ( channelID == StdIDToChannel( ID_AM ) && - (flags & NEWSTDMTL_LOCK_ADTEX) == NEWSTDMTL_LOCK_ADTEX ) - { - // Treat exceptional situations first - // - // Evaluat the ambient channel using the diffuse texmap - // if AD texmap lock is on - - long diffChanID = StdIDToChannel( ID_DI ); - long diffChanType = pShad->ChannelType( ID_DI ); - if ( diffChanID >= 0 && - SubTexmapOn( diffChanID ) && - ( diffChanType & SKIP_CHANNELS ) == 0 ) - { - Texmap* texMap = GetSubTexmap( diffChanID ); - if ( texMap != NULL && texMap->IsOutputMeaningful( sc ) ) - { - // Evaluate the diffuse channel first - AColor diffColor; - if ( (diffChanType & MONO_CHANNEL ) == MONO_CHANNEL ) - { - diffColor.r = (*maps)[diffChanID].LerpEvalMono( sc, ip.channels[diffChanID].r ); - diffColor.g = diffColor.b = diffColor.r; - diffColor.a = 0.0f; - } - else //if ( (diffChanType & CLR_CHANNEL ) == CLR_CHANNEL ) - { - diffColor = (*maps)[diffChanID].Eval( sc ); - AlphaCompCol( ip.channels[diffChanID], diffColor ); - } - - // Now evaluate the ambient channel - if ( (channelType & MONO_CHANNEL ) == MONO_CHANNEL ) - { - ip.channels[channelID].r = (*maps)[diffChanID].LerpEvalMono( sc, ip.channels[diffChanID].r ); - ip.channels[channelID].g = ip.channels[channelID].b = ip.channels[channelID].r; - } - else //if ( (channelType & CLR_CHANNEL ) == CLR_CHANNEL ) - AlphaCompCol( ip.channels[channelID], diffColor ); - } - } - } - else - { - // Normal course of channel evaluation - - if ( SubTexmapOn( channelID ) && - ( channelType & SKIP_CHANNELS ) == 0 ) - { - Texmap* texMap = GetSubTexmap( channelID ); - if ( texMap != NULL && texMap->IsOutputMeaningful( sc ) ) - { - if ( (channelType & MONO_CHANNEL ) == MONO_CHANNEL ) - { - ip.channels[channelID].r = (*maps)[channelID].LerpEvalMono( sc, ip.channels[channelID].r ); - ip.channels[channelID].g = ip.channels[channelID].b = ip.channels[channelID].r; - } - else //if ( (channelType & CLR_CHANNEL ) == CLR_CHANNEL ) - { - AColor c = (*maps)[channelID].Eval( sc ); - AlphaCompCol( ip.channels[channelID], c ); - } - } - } - } - } - - // Return a potentialy texture mapped value - outClr = ip.channels[channelID]; - - return true; + // For exmple, the Strauss shader doesn't support the ID_AM channel + DbgAssert(0 <= channelID && channelID < NumSubTexmaps()); + + // Check if the mtl has or not a shader + Shader* pShad = GetShader(); + DbgAssert(pShader != NULL); + if (pShad == NULL) { + // Filter color and opacity values are managed by the stdmtl2? + if (channelID == StdIDToChannel(ID_FI)) { + outClr = filter; + return true; + } + else if (channelID == StdIDToChannel(ID_FI)) + { + outClr.r = outClr.g = outClr.b = opacity; + return true; + } + return false; + } + + // Get raw color\value from the shader + IllumParams ip(0, NULL); + memset(static_cast(&ip), 0, sizeof(IllumParams)); + // ip.mtlFlags = flags; + pShad->GetIllumParams(sc, ip); + + // Filter color and opacity values are managed by the stdmtl2? + if (channelID == StdIDToChannel(ID_FI)) + ip.channels[channelID] = filter; + else if (channelID == StdIDToChannel(ID_OP)) + { + ip.channels[channelID].r = opacity; + ip.channels[channelID].g = opacity; + ip.channels[channelID].b = opacity; + } + long channelType = pShad->ChannelType(channelID); + + // Evaluate the texture map + if (sc.doMaps) { + if (channelID == StdIDToChannel(ID_AM) && (flags & NEWSTDMTL_LOCK_ADTEX) == NEWSTDMTL_LOCK_ADTEX) { + // Treat exceptional situations first + // + // Evaluat the ambient channel using the diffuse texmap + // if AD texmap lock is on + + long diffChanID = StdIDToChannel(ID_DI); + long diffChanType = pShad->ChannelType(ID_DI); + if (diffChanID >= 0 && SubTexmapOn(diffChanID) && (diffChanType & SKIP_CHANNELS) == 0) { + Texmap* texMap = GetSubTexmap(diffChanID); + if (texMap != NULL && texMap->IsOutputMeaningful(sc)) { + // Evaluate the diffuse channel first + AColor diffColor; + if ((diffChanType & MONO_CHANNEL) == MONO_CHANNEL) { + diffColor.r = (*maps)[diffChanID].LerpEvalMono(sc, ip.channels[diffChanID].r); + diffColor.g = diffColor.b = diffColor.r; + diffColor.a = 0.0f; + } + else // if ( (diffChanType & CLR_CHANNEL ) == CLR_CHANNEL ) + { + diffColor = (*maps)[diffChanID].Eval(sc); + AlphaCompCol(ip.channels[diffChanID], diffColor); + } + + // Now evaluate the ambient channel + if ((channelType & MONO_CHANNEL) == MONO_CHANNEL) { + ip.channels[channelID].r = (*maps)[diffChanID].LerpEvalMono(sc, ip.channels[diffChanID].r); + ip.channels[channelID].g = ip.channels[channelID].b = ip.channels[channelID].r; + } + else // if ( (channelType & CLR_CHANNEL ) == CLR_CHANNEL ) + AlphaCompCol(ip.channels[channelID], diffColor); + } + } + } + else + { + // Normal course of channel evaluation + + if (SubTexmapOn(channelID) && (channelType & SKIP_CHANNELS) == 0) { + Texmap* texMap = GetSubTexmap(channelID); + if (texMap != NULL && texMap->IsOutputMeaningful(sc)) { + if ((channelType & MONO_CHANNEL) == MONO_CHANNEL) { + ip.channels[channelID].r = (*maps)[channelID].LerpEvalMono(sc, ip.channels[channelID].r); + ip.channels[channelID].g = ip.channels[channelID].b = ip.channels[channelID].r; + } + else // if ( (channelType & CLR_CHANNEL ) == CLR_CHANNEL ) + { + AColor c = (*maps)[channelID].Eval(sc); + AlphaCompCol(ip.channels[channelID], c); + } + } + } + } + } + + // Return a potentialy texture mapped value + outClr = ip.channels[channelID]; + + return true; } //������������������������������������������������������������������������ // Evaluates the bump map. Returns false if the result is not meaningful // -bool XRayMtl::EvalBump( ShadeContext& sc, Color& outClr ) +bool XRayMtl::EvalBump(ShadeContext& sc, Color& outClr) { - int id = StdIDToChannel( ID_BU ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - { - outClr.Black(); - return false; - } + int id = StdIDToChannel(ID_BU); + if (!ShouldEvalSubTexmap(sc, id)) { + outClr.Black(); + return false; + } - Point3 dn = (*maps)[id].EvalNormalPerturb(sc); - outClr = Normalize( ( sc.backFace ? -dn : dn ) ); + Point3 dn = (*maps)[id].EvalNormalPerturb(sc); + outClr = Normalize((sc.backFace ? -dn : dn)); - return true; + return true; } //������������������������������������������������������������������������ -// Evaluates reflection map as a color. Returns false if the result is not +// Evaluates reflection map as a color. Returns false if the result is not // meaningful // -bool XRayMtl::EvalReflection( ShadeContext& sc, Color& outClr ) +bool XRayMtl::EvalReflection(ShadeContext& sc, Color& outClr) { - int id = StdIDToChannel( ID_RL ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - { - return false; - } + int id = StdIDToChannel(ID_RL); + if (!ShouldEvalSubTexmap(sc, id)) { + return false; + } - AColor rcol; - Texmap* reflmap = (*maps)[id].map; - DbgAssert( reflmap != NULL ); - if ( reflmap->HandleOwnViewPerturb() ) - { - sc.TossCache( reflmap ); - rcol = reflmap->EvalColor( sc ); - } - else - rcol = sc.EvalEnvironMap( reflmap, sc.ReflectVector() ); + AColor rcol; + Texmap* reflmap = (*maps)[id].map; + DbgAssert(reflmap != NULL); + if (reflmap->HandleOwnViewPerturb()) { + sc.TossCache(reflmap); + rcol = reflmap->EvalColor(sc); + } + else + rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); - outClr.r = rcol.r; - outClr.g = rcol.g; - outClr.b = rcol.b; + outClr.r = rcol.r; + outClr.g = rcol.g; + outClr.b = rcol.b; - return true; + return true; } //������������������������������������������������������������������������ -// Evaluates reflection map as (mono) value. Returns false if the result +// Evaluates reflection map as (mono) value. Returns false if the result // is not meaningful // -bool XRayMtl::EvalReflection( ShadeContext& sc, float& outVal ) +bool XRayMtl::EvalReflection(ShadeContext& sc, float& outVal) { - int id = StdIDToChannel( ID_RL ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - return false; + int id = StdIDToChannel(ID_RL); + if (!ShouldEvalSubTexmap(sc, id)) return false; - Texmap* reflmap = (*maps)[id].map; - DbgAssert( reflmap != NULL ); - if ( reflmap->HandleOwnViewPerturb() ) - { - sc.TossCache( reflmap ); - outVal = reflmap->EvalMono( sc ); - } - else - { - AColor rcol; - rcol = sc.EvalEnvironMap( reflmap, sc.ReflectVector() ); - outVal = Intens( rcol ); - } + Texmap* reflmap = (*maps)[id].map; + DbgAssert(reflmap != NULL); + if (reflmap->HandleOwnViewPerturb()) { + sc.TossCache(reflmap); + outVal = reflmap->EvalMono(sc); + } + else + { + AColor rcol; + rcol = sc.EvalEnvironMap(reflmap, sc.ReflectVector()); + outVal = Intens(rcol); + } - return true; + return true; } //������������������������������������������������������������������������ -// Evaluates refraction map as a color. Returns false if the result is not +// Evaluates refraction map as a color. Returns false if the result is not // meaningful // -bool XRayMtl::EvalRefraction( ShadeContext& sc, Color& outClr ) +bool XRayMtl::EvalRefraction(ShadeContext& sc, Color& outClr) { - int id = StdIDToChannel( ID_RR ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - return false; + int id = StdIDToChannel(ID_RR); + if (!ShouldEvalSubTexmap(sc, id)) return false; - AColor rcol; - Texmap* refrmap = (*maps)[id].map; - DbgAssert( refrmap != NULL ); - if ( refrmap->HandleOwnViewPerturb() ) - { - rcol = refrmap->EvalColor( sc ); - } - else - rcol = sc.EvalEnvironMap( refrmap, sc.RefractVector( ioRefract ) ); + AColor rcol; + Texmap* refrmap = (*maps)[id].map; + DbgAssert(refrmap != NULL); + if (refrmap->HandleOwnViewPerturb()) { + rcol = refrmap->EvalColor(sc); + } + else + rcol = sc.EvalEnvironMap(refrmap, sc.RefractVector(ioRefract)); - outClr.r = rcol.r; - outClr.g = rcol.g; - outClr.b = rcol.b; + outClr.r = rcol.r; + outClr.g = rcol.g; + outClr.b = rcol.b; - return true; + return true; } //������������������������������������������������������������������������ -// Evaluates reflection map as (mono) value. Returns false if the result +// Evaluates reflection map as (mono) value. Returns false if the result // is not meaningful // -bool XRayMtl::EvalRefraction( ShadeContext& sc, float& outVal ) +bool XRayMtl::EvalRefraction(ShadeContext& sc, float& outVal) { - int id = StdIDToChannel( ID_RR ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - return false; + int id = StdIDToChannel(ID_RR); + if (!ShouldEvalSubTexmap(sc, id)) return false; - Texmap* refrmap = (*maps)[id].map; - DbgAssert( refrmap != NULL ); - if ( refrmap->HandleOwnViewPerturb() ) - { - outVal = refrmap->EvalMono( sc ); - } - else - { - AColor rcol; - rcol = sc.EvalEnvironMap( refrmap, sc.RefractVector( ioRefract ) ); - outVal = Intens( rcol ); - } + Texmap* refrmap = (*maps)[id].map; + DbgAssert(refrmap != NULL); + if (refrmap->HandleOwnViewPerturb()) { + outVal = refrmap->EvalMono(sc); + } + else + { + AColor rcol; + rcol = sc.EvalEnvironMap(refrmap, sc.RefractVector(ioRefract)); + outVal = Intens(rcol); + } - return true; + return true; } //������������������������������������������������������������������������ -// Evaluates Displacement map as a color. Returns false if the result is not +// Evaluates Displacement map as a color. Returns false if the result is not // meaningful // -bool XRayMtl::EvalDisplacement( ShadeContext& sc, float& outVal ) +bool XRayMtl::EvalDisplacement(ShadeContext& sc, float& outVal) { - int id = StdIDToChannel( ID_DP ); - if ( !ShouldEvalSubTexmap( sc, id ) ) - return false; + int id = StdIDToChannel(ID_DP); + if (!ShouldEvalSubTexmap(sc, id)) return false; - outVal = (*maps)[id].EvalMono(sc); - return true; + outVal = (*maps)[id].EvalMono(sc); + return true; } //������������������������������������������������������������������������ // Helper method // -bool XRayMtl::ShouldEvalSubTexmap( ShadeContext& sc, int id ) +bool XRayMtl::ShouldEvalSubTexmap(ShadeContext& sc, int id) { - if ( id >= 0 && id < NumSubTexmaps() && - sc.doMaps && SubTexmapOn( id ) ) - { - Texmap* texMap = GetSubTexmap( id ); - if ( texMap != NULL && texMap->IsOutputMeaningful( sc ) ) - return true; - } + if (id >= 0 && id < NumSubTexmaps() && sc.doMaps && SubTexmapOn(id)) { + Texmap* texMap = GetSubTexmap(id); + if (texMap != NULL && texMap->IsOutputMeaningful(sc)) return true; + } - return false; + return false; } // XRay Part void XRayMtl::LoadXRayShaderList() { - XRayMtl::EShaders.clear (); - XRayMtl::CShaders.clear (); - XRayMtl::GameMtls.clear (); - int e_res = LoadBlenderList (XRayMtl::EShaders); - int c_res = LoadShaderLCList(XRayMtl::CShaders); - int g_res = LoadGameMtlList (XRayMtl::GameMtls); - if ((e_res==-1)||(c_res==-1)||(g_res==-1)) - { - Log("Can't load shader files!\nGame material will work incorrectly."); - THROW; - } + XRayMtl::EShaders.clear(); + XRayMtl::CShaders.clear(); + XRayMtl::GameMtls.clear(); + int e_res = LoadBlenderList(XRayMtl::EShaders); + int c_res = LoadShaderLCList(XRayMtl::CShaders); + int g_res = LoadGameMtlList(XRayMtl::GameMtls); + if ((e_res == -1) || (c_res == -1) || (g_res == -1)) { + Log("Can't load shader files!\nGame material will work incorrectly."); + THROW; + } } void XRayMtl::UnloadXRayShaderList() { - ClearList(XRayMtl::EShaders); - ClearList(XRayMtl::CShaders); - ClearList(XRayMtl::GameMtls); + ClearList(XRayMtl::EShaders); + ClearList(XRayMtl::CShaders); + ClearList(XRayMtl::GameMtls); } -void XRayMtl::SetEShaderIndx( long indx ) +void XRayMtl::SetEShaderIndx(long indx) { - pb_xray->SetValue(std2_eshader_type, 0, indx<0 ? 0 : indx ); - eshaderId = indx; + pb_xray->SetValue(std2_eshader_type, 0, indx < 0 ? 0 : indx); + eshaderId = indx; } -void XRayMtl::SetCShaderIndx( long indx ) +void XRayMtl::SetCShaderIndx(long indx) { - pb_xray->SetValue(std2_cshader_type, 0, indx<0 ? 0 : indx ); - cshaderId = indx; + pb_xray->SetValue(std2_cshader_type, 0, indx < 0 ? 0 : indx); + cshaderId = indx; } -void XRayMtl::SetGameMtlIndx( long indx ) +void XRayMtl::SetGameMtlIndx(long indx) { - pb_xray->SetValue(std2_gamemtl_type, 0, indx<0 ? 0 : indx ); - gamemtlId = indx; + pb_xray->SetValue(std2_gamemtl_type, 0, indx < 0 ? 0 : indx); + gamemtlId = indx; } -TCHAR* XRayMtl::GetEShader (DWORD i) -{ - return (i shaderList; - static Tab samplerList; - static LPSTRVec EShaders; - static LPSTRVec CShaders; - static LPSTRVec GameMtls; - - IParamBlock *old_pblock; // ref 0, for old version loading - Texmaps* maps; // ref 1 - Interval ivalid; - ReshadeRequirements mReshadeRQ; // mjm - 06.02.00 - ReshadeRequirements mInRQ; // ca - 12/7/00 - ULONG flags; - int shaderId; - Shader *pShader; // ref 2 - // new PB2 paramblocks, one per rollout - IParamBlock2 *pb_xray; // - IParamBlock2 *pb_shader; // ref 3, 4, ... - IParamBlock2 *pb_extended; - IParamBlock2 *pb_sampling; - IParamBlock2 *pb_maps; - IParamBlock2 *pb_dynamics; - - // xray - int eshaderId; - int cshaderId; - int gamemtlId; - - Color filter; - float opacity; - float opfall; - float wireSize; - float ioRefract; - float dimIntens; - float dimMult; - BOOL dimReflect; - - // sampling - int samplerId; - Sampler* pixelSampler; // ref 8 - - // composite of shader/mtl channel types - int channelTypes[ STD2_NMAX_TEXMAPS ]; - int stdIDToChannel[ N_ID_CHANNELS ]; - - // experiment: override filter - BOOL filterOverrideOn; - float filterSz; - - // Kill REFMSG_CHANGE messages. This counter is used to - // prevent these messages when things really aren't changing. - // Use the class KillRefmsg - RefmsgKillCounter killRefmsg; - - void SetFlag(ULONG f, ULONG val); - void EnableMap(int i, BOOL onoff); - BOOL IsMapEnabled(int i) { return (*maps)[i].mapOn; } - BOOL KeyAtTime(int id,TimeValue t) { return (id == OPACITY_PARAM) ? pb_extended->KeyFrameAtTime(std2_opacity, t) : FALSE; } - BOOL AmtKeyAtTime(int i, TimeValue t); - int GetMapState( int indx ); //returns 0 = no map, 1 = disable, 2 = mapon - TSTR GetMapName( int indx ); - void SyncADTexLock( BOOL lockOn ); - - // from StdMat - // these set Approximate colors into the plug in shader - BOOL IsSelfIllumColorOn(); - void SetSelfIllumColorOn( BOOL on ); - void SetSelfIllumColor(Color c, TimeValue t); - void SetAmbient(Color c, TimeValue t); - void SetDiffuse(Color c, TimeValue t); - void SetSpecular(Color c, TimeValue t); - void SetShininess(float v, TimeValue t); - void SetShinStr(float v, TimeValue t); - void SetSelfIllum(float v, TimeValue t); - void SetSoften(BOOL onoff) { SetFlag(NEWSTDMTL_SOFTEN,onoff); } - - void SetTexmapAmt(int imap, float amt, TimeValue t); - void LockAmbDiffTex(BOOL onoff) { SetFlag(NEWSTDMTL_LOCK_ADTEX,onoff); } - - void SetWire(BOOL onoff){ pb_shader->SetValue(std2_wire,0, (onoff!=0) ); }//SetFlag(NEWSTDMTL_WIRE,onoff); } - void SetWireSize(float s, TimeValue t); - void SetWireUnits(BOOL onoff) { pb_extended->SetValue(std2_wire_units,0, (onoff!=0) ); } //SetFlag(NEWSTDMTL_WIRE_UNITS,onoff); } - - void SetFaceMap(BOOL onoff) { pb_shader->SetValue(std2_face_map,0, (onoff!=0) ); } //SetFlag(NEWSTDMTL_FACEMAP,onoff); } - void SetTwoSided(BOOL onoff) { pb_shader->SetValue(std2_two_sided,0, (onoff!=0) ); } //SetFlag(NEWSTDMTL_2SIDE,onoff); } - void SetFalloffOut(BOOL outOn) { pb_extended->SetValue(std2_falloff_type,0, (outOn!=0) ); } //SetFlag(NEWSTDMTL_FALLOFF_OUT,onoff); } - void SetTransparencyType(int type); - - void SetFilter(Color c, TimeValue t); - void SetOpacity(float v, TimeValue t); - void SetOpacFalloff(float v, TimeValue t); - void SetIOR(float v, TimeValue t); - void SetDimIntens(float v, TimeValue t); - void SetDimMult(float v, TimeValue t); - - int GetFlag(ULONG f) { return (flags&f)?1:0; } - - // >>>Shaders - - // these 3 internal only - void SetShaderIndx( long shaderId, BOOL update=TRUE ); - long GetShaderIndx(){ return shaderId; } - void SetShader( Shader* pNewShader ); - void ShuffleTexMaps( Shader* newShader, Shader* oldShader ); - void ShuffleShaderParams( Shader* newShader, Shader* oldShader ); - - Shader* GetShader(){ return pShader; } - void SwitchShader(Shader* pNewShader, BOOL loadDlg = FALSE); - void SwitchShader(ClassDesc* pNewCD); - BOOL SwitchShader(Class_ID shaderId); - int FindShader( Class_ID& findId, ClassDesc** ppCD=NULL ); - BOOL IsShaderInUI() { return pb_shader && pb_shader->GetMap() && pShader && pShader->GetParamDlg(); } - - static void XRayMtl::LoadShaderList(); - static int XRayMtl::NumShaders(); - static ClassDesc* XRayMtl::GetShaderCD(int i); - static void XRayMtl::LoadSamplerList(); - static int XRayMtl::NumSamplers(); - static ClassDesc* XRayMtl::GetSamplerCD(int i); - - void SetEShaderIndx(long shaderId); - void SetCShaderIndx(long shaderId); - void SetGameMtlIndx(long shaderId); - long GetEShaderIndx(){ return eshaderId; } - long GetCShaderIndx(){ return cshaderId; } - long GetGameMtlIndx(){ return gamemtlId; } - LPCSTR GetEShaderName(){ return GetEShader(eshaderId); } - LPCSTR GetCShaderName(){ return GetCShader(cshaderId); } - LPCSTR GetGameMtlName(){ return GetGameMtl(gamemtlId); } - - static void XRayMtl::LoadXRayShaderList (); - static void XRayMtl::UnloadXRayShaderList (); - virtual TCHAR* GetEShader (DWORD i); - virtual TCHAR* GetCShader (DWORD i); - virtual TCHAR* GetGameMtl (DWORD i); - virtual int FindEShader (LPCSTR name); - virtual int FindCShader (LPCSTR name); - virtual int FindGameMtl (LPCSTR name); - - BOOL IsFaceted(){ return GetFlag(NEWSTDMTL_FACETED); } - void SetFaceted( BOOL on ){ pb_shader->SetValue(std2_faceted,0, (on!=0) ); } - - // These utilitys provide R2.5 shaders, ONLY used for Translators - // Does not & will not work for plug-in shaders - void SetShading(int s); - int GetShading(); - - // from Mtl - Color GetAmbient(int mtlNum=0, BOOL backFace=FALSE); - Color GetDiffuse(int mtlNum=0, BOOL backFace=FALSE); - Color GetSpecular(int mtlNum=0, BOOL backFace=FALSE); - float GetShininess(int mtlNum=0, BOOL backFace=FALSE); - float GetShinStr(int mtlNum=0, BOOL backFace=FALSE) ; - float GetXParency(int mtlNum=0, BOOL backFace=FALSE); - float WireSize(int mtlNum=0, BOOL backFace=FALSE) { return wireSize; } - - // >>>> Self Illumination - float GetSelfIllum(int mtlNum, BOOL backFace) ; - BOOL GetSelfIllumColorOn(int mtlNum, BOOL backFace); - Color GetSelfIllumColor(int mtlNum, BOOL backFace); - - // >>>> sampling - void SetSamplingOn( BOOL on ) - { - pb_sampling->SetValue(std2_ssampler_enable, 0, on!=0 ); - } - BOOL GetSamplingOn() - { Interval iv; - BOOL on; - pb_sampling->GetValue(std2_ssampler_enable, 0, on, iv ); - return on; - } - void SetSamplingQuality( float quality ) - { - pb_sampling->SetValue(std2_ssampler_qual, 0, quality ); - } - float GetSamplingQuality() - { Interval iv; - float q; - pb_sampling->GetValue(std2_ssampler_qual, 0, q, iv ); - return q; - } - - void SwitchSampler(ClassDesc* pNewCD); - void SwitchSampler(Sampler* pNewSampler); - BOOL SwitchSampler(Class_ID samplerId); - int FindSampler( Class_ID findId, ClassDesc** pNewCD=NULL ); - Sampler * GetPixelSampler(int mtlNum=0, BOOL backFace=FALSE){ return pixelSampler; } - - // these 2 internal only - void SetSamplerIndx( long indx, BOOL update=TRUE ); - long GetSamplerIndx(){ return samplerId; } - void SetPixelSampler( Sampler * sampler ); - - // Dynamics properties - float GetDynamicsProperty(TimeValue t, int mtlNum, int propID); - void SetDynamicsProperty(TimeValue t, int mtlNum, int propID, float value); - - // from StdMat - BOOL GetSoften() { return GetFlag(NEWSTDMTL_SOFTEN); } - BOOL GetFaceMap() { return GetFlag(NEWSTDMTL_FACEMAP); } - BOOL GetTwoSided() { return GetFlag(NEWSTDMTL_2SIDE); } - BOOL GetWire() { return GetFlag(NEWSTDMTL_WIRE); } - BOOL GetWireUnits() { return GetFlag(NEWSTDMTL_WIRE_UNITS); } - BOOL GetFalloffOut() { return GetFlag(NEWSTDMTL_FALLOFF_OUT); } // 1: out, 0: in - BOOL GetAmbDiffTexLock(){ return GetFlag(NEWSTDMTL_LOCK_ADTEX); } - int GetTransparencyType() { - return (flags&NEWSTDMTL_FILT_TRANSP)?TRANSP_FILTER: - flags&NEWSTDMTL_ADD_TRANSP ? TRANSP_ADDITIVE: TRANSP_SUBTRACTIVE; - } - Color GetFilter(TimeValue t); - - // these are stubs till i figure out scripting - Color GetAmbient(TimeValue t); - Color GetDiffuse(TimeValue t); - Color GetSpecular(TimeValue t); - float GetShininess( TimeValue t); - float GetShinStr(TimeValue t); - float GetSelfIllum(TimeValue t); - BOOL GetSelfIllumColorOn(); - Color GetSelfIllumColor(TimeValue t); - - float GetOpacity( TimeValue t); - float GetOpacFalloff(TimeValue t); - float GetWireSize(TimeValue t); - float GetIOR( TimeValue t); - float GetDimIntens( TimeValue t); - float GetDimMult( TimeValue t); - float GetSoftenLevel( TimeValue t); - BOOL MapEnabled(int i); - float GetTexmapAmt(int imap, TimeValue t); - - // internal - float GetOpacity() { return opacity; } - float GetOpacFalloff() { return opfall; } - float GetTexmapAmt(int imap); - Color GetFilter(); - float GetIOR() { return ioRefract; } - - XRayMtl(BOOL loading = FALSE); - ~XRayMtl() { - DiscardTexHandles(); - } - BOOL ParamWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp); - BOOL SetDlgThing(ParamDlg* dlg); - void UpdateTexmaps(); - void UpdateMapButtons(); - void UpdateExtendedMapButtons(); - void UpdateMtlDisplay(); - void UpdateLockADTex( BOOL passOn ); - void UpdateExtraParams( ULONG stdParams ); - void UpdateSamplingParams(); - - - Color TranspColor(ShadeContext& sc, float opac, Color& diff); - void Shade(ShadeContext& sc); - float EvalDisplacement(ShadeContext& sc); - Interval DisplacementValidity(TimeValue t); - void Update(TimeValue t, Interval& validr); - void Reset(); - void OldVerFix(int loadVer); - void BumpFix(); - Interval Validity(TimeValue t); - void NotifyChanged(); - - // Requirements - ULONG Requirements(int subMtlNum); - void MappingsRequired(int subMtlNum, BitArray & mapreq, BitArray &bumpreq); - - // Methods to access texture maps of material - int NumSubTexmaps() { return STD2_NMAX_TEXMAPS; } - Texmap* GetSubTexmap(int i) { return (*maps)[i].map; } - int MapSlotType(int i); - void SetSubTexmap(int i, Texmap *m); - TSTR GetSubTexmapSlotName(int i); - int SubTexmapOn(int i) { return MAPACTIVE(i); } - long StdIDToChannel( long id ){ return stdIDToChannel[id]; } - - Class_ID ClassID(); - SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; } - void GetClassName(TSTR& s) { s = GetString(IDS_CLASS_NAME); } - - void DeleteThis(); - - int NumSubs() { return NUM_SUB_ANIMS; } - Animatable* SubAnim(int i); - TSTR SubAnimName(int i); - int SubNumToRefNum(int subNum); - - // JBW: add direct ParamBlock access - int NumParamBlocks() { return 5; } - IParamBlock2* GetParamBlock(int i); - IParamBlock2* GetParamBlockByID(BlockID id); - - // From ref - int NumRefs() { return NUM_REFS; } - RefTargetHandle GetReference(int i); - void SetReference(int i, RefTargetHandle rtarg); - - RefTargetHandle Clone(RemapDir &remap = NoRemap()); - RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget, - PartID& partID, RefMessage message ); - - // IO - IOResult Save(ISave *isave); - IOResult Load(ILoad *iload); - - // begin - ke/mjm - 03.16.00 - merge reshading code - BOOL SupportsRenderElements(){ return TRUE; } - // BOOL SupportsReShading(ShadeContext& sc); - void UpdateReshadeRequirements(RefTargetHandle hTarget, PartID partID); // mjm - 06.02.00 - ReshadeRequirements GetReshadeRequirements() { return mReshadeRQ; } // mjm - 06.02.00 - void PreShade(ShadeContext& sc, IReshadeFragment* pFrag); - void PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams* ip); - // end - ke/mjm - 03.16.00 - merge reshading code - - // begin - dds- 04.27.00 - multiple map display support + // current UI if open + static ShaderParamDlg* pShaderDlg; + static IAutoMParamDlg* masterDlg; + static IAutoMParamDlg* texmapDlg; + static IAutoMParamDlg* extendedDlg; + static IAutoMParamDlg* samplingDlg; + static IAutoMParamDlg* xrayDlg; + static HWND curHwmEdit; + static IMtlParams* curImp; + static Tab shaderList; + static Tab samplerList; + static LPSTRVec EShaders; + static LPSTRVec CShaders; + static LPSTRVec GameMtls; + + IParamBlock* old_pblock; // ref 0, for old version loading + Texmaps* maps; // ref 1 + Interval ivalid; + ReshadeRequirements mReshadeRQ; // mjm - 06.02.00 + ReshadeRequirements mInRQ; // ca - 12/7/00 + ULONG flags; + int shaderId; + Shader* pShader; // ref 2 + // new PB2 paramblocks, one per rollout + IParamBlock2* pb_xray; // + IParamBlock2* pb_shader; // ref 3, 4, ... + IParamBlock2* pb_extended; + IParamBlock2* pb_sampling; + IParamBlock2* pb_maps; + IParamBlock2* pb_dynamics; + + // xray + int eshaderId; + int cshaderId; + int gamemtlId; + + Color filter; + float opacity; + float opfall; + float wireSize; + float ioRefract; + float dimIntens; + float dimMult; + BOOL dimReflect; + + // sampling + int samplerId; + Sampler* pixelSampler; // ref 8 + + // composite of shader/mtl channel types + int channelTypes[STD2_NMAX_TEXMAPS]; + int stdIDToChannel[N_ID_CHANNELS]; + + // experiment: override filter + BOOL filterOverrideOn; + float filterSz; + + // Kill REFMSG_CHANGE messages. This counter is used to + // prevent these messages when things really aren't changing. + // Use the class KillRefmsg + RefmsgKillCounter killRefmsg; + + void SetFlag(ULONG f, ULONG val); + void EnableMap(int i, BOOL onoff); + BOOL IsMapEnabled(int i) { return (*maps)[i].mapOn; } + BOOL KeyAtTime(int id, TimeValue t) + { + return (id == OPACITY_PARAM) ? pb_extended->KeyFrameAtTime(std2_opacity, t) : FALSE; + } + BOOL AmtKeyAtTime(int i, TimeValue t); + int GetMapState(int indx); // returns 0 = no map, 1 = disable, 2 = mapon + TSTR GetMapName(int indx); + void SyncADTexLock(BOOL lockOn); + + // from StdMat + // these set Approximate colors into the plug in shader + BOOL IsSelfIllumColorOn(); + void SetSelfIllumColorOn(BOOL on); + void SetSelfIllumColor(Color c, TimeValue t); + void SetAmbient(Color c, TimeValue t); + void SetDiffuse(Color c, TimeValue t); + void SetSpecular(Color c, TimeValue t); + void SetShininess(float v, TimeValue t); + void SetShinStr(float v, TimeValue t); + void SetSelfIllum(float v, TimeValue t); + void SetSoften(BOOL onoff) { SetFlag(NEWSTDMTL_SOFTEN, onoff); } + void SetTexmapAmt(int imap, float amt, TimeValue t); + void LockAmbDiffTex(BOOL onoff) { SetFlag(NEWSTDMTL_LOCK_ADTEX, onoff); } + void SetWire(BOOL onoff) { pb_shader->SetValue(std2_wire, 0, (onoff != 0)); } // SetFlag(NEWSTDMTL_WIRE,onoff); } + void SetWireSize(float s, TimeValue t); + void SetWireUnits(BOOL onoff) + { + pb_extended->SetValue(std2_wire_units, 0, (onoff != 0)); + } // SetFlag(NEWSTDMTL_WIRE_UNITS,onoff); } + + void SetFaceMap(BOOL onoff) + { + pb_shader->SetValue(std2_face_map, 0, (onoff != 0)); + } // SetFlag(NEWSTDMTL_FACEMAP,onoff); } + void SetTwoSided(BOOL onoff) + { + pb_shader->SetValue(std2_two_sided, 0, (onoff != 0)); + } // SetFlag(NEWSTDMTL_2SIDE,onoff); } + void SetFalloffOut(BOOL outOn) + { + pb_extended->SetValue(std2_falloff_type, 0, (outOn != 0)); + } // SetFlag(NEWSTDMTL_FALLOFF_OUT,onoff); } + void SetTransparencyType(int type); + + void SetFilter(Color c, TimeValue t); + void SetOpacity(float v, TimeValue t); + void SetOpacFalloff(float v, TimeValue t); + void SetIOR(float v, TimeValue t); + void SetDimIntens(float v, TimeValue t); + void SetDimMult(float v, TimeValue t); + + int GetFlag(ULONG f) { return (flags & f) ? 1 : 0; } + // >>>Shaders + + // these 3 internal only + void SetShaderIndx(long shaderId, BOOL update = TRUE); + long GetShaderIndx() { return shaderId; } + void SetShader(Shader* pNewShader); + void ShuffleTexMaps(Shader* newShader, Shader* oldShader); + void ShuffleShaderParams(Shader* newShader, Shader* oldShader); + + Shader* GetShader() { return pShader; } + void SwitchShader(Shader* pNewShader, BOOL loadDlg = FALSE); + void SwitchShader(ClassDesc* pNewCD); + BOOL SwitchShader(Class_ID shaderId); + int FindShader(Class_ID& findId, ClassDesc** ppCD = NULL); + BOOL IsShaderInUI() { return pb_shader && pb_shader->GetMap() && pShader && pShader->GetParamDlg(); } + static void XRayMtl::LoadShaderList(); + static int XRayMtl::NumShaders(); + static ClassDesc* XRayMtl::GetShaderCD(int i); + static void XRayMtl::LoadSamplerList(); + static int XRayMtl::NumSamplers(); + static ClassDesc* XRayMtl::GetSamplerCD(int i); + + void SetEShaderIndx(long shaderId); + void SetCShaderIndx(long shaderId); + void SetGameMtlIndx(long shaderId); + long GetEShaderIndx() { return eshaderId; } + long GetCShaderIndx() { return cshaderId; } + long GetGameMtlIndx() { return gamemtlId; } + LPCSTR GetEShaderName() { return GetEShader(eshaderId); } + LPCSTR GetCShaderName() { return GetCShader(cshaderId); } + LPCSTR GetGameMtlName() { return GetGameMtl(gamemtlId); } + static void XRayMtl::LoadXRayShaderList(); + static void XRayMtl::UnloadXRayShaderList(); + virtual TCHAR* GetEShader(DWORD i); + virtual TCHAR* GetCShader(DWORD i); + virtual TCHAR* GetGameMtl(DWORD i); + virtual int FindEShader(LPCSTR name); + virtual int FindCShader(LPCSTR name); + virtual int FindGameMtl(LPCSTR name); + + BOOL IsFaceted() { return GetFlag(NEWSTDMTL_FACETED); } + void SetFaceted(BOOL on) { pb_shader->SetValue(std2_faceted, 0, (on != 0)); } + // These utilitys provide R2.5 shaders, ONLY used for Translators + // Does not & will not work for plug-in shaders + void SetShading(int s); + int GetShading(); + + // from Mtl + Color GetAmbient(int mtlNum = 0, BOOL backFace = FALSE); + Color GetDiffuse(int mtlNum = 0, BOOL backFace = FALSE); + Color GetSpecular(int mtlNum = 0, BOOL backFace = FALSE); + float GetShininess(int mtlNum = 0, BOOL backFace = FALSE); + float GetShinStr(int mtlNum = 0, BOOL backFace = FALSE); + float GetXParency(int mtlNum = 0, BOOL backFace = FALSE); + float WireSize(int mtlNum = 0, BOOL backFace = FALSE) { return wireSize; } + // >>>> Self Illumination + float GetSelfIllum(int mtlNum, BOOL backFace); + BOOL GetSelfIllumColorOn(int mtlNum, BOOL backFace); + Color GetSelfIllumColor(int mtlNum, BOOL backFace); + + // >>>> sampling + void SetSamplingOn(BOOL on) { pb_sampling->SetValue(std2_ssampler_enable, 0, on != 0); } + BOOL GetSamplingOn() + { + Interval iv; + BOOL on; + pb_sampling->GetValue(std2_ssampler_enable, 0, on, iv); + return on; + } + void SetSamplingQuality(float quality) { pb_sampling->SetValue(std2_ssampler_qual, 0, quality); } + float GetSamplingQuality() + { + Interval iv; + float q; + pb_sampling->GetValue(std2_ssampler_qual, 0, q, iv); + return q; + } + + void SwitchSampler(ClassDesc* pNewCD); + void SwitchSampler(Sampler* pNewSampler); + BOOL SwitchSampler(Class_ID samplerId); + int FindSampler(Class_ID findId, ClassDesc** pNewCD = NULL); + Sampler* GetPixelSampler(int mtlNum = 0, BOOL backFace = FALSE) { return pixelSampler; } + // these 2 internal only + void SetSamplerIndx(long indx, BOOL update = TRUE); + long GetSamplerIndx() { return samplerId; } + void SetPixelSampler(Sampler* sampler); + + // Dynamics properties + float GetDynamicsProperty(TimeValue t, int mtlNum, int propID); + void SetDynamicsProperty(TimeValue t, int mtlNum, int propID, float value); + + // from StdMat + BOOL GetSoften() { return GetFlag(NEWSTDMTL_SOFTEN); } + BOOL GetFaceMap() { return GetFlag(NEWSTDMTL_FACEMAP); } + BOOL GetTwoSided() { return GetFlag(NEWSTDMTL_2SIDE); } + BOOL GetWire() { return GetFlag(NEWSTDMTL_WIRE); } + BOOL GetWireUnits() { return GetFlag(NEWSTDMTL_WIRE_UNITS); } + BOOL GetFalloffOut() { return GetFlag(NEWSTDMTL_FALLOFF_OUT); } // 1: out, 0: in + BOOL GetAmbDiffTexLock() { return GetFlag(NEWSTDMTL_LOCK_ADTEX); } + int GetTransparencyType() + { + return (flags & NEWSTDMTL_FILT_TRANSP) ? TRANSP_FILTER : + flags & NEWSTDMTL_ADD_TRANSP ? TRANSP_ADDITIVE : TRANSP_SUBTRACTIVE; + } + Color GetFilter(TimeValue t); + + // these are stubs till i figure out scripting + Color GetAmbient(TimeValue t); + Color GetDiffuse(TimeValue t); + Color GetSpecular(TimeValue t); + float GetShininess(TimeValue t); + float GetShinStr(TimeValue t); + float GetSelfIllum(TimeValue t); + BOOL GetSelfIllumColorOn(); + Color GetSelfIllumColor(TimeValue t); + + float GetOpacity(TimeValue t); + float GetOpacFalloff(TimeValue t); + float GetWireSize(TimeValue t); + float GetIOR(TimeValue t); + float GetDimIntens(TimeValue t); + float GetDimMult(TimeValue t); + float GetSoftenLevel(TimeValue t); + BOOL MapEnabled(int i); + float GetTexmapAmt(int imap, TimeValue t); + + // internal + float GetOpacity() { return opacity; } + float GetOpacFalloff() { return opfall; } + float GetTexmapAmt(int imap); + Color GetFilter(); + float GetIOR() { return ioRefract; } + XRayMtl(BOOL loading = FALSE); + ~XRayMtl() { DiscardTexHandles(); } + BOOL ParamWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams* imp); + BOOL SetDlgThing(ParamDlg* dlg); + void UpdateTexmaps(); + void UpdateMapButtons(); + void UpdateExtendedMapButtons(); + void UpdateMtlDisplay(); + void UpdateLockADTex(BOOL passOn); + void UpdateExtraParams(ULONG stdParams); + void UpdateSamplingParams(); + + Color TranspColor(ShadeContext& sc, float opac, Color& diff); + void Shade(ShadeContext& sc); + float EvalDisplacement(ShadeContext& sc); + Interval DisplacementValidity(TimeValue t); + void Update(TimeValue t, Interval& validr); + void Reset(); + void OldVerFix(int loadVer); + void BumpFix(); + Interval Validity(TimeValue t); + void NotifyChanged(); + + // Requirements + ULONG Requirements(int subMtlNum); + void MappingsRequired(int subMtlNum, BitArray& mapreq, BitArray& bumpreq); + + // Methods to access texture maps of material + int NumSubTexmaps() { return STD2_NMAX_TEXMAPS; } + Texmap* GetSubTexmap(int i) { return (*maps)[i].map; } + int MapSlotType(int i); + void SetSubTexmap(int i, Texmap* m); + TSTR GetSubTexmapSlotName(int i); + int SubTexmapOn(int i) { return MAPACTIVE(i); } + long StdIDToChannel(long id) { return stdIDToChannel[id]; } + Class_ID ClassID(); + SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; } + void GetClassName(TSTR& s) { s = GetString(IDS_CLASS_NAME); } + void DeleteThis(); + + int NumSubs() { return NUM_SUB_ANIMS; } + Animatable* SubAnim(int i); + TSTR SubAnimName(int i); + int SubNumToRefNum(int subNum); + + // JBW: add direct ParamBlock access + int NumParamBlocks() { return 5; } + IParamBlock2* GetParamBlock(int i); + IParamBlock2* GetParamBlockByID(BlockID id); + + // From ref + int NumRefs() { return NUM_REFS; } + RefTargetHandle GetReference(int i); + void SetReference(int i, RefTargetHandle rtarg); + + RefTargetHandle Clone(RemapDir& remap = NoRemap()); + RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message); + + // IO + IOResult Save(ISave* isave); + IOResult Load(ILoad* iload); + + // begin - ke/mjm - 03.16.00 - merge reshading code + BOOL SupportsRenderElements() { return TRUE; } + // BOOL SupportsReShading(ShadeContext& sc); + void UpdateReshadeRequirements(RefTargetHandle hTarget, PartID partID); // mjm - 06.02.00 + ReshadeRequirements GetReshadeRequirements() { return mReshadeRQ; } // mjm - 06.02.00 + void PreShade(ShadeContext& sc, IReshadeFragment* pFrag); + void PostShade(ShadeContext& sc, IReshadeFragment* pFrag, int& nextTexIndex, IllumParams* ip); +// end - ke/mjm - 03.16.00 - merge reshading code + +// begin - dds- 04.27.00 - multiple map display support #define NTEXHANDLES 2 - TexHandle *texHandle[NTEXHANDLES]; - short useSubForTex[NTEXHANDLES]; - short texOpsType[NTEXHANDLES]; - int numTexHandlesUsed; - Interval texHandleValid; - void SetTexOps(Material *mtl, int i, int type); - void DiscardTexHandles(); - BOOL SupportTexDisplay() { return TRUE; } - BOOL SupportsMultiMapsInViewport() { return TRUE; } - void ActivateTexDisplay(BOOL onoff); - void SetupGfxMultiMaps(TimeValue t, Material *mtl, MtlMakerCallback &cb); - // end - dds- 04.27.00 - multiple map display support - - // --- Material evaluation - from Mtl --- - bool IsOutputConst( ShadeContext& sc, int stdID ); - bool EvalColorStdChannel( ShadeContext& sc, int stdID, Color& outClr ); - bool EvalMonoStdChannel( ShadeContext& sc, int stdID, float& outVal ); - - void* GetInterface(ULONG id); - - float GetReflectionDim(float diffIllumIntensity ){ - if (dimReflect) - return ((1.0f-dimIntens)*diffIllumIntensity*dimMult + dimIntens); - else - return 1.0f; - } - Color TranspColor( float opac, Color filt, Color diff ); - - float GetEffOpacity(ShadeContext& sc, float opac){ - if ( opac != 1.0f || opfall != 0.0f) { - if (opfall != 0.0f) { - Point3 N = (flags & NEWSTDMTL_FACETED) ? sc.GNormal() : sc.Normal(); - float d = _abs( DotProd( N, sc.V() ) ); - if (flags & NEWSTDMTL_FALLOFF_OUT) d = 1.0f-d; - return opac * (1.0f - opfall * d); - } else return opac; - } else return 1.0f; - } + TexHandle* texHandle[NTEXHANDLES]; + short useSubForTex[NTEXHANDLES]; + short texOpsType[NTEXHANDLES]; + int numTexHandlesUsed; + Interval texHandleValid; + void SetTexOps(Material* mtl, int i, int type); + void DiscardTexHandles(); + BOOL SupportTexDisplay() { return TRUE; } + BOOL SupportsMultiMapsInViewport() { return TRUE; } + void ActivateTexDisplay(BOOL onoff); + void SetupGfxMultiMaps(TimeValue t, Material* mtl, MtlMakerCallback& cb); + // end - dds- 04.27.00 - multiple map display support + + // --- Material evaluation - from Mtl --- + bool IsOutputConst(ShadeContext& sc, int stdID); + bool EvalColorStdChannel(ShadeContext& sc, int stdID, Color& outClr); + bool EvalMonoStdChannel(ShadeContext& sc, int stdID, float& outVal); + + void* GetInterface(ULONG id); + + float GetReflectionDim(float diffIllumIntensity) + { + if (dimReflect) + return ((1.0f - dimIntens) * diffIllumIntensity * dimMult + dimIntens); + else + return 1.0f; + } + Color TranspColor(float opac, Color filt, Color diff); + + float GetEffOpacity(ShadeContext& sc, float opac) + { + if (opac != 1.0f || opfall != 0.0f) { + if (opfall != 0.0f) { + Point3 N = (flags & NEWSTDMTL_FACETED) ? sc.GNormal() : sc.Normal(); + float d = _abs(DotProd(N, sc.V())); + if (flags & NEWSTDMTL_FALLOFF_OUT) d = 1.0f - d; + return opac * (1.0f - opfall * d); + } + else + return opac; + } + else + return 1.0f; + } private: - // --- Material evaluation --- - bool EvalChannel( ShadeContext& sc, int channelID, Color& outClr); - bool EvalBump( ShadeContext& sc, Color& outClr ); - bool EvalReflection( ShadeContext& sc, Color& outClr ); - bool EvalReflection( ShadeContext& sc, float& outVal ); - bool EvalRefraction( ShadeContext& sc, Color& outClr ); - bool EvalRefraction( ShadeContext& sc, float& outVal ); - bool EvalDisplacement( ShadeContext& sc, float& outVal ); - bool ShouldEvalSubTexmap( ShadeContext& sc, int id ); - + // --- Material evaluation --- + bool EvalChannel(ShadeContext& sc, int channelID, Color& outClr); + bool EvalBump(ShadeContext& sc, Color& outClr); + bool EvalReflection(ShadeContext& sc, Color& outClr); + bool EvalReflection(ShadeContext& sc, float& outVal); + bool EvalRefraction(ShadeContext& sc, Color& outClr); + bool EvalRefraction(ShadeContext& sc, float& outVal); + bool EvalDisplacement(ShadeContext& sc, float& outVal); + bool ShouldEvalSubTexmap(ShadeContext& sc, int id); }; Mtl* CreateXRayMtl(); -#endif // __GAME_MATERIAL__H +#endif // __GAME_MATERIAL__H diff --git a/src/plugins/Shared/GameMaterial.rc b/src/plugins/Shared/GameMaterial.rc index cdb31d06ad6..4d771712ef7 100644 --- a/src/plugins/Shared/GameMaterial.rc +++ b/src/plugins/Shared/GameMaterial.rc @@ -19,316 +19,156 @@ #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_PANEL DIALOGEX 0, 0, 216, 80 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - RTEXT " Color :",IDC_STATIC,22,26,26,10 - CONTROL "User1",IDC_COLOR_NEW,"ColorSwatch",0x0,51,18,50,26 - CONTROL "M",IDC_MAPON_CLR,"CustButton",0x0,106,27,10,10 - CONTROL "",IDC_HIGHLIGHT,"Static",SS_BLACKFRAME,135,25,67,47 - LTEXT " Opacity :",IDC_STATIC,19,60,31,8 - CONTROL "",IDC_TR_EDIT,"CustEdit",WS_TABSTOP,52,60,22,10 - CONTROL "0,255,0",IDC_TR_SPIN,"SpinnerControl",WS_TABSTOP,74,60, - 11,10 - CONTROL "M",IDC_MAPON_TR,"CustButton",0x0,91,60,10,10 - RTEXT "Brightness :",IDC_STATIC,12,48,37,8 - CONTROL "",IDC_BR_EDIT,"CustEdit",WS_TABSTOP,52,48,22,10 - CONTROL "0,255,0",IDC_BR_SPIN,"SpinnerControl",WS_TABSTOP,74,48, - 11,10 - CONTROL "M",IDC_MAPON_BR,"CustButton",0x0,91,48,10,10 - GROUPBOX "Shading Settings",IDC_STATIC,4,4,119,72 - CTEXT "Specular Curve",IDC_STATIC,135,11,67,12,SS_CENTERIMAGE | - SS_SUNKEN -END - -IDD_DMTL_SHADER4 DIALOGEX 0, 0, 216, 28 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - COMBOBOX IDC_SHADER,8,3,85,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - CONTROL "Wire",IDC_WIRE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, - 109,2,27,10 - CONTROL "2-Sided",IDC_2SIDE,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,162,2,36,10 - CONTROL "Face Map",IDC_FACE_MAP,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,110,14,44,10 - CONTROL "Faceted",IDC_FACETED,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,162,14,44,10 -END - -IDD_DMTL_DYNAM DIALOG 0, 0, 216, 49 -STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE -FONT 8, "MS Sans Serif" -BEGIN - CONTROL "",IDC_BOUNCE_EDIT,"CustEdit",WS_TABSTOP,108,6,35,10 - LTEXT "Bounce Coefficient:",IDC_STATIC,44,7,63,9 - CONTROL "0,255,0",IDC_BOUNCE_SPIN,"SpinnerControl",0x0,144,6,11, - 10 - CONTROL "",IDC_STATFRIC_EDIT,"CustEdit",WS_TABSTOP,108,20,35,10 - LTEXT "Static Friction:",IDC_STATIC,58,21,49,9 - CONTROL "0,255,0",IDC_STATFRIC_SPIN,"SpinnerControl",0x0,144,20, - 11,10 - CONTROL "",IDC_SLIDFRIC_EDIT,"CustEdit",WS_TABSTOP,108,33,35,10 - LTEXT "Sliding Friction:",IDC_STATIC,56,33,50,9 - CONTROL "0,255,0",IDC_SLIDFRIC_SPIN,"SpinnerControl",0x0,144,33, - 11,10 -END - -IDD_DMTL_TEXMAP4 DIALOG 0, 0, 216, 309 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Amount",IDC_STATIC,76,4,24,8 - LTEXT "Map Type",IDC_STATIC,152,4,16,8 - CONTROL "",IDC_USEMAP_0,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 16,68,10 - CONTROL "",IDC_AMTEDIT_0,"CustEdit",WS_TABSTOP,72,16,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_0,"SpinnerControl",0x0,92,16,11,10 - CONTROL "",IDC_MAP_0,"CustButton",WS_TABSTOP,104,16,100,10 - CONTROL "User1",IDC_LOCK_TEX01,"CustButton",0x0,206,22,10,10 - CONTROL "",IDC_USEMAP_1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 28,68,10 - CONTROL "",IDC_AMTEDIT_1,"CustEdit",WS_TABSTOP,72,28,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_1,"SpinnerControl",0x0,92,28,11,10 - CONTROL "",IDC_MAP_1,"CustButton",WS_TABSTOP,104,28,100,10 - CONTROL "",IDC_USEMAP_2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 40,68,10 - CONTROL "",IDC_AMTEDIT_2,"CustEdit",WS_TABSTOP,72,40,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_2,"SpinnerControl",0x0,92,40,11,10 - CONTROL "",IDC_MAP_2,"CustButton",WS_TABSTOP,104,40,100,10 - CONTROL "",IDC_USEMAP_3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 52,68,10 - CONTROL "",IDC_AMTEDIT_3,"CustEdit",WS_TABSTOP,72,52,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_3,"SpinnerControl",0x0,92,52,11,10 - CONTROL "",IDC_MAP_3,"CustButton",WS_TABSTOP,104,52,100,10 - CONTROL "",IDC_USEMAP_4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 64,68,10 - CONTROL "",IDC_AMTEDIT_4,"CustEdit",WS_TABSTOP,72,64,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_4,"SpinnerControl",0x0,92,64,11,10 - CONTROL "",IDC_MAP_4,"CustButton",WS_TABSTOP,104,64,100,10 - CONTROL "",IDC_USEMAP_5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 76,68,10 - CONTROL "",IDC_AMTEDIT_5,"CustEdit",WS_TABSTOP,72,76,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_5,"SpinnerControl",0x0,92,76,11,10 - CONTROL "",IDC_MAP_5,"CustButton",WS_TABSTOP,104,76,100,10 - CONTROL "",IDC_USEMAP_6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 88,68,10 - CONTROL "",IDC_AMTEDIT_6,"CustEdit",WS_TABSTOP,72,88,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_6,"SpinnerControl",0x0,92,88,11,10 - CONTROL "",IDC_MAP_6,"CustButton",WS_TABSTOP,104,88,100,10 - CONTROL "",IDC_USEMAP_7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 100,68,10 - CONTROL "",IDC_AMTEDIT_7,"CustEdit",WS_TABSTOP,72,100,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_7,"SpinnerControl",0x0,92,100,11, - 10 - CONTROL "",IDC_MAP_7,"CustButton",WS_TABSTOP,104,100,100,10 - CONTROL "",IDC_USEMAP_8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 112,68,10 - CONTROL "",IDC_AMTEDIT_8,"CustEdit",WS_TABSTOP,72,112,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_8,"SpinnerControl",0x0,92,112,11, - 10 - CONTROL "",IDC_MAP_8,"CustButton",WS_TABSTOP,104,112,100,10 - CONTROL "",IDC_USEMAP_9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 124,68,10 - CONTROL "",IDC_AMTEDIT_9,"CustEdit",WS_TABSTOP,72,124,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_9,"SpinnerControl",0x0,92,124,11, - 10 - CONTROL "",IDC_MAP_9,"CustButton",WS_TABSTOP,104,124,100,10 - CONTROL "",IDC_USEMAP_10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 136,68,10 - CONTROL "",IDC_AMTEDIT_10,"CustEdit",WS_TABSTOP,72,136,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_10,"SpinnerControl",0x0,92,136,11, - 10 - CONTROL "",IDC_MAP_10,"CustButton",WS_TABSTOP,104,136,100,10 - CONTROL "",IDC_USEMAP_11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 148,68,10 - CONTROL "",IDC_AMTEDIT_11,"CustEdit",WS_TABSTOP,72,148,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_11,"SpinnerControl",0x0,92,148,11, - 10 - CONTROL "",IDC_MAP_11,"CustButton",WS_TABSTOP,104,148,100,10 - CONTROL "",IDC_USEMAP_12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 160,68,10 - CONTROL "",IDC_AMTEDIT_12,"CustEdit",WS_TABSTOP,72,160,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_12,"SpinnerControl",0x0,92,160,11, - 10 - CONTROL "",IDC_MAP_12,"CustButton",WS_TABSTOP,104,160,100,10 - CONTROL "",IDC_USEMAP_13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 172,68,10 - CONTROL "",IDC_AMTEDIT_13,"CustEdit",WS_TABSTOP,72,172,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_13,"SpinnerControl",0x0,92,172,11, - 10 - CONTROL "",IDC_MAP_13,"CustButton",WS_TABSTOP,104,172,100,10 - CONTROL "",IDC_USEMAP_14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 184,68,10 - CONTROL "",IDC_AMTEDIT_14,"CustEdit",WS_TABSTOP,72,184,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_14,"SpinnerControl",0x0,92,184,11, - 10 - CONTROL "",IDC_MAP_14,"CustButton",WS_TABSTOP,104,184,100,10 - CONTROL "",IDC_USEMAP_15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 196,68,10 - CONTROL "",IDC_AMTEDIT_15,"CustEdit",WS_TABSTOP,72,196,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_15,"SpinnerControl",0x0,92,196,11, - 10 - CONTROL "",IDC_MAP_15,"CustButton",WS_TABSTOP,104,196,100,10 - CONTROL "",IDC_USEMAP_16,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 208,68,10 - CONTROL "",IDC_AMTEDIT_16,"CustEdit",WS_TABSTOP,72,208,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_16,"SpinnerControl",0x0,92,208,11, - 10 - CONTROL "",IDC_MAP_16,"CustButton",WS_TABSTOP,104,208,100,10 - CONTROL "",IDC_USEMAP_17,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 220,68,10 - CONTROL "",IDC_AMTEDIT_17,"CustEdit",WS_TABSTOP,72,220,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_17,"SpinnerControl",0x0,92,220,11, - 10 - CONTROL "",IDC_MAP_17,"CustButton",WS_TABSTOP,104,220,100,10 - CONTROL "",IDC_USEMAP_18,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 232,68,10 - CONTROL "",IDC_AMTEDIT_18,"CustEdit",WS_TABSTOP,72,232,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_18,"SpinnerControl",0x0,92,232,11, - 10 - CONTROL "",IDC_MAP_18,"CustButton",WS_TABSTOP,104,232,100,10 - CONTROL "",IDC_USEMAP_19,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 244,68,10 - CONTROL "",IDC_AMTEDIT_19,"CustEdit",WS_TABSTOP,72,244,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_19,"SpinnerControl",0x0,92,244,11, - 10 - CONTROL "",IDC_MAP_19,"CustButton",WS_TABSTOP,104,244,100,10 - CONTROL "",IDC_USEMAP_20,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 256,68,10 - CONTROL "",IDC_AMTEDIT_20,"CustEdit",WS_TABSTOP,72,256,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_20,"SpinnerControl",0x0,92,256,11, - 10 - CONTROL "",IDC_MAP_20,"CustButton",WS_TABSTOP,104,256,100,10 - CONTROL "",IDC_USEMAP_21,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 268,68,10 - CONTROL "",IDC_AMTEDIT_21,"CustEdit",WS_TABSTOP,72,268,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_21,"SpinnerControl",0x0,92,268,11, - 10 - CONTROL "",IDC_MAP_21,"CustButton",WS_TABSTOP,104,268,100,10 - CONTROL "",IDC_USEMAP_22,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 280,68,10 - CONTROL "",IDC_AMTEDIT_22,"CustEdit",WS_TABSTOP,72,280,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_22,"SpinnerControl",0x0,92,280,11, - 10 - CONTROL "",IDC_MAP_22,"CustButton",WS_TABSTOP,104,280,100,10 - CONTROL "",IDC_USEMAP_23,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,3, - 292,68,10 - CONTROL "",IDC_AMTEDIT_23,"CustEdit",WS_TABSTOP,72,292,20,10 - CONTROL "0,255,0",IDC_AMTSPIN_23,"SpinnerControl",0x0,92,292,11, - 10 - CONTROL "",IDC_MAP_23,"CustButton",WS_TABSTOP,104,292,100,10 -END - -IDD_DMTL_SAMPLING3 DIALOG 0, 0, 216, 59 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif" -BEGIN - CONTROL "Enable Sampler",IDC_SUPER_SAMP,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,3,5,64,10 - COMBOBOX IDC_PIX_SAMPLER,75,3,80,84,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - RTEXT "Quality:",IDC_QUALITY_TEXT,155,4,27,9,NOT WS_GROUP - CONTROL "",IDC_SAMPLEQUALITY_EDIT,"CustEdit",WS_TABSTOP,183,3,19, - 10 - CONTROL "0,255,0",IDC_SAMPLEQUALITY_SPIN,"SpinnerControl", - WS_TABSTOP,202,3,11,10 - CONTROL "Supersamp. Tex.",IDC_SAMPLE_TEX,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,3,18,71,10 - GROUPBOX "",IDC_COMMENT_BOX,75,16,80,41 - LTEXT "No Comment",IDC_COMMENT_TEXT,77,21,76,34 - RTEXT "Param0",IDC_PARAM0_TEXT,155,17,27,9,NOT WS_GROUP - CONTROL "",IDC_PARAM0_EDIT,"CustEdit",WS_TABSTOP,183,16,19,10 - CONTROL "0,255,0",IDC_PARAM0_SPIN,"SpinnerControl",WS_TABSTOP, - 202,16,11,10 - CONTROL "Adaptive",IDC_ADAPT_ON,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,3,32,56,10 - RTEXT "Param1",IDC_PARAM1_TEXT,155,30,27,9,NOT WS_GROUP - CONTROL "",IDC_PARAM1_EDIT,"CustEdit",WS_TABSTOP,183,30,19,10 - CONTROL "0,255,0",IDC_PARAM1_SPIN,"SpinnerControl",WS_TABSTOP, - 201,30,11,10 - RTEXT "Threshold:",IDC_ADAPT_STATIC,2,46,34,8,NOT WS_GROUP - CONTROL "",IDC_THRESHOLD_EDIT,"CustEdit",WS_TABSTOP,38,45,25,10 - CONTROL "0,255,0",IDC_THRESHOLD_SPIN,"SpinnerControl",WS_TABSTOP, - 63,45,11,10 - PUSHBUTTON "Advanced...",IDC_ADVANCED_BUTTON,166,43,46,12 -END - -IDD_DMTL_EXTRA6 DIALOGEX 0, 0, 216, 101 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x1 -BEGIN - GROUPBOX "Advanced Transparency",IDC_OPAC_BOX,4,1,147,71 - LTEXT "Falloff:",IDC_OPAC_TEXT1,9,11,22,8 - LTEXT "Type:",IDC_OPAC_TEXT3,56,11,18,8 - CONTROL "In",IDC_TF_IN,"Button",BS_AUTORADIOBUTTON | WS_GROUP | - WS_TABSTOP,26,21,20,8 - CONTROL "Out",IDC_TF_OUT,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,26,32,24,10 - RTEXT "Refraction Filter: ",IDC_FILTER_OVERLAY,44,19,59,11 - CONTROL "Filter:",IDC_TR_SUB2,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,72,20,29,8 - CONTROL "Subtractive",IDC_TR_SUB,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,72,33,52,8 - CONTROL "Additive",IDC_TR_ADD,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,72,45,37,8 - CONTROL "User1",IDC_FILTER_CS,"ColorSwatch",WS_TABSTOP,105,17,27, - 14 - CONTROL "M",IDC_MAPON_FI,"CustButton",WS_TABSTOP,136,20,10,10 - GROUPBOX "Wire",IDC_STATIC,153,1,59,71 - LTEXT "Size:",IDC_STATIC,156,21,16,9,0,WS_EX_RIGHT - CONTROL "",IDC_WIRE_EDIT,"CustEdit",WS_TABSTOP,174,20,22,10 - CONTROL "0,255,0",IDC_WIRE_SPIN,"SpinnerControl",0x0,196,20,11, - 10 - LTEXT "In:",IDC_STATIC,160,45,8,8 - CONTROL "Pixels",IDC_PIXELS,"Button",BS_AUTORADIOBUTTON | - WS_GROUP | WS_TABSTOP,172,41,32,8 - CONTROL "Units",IDC_UNITS,"Button",BS_AUTORADIOBUTTON | - WS_TABSTOP,172,52,28,8 - LTEXT "Index of Refraction:",IDC_REFR_TEXT1,11,57,91,9,0, - WS_EX_RIGHT - CONTROL "",IDC_IOR_EDIT,"CustEdit",WS_TABSTOP,105,57,19,10 - CONTROL "0,255,0",IDC_IOR_SPIN,"SpinnerControl",0x0,124,57,11,10 - GROUPBOX "Reflection Dimming",IDC_REFL_BOX,4,72,209,27 - CONTROL "Apply",IDC_DIM_REFL,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,11,83,36,10 - LTEXT "Dim Level:",IDC_REFL_TEXT1,52,84,33,8,0,WS_EX_RIGHT - CONTROL "",IDC_DIM_AMT,"CustEdit",WS_TABSTOP,87,83,24,10 - CONTROL "0,255,0",IDC_DIM_AMTSPIN,"SpinnerControl",0x0,112,83,11, - 10 - LTEXT "Refl. Level:",IDC_REFL_TEXT2,132,84,38,8 - CONTROL "",IDC_DIM_MULT,"CustEdit",WS_TABSTOP,173,83,24,10 - CONTROL "0,255,0",IDC_DIM_MULTSPIN,"SpinnerControl",0x0,198,83, - 11,10 - LTEXT "Amt:",IDC_OPAC_TEXT2,12,44,16,8 - CONTROL "",IDC_TF_EDIT,"CustEdit",WS_TABSTOP,28,44,20,10 - CONTROL "0,255,0",IDC_TF_SPIN,"SpinnerControl",0x0,48,44,11,10 -END - -IDD_DMTL_XRAY DIALOGEX 0, 0, 216, 50 -STYLE DS_SETFONT | WS_CHILD -FONT 8, "MS Sans Serif", 0, 0, 0x0 -BEGIN - LTEXT "Engine Shader",IDC_STATIC,8,7,52,8 - COMBOBOX IDC_ESHADER,63,4,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - COMBOBOX IDC_CSHADER,63,19,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - LTEXT "Compiler Shader",IDC_STATIC,8,22,52,8 - COMBOBOX IDC_GAMEMTL,63,34,143,75,CBS_DROPDOWNLIST | WS_VSCROLL | - WS_TABSTOP - LTEXT "Game Material",IDC_STATIC,8,37,46,8 -END - +#endif //_WIN32 + + ///////////////////////////////////////////////////////////////////////////// + // + // Dialog + // + + IDD_PANEL DIALOGEX 0, + 0, 216, 80 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN RTEXT " Color :", IDC_STATIC, 22, + 26, 26, 10 CONTROL "User1", IDC_COLOR_NEW, "ColorSwatch", 0x0, 51, 18, 50, 26 CONTROL "M", IDC_MAPON_CLR, + "CustButton", 0x0, 106, 27, 10, 10 CONTROL "", IDC_HIGHLIGHT, "Static", SS_BLACKFRAME, 135, 25, 67, + 47 LTEXT " Opacity :", IDC_STATIC, 19, 60, 31, 8 CONTROL "", IDC_TR_EDIT, "CustEdit", WS_TABSTOP, 52, 60, 22, + 10 CONTROL "0,255,0", IDC_TR_SPIN, "SpinnerControl", WS_TABSTOP, 74, 60, 11, 10 CONTROL "M", IDC_MAPON_TR, + "CustButton", 0x0, 91, 60, 10, 10 RTEXT "Brightness :", IDC_STATIC, 12, 48, 37, 8 CONTROL "", IDC_BR_EDIT, + "CustEdit", WS_TABSTOP, 52, 48, 22, 10 CONTROL "0,255,0", IDC_BR_SPIN, "SpinnerControl", WS_TABSTOP, 74, 48, 11, + 10 CONTROL "M", IDC_MAPON_BR, "CustButton", 0x0, 91, 48, 10, 10 GROUPBOX "Shading Settings", IDC_STATIC, 4, 4, 119, + 72 CTEXT "Specular Curve", IDC_STATIC, 135, 11, 67, 12, SS_CENTERIMAGE | SS_SUNKEN END + + IDD_DMTL_SHADER4 DIALOGEX 0, + 0, 216, 28 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN COMBOBOX IDC_SHADER, 8, 3, 85, 75, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Wire", IDC_WIRE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 109, 2, + 27, 10 CONTROL "2-Sided", IDC_2SIDE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 162, 2, 36, 10 CONTROL "Face Map", + IDC_FACE_MAP, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 110, 14, 44, 10 CONTROL "Faceted", IDC_FACETED, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 162, 14, 44, 10 END + + IDD_DMTL_DYNAM DIALOG 0, + 0, 216, 49 STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE FONT 8, "MS Sans Serif" BEGIN CONTROL "", IDC_BOUNCE_EDIT, + "CustEdit", WS_TABSTOP, 108, 6, 35, 10 LTEXT "Bounce Coefficient:", IDC_STATIC, 44, 7, 63, 9 CONTROL "0,255,0", + IDC_BOUNCE_SPIN, "SpinnerControl", 0x0, 144, 6, 11, 10 CONTROL "", IDC_STATFRIC_EDIT, "CustEdit", WS_TABSTOP, 108, + 20, 35, 10 LTEXT "Static Friction:", IDC_STATIC, 58, 21, 49, 9 CONTROL "0,255,0", IDC_STATFRIC_SPIN, + "SpinnerControl", 0x0, 144, 20, 11, 10 CONTROL "", IDC_SLIDFRIC_EDIT, "CustEdit", WS_TABSTOP, 108, 33, 35, + 10 LTEXT "Sliding Friction:", IDC_STATIC, 56, 33, 50, 9 CONTROL "0,255,0", IDC_SLIDFRIC_SPIN, "SpinnerControl", 0x0, + 144, 33, 11, 10 END + + IDD_DMTL_TEXMAP4 DIALOG 0, + 0, 216, 309 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif" BEGIN LTEXT "Amount", IDC_STATIC, 76, 4, 24, + 8 LTEXT "Map Type", IDC_STATIC, 152, 4, 16, 8 CONTROL "", IDC_USEMAP_0, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, + 16, 68, 10 CONTROL "", IDC_AMTEDIT_0, "CustEdit", WS_TABSTOP, 72, 16, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_0, + "SpinnerControl", 0x0, 92, 16, 11, 10 CONTROL "", IDC_MAP_0, "CustButton", WS_TABSTOP, 104, 16, 100, + 10 CONTROL "User1", IDC_LOCK_TEX01, "CustButton", 0x0, 206, 22, 10, 10 CONTROL "", IDC_USEMAP_1, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 28, 68, 10 CONTROL "", IDC_AMTEDIT_1, "CustEdit", WS_TABSTOP, 72, 28, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_1, "SpinnerControl", 0x0, 92, 28, 11, 10 CONTROL "", IDC_MAP_1, "CustButton", + WS_TABSTOP, 104, 28, 100, 10 CONTROL "", IDC_USEMAP_2, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 40, 68, + 10 CONTROL "", IDC_AMTEDIT_2, "CustEdit", WS_TABSTOP, 72, 40, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_2, + "SpinnerControl", 0x0, 92, 40, 11, 10 CONTROL "", IDC_MAP_2, "CustButton", WS_TABSTOP, 104, 40, 100, 10 CONTROL "", + IDC_USEMAP_3, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 52, 68, 10 CONTROL "", IDC_AMTEDIT_3, "CustEdit", + WS_TABSTOP, 72, 52, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_3, "SpinnerControl", 0x0, 92, 52, 11, 10 CONTROL "", + IDC_MAP_3, "CustButton", WS_TABSTOP, 104, 52, 100, 10 CONTROL "", IDC_USEMAP_4, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 64, 68, 10 CONTROL "", IDC_AMTEDIT_4, "CustEdit", WS_TABSTOP, 72, 64, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_4, "SpinnerControl", 0x0, 92, 64, 11, 10 CONTROL "", IDC_MAP_4, "CustButton", + WS_TABSTOP, 104, 64, 100, 10 CONTROL "", IDC_USEMAP_5, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 76, 68, + 10 CONTROL "", IDC_AMTEDIT_5, "CustEdit", WS_TABSTOP, 72, 76, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_5, + "SpinnerControl", 0x0, 92, 76, 11, 10 CONTROL "", IDC_MAP_5, "CustButton", WS_TABSTOP, 104, 76, 100, 10 CONTROL "", + IDC_USEMAP_6, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 88, 68, 10 CONTROL "", IDC_AMTEDIT_6, "CustEdit", + WS_TABSTOP, 72, 88, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_6, "SpinnerControl", 0x0, 92, 88, 11, 10 CONTROL "", + IDC_MAP_6, "CustButton", WS_TABSTOP, 104, 88, 100, 10 CONTROL "", IDC_USEMAP_7, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 100, 68, 10 CONTROL "", IDC_AMTEDIT_7, "CustEdit", WS_TABSTOP, 72, 100, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_7, "SpinnerControl", 0x0, 92, 100, 11, 10 CONTROL "", IDC_MAP_7, "CustButton", + WS_TABSTOP, 104, 100, 100, 10 CONTROL "", IDC_USEMAP_8, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 112, 68, + 10 CONTROL "", IDC_AMTEDIT_8, "CustEdit", WS_TABSTOP, 72, 112, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_8, + "SpinnerControl", 0x0, 92, 112, 11, 10 CONTROL "", IDC_MAP_8, "CustButton", WS_TABSTOP, 104, 112, 100, + 10 CONTROL "", IDC_USEMAP_9, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 124, 68, 10 CONTROL "", IDC_AMTEDIT_9, + "CustEdit", WS_TABSTOP, 72, 124, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_9, "SpinnerControl", 0x0, 92, 124, 11, + 10 CONTROL "", IDC_MAP_9, "CustButton", WS_TABSTOP, 104, 124, 100, 10 CONTROL "", IDC_USEMAP_10, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 136, 68, 10 CONTROL "", IDC_AMTEDIT_10, "CustEdit", WS_TABSTOP, 72, 136, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_10, "SpinnerControl", 0x0, 92, 136, 11, 10 CONTROL "", IDC_MAP_10, "CustButton", + WS_TABSTOP, 104, 136, 100, 10 CONTROL "", IDC_USEMAP_11, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 148, 68, + 10 CONTROL "", IDC_AMTEDIT_11, "CustEdit", WS_TABSTOP, 72, 148, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_11, + "SpinnerControl", 0x0, 92, 148, 11, 10 CONTROL "", IDC_MAP_11, "CustButton", WS_TABSTOP, 104, 148, 100, + 10 CONTROL "", IDC_USEMAP_12, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 160, 68, 10 CONTROL "", IDC_AMTEDIT_12, + "CustEdit", WS_TABSTOP, 72, 160, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_12, "SpinnerControl", 0x0, 92, 160, 11, + 10 CONTROL "", IDC_MAP_12, "CustButton", WS_TABSTOP, 104, 160, 100, 10 CONTROL "", IDC_USEMAP_13, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 172, 68, 10 CONTROL "", IDC_AMTEDIT_13, "CustEdit", WS_TABSTOP, 72, 172, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_13, "SpinnerControl", 0x0, 92, 172, 11, 10 CONTROL "", IDC_MAP_13, "CustButton", + WS_TABSTOP, 104, 172, 100, 10 CONTROL "", IDC_USEMAP_14, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 184, 68, + 10 CONTROL "", IDC_AMTEDIT_14, "CustEdit", WS_TABSTOP, 72, 184, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_14, + "SpinnerControl", 0x0, 92, 184, 11, 10 CONTROL "", IDC_MAP_14, "CustButton", WS_TABSTOP, 104, 184, 100, + 10 CONTROL "", IDC_USEMAP_15, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 196, 68, 10 CONTROL "", IDC_AMTEDIT_15, + "CustEdit", WS_TABSTOP, 72, 196, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_15, "SpinnerControl", 0x0, 92, 196, 11, + 10 CONTROL "", IDC_MAP_15, "CustButton", WS_TABSTOP, 104, 196, 100, 10 CONTROL "", IDC_USEMAP_16, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 208, 68, 10 CONTROL "", IDC_AMTEDIT_16, "CustEdit", WS_TABSTOP, 72, 208, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_16, "SpinnerControl", 0x0, 92, 208, 11, 10 CONTROL "", IDC_MAP_16, "CustButton", + WS_TABSTOP, 104, 208, 100, 10 CONTROL "", IDC_USEMAP_17, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 220, 68, + 10 CONTROL "", IDC_AMTEDIT_17, "CustEdit", WS_TABSTOP, 72, 220, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_17, + "SpinnerControl", 0x0, 92, 220, 11, 10 CONTROL "", IDC_MAP_17, "CustButton", WS_TABSTOP, 104, 220, 100, + 10 CONTROL "", IDC_USEMAP_18, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 232, 68, 10 CONTROL "", IDC_AMTEDIT_18, + "CustEdit", WS_TABSTOP, 72, 232, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_18, "SpinnerControl", 0x0, 92, 232, 11, + 10 CONTROL "", IDC_MAP_18, "CustButton", WS_TABSTOP, 104, 232, 100, 10 CONTROL "", IDC_USEMAP_19, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 244, 68, 10 CONTROL "", IDC_AMTEDIT_19, "CustEdit", WS_TABSTOP, 72, 244, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_19, "SpinnerControl", 0x0, 92, 244, 11, 10 CONTROL "", IDC_MAP_19, "CustButton", + WS_TABSTOP, 104, 244, 100, 10 CONTROL "", IDC_USEMAP_20, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 256, 68, + 10 CONTROL "", IDC_AMTEDIT_20, "CustEdit", WS_TABSTOP, 72, 256, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_20, + "SpinnerControl", 0x0, 92, 256, 11, 10 CONTROL "", IDC_MAP_20, "CustButton", WS_TABSTOP, 104, 256, 100, + 10 CONTROL "", IDC_USEMAP_21, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 268, 68, 10 CONTROL "", IDC_AMTEDIT_21, + "CustEdit", WS_TABSTOP, 72, 268, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_21, "SpinnerControl", 0x0, 92, 268, 11, + 10 CONTROL "", IDC_MAP_21, "CustButton", WS_TABSTOP, 104, 268, 100, 10 CONTROL "", IDC_USEMAP_22, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 280, 68, 10 CONTROL "", IDC_AMTEDIT_22, "CustEdit", WS_TABSTOP, 72, 280, 20, + 10 CONTROL "0,255,0", IDC_AMTSPIN_22, "SpinnerControl", 0x0, 92, 280, 11, 10 CONTROL "", IDC_MAP_22, "CustButton", + WS_TABSTOP, 104, 280, 100, 10 CONTROL "", IDC_USEMAP_23, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 292, 68, + 10 CONTROL "", IDC_AMTEDIT_23, "CustEdit", WS_TABSTOP, 72, 292, 20, 10 CONTROL "0,255,0", IDC_AMTSPIN_23, + "SpinnerControl", 0x0, 92, 292, 11, 10 CONTROL "", IDC_MAP_23, "CustButton", WS_TABSTOP, 104, 292, 100, + 10 END + + IDD_DMTL_SAMPLING3 DIALOG 0, + 0, 216, 59 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif" BEGIN CONTROL "Enable Sampler", IDC_SUPER_SAMP, + "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 5, 64, 10 COMBOBOX IDC_PIX_SAMPLER, 75, 3, 80, 84, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP RTEXT "Quality:", IDC_QUALITY_TEXT, 155, 4, 27, 9, + NOT WS_GROUP CONTROL "", IDC_SAMPLEQUALITY_EDIT, "CustEdit", WS_TABSTOP, 183, 3, 19, 10 CONTROL "0,255,0", + IDC_SAMPLEQUALITY_SPIN, "SpinnerControl", WS_TABSTOP, 202, 3, 11, 10 CONTROL "Supersamp. Tex.", IDC_SAMPLE_TEX, + "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 3, 18, 71, 10 GROUPBOX "", IDC_COMMENT_BOX, 75, 16, 80, + 41 LTEXT "No Comment", IDC_COMMENT_TEXT, 77, 21, 76, 34 RTEXT "Param0", IDC_PARAM0_TEXT, 155, 17, 27, 9, + NOT WS_GROUP CONTROL "", IDC_PARAM0_EDIT, "CustEdit", WS_TABSTOP, 183, 16, 19, 10 CONTROL "0,255,0", + IDC_PARAM0_SPIN, "SpinnerControl", WS_TABSTOP, 202, 16, 11, 10 CONTROL "Adaptive", IDC_ADAPT_ON, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 3, 32, 56, 10 RTEXT "Param1", IDC_PARAM1_TEXT, 155, 30, 27, 9, + NOT WS_GROUP CONTROL "", IDC_PARAM1_EDIT, "CustEdit", WS_TABSTOP, 183, 30, 19, 10 CONTROL "0,255,0", + IDC_PARAM1_SPIN, "SpinnerControl", WS_TABSTOP, 201, 30, 11, 10 RTEXT "Threshold:", IDC_ADAPT_STATIC, 2, 46, 34, 8, + NOT WS_GROUP CONTROL "", IDC_THRESHOLD_EDIT, "CustEdit", WS_TABSTOP, 38, 45, 25, 10 CONTROL "0,255,0", + IDC_THRESHOLD_SPIN, "SpinnerControl", WS_TABSTOP, 63, 45, 11, 10 PUSHBUTTON "Advanced...", IDC_ADVANCED_BUTTON, 166, + 43, 46, 12 END + + IDD_DMTL_EXTRA6 DIALOGEX 0, + 0, 216, 101 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN GROUPBOX "Advanced Transparency", + IDC_OPAC_BOX, 4, 1, 147, 71 LTEXT "Falloff:", IDC_OPAC_TEXT1, 9, 11, 22, 8 LTEXT "Type:", IDC_OPAC_TEXT3, 56, 11, + 18, 8 CONTROL "In", IDC_TF_IN, "Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 26, 21, 20, 8 CONTROL "Out", + IDC_TF_OUT, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, 26, 32, 24, 10 RTEXT "Refraction Filter: ", + IDC_FILTER_OVERLAY, 44, 19, 59, 11 CONTROL "Filter:", IDC_TR_SUB2, "Button", + BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 72, 20, 29, 8 CONTROL "Subtractive", IDC_TR_SUB, "Button", + BS_AUTORADIOBUTTON | WS_TABSTOP, 72, 33, 52, 8 CONTROL "Additive", IDC_TR_ADD, "Button", + BS_AUTORADIOBUTTON | WS_TABSTOP, 72, 45, 37, 8 CONTROL "User1", IDC_FILTER_CS, "ColorSwatch", WS_TABSTOP, 105, 17, + 27, 14 CONTROL "M", IDC_MAPON_FI, "CustButton", WS_TABSTOP, 136, 20, 10, 10 GROUPBOX "Wire", IDC_STATIC, 153, 1, 59, + 71 LTEXT "Size:", IDC_STATIC, 156, 21, 16, 9, 0, WS_EX_RIGHT CONTROL "", IDC_WIRE_EDIT, "CustEdit", WS_TABSTOP, 174, + 20, 22, 10 CONTROL "0,255,0", IDC_WIRE_SPIN, "SpinnerControl", 0x0, 196, 20, 11, 10 LTEXT "In:", IDC_STATIC, 160, + 45, 8, 8 CONTROL "Pixels", IDC_PIXELS, "Button", BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP, 172, 41, 32, + 8 CONTROL "Units", IDC_UNITS, "Button", BS_AUTORADIOBUTTON | WS_TABSTOP, 172, 52, 28, + 8 LTEXT "Index of Refraction:", IDC_REFR_TEXT1, 11, 57, 91, 9, 0, WS_EX_RIGHT CONTROL "", IDC_IOR_EDIT, "CustEdit", + WS_TABSTOP, 105, 57, 19, 10 CONTROL "0,255,0", IDC_IOR_SPIN, "SpinnerControl", 0x0, 124, 57, 11, + 10 GROUPBOX "Reflection Dimming", IDC_REFL_BOX, 4, 72, 209, 27 CONTROL "Apply", IDC_DIM_REFL, "Button", + BS_AUTOCHECKBOX | WS_TABSTOP, 11, 83, 36, 10 LTEXT "Dim Level:", IDC_REFL_TEXT1, 52, 84, 33, 8, 0, + WS_EX_RIGHT CONTROL "", IDC_DIM_AMT, "CustEdit", WS_TABSTOP, 87, 83, 24, 10 CONTROL "0,255,0", IDC_DIM_AMTSPIN, + "SpinnerControl", 0x0, 112, 83, 11, 10 LTEXT "Refl. Level:", IDC_REFL_TEXT2, 132, 84, 38, 8 CONTROL "", + IDC_DIM_MULT, "CustEdit", WS_TABSTOP, 173, 83, 24, 10 CONTROL "0,255,0", IDC_DIM_MULTSPIN, "SpinnerControl", 0x0, + 198, 83, 11, 10 LTEXT "Amt:", IDC_OPAC_TEXT2, 12, 44, 16, 8 CONTROL "", IDC_TF_EDIT, "CustEdit", WS_TABSTOP, 28, 44, + 20, 10 CONTROL "0,255,0", IDC_TF_SPIN, "SpinnerControl", 0x0, 48, 44, 11, 10 END + + IDD_DMTL_XRAY DIALOGEX 0, + 0, 216, 50 STYLE DS_SETFONT | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN LTEXT "Engine Shader", IDC_STATIC, + 8, 7, 52, 8 COMBOBOX IDC_ESHADER, 63, 4, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_CSHADER, + 63, 19, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Compiler Shader", IDC_STATIC, 8, 22, 52, + 8 COMBOBOX IDC_GAMEMTL, 63, 34, 143, 75, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Game Material", + IDC_STATIC, 8, 37, 46, 8 END ///////////////////////////////////////////////////////////////////////////// // @@ -336,265 +176,126 @@ END // #ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_PANEL, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 101 - TOPMARGIN, 7 - END - - IDD_DMTL_SHADER4, DIALOG - BEGIN - VERTGUIDE, 8 - VERTGUIDE, 206 - END - - IDD_DMTL_EXTRA6, DIALOG - BEGIN - TOPMARGIN, 1 - END - - IDD_DMTL_XRAY, DIALOG - BEGIN - VERTGUIDE, 8 - VERTGUIDE, 206 - BOTTOMMARGIN, 46 - END -END -#endif // APSTUDIO_INVOKED + GUIDELINES DESIGNINFO BEGIN IDD_PANEL, + DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 101 TOPMARGIN, 7 END + IDD_DMTL_SHADER4, + DIALOG BEGIN VERTGUIDE, 8 VERTGUIDE, 206 END -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// + IDD_DMTL_EXTRA6, + DIALOG BEGIN TOPMARGIN, 1 END -1 TEXTINCLUDE -BEGIN - "XRayMtlRes.h\0" -END + IDD_DMTL_XRAY, + DIALOG BEGIN VERTGUIDE, 8 VERTGUIDE, 206 BOTTOMMARGIN, 46 END END +#endif // APSTUDIO_INVOKED -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END +#ifdef APSTUDIO_INVOKED + ///////////////////////////////////////////////////////////////////////////// + // + // TEXTINCLUDE + // -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END + 1 TEXTINCLUDE BEGIN "XRayMtlRes.h\0" END -#endif // APSTUDIO_INVOKED + 2 TEXTINCLUDE BEGIN "#include " + "afxres.h" + "\r\n" + "\0" END + 3 TEXTINCLUDE BEGIN "\r\n" + "\0" END -///////////////////////////////////////////////////////////////////////////// -// -// Version -// +#endif // APSTUDIO_INVOKED + + ///////////////////////////////////////////////////////////////////////////// + // + // Version + // -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,0,0,0 - PRODUCTVERSION 3,0,0,0 - FILEFLAGSMASK 0x3fL + VS_VERSION_INFO VERSIONINFO FILEVERSION 3, + 0, 0, 0 PRODUCTVERSION 3, 0, 0, 0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG - FILEFLAGS 0x1L + FILEFLAGS 0x1L #else - FILEFLAGS 0x0L + FILEFLAGS 0x0L #endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "TECH: " - VALUE "FileDescription", "Demo Material for testing" - VALUE "FileVersion", "4.0.0.0" - VALUE "InternalName", "DemoMtl" - VALUE "LegalTrademarks", "3D Studio MAX, Biped, Character Studio, Heidi, Kinetix and Physique are registered trademarks and 3ds max, combustion, Discreet, DWG Unplugged, DXF, FLI and FLC are trademarks of Autodesk, Inc." - VALUE "OriginalFilename", "DemoMtl.dlb" - VALUE "ProductName", "3ds max" - VALUE "ProductVersion", "4.0.0.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END + FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE + "Comments", + "TECH: " VALUE "FileDescription", "Demo Material for testing" VALUE "FileVersion", "4.0.0.0" VALUE "InternalName", + "DemoMtl" VALUE "LegalTrademarks", "3D Studio MAX, Biped, Character Studio, Heidi, Kinetix and Physique are " + "registered trademarks and 3ds max, combustion, Discreet, DWG Unplugged, DXF, " + "FLI and FLC are trademarks of Autodesk, Inc." VALUE "OriginalFilename", + "DemoMtl.dlb" VALUE "ProductName", "3ds max" VALUE "ProductVersion", + "4.0.0.0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END + ///////////////////////////////////////////////////////////////////////////// + // + // Bitmap + // -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// + IDB_DMTL_MASKBUTTONS BITMAP + "dmtlmsk.bmp" IDB_DMTL_BUTTONS BITMAP "dmtlbut.bmp" -IDB_DMTL_MASKBUTTONS BITMAP "dmtlmsk.bmp" -IDB_DMTL_BUTTONS BITMAP "dmtlbut.bmp" + ///////////////////////////////////////////////////////////////////////////// + // + // String Table + // -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// + STRINGTABLE BEGIN IDS_LIBDESCRIPTION "Demo Shader for testing" IDS_CATEGORY "XRay Game Material" IDS_CLASS_NAME + "XRayMtl" IDS_PARAMS "Parameters" IDS_SPIN "Spin" IDS_COMMENT "Appwizard generated Plugin" IDS_MN_DIFFUSE + "Diffuse" IDS_MN_BRIGHTNESS "Brightness" IDS_MN_OPACITY "Opacity" IDS_MN_NONE "None" IDS_COLOR + "Diffuse Color" IDS_PARAMCHG "Parameter Change" IDS_MN_DIFFUSE_I "Diffuse" IDS_MN_BRIGHTNESS_I + "Brightness" IDS_MN_OPACITY_I "Opacity" END -STRINGTABLE -BEGIN - IDS_LIBDESCRIPTION "Demo Shader for testing" - IDS_CATEGORY "XRay Game Material" - IDS_CLASS_NAME "XRayMtl" - IDS_PARAMS "Parameters" - IDS_SPIN "Spin" - IDS_COMMENT "Appwizard generated Plugin" - IDS_MN_DIFFUSE "Diffuse" - IDS_MN_BRIGHTNESS "Brightness" - IDS_MN_OPACITY "Opacity" - IDS_MN_NONE "None" - IDS_COLOR "Diffuse Color" - IDS_PARAMCHG "Parameter Change" - IDS_MN_DIFFUSE_I "Diffuse" - IDS_MN_BRIGHTNESS_I "Brightness" - IDS_MN_OPACITY_I "Opacity" -END - -STRINGTABLE -BEGIN - IDS_DS_DP "Displacement" - IDS_KE_STANDARD2 "Standard" - IDS_KE_SHADER "Shader Basic Parameters" -END - -STRINGTABLE -BEGIN - IDS_DS_WIREFRAME "Wire" - IDS_DS_SHIN_STR "Specular Level" - IDS_DS_OPACITY "Opacity" - IDS_JW_SHADERTYPE "Shader Type" - IDS_DS_EXTRA "Extended Parameters" - IDS_DS_TEXMAP "Maps" -END - -STRINGTABLE -BEGIN - IDS_JW_TWOSIDED "Two-sided" - IDS_JW_FACEMAP "Face Map" - IDS_JW_OPACITYTYPE "Opacity Type" - IDS_JW_FILTERMAP "Filter Map" - IDS_JW_FALLOFFTYPE "Falloff Type" - IDS_JW_WIREUNITS "Wire Units" - IDS_JW_APPLYREFDIM "Apply Reflection Dimming" - IDS_JW_PIXELSAMPLER "Pixel Sampler" - IDS_JW_SAMPLERQUAL "Sampler Quality" - IDS_JW_SAMPLERENABLE "Sampler Enable" -END - -STRINGTABLE -BEGIN - IDS_JW_MAPAMOUNTS "Map Amounts" - IDS_JW_ENABLE "Enable" - IDS_JW_AMOUNT "Amount" - IDS_JW_SHADERBYNAME "Shader Name" - IDS_JW_SAMPLERBYNAME "Sampler Name" -END - -STRINGTABLE -BEGIN - IDS_KE_FACETED "Faceted" - IDS_JW_ESHADERTYPE "EShader Type" - IDS_JW_CSHADERTYPE "CShader Type" - IDS_KE_SAMPLERADAPTTHRESH "Adaptive Threshold" - IDS_KE_SAMPLERADAPTON "Adaptive On" - IDS_KE_SAMPLERADVANCED "Advanced Options..." - IDS_JW_ESHADERBYNAME "EShader Name" - IDS_JW_CSHADERBYNAME "CShader Name" -END - -STRINGTABLE -BEGIN - IDS_KE_STANDARD2_CDESC "Standard" -END - -STRINGTABLE -BEGIN - IDS_DS_DYNAMICS "Dynamics Properties" - IDS_DS_BOUNCE "Bounce Coefficient" - IDS_DS_STATFRIC "Static Friction" - IDS_DS_SLIDFRIC "Sliding Friction" -END - -STRINGTABLE -BEGIN - IDS_JW_MAPENABLES "Map Enables" - IDS_DS_BU "Bump" - IDS_DS_RL "Reflection" - IDS_DS_RR "Refraction" - IDS_DS_TEXMAPS "Maps" - IDS_DS_FILTER "Filter Color" -END - -STRINGTABLE -BEGIN - IDS_DS_DIMLEV "Dim Level" - IDS_DS_DIMMULT "Reflection Level" -END - -STRINGTABLE -BEGIN - IDS_DS_FALLOFF "Falloff" -END - -STRINGTABLE -BEGIN - IDS_DS_WIRESZ "Wire Size" - IDS_DS_IOR "Index of Refraction" - IDS_JW_MAPS "Maps" -END - -STRINGTABLE -BEGIN - IDS_JW_ADTEXLOCK "Ambient-Diffuse Texture Lock" -END - -STRINGTABLE -BEGIN - IDS_KE_SAMPLING "SuperSampling" - IDS_KE_XRAY "X-Ray Params" - IDS_KE_NONE "None" -END - -STRINGTABLE -BEGIN - IDS_KE_SAMPLER_PARAM0 "Optional Param0" - IDS_KE_SAMPLER_PARAM1 "Optional Param1" -END - -STRINGTABLE -BEGIN - IDS_KE_SUBSAMPLE_TEX_ON "SubSample Textures" -END - -STRINGTABLE -BEGIN - IDS_DS_CLASSTEXMAPS "Texmaps" -END - -STRINGTABLE -BEGIN - IDS_DS_AMOUNT "Amount" - IDS_JW_GAMEMTLTYPE "Game Mtl Type" - IDS_JW_GAMEMTLBYNAME "Game Mtl Name" -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// + STRINGTABLE BEGIN IDS_DS_DP "Displacement" IDS_KE_STANDARD2 "Standard" IDS_KE_SHADER + "Shader Basic Parameters" END + + STRINGTABLE BEGIN IDS_DS_WIREFRAME "Wire" IDS_DS_SHIN_STR "Specular Level" IDS_DS_OPACITY + "Opacity" IDS_JW_SHADERTYPE "Shader Type" IDS_DS_EXTRA "Extended Parameters" IDS_DS_TEXMAP "Maps" END + + STRINGTABLE BEGIN IDS_JW_TWOSIDED "Two-sided" IDS_JW_FACEMAP "Face Map" IDS_JW_OPACITYTYPE + "Opacity Type" IDS_JW_FILTERMAP "Filter Map" IDS_JW_FALLOFFTYPE "Falloff Type" IDS_JW_WIREUNITS + "Wire Units" IDS_JW_APPLYREFDIM "Apply Reflection Dimming" IDS_JW_PIXELSAMPLER "Pixel Sampler" IDS_JW_SAMPLERQUAL + "Sampler Quality" IDS_JW_SAMPLERENABLE "Sampler Enable" END + + STRINGTABLE BEGIN IDS_JW_MAPAMOUNTS "Map Amounts" IDS_JW_ENABLE "Enable" IDS_JW_AMOUNT + "Amount" IDS_JW_SHADERBYNAME "Shader Name" IDS_JW_SAMPLERBYNAME "Sampler Name" END + + STRINGTABLE BEGIN IDS_KE_FACETED "Faceted" IDS_JW_ESHADERTYPE "EShader Type" IDS_JW_CSHADERTYPE + "CShader Type" IDS_KE_SAMPLERADAPTTHRESH "Adaptive Threshold" IDS_KE_SAMPLERADAPTON + "Adaptive On" IDS_KE_SAMPLERADVANCED "Advanced Options..." IDS_JW_ESHADERBYNAME "EShader Name" IDS_JW_CSHADERBYNAME + "CShader Name" END + + STRINGTABLE BEGIN IDS_KE_STANDARD2_CDESC "Standard" END + + STRINGTABLE BEGIN IDS_DS_DYNAMICS "Dynamics Properties" IDS_DS_BOUNCE "Bounce Coefficient" IDS_DS_STATFRIC + "Static Friction" IDS_DS_SLIDFRIC "Sliding Friction" END + + STRINGTABLE BEGIN IDS_JW_MAPENABLES "Map Enables" IDS_DS_BU "Bump" IDS_DS_RL "Reflection" IDS_DS_RR + "Refraction" IDS_DS_TEXMAPS "Maps" IDS_DS_FILTER "Filter Color" END + + STRINGTABLE BEGIN IDS_DS_DIMLEV "Dim Level" IDS_DS_DIMMULT "Reflection Level" END + STRINGTABLE BEGIN IDS_DS_FALLOFF "Falloff" END + STRINGTABLE BEGIN IDS_DS_WIRESZ "Wire Size" IDS_DS_IOR "Index of Refraction" IDS_JW_MAPS "Maps" END + + STRINGTABLE BEGIN IDS_JW_ADTEXLOCK "Ambient-Diffuse Texture Lock" END + + STRINGTABLE BEGIN IDS_KE_SAMPLING "SuperSampling" IDS_KE_XRAY "X-Ray Params" IDS_KE_NONE + "None" END + + STRINGTABLE BEGIN IDS_KE_SAMPLER_PARAM0 "Optional Param0" IDS_KE_SAMPLER_PARAM1 "Optional Param1" END + + STRINGTABLE BEGIN IDS_KE_SUBSAMPLE_TEX_ON "SubSample Textures" END + + STRINGTABLE BEGIN IDS_DS_CLASSTEXMAPS "Texmaps" END + + STRINGTABLE BEGIN IDS_DS_AMOUNT "Amount" IDS_JW_GAMEMTLTYPE "Game Mtl Type" IDS_JW_GAMEMTLBYNAME + "Game Mtl Name" END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -602,7 +303,5 @@ END // Generated from the TEXTINCLUDE 3 resource. // - ///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +#endif // not APSTUDIO_INVOKED diff --git a/src/plugins/Shared/Helper.cpp b/src/plugins/Shared/Helper.cpp index 717f9dbe844..c15e79a9f33 100644 --- a/src/plugins/Shared/Helper.cpp +++ b/src/plugins/Shared/Helper.cpp @@ -12,8 +12,8 @@ // Includes // //----------------------------------------------------------------------------// -#include "StdAfx.h" #include "Helper.h" +#include "StdAfx.h" //----------------------------------------------------------------------------// // Constructors // @@ -34,103 +34,106 @@ Helper::~Helper() //----------------------------------------------------------------------------// // Get the transformation matrix of a bone node // //----------------------------------------------------------------------------// -Matrix3 Helper::GetBoneTM(INode *pNode, TimeValue t) +Matrix3 Helper::GetBoneTM(INode* pNode, TimeValue t) { - // get node transformation - Matrix3 tm; - tm = pNode->GetNodeTM(t); + // get node transformation + Matrix3 tm; + tm = pNode->GetNodeTM(t); - // make transformation uniform - tm.NoScale(); + // make transformation uniform + tm.NoScale(); - return tm; + return tm; } //----------------------------------------------------------------------------// // Check if the given node is a biped bone // //----------------------------------------------------------------------------// -BOOL Helper::IsBipedBone(INode *pNode) +BOOL Helper::IsBipedBone(INode* pNode) { - // check for invalid and root nodes - if((pNode == 0) || pNode->IsRootNode()) return false; + // check for invalid and root nodes + if ((pNode == 0) || pNode->IsRootNode()) return false; - // check for biped nodes - Control *pControl; - pControl = pNode->GetTMController(); - if((pControl->ClassID() == BIPSLAVE_CONTROL_CLASS_ID) || (pControl->ClassID() == BIPBODY_CONTROL_CLASS_ID)) return true; + // check for biped nodes + Control* pControl; + pControl = pNode->GetTMController(); + if ((pControl->ClassID() == BIPSLAVE_CONTROL_CLASS_ID) || (pControl->ClassID() == BIPBODY_CONTROL_CLASS_ID)) + return true; - return false; + return false; } //----------------------------------------------------------------------------// // Check if the given node is a bone // //----------------------------------------------------------------------------// -BOOL Helper::IsBone (INode *pNode, BOOL bAllowDummy) +BOOL Helper::IsBone(INode* pNode, BOOL bAllowDummy) { - // check for invalid nodes - if(pNode == 0) return false; - - // check for root node - if(pNode->IsRootNode()) return false; - - // check for bone node - ObjectState os; - os = pNode->EvalWorldState(0); - if(os.obj->ClassID() == Class_ID(BONE_CLASS_ID, 0)) return true; - if(os.obj->ClassID() == BONE_OBJ_CLASSID) return true; - if(os.obj->ClassID() == Class_ID(DUMMY_CLASS_ID, 0)) - return bAllowDummy; - - // check for biped node - Control *pControl; - pControl = pNode->GetTMController(); - if((pControl->ClassID() == BIPSLAVE_CONTROL_CLASS_ID) || (pControl->ClassID() == BIPBODY_CONTROL_CLASS_ID)) return true; - return false; + // check for invalid nodes + if (pNode == 0) return false; + + // check for root node + if (pNode->IsRootNode()) return false; + + // check for bone node + ObjectState os; + os = pNode->EvalWorldState(0); + if (os.obj->ClassID() == Class_ID(BONE_CLASS_ID, 0)) return true; + if (os.obj->ClassID() == BONE_OBJ_CLASSID) return true; + if (os.obj->ClassID() == Class_ID(DUMMY_CLASS_ID, 0)) return bAllowDummy; + + // check for biped node + Control* pControl; + pControl = pNode->GetTMController(); + if ((pControl->ClassID() == BIPSLAVE_CONTROL_CLASS_ID) || (pControl->ClassID() == BIPBODY_CONTROL_CLASS_ID)) + return true; + return false; } //----------------------------------------------------------------------------// // Check if the given node is a mesh // //----------------------------------------------------------------------------// -BOOL Helper::IsMesh(INode *pNode) +BOOL Helper::IsMesh(INode* pNode) { - // check for invalid and root nodes - if((pNode == 0) || pNode->IsRootNode()) return false; + // check for invalid and root nodes + if ((pNode == 0) || pNode->IsRootNode()) return false; - // check for mesh - ObjectState os; - os = pNode->EvalWorldState(0); - if(os.obj->SuperClassID() == GEOMOBJECT_CLASS_ID) return true; + // check for mesh + ObjectState os; + os = pNode->EvalWorldState(0); + if (os.obj->SuperClassID() == GEOMOBJECT_CLASS_ID) return true; - return false; + return false; } //----------------------------------------------------------------------------// // Set/Unset biped uniform scale // //----------------------------------------------------------------------------// -void Helper::SetBipedUniform(INode *pNode, BOOL bUniform, BOOL bFigure) +void Helper::SetBipedUniform(INode* pNode, BOOL bUniform, BOOL bFigure) { - if(IsBipedBone(pNode)){ - // get the TM controller of the node - Control *pControl; - pControl = pNode->GetTMController(); - - // get the biped export interface - IBipedExport *pBipedExport; - pBipedExport = (IBipedExport *)pControl->GetInterface(I_BIPINTERFACE); - - // remove/add uniform scale - pBipedExport->RemoveNonUniformScale (bUniform); - if (bFigure) pBipedExport->BeginFigureMode (0); - else pBipedExport->EndFigureMode (0); - - // notify all dependents - Control *pMasterControl; - pMasterControl = (Control *)pControl->GetInterface(I_MASTER); - pMasterControl->NotifyDependents(FOREVER, PART_TM, REFMSG_CHANGE); - pControl->ReleaseInterface(I_MASTER, pMasterControl); - - // release the biped export interface - pControl->ReleaseInterface(I_BIPINTERFACE, pBipedExport); - } + if (IsBipedBone(pNode)) { + // get the TM controller of the node + Control* pControl; + pControl = pNode->GetTMController(); + + // get the biped export interface + IBipedExport* pBipedExport; + pBipedExport = (IBipedExport*)pControl->GetInterface(I_BIPINTERFACE); + + // remove/add uniform scale + pBipedExport->RemoveNonUniformScale(bUniform); + if (bFigure) + pBipedExport->BeginFigureMode(0); + else + pBipedExport->EndFigureMode(0); + + // notify all dependents + Control* pMasterControl; + pMasterControl = (Control*)pControl->GetInterface(I_MASTER); + pMasterControl->NotifyDependents(FOREVER, PART_TM, REFMSG_CHANGE); + pControl->ReleaseInterface(I_MASTER, pMasterControl); + + // release the biped export interface + pControl->ReleaseInterface(I_BIPINTERFACE, pBipedExport); + } } diff --git a/src/plugins/Shared/Helper.h b/src/plugins/Shared/Helper.h index c88edee1ef9..cf7e5c04d0b 100644 --- a/src/plugins/Shared/Helper.h +++ b/src/plugins/Shared/Helper.h @@ -16,9 +16,9 @@ //----------------------------------------------------------------------------// // this is the class for all biped controllers except the root and the footsteps -#define BIPSLAVE_CONTROL_CLASS_ID Class_ID(0x9154,0) +#define BIPSLAVE_CONTROL_CLASS_ID Class_ID(0x9154, 0) // this is the class for the center of mass, biped root controller ("Bip01") -#define BIPBODY_CONTROL_CLASS_ID Class_ID(0x9156,0) +#define BIPBODY_CONTROL_CLASS_ID Class_ID(0x9156, 0) //----------------------------------------------------------------------------// // Class declaration // @@ -26,60 +26,61 @@ class Helper { -// constructors/destructor + // constructors/destructor protected: - Helper (); - virtual ~Helper (); + Helper(); + virtual ~Helper(); -// member functions + // member functions public: - static Matrix3 GetBoneTM (INode *pNode, TimeValue t); - static BOOL IsBipedBone (INode *pNode); - static BOOL IsBone (INode *pNode, BOOL bAllowDummy); - static BOOL IsMesh (INode *pNode); - static void SetBipedUniform (INode *pNode, BOOL bUniform, BOOL bFigure); - static IC string ConvertSpace (string input) - { - string result = ""; - for (DWORD i=0; iUpdate(t,ivalid); - if (amtCtrl) { - amtCtrl->GetValue(t,&amount,ivalid); - } - } - -float TexmapSlot::GetAmount(TimeValue t) { - Interval v; - float f; - if (amtCtrl) { - amtCtrl->GetValue(t,&f,v); - return f; - } - else return amount; - } - -Texmaps::Texmaps() { - loadingOld = FALSE; - client = NULL; - } - - -Texmaps::Texmaps(MtlBase *mb) { - loadingOld = FALSE; - client = mb; - } - -SvGraphNodeReference Texmaps::SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags) - { - int i, nUsedSlots; - - if (!gom->TestFilter(SV_FILTER_MAPS)) - return SvGraphNodeReference(); - - nUsedSlots = 0; - for (i = 0; i < STD2_NMAX_TEXMAPS; i++) - if (txmap[i].map) - nUsedSlots++; - - if (nUsedSlots) - return SvStdTraverseAnimGraph(gom, owner, id, flags); - else - return SvGraphNodeReference(); - } +class OldTexmapsClassDesc : public ClassDesc +{ +public: + int IsPublic() { return 0; } + void* Create(BOOL loading) { return new Texmaps((MtlBase*)NULL); } + const TCHAR* ClassName() { return GetString(IDS_DS_CLASSTEXMAPS); } + SClass_ID SuperClassID() { return REF_MAKER_CLASS_ID; } + Class_ID ClassID() { return TexmapsClassID; } + const TCHAR* Category() { return _T(""); } +}; + +class TexmapsClassDesc : public ClassDesc +{ +public: + int IsPublic() { return 0; } + void* Create(BOOL loading) { return new Texmaps((MtlBase*)NULL); } + const TCHAR* ClassName() { return GetString(IDS_DS_CLASSTEXMAPS); } + SClass_ID SuperClassID() { return TEXMAP_CONTAINER_CLASS_ID; } + Class_ID ClassID() { return TexmapsClassID; } + const TCHAR* Category() { return _T(""); } +}; + +TexmapSlot::TexmapSlot() +{ + amount = 1.0f; + map = NULL; + mapOn = FALSE; + amtCtrl = NULL; +} + +void TexmapSlot::Update(TimeValue t, Interval& ivalid) +{ + if (IsActive()) map->Update(t, ivalid); + if (amtCtrl) { + amtCtrl->GetValue(t, &amount, ivalid); + } +} + +float TexmapSlot::GetAmount(TimeValue t) +{ + Interval v; + float f; + if (amtCtrl) { + amtCtrl->GetValue(t, &f, v); + return f; + } + else + return amount; +} + +Texmaps::Texmaps() +{ + loadingOld = FALSE; + client = NULL; +} + +Texmaps::Texmaps(MtlBase* mb) +{ + loadingOld = FALSE; + client = mb; +} + +SvGraphNodeReference Texmaps::SvTraverseAnimGraph(IGraphObjectManager* gom, Animatable* owner, int id, DWORD flags) +{ + int i, nUsedSlots; + + if (!gom->TestFilter(SV_FILTER_MAPS)) return SvGraphNodeReference(); + + nUsedSlots = 0; + for (i = 0; i < STD2_NMAX_TEXMAPS; i++) + if (txmap[i].map) nUsedSlots++; + + if (nUsedSlots) + return SvStdTraverseAnimGraph(gom, owner, id, flags); + else + return SvGraphNodeReference(); +} static TexmapsClassDesc texmapsCD; -ClassDesc* GetTexmapsDesc() { return &texmapsCD; } +ClassDesc* GetTexmapsDesc() +{ + return &texmapsCD; +} static OldTexmapsClassDesc oldtexmapsCD; -ClassDesc* GetOldTexmapsDesc() { return &oldtexmapsCD; } - -Class_ID Texmaps::ClassID() { return TexmapsClassID; } - -int Texmaps::NumSubs() { return STD2_NMAX_TEXMAPS*2; } - -int Texmaps::NumRefs() { return STD2_NMAX_TEXMAPS*2; } - -Animatable* Texmaps::SubAnim(int i) { - if (i&1) - return txmap[i/2].map; - else - return txmap[i/2].amtCtrl; - } - -TSTR Texmaps::SubAnimName(int i) { - if (i&1) - return client->GetSubTexmapTVName(i/2); - else { - TSTR nm; -// nm = GetString(texNameID[i/2]); -// nm = textureChannelNames[ i/2 ]; - nm = txmap[ i/2 ].name; - nm += TSTR(" "); - nm += TSTR(GetString(IDS_DS_AMOUNT)); - return nm; - } - } - -RefTargetHandle Texmaps::GetReference(int i) { - if (i&1) - return txmap[i/2].map; - else - return txmap[i/2].amtCtrl; - } - -void Texmaps::SetReference(int i, RefTargetHandle rtarg) { - if (loadingOld) - txmap[i].map = (Texmap*)rtarg; - else { - if (i&1) - txmap[i/2].map = (Texmap*)rtarg; - else - txmap[i/2].amtCtrl = (Control*)rtarg; - } - } - -void Texmaps::DeleteThis() { xr_delete((Texmaps*)this);} - -RefResult Texmaps::NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, - PartID& partID, RefMessage message ) { - switch (message) { - case REFMSG_GET_PARAM_DIM: { - GetParamDim *gpd = (GetParamDim*)partID; - gpd->dim = defaultDim; - break; - } - case REFMSG_GET_PARAM_NAME: { - GetParamName *gpn = (GetParamName*)partID; - return REF_STOP; - } - } - return(REF_SUCCEED); - } - -void Texmaps::RescaleWorldUnits(float f) { - if (TestAFlag(A_WORK1)) - return; - SetAFlag(A_WORK1); - // This code will be replaced in particular implementations - for (int i=0; iRescaleWorldUnits(f); - } - } - - } - -RefTargetHandle Texmaps::Clone(RemapDir &remap) { - Texmaps *tm = new Texmaps((MtlBase*)NULL); - for (int i = 0; itxmap[i].amount = txmap[i].amount; - tm->txmap[i].mapOn = txmap[i].mapOn; - tm->txmap[i].map = NULL; - if (txmap[i].amtCtrl) - tm->ReplaceReference(2*i,remap.CloneRef(txmap[i].amtCtrl)); - if (txmap[i].map) - tm->ReplaceReference(2*i+1,remap.CloneRef(txmap[i].map)); - } - BaseClone(this, tm, remap); - return tm; - } +ClassDesc* GetOldTexmapsDesc() +{ + return &oldtexmapsCD; +} + +Class_ID Texmaps::ClassID() +{ + return TexmapsClassID; +} + +int Texmaps::NumSubs() +{ + return STD2_NMAX_TEXMAPS * 2; +} + +int Texmaps::NumRefs() +{ + return STD2_NMAX_TEXMAPS * 2; +} + +Animatable* Texmaps::SubAnim(int i) +{ + if (i & 1) + return txmap[i / 2].map; + else + return txmap[i / 2].amtCtrl; +} + +TSTR Texmaps::SubAnimName(int i) +{ + if (i & 1) + return client->GetSubTexmapTVName(i / 2); + else + { + TSTR nm; + // nm = GetString(texNameID[i/2]); + // nm = textureChannelNames[ i/2 ]; + nm = txmap[i / 2].name; + nm += TSTR(" "); + nm += TSTR(GetString(IDS_DS_AMOUNT)); + return nm; + } +} + +RefTargetHandle Texmaps::GetReference(int i) +{ + if (i & 1) + return txmap[i / 2].map; + else + return txmap[i / 2].amtCtrl; +} + +void Texmaps::SetReference(int i, RefTargetHandle rtarg) +{ + if (loadingOld) + txmap[i].map = (Texmap*)rtarg; + else + { + if (i & 1) + txmap[i / 2].map = (Texmap*)rtarg; + else + txmap[i / 2].amtCtrl = (Control*)rtarg; + } +} + +void Texmaps::DeleteThis() +{ + xr_delete((Texmaps*)this); +} + +RefResult Texmaps::NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message) +{ + switch (message) + { + case REFMSG_GET_PARAM_DIM: + { + GetParamDim* gpd = (GetParamDim*)partID; + gpd->dim = defaultDim; + break; + } + case REFMSG_GET_PARAM_NAME: + { + GetParamName* gpn = (GetParamName*)partID; + return REF_STOP; + } + } + return (REF_SUCCEED); +} + +void Texmaps::RescaleWorldUnits(float f) +{ + if (TestAFlag(A_WORK1)) return; + SetAFlag(A_WORK1); + // This code will be replaced in particular implementations + for (int i = 0; i < NumRefs(); i++) + { + if ((i & 1) == 0) continue; // skip the amount controllers + ReferenceMaker* srm = GetReference(i); + if (srm) { + srm->RescaleWorldUnits(f); + } + } +} + +RefTargetHandle Texmaps::Clone(RemapDir& remap) +{ + Texmaps* tm = new Texmaps((MtlBase*)NULL); + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + tm->txmap[i].amount = txmap[i].amount; + tm->txmap[i].mapOn = txmap[i].mapOn; + tm->txmap[i].map = NULL; + if (txmap[i].amtCtrl) tm->ReplaceReference(2 * i, remap.CloneRef(txmap[i].amtCtrl)); + if (txmap[i].map) tm->ReplaceReference(2 * i + 1, remap.CloneRef(txmap[i].map)); + } + BaseClone(this, tm, remap); + return tm; +} #define TEX_OLD_ONOFF_CHUNK 0x5002 #define TEX_ONOFF_CHUNK 0x5003 @@ -209,65 +238,78 @@ RefTargetHandle Texmaps::Clone(RemapDir &remap) { #define TEX_AMTE 0x510E #define TEX_AMTF 0x510F -IOResult Texmaps::Save(ISave *isave) { - isave->BeginChunk(TEX_ONOFF_CHUNK); - ULONG nb,f=0; - for ( int i=0; iWrite(&f,sizeof(f),&nb); - isave->EndChunk(); - - for (int i=0; iBeginChunk(TEX_AMT0+i); - isave->Write(&txmap[i].amount,sizeof(float),&nb); - isave->EndChunk(); - } - } - return IO_OK; - } - -class TexmapsPostLoad : public PostLoadCallback { - public: - Texmaps *tm; - TexmapsPostLoad(Texmaps *b) {tm=b;} - void proc(ILoad *iload) { tm->loadingOld = FALSE; xr_delete((TexmapsPostLoad*)this); } - }; - - -IOResult Texmaps::Load(ILoad *iload) { - ULONG nb; - int id; - IOResult res; - while (IO_OK==(res=iload->OpenChunk())) { - switch(id = iload->CurChunkID()) { - case TEX_OLD_ONOFF_CHUNK: - iload->SetObsolete(); - iload->RegisterPostLoadCallback(new TexmapsPostLoad(this)); - loadingOld = TRUE; - case TEX_ONOFF_CHUNK: - { - ULONG f; - res = iload->Read(&f,sizeof(f), &nb); - for (int i=0; iRead(&txmap[id-TEX_AMT0].amount,sizeof(float), &nb); - break; - } - iload->CloseChunk(); - if (res!=IO_OK) - return res; - } - return IO_OK; - - } +IOResult Texmaps::Save(ISave* isave) +{ + isave->BeginChunk(TEX_ONOFF_CHUNK); + ULONG nb, f = 0; + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + if (txmap[i].mapOn) f |= (1 << i); + isave->Write(&f, sizeof(f), &nb); + isave->EndChunk(); + + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + { + if (txmap[i].amount != 1.0f) { + isave->BeginChunk(TEX_AMT0 + i); + isave->Write(&txmap[i].amount, sizeof(float), &nb); + isave->EndChunk(); + } + } + return IO_OK; +} + +class TexmapsPostLoad : public PostLoadCallback +{ +public: + Texmaps* tm; + TexmapsPostLoad(Texmaps* b) { tm = b; } + void proc(ILoad* iload) + { + tm->loadingOld = FALSE; + xr_delete((TexmapsPostLoad*)this); + } +}; + +IOResult Texmaps::Load(ILoad* iload) +{ + ULONG nb; + int id; + IOResult res; + while (IO_OK == (res = iload->OpenChunk())) + { + switch (id = iload->CurChunkID()) + { + case TEX_OLD_ONOFF_CHUNK: + iload->SetObsolete(); + iload->RegisterPostLoadCallback(new TexmapsPostLoad(this)); + loadingOld = TRUE; + case TEX_ONOFF_CHUNK: + { + ULONG f; + res = iload->Read(&f, sizeof(f), &nb); + for (int i = 0; i < STD2_NMAX_TEXMAPS; i++) + txmap[i].mapOn = (f & (1 << i)) ? 1 : 0; + } + break; + case TEX_AMT0: + case TEX_AMT1: + case TEX_AMT2: + case TEX_AMT3: + case TEX_AMT4: + case TEX_AMT5: + case TEX_AMT6: + case TEX_AMT7: + case TEX_AMT8: + case TEX_AMT9: + case TEX_AMTA: + case TEX_AMTB: + case TEX_AMTC: + case TEX_AMTD: + case TEX_AMTE: + case TEX_AMTF: res = iload->Read(&txmap[id - TEX_AMT0].amount, sizeof(float), &nb); break; + } + iload->CloseChunk(); + if (res != IO_OK) return res; + } + return IO_OK; +} diff --git a/src/plugins/Shared/TexMaps.h b/src/plugins/Shared/TexMaps.h index d703fff7100..d9baedf7a62 100644 --- a/src/plugins/Shared/TexMaps.h +++ b/src/plugins/Shared/TexMaps.h @@ -3,107 +3,105 @@ //----------------------------------------------------------------------------- #define MAPACTIVE(i) ((*maps)[i].IsActive()) -#define MAX_TEXTURE_CHANNELS 32 - - -class TexmapSlot { - public: - float amount; - Control *amtCtrl; // ref to controller - Texmap *map; // ref to map - BOOL mapOn; - TSTR name; - - TexmapSlot(); - RGBA Eval(ShadeContext& sc) { - return amount * map->EvalColor(sc); - } - float EvalMono(ShadeContext& sc) { - return amount * map->EvalMono(sc); - } - float LerpEvalMono(ShadeContext& sc, float v) { - if( amount<0.0f ){ - float b = 1.0f + amount; - if ( b < 0.0f ) b = 0.0f; - return -amount * (1.0f - map->EvalMono(sc)) + b*v; - } else { - float b = 1.0f - amount; - if ( b < 0.0f ) b = 0.0f; - return amount * map->EvalMono(sc) + b*v; - } -// float b = 1.0f - (amount<0.0f ? -amount : amount); -// if ( b < 0.0f ) b = 0.0f; -// return amount * map->EvalMono(sc) + b*v; - } - -// begin - ke/mjm - 03.16.00 - merge reshading code - float LerpMono( float origVal, float texVal ) // for reShading, no eval - { - if( amount<0.0f ) - { - float b = 1.0f + amount; - if ( b < 0.0f ) b = 0.0f; - return -amount * texVal + b * (1.0f - origVal); - } else { - float b = 1.0f - amount; - if ( b < 0.0f ) b = 0.0f; - return amount * texVal + b * origVal; - } - } -// end - ke/mjm - 03.16.00 - merge reshading code - - Point3 EvalNormalPerturb(ShadeContext &sc) { - return amount * map->EvalNormalPerturb(sc); - } - BOOL IsActive() { return (map&&mapOn&&(amtCtrl||amount!=0.0f)); } - void Update(TimeValue t, Interval &ivalid); - float GetAmount(TimeValue t); +#define MAX_TEXTURE_CHANNELS 32 + +class TexmapSlot +{ +public: + float amount; + Control* amtCtrl; // ref to controller + Texmap* map; // ref to map + BOOL mapOn; + TSTR name; + + TexmapSlot(); + RGBA Eval(ShadeContext& sc) { return amount * map->EvalColor(sc); } + float EvalMono(ShadeContext& sc) { return amount * map->EvalMono(sc); } + float LerpEvalMono(ShadeContext& sc, float v) + { + if (amount < 0.0f) { + float b = 1.0f + amount; + if (b < 0.0f) b = 0.0f; + return -amount * (1.0f - map->EvalMono(sc)) + b * v; + } + else + { + float b = 1.0f - amount; + if (b < 0.0f) b = 0.0f; + return amount * map->EvalMono(sc) + b * v; + } + // float b = 1.0f - (amount<0.0f ? -amount : amount); + // if ( b < 0.0f ) b = 0.0f; + // return amount * map->EvalMono(sc) + b*v; + } + + // begin - ke/mjm - 03.16.00 - merge reshading code + float LerpMono(float origVal, float texVal) // for reShading, no eval + { + if (amount < 0.0f) { + float b = 1.0f + amount; + if (b < 0.0f) b = 0.0f; + return -amount * texVal + b * (1.0f - origVal); + } + else + { + float b = 1.0f - amount; + if (b < 0.0f) b = 0.0f; + return amount * texVal + b * origVal; + } + } + // end - ke/mjm - 03.16.00 - merge reshading code + + Point3 EvalNormalPerturb(ShadeContext& sc) { return amount * map->EvalNormalPerturb(sc); } + BOOL IsActive() { return (map && mapOn && (amtCtrl || amount != 0.0f)); } + void Update(TimeValue t, Interval& ivalid); + float GetAmount(TimeValue t); }; - -class Texmaps: public TexmapContainer { - public: - MtlBase *client; - TexmapSlot txmap[32]; - BOOL loadingOld; - - Texmaps(); - Texmaps(MtlBase *mb); - void SetClientPtr(MtlBase *mb) { client = mb; } - TexmapSlot& operator[](int i) { return txmap[i]; } - - Class_ID ClassID(); - - void DeleteThis(); - RefTargetHandle Clone(RemapDir &remap = NoRemap()); - RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget, - PartID& partID, RefMessage message ); - - void RescaleWorldUnits(float f); - - BOOL AssignController(Animatable *control,int subAnim) { - ReplaceReference(SubNumToRefNum(subAnim),(ReferenceTarget *)control); - return TRUE; - } - - int NumSubs(); - Animatable* SubAnim(int i); - TSTR SubAnimName(int i); - int SubNumToRefNum(int subNum) {return subNum; } - BOOL InvisibleProperty() { return TRUE; } // maps are made visible in scripter by pb_maps paramblock in the material so don't expose them as a subanim - -// int NumRefs() { return STD2_NMAX_TEXMAPS*2; } - int NumRefs(); - RefTargetHandle GetReference(int i); - void SetReference(int i, RefTargetHandle rtarg); - - // IO - IOResult Save(ISave *isave); - IOResult Load(ILoad *iload); - - void SetName( long i, TSTR& nm ){txmap[i].name = nm; } - TSTR& GetName( long i ){return txmap[i].name; } - SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager *gom, Animatable *owner, int id, DWORD flags); - }; - - +class Texmaps : public TexmapContainer +{ +public: + MtlBase* client; + TexmapSlot txmap[32]; + BOOL loadingOld; + + Texmaps(); + Texmaps(MtlBase* mb); + void SetClientPtr(MtlBase* mb) { client = mb; } + TexmapSlot& operator[](int i) { return txmap[i]; } + Class_ID ClassID(); + + void DeleteThis(); + RefTargetHandle Clone(RemapDir& remap = NoRemap()); + RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message); + + void RescaleWorldUnits(float f); + + BOOL AssignController(Animatable* control, int subAnim) + { + ReplaceReference(SubNumToRefNum(subAnim), (ReferenceTarget*)control); + return TRUE; + } + + int NumSubs(); + Animatable* SubAnim(int i); + TSTR SubAnimName(int i); + int SubNumToRefNum(int subNum) { return subNum; } + BOOL InvisibleProperty() + { + return TRUE; + } // maps are made visible in scripter by pb_maps paramblock in the material so don't expose them as a subanim + + // int NumRefs() { return STD2_NMAX_TEXMAPS*2; } + int NumRefs(); + RefTargetHandle GetReference(int i); + void SetReference(int i, RefTargetHandle rtarg); + + // IO + IOResult Save(ISave* isave); + IOResult Load(ILoad* iload); + + void SetName(long i, TSTR& nm) { txmap[i].name = nm; } + TSTR& GetName(long i) { return txmap[i].name; } + SvGraphNodeReference SvTraverseAnimGraph(IGraphObjectManager* gom, Animatable* owner, int id, DWORD flags); +}; diff --git a/src/plugins/Shared/Vert.h b/src/plugins/Shared/Vert.h index 6d0ee57533d..baa959d0fe6 100644 --- a/src/plugins/Shared/Vert.h +++ b/src/plugins/Shared/Vert.h @@ -1,63 +1,65 @@ #pragma once -const u32 BONE_NONE = 0xffffffff; +const u32 BONE_NONE = 0xffffffff; -struct SVertexData{ - u32 bone; - float weight; - SVertexData (u32 b, float w):bone(b),weight(w){;} +struct SVertexData +{ + u32 bone; + float weight; + SVertexData(u32 b, float w) : bone(b), weight(w) { ; } }; -DEFINE_VECTOR(SVertexData,VDVec,VDIt); +DEFINE_VECTOR(SVertexData, VDVec, VDIt); class CVertexDef { public: - Fvector P; - VDVec data; + Fvector P; + VDVec data; + public: - CVertexDef () {ZeroMemory(this,sizeof(this));} - void SetPosition (Point3 &p) {P.set(p.x,p.z,p.y);} - void Append (u32 bone, float weight) - { - data.push_back(SVertexData(bone,weight)); - } + CVertexDef() { ZeroMemory(this, sizeof(this)); } + void SetPosition(Point3& p) { P.set(p.x, p.z, p.y); } + void Append(u32 bone, float weight) { data.push_back(SVertexData(bone, weight)); } }; -DEFINE_VECTOR(CVertexDef*,VertexDefVec,VertexDefIt); +DEFINE_VECTOR(CVertexDef*, VertexDefVec, VertexDefIt); + +struct st_VERT +{ + Fvector P; + // u32 sm_group; + Fvector2 uv; + VDVec data; -struct st_VERT { - Fvector P; -// u32 sm_group; - Fvector2 uv; - VDVec data; public: - st_VERT() - { - P.set (0,0,0); - uv.set (0.f,0.f); - } - void Set (const CVertexDef& D) - { - R_ASSERT (data.empty()); - data = D.data; - } - - void SetUV(float _u, float _v) - { - uv.x = _u; uv.y = _v; - } - BOOL similar(const st_VERT& V) const - { - if (data.size()!=V.data.size()) return FALSE; - if (!uv.similar (V.uv)) return FALSE; - if (!P.similar (V.P)) return FALSE; -// if ((0==sm_group)||(0==(sm_group&V.sm_group))) return FALSE; - for (u32 k=0; kverts[0]); - parent.transform_tiny(verts[1],r->verts[1]); - parent.transform_tiny(verts[2],r->verts[2]); - u = r->u; - v = r->v; - range = r->range; - tag = r->dummy; - e_obj = obj; - e_mesh = mesh; - } - SResult (CDB::RESULT* r, CEditableObject* obj, CEditableMesh* mesh) - { - verts[0] = r->verts[0]; - verts[1] = r->verts[1]; - verts[2] = r->verts[2]; - u = r->u; - v = r->v; - range = r->range; - tag = r->dummy; - e_obj = obj; - e_mesh = mesh; - } - }; - DEFINE_VECTOR(SResult,ResultVec,ResultIt); - protected: - ResultVec results; +class SPickQuery +{ + Flags32 m_Flags; + +public: + Fvector m_Start; + Fvector m_Direction; + float m_Dist; + Fbox m_BB; + +public: + class SResult + { public: - IC void prepare_rq (const Fvector& start, const Fvector& dir, float dist, u32 flags) - { - m_Start.set (start); - m_Direction.set (dir); - m_Dist = dist; - m_Flags.assign (flags); - results.clear (); - } - IC void prepare_bq (const Fbox& bbox, u32 flags) - { - m_BB.set (bbox); - m_Flags.assign (flags); - results.clear (); - } - IC void append_mtx (const Fmatrix& parent, CDB::RESULT* R, CEditableObject* obj, CEditableMesh* mesh) - { - SResult D (parent, R, obj, mesh); - if (m_Flags.is(CDB::OPT_ONLYNEAREST)&&!results.empty()){ - SResult& S = results.back(); - if (D.rangeverts[0]); + parent.transform_tiny(verts[1], r->verts[1]); + parent.transform_tiny(verts[2], r->verts[2]); + u = r->u; + v = r->v; + range = r->range; + tag = r->dummy; + e_obj = obj; + e_mesh = mesh; } - IC SResult* r_end () + SResult(CDB::RESULT* r, CEditableObject* obj, CEditableMesh* mesh) { - return results.end(); + verts[0] = r->verts[0]; + verts[1] = r->verts[1]; + verts[2] = r->verts[2]; + u = r->u; + v = r->v; + range = r->range; + tag = r->dummy; + e_obj = obj; + e_mesh = mesh; } - IC void r_clear () - { - results.clear (); + }; + DEFINE_VECTOR(SResult, ResultVec, ResultIt); + +protected: + ResultVec results; + +public: + IC void prepare_rq(const Fvector& start, const Fvector& dir, float dist, u32 flags) + { + m_Start.set(start); + m_Direction.set(dir); + m_Dist = dist; + m_Flags.assign(flags); + results.clear(); + } + IC void prepare_bq(const Fbox& bbox, u32 flags) + { + m_BB.set(bbox); + m_Flags.assign(flags); + results.clear(); + } + IC void append_mtx(const Fmatrix& parent, CDB::RESULT* R, CEditableObject* obj, CEditableMesh* mesh) + { + SResult D(parent, R, obj, mesh); + if (m_Flags.is(CDB::OPT_ONLYNEAREST) && !results.empty()) { + SResult& S = results.back(); + if (D.range < S.range) S = D; } - IC void r_sort () - { - std::sort (results.begin(),results.end()); + else + results.push_back(D); + } + IC void append(CDB::RESULT* R, CEditableObject* obj, CEditableMesh* mesh) + { + SResult D(R, obj, mesh); + if (m_Flags.is(CDB::OPT_ONLYNEAREST) && !results.empty()) { + SResult& S = results.back(); + if (D.range < S.range) S = D; } - }; - struct SRayPickInfo{ - CDB::RESULT inf; - CCustomObject* s_obj; - CEditableObject* e_obj; - CEditableMesh* e_mesh; - Fvector pt; - SRayPickInfo (){Reset();} - IC void Reset (){ ZeroMemory(this,sizeof(SRayPickInfo));inf.range = 5000;} - IC void SetRESULT (CDB::MODEL* M, CDB::RESULT* R){inf=*R;inf.id=(M->get_tris()+inf.id)->dummy;} - }; - DEFINE_VECTOR(CDB::RESULT,BPInfVec,BPInfIt); - struct SBoxPickInfo{ - BPInfVec inf; - CCustomObject* s_obj; - CEditableObject* e_obj; - CEditableMesh* e_mesh; - SBoxPickInfo (){Reset();} - IC void Reset (){ZeroMemory(this,sizeof(SBoxPickInfo));} - IC void AddRESULT (CDB::MODEL* M, CDB::RESULT* R){inf.push_back(*R); inf.back().id=(M->get_tris()+inf.back().id)->dummy;} - }; - DEFINE_VECTOR(SBoxPickInfo,SBoxPickInfoVec,SBoxPickInfoIt); + else + results.push_back(D); + } + IC int r_count() { return results.size(); } + IC SResult* r_begin() { return results.begin(); } + IC SResult* r_end() { return results.end(); } + IC void r_clear() { results.clear(); } + IC void r_sort() { std::sort(results.begin(), results.end()); } +}; +struct SRayPickInfo +{ + CDB::RESULT inf; + CCustomObject* s_obj; + CEditableObject* e_obj; + CEditableMesh* e_mesh; + Fvector pt; + SRayPickInfo() { Reset(); } + IC void Reset() + { + ZeroMemory(this, sizeof(SRayPickInfo)); + inf.range = 5000; + } + IC void SetRESULT(CDB::MODEL* M, CDB::RESULT* R) + { + inf = *R; + inf.id = (M->get_tris() + inf.id)->dummy; + } +}; +DEFINE_VECTOR(CDB::RESULT, BPInfVec, BPInfIt); +struct SBoxPickInfo +{ + BPInfVec inf; + CCustomObject* s_obj; + CEditableObject* e_obj; + CEditableMesh* e_mesh; + SBoxPickInfo() { Reset(); } + IC void Reset() { ZeroMemory(this, sizeof(SBoxPickInfo)); } + IC void AddRESULT(CDB::MODEL* M, CDB::RESULT* R) + { + inf.push_back(*R); + inf.back().id = (M->get_tris() + inf.back().id)->dummy; + } +}; +DEFINE_VECTOR(SBoxPickInfo, SBoxPickInfoVec, SBoxPickInfoIt); #endif //---------------------------------------------------- -enum EObjClass{ - OBJCLASS_DUMMY = -1, - OBJCLASS_GROUP = 0, - OBJCLASS_GLOW = 1, - OBJCLASS_SCENEOBJECT= 2, - OBJCLASS_LIGHT = 3, - OBJCLASS_SHAPE = 4, - OBJCLASS_SOUND_SRC = 5, - OBJCLASS_SPAWNPOINT = 6, - OBJCLASS_WAY = 7, - OBJCLASS_SECTOR = 8, - OBJCLASS_PORTAL = 9, - OBJCLASS_SOUND_ENV = 10, - OBJCLASS_PS = 11, - OBJCLASS_DO = 12, - OBJCLASS_AIMAP = 13, - OBJCLASS_WM = 14, +enum EObjClass +{ + OBJCLASS_DUMMY = -1, + OBJCLASS_GROUP = 0, + OBJCLASS_GLOW = 1, + OBJCLASS_SCENEOBJECT = 2, + OBJCLASS_LIGHT = 3, + OBJCLASS_SHAPE = 4, + OBJCLASS_SOUND_SRC = 5, + OBJCLASS_SPAWNPOINT = 6, + OBJCLASS_WAY = 7, + OBJCLASS_SECTOR = 8, + OBJCLASS_PORTAL = 9, + OBJCLASS_SOUND_ENV = 10, + OBJCLASS_PS = 11, + OBJCLASS_DO = 12, + OBJCLASS_AIMAP = 13, + OBJCLASS_WM = 14, OBJCLASS_COUNT, OBJCLASS_force_dword = -1 }; //---------------------------------------------------- #endif /*_INCDEF_SceneClassList_H_*/ - - diff --git a/src/plugins/lw/Export/EditObjectImport.cpp b/src/plugins/lw/Export/EditObjectImport.cpp index a2db70ed051..ef3652342a2 100644 --- a/src/plugins/lw/Export/EditObjectImport.cpp +++ b/src/plugins/lw/Export/EditObjectImport.cpp @@ -7,343 +7,399 @@ #include "..\..\Shared\EditObject.h" //#include "lwo2.h" -#include "..\lw_shared\LW_SHADERDEF.h" #include "..\..\Shared\EditMesh.h" +#include "..\lw_shared\LW_SHADERDEF.h" extern "C" { #include "lwo2.h" }; #ifdef _EDITOR - #include "ResourceManager.h" - - extern "C" __declspec(dllimport) lwObject* LWO_ImportObject(char* filename, lwObject *new_obj); - extern "C" __declspec(dllimport) void LWO_CloseFile(lwObject *new_obj); +#include "ResourceManager.h" + +extern "C" __declspec(dllimport) lwObject* LWO_ImportObject(char* filename, lwObject* new_obj); +extern "C" __declspec(dllimport) void LWO_CloseFile(lwObject* new_obj); #endif -DEFINE_MAP(void*,int,VMIndexLink,VMIndexLinkIt); +DEFINE_MAP(void*, int, VMIndexLink, VMIndexLinkIt); -bool CompareFunc(const st_VMapPt& vm0, const st_VMapPt& vm1){ - return vm0.vmap_indexSetStatus("Importing..."); -// UI->ProgressStart(100,"Read file:"); -// UI->ProgressUpdate(1); + lwObject* I = 0; + // UI->SetStatus("Importing..."); + // UI->ProgressStart(100,"Read file:"); + // UI->ProgressUpdate(1); string512 fname; - strcpy(fname,fn); + strcpy(fname, fn); #ifdef _EDITOR - I=LWO_ImportObject(fname,I); + I = LWO_ImportObject(fname, I); #else - unsigned int failID; - int failpos; - I = lwGetObject( fname, &failID, &failpos ); + unsigned int failID; + int failpos; + I = lwGetObject(fname, &failID, &failpos); #endif -// UI->ProgressUpdate(100); - if (I){ - bool bResult=true; - ELog.Msg( mtInformation, "CEditableObject: import lwo %s...", fname ); + // UI->ProgressUpdate(100); + if (I) { + bool bResult = true; + ELog.Msg(mtInformation, "CEditableObject: import lwo %s...", fname); // parse lwo object { - m_Meshes.reserve (I->nlayers); - m_Surfaces.reserve (I->nsurfs); + m_Meshes.reserve(I->nlayers); + m_Surfaces.reserve(I->nsurfs); // surfaces - st_lwSurface* Isf=0; + st_lwSurface* Isf = 0; { - int i=0; -// UI->ProgressStart(I->nsurfs,"Check surf:"); - for (Isf=I->surf; Isf; Isf=Isf->next){ -// UI->ProgressUpdate(i); - Isf->alpha_mode=i; // ���������� ��� ���������� ����� !!! + int i = 0; + // UI->ProgressStart(I->nsurfs,"Check surf:"); + for (Isf = I->surf; Isf; Isf = Isf->next) + { + // UI->ProgressUpdate(i); + Isf->alpha_mode = i; // ���������� ��� ���������� ����� !!! CSurface* Osf = xr_new(); m_Surfaces.push_back(Osf); - if (Isf->name&&Isf->name[0]) Osf->SetName(Isf->name); else Osf->SetName("Default"); - Osf->m_Flags.set(CSurface::sf2Sided,(Isf->sideflags==3)?TRUE:FALSE); - AnsiString en_name="default", lc_name="default", gm_name="default"; + if (Isf->name && Isf->name[0]) + Osf->SetName(Isf->name); + else + Osf->SetName("Default"); + Osf->m_Flags.set(CSurface::sf2Sided, (Isf->sideflags == 3) ? TRUE : FALSE); + AnsiString en_name = "default", lc_name = "default", gm_name = "default"; XRShader* sh_info = 0; - if (Isf->nshaders&&(stricmp(Isf->shader->name,SH_PLUGIN_NAME)==0)){ - sh_info = (XRShader*)Isf->shader->data; - en_name = sh_info->en_name; - lc_name = sh_info->lc_name; - gm_name = sh_info->gm_name; - }else - ELog.Msg(mtError,"CEditableObject: Shader not found on surface '%s'.",Osf->_Name()); + if (Isf->nshaders && (stricmp(Isf->shader->name, SH_PLUGIN_NAME) == 0)) { + sh_info = (XRShader*)Isf->shader->data; + en_name = sh_info->en_name; + lc_name = sh_info->lc_name; + gm_name = sh_info->gm_name; + } + else + ELog.Msg(mtError, "CEditableObject: Shader not found on surface '%s'.", Osf->_Name()); #ifdef _EDITOR - if (!Device.Resources->_FindBlender(en_name.c_str())){ - ELog.Msg(mtError,"CEditableObject: Render shader '%s' - can't find in library.\nUsing 'default' shader on surface '%s'.", en_name.c_str(), Osf->_Name()); - en_name = "default"; - } - if (!Device.ShaderXRLC.Get(lc_name.c_str())){ - ELog.Msg(mtError,"CEditableObject: Compiler shader '%s' - can't find in library.\nUsing 'default' shader on surface '%s'.", lc_name.c_str(), Osf->_Name()); - lc_name = "default"; - } - if (!GMLib.GetMaterial(gm_name.c_str())){ - ELog.Msg(mtError,"CEditableObject: Game material '%s' - can't find in library.\nUsing 'default' material on surface '%s'.", lc_name.c_str(), Osf->_Name()); - gm_name = "default"; - } + if (!Device.Resources->_FindBlender(en_name.c_str())) { + ELog.Msg(mtError, "CEditableObject: Render shader '%s' - can't find in library.\nUsing " + "'default' shader on surface '%s'.", + en_name.c_str(), Osf->_Name()); + en_name = "default"; + } + if (!Device.ShaderXRLC.Get(lc_name.c_str())) { + ELog.Msg(mtError, "CEditableObject: Compiler shader '%s' - can't find in library.\nUsing " + "'default' shader on surface '%s'.", + lc_name.c_str(), Osf->_Name()); + lc_name = "default"; + } + if (!GMLib.GetMaterial(gm_name.c_str())) { + ELog.Msg(mtError, "CEditableObject: Game material '%s' - can't find in library.\nUsing " + "'default' material on surface '%s'.", + lc_name.c_str(), Osf->_Name()); + gm_name = "default"; + } #endif // fill texture layers int cidx; st_lwClip* Icl; - u32 dwNumTextures=0; - for (st_lwTexture* Itx=Isf->color.tex; Itx; Itx=Itx->next){ - string1024 tname=""; + u32 dwNumTextures = 0; + for (st_lwTexture* Itx = Isf->color.tex; Itx; Itx = Itx->next) + { + string1024 tname = ""; dwNumTextures++; cidx = -1; - if (Itx->type==ID_IMAP) cidx=Itx->param.imap.cindex; - else{ - ELog.DlgMsg(mtError, "Import LWO (Surface '%s'): 'Texture' is not Image Map!",Osf->_Name()); - bResult=false; + if (Itx->type == ID_IMAP) + cidx = Itx->param.imap.cindex; + else + { + ELog.DlgMsg( + mtError, "Import LWO (Surface '%s'): 'Texture' is not Image Map!", Osf->_Name()); + bResult = false; break; } - if (cidx!=-1){ + if (cidx != -1) { // get textures - for (Icl=I->clip; Icl; Icl=Icl->next) - if ((cidx==Icl->index)&&(Icl->type==ID_STIL)){ - strcpy(tname,Icl->source.still.name); + for (Icl = I->clip; Icl; Icl = Icl->next) + if ((cidx == Icl->index) && (Icl->type == ID_STIL)) { + strcpy(tname, Icl->source.still.name); break; } - if (tname[0]==0){ - ELog.DlgMsg(mtError, "Import LWO (Surface '%s'): 'Texture' name is empty or non 'STIL' type!",Osf->_Name()); - bResult=false; + if (tname[0] == 0) { + ELog.DlgMsg(mtError, + "Import LWO (Surface '%s'): 'Texture' name is empty or non 'STIL' type!", + Osf->_Name()); + bResult = false; break; } string256 tex_name; - _splitpath( tname, 0, 0, tex_name, 0 ); - Osf->SetTexture(EFS.AppendFolderToName(tex_name,1,TRUE)); + _splitpath(tname, 0, 0, tex_name, 0); + Osf->SetTexture(EFS.AppendFolderToName(tex_name, 1, TRUE)); // get vmap refs Osf->SetVMap(Itx->param.imap.vmap_name); } } if (!bResult) break; - if (!Osf->_VMap()||!Osf->_VMap()[0]){ - ELog.DlgMsg(mtError, "Invalid surface '%s'. VMap empty.",Osf->_Name()); + if (!Osf->_VMap() || !Osf->_VMap()[0]) { + ELog.DlgMsg(mtError, "Invalid surface '%s'. VMap empty.", Osf->_Name()); bResult = false; - break; + break; } - if (!Osf->_Texture()||!Osf->_Texture()[0]){ - ELog.DlgMsg(mtError, "Can't create shader. Invalid surface '%s'. Textures empty.",Osf->_Name()); + if (!Osf->_Texture() || !Osf->_Texture()[0]) { + ELog.DlgMsg( + mtError, "Can't create shader. Invalid surface '%s'. Textures empty.", Osf->_Name()); bResult = false; - break; + break; } - if (en_name.c_str()==0){ - ELog.DlgMsg(mtError, "Can't create shader. Invalid surface '%s'. Shader empty.",Osf->_Name()); + if (en_name.c_str() == 0) { + ELog.DlgMsg(mtError, "Can't create shader. Invalid surface '%s'. Shader empty.", Osf->_Name()); bResult = false; - break; + break; } - Osf->SetShader (en_name.c_str()); - Osf->SetShaderXRLC (lc_name.c_str()); - Osf->SetGameMtl (gm_name.c_str()); - Osf->SetFVF (D3DFVF_XYZ|D3DFVF_NORMAL|(dwNumTextures<SetShader(en_name.c_str()); + Osf->SetShaderXRLC(lc_name.c_str()); + Osf->SetGameMtl(gm_name.c_str()); + Osf->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | (dwNumTextures << D3DFVF_TEXCOUNT_SHIFT)); i++; } - } - if (bResult){ + } + if (bResult) { // mesh layers - st_lwLayer* Ilr=0; - int k=0; - for (Ilr=I->layer; Ilr; Ilr=Ilr->next){ + st_lwLayer* Ilr = 0; + int k = 0; + for (Ilr = I->layer; Ilr; Ilr = Ilr->next) + { // create new mesh - CEditableMesh* MESH=xr_new(this); + CEditableMesh* MESH = xr_new(this); m_Meshes.push_back(MESH); - if (Ilr->name) MESH->SetName(Ilr->name); else MESH->SetName(""); - MESH->m_Box.set(Ilr->bbox[0],Ilr->bbox[1],Ilr->bbox[2], Ilr->bbox[3],Ilr->bbox[4],Ilr->bbox[5]); + if (Ilr->name) + MESH->SetName(Ilr->name); + else + MESH->SetName(""); + MESH->m_Box.set(Ilr->bbox[0], Ilr->bbox[1], Ilr->bbox[2], Ilr->bbox[3], Ilr->bbox[4], Ilr->bbox[5]); // parse mesh(lwo-layer) data // vmaps - st_lwVMap* Ivmap=0; - int vmap_count=0; - if (Ilr->nvmaps==0){ + st_lwVMap* Ivmap = 0; + int vmap_count = 0; + if (Ilr->nvmaps == 0) { ELog.DlgMsg(mtError, "Import LWO: Mesh layer must contain UV!"); - bResult=false; + bResult = false; break; } // ������� ������������ ������������� ��� - static VMIndexLink VMIndices; - VMIndices.clear(); + static VMIndexLink VMIndices; + VMIndices.clear(); - for (Ivmap=Ilr->vmap; Ivmap; Ivmap=Ivmap->next){ - switch(Ivmap->type){ - case ID_TXUV:{ - if (Ivmap->dim!=2){ + for (Ivmap = Ilr->vmap; Ivmap; Ivmap = Ivmap->next) + { + switch (Ivmap->type) + { + case ID_TXUV: + { + if (Ivmap->dim != 2) { ELog.DlgMsg(mtError, "Import LWO: 'UV Map' must contain 2 value!"); - bResult=false; + bResult = false; break; } - MESH->m_VMaps.push_back(xr_new(Ivmap->name,vmtUV,Ivmap->perpoly)); - st_VMap* Mvmap=MESH->m_VMaps.back(); - int vcnt=Ivmap->nverts; + MESH->m_VMaps.push_back(xr_new(Ivmap->name, vmtUV, Ivmap->perpoly)); + st_VMap* Mvmap = MESH->m_VMaps.back(); + int vcnt = Ivmap->nverts; // VMap - Mvmap->copyfrom(*Ivmap->val,vcnt); + Mvmap->copyfrom(*Ivmap->val, vcnt); // flip uv - for (int k=0; ksize(); k++){ - Fvector2& uv = Mvmap->getUV(k); - uv.y=1.f-uv.y; + for (int k = 0; k < Mvmap->size(); k++) + { + Fvector2& uv = Mvmap->getUV(k); + uv.y = 1.f - uv.y; } // vmap index VMIndices[Ivmap] = vmap_count++; - }break; - case ID_WGHT:{ - if (Ivmap->dim!=1){ + } + break; + case ID_WGHT: + { + if (Ivmap->dim != 1) { ELog.DlgMsg(mtError, "Import LWO: 'Weight' must contain 1 value!"); - bResult=false; + bResult = false; break; } - MESH->m_VMaps.push_back(xr_new(Ivmap->name,vmtWeight,FALSE)); - st_VMap* Mvmap=MESH->m_VMaps.back(); - int vcnt=Ivmap->nverts; + MESH->m_VMaps.push_back(xr_new(Ivmap->name, vmtWeight, FALSE)); + st_VMap* Mvmap = MESH->m_VMaps.back(); + int vcnt = Ivmap->nverts; // VMap - Mvmap->copyfrom(*Ivmap->val,vcnt); + Mvmap->copyfrom(*Ivmap->val, vcnt); // vmap index VMIndices[Ivmap] = vmap_count++; - }break; - case ID_PICK: ELog.Msg(mtError,"Found 'PICK' VMAP. Import failed."); bResult = false; break; - case ID_MNVW: ELog.Msg(mtError,"Found 'MNVW' VMAP. Import failed."); bResult = false; break; - case ID_MORF: ELog.Msg(mtError,"Found 'MORF' VMAP. Import failed."); bResult = false; break; - case ID_SPOT: ELog.Msg(mtError,"Found 'SPOT' VMAP. Import failed."); bResult = false; break; - case ID_RGB: ELog.Msg(mtError,"Found 'RGB' VMAP. Import failed."); bResult = false; break; - case ID_RGBA: ELog.Msg(mtError,"Found 'RGBA' VMAP. Import failed."); bResult = false; break; } - if (!bResult) break; + break; + case ID_PICK: + ELog.Msg(mtError, "Found 'PICK' VMAP. Import failed."); + bResult = false; + break; + case ID_MNVW: + ELog.Msg(mtError, "Found 'MNVW' VMAP. Import failed."); + bResult = false; + break; + case ID_MORF: + ELog.Msg(mtError, "Found 'MORF' VMAP. Import failed."); + bResult = false; + break; + case ID_SPOT: + ELog.Msg(mtError, "Found 'SPOT' VMAP. Import failed."); + bResult = false; + break; + case ID_RGB: + ELog.Msg(mtError, "Found 'RGB' VMAP. Import failed."); + bResult = false; + break; + case ID_RGBA: + ELog.Msg(mtError, "Found 'RGBA' VMAP. Import failed."); + bResult = false; + break; + } + if (!bResult) break; } if (!bResult) break; // points -// UI->ProgressStart(Ilr->point.count,"Fill points:"); + // UI->ProgressStart(Ilr->point.count,"Fill points:"); { - MESH->m_VertCount = Ilr->point.count; - MESH->m_Verts = xr_alloc(MESH->m_VertCount); - int id = Ilr->polygon.count/50; - if (id==0) id = 1; - for (int i=0; ipoint.count; i++){ -// if ((i%id)==0) UI->ProgressUpdate(i); + MESH->m_VertCount = Ilr->point.count; + MESH->m_Verts = xr_alloc(MESH->m_VertCount); + int id = Ilr->polygon.count / 50; + if (id == 0) id = 1; + for (int i = 0; i < Ilr->point.count; i++) + { + // if ((i%id)==0) UI->ProgressUpdate(i); st_lwPoint& Ipt = Ilr->point.pt[i]; - Fvector& Mpt = MESH->m_Verts[i]; - Mpt.set (Ipt.pos); + Fvector& Mpt = MESH->m_Verts[i]; + Mpt.set(Ipt.pos); } } if (!bResult) break; // polygons -// UI->ProgressStart(Ilr->polygon.count,"Fill polygons:"); - MESH->m_FaceCount = Ilr->polygon.count; - MESH->m_Faces = xr_alloc(MESH->m_FaceCount); - MESH->m_SGs = xr_alloc(MESH->m_FaceCount); - Memory.mem_fill32 (MESH->m_SGs,u32(-1),MESH->m_FaceCount); - MESH->m_VMRefs.reserve (Ilr->polygon.count*3); + // UI->ProgressStart(Ilr->polygon.count,"Fill polygons:"); + MESH->m_FaceCount = Ilr->polygon.count; + MESH->m_Faces = xr_alloc(MESH->m_FaceCount); + MESH->m_SGs = xr_alloc(MESH->m_FaceCount); + Memory.mem_fill32(MESH->m_SGs, u32(-1), MESH->m_FaceCount); + MESH->m_VMRefs.reserve(Ilr->polygon.count * 3); IntVec surf_ids; surf_ids.resize(Ilr->polygon.count); - int id = Ilr->polygon.count/50; - if (id==0) id = 1; - for (int i=0; ipolygon.count; i++){ -// if ((i%id)==0) UI->ProgressUpdate(i); - st_Face& Mpol=MESH->m_Faces[i]; - st_lwPolygon& Ipol=Ilr->polygon.pol[i]; - if (Ipol.nverts!=3) { - ELog.DlgMsg(mtError, "Import LWO: Face must contain only 3 vertices!"); - bResult=false; + int id = Ilr->polygon.count / 50; + if (id == 0) id = 1; + for (int i = 0; i < Ilr->polygon.count; i++) + { + // if ((i%id)==0) UI->ProgressUpdate(i); + st_Face& Mpol = MESH->m_Faces[i]; + st_lwPolygon& Ipol = Ilr->polygon.pol[i]; + if (Ipol.nverts != 3) { + ELog.DlgMsg(mtError, "Import LWO: Face must contain only 3 vertices!"); + bResult = false; break; } - for (int pv_i=0; pv_i<3; pv_i++){ - st_lwPolVert& Ipv=Ipol.v[pv_i]; - st_FaceVert& Mpv=Mpol.pv[pv_i]; - Mpv.pindex =Ipv.index; + for (int pv_i = 0; pv_i < 3; pv_i++) + { + st_lwPolVert& Ipv = Ipol.v[pv_i]; + st_FaceVert& Mpv = Mpol.pv[pv_i]; + Mpv.pindex = Ipv.index; + + MESH->m_VMRefs.push_back(st_VMapPtLst()); + st_VMapPtLst& m_vm_lst = MESH->m_VMRefs.back(); - MESH->m_VMRefs.push_back(st_VMapPtLst()); - st_VMapPtLst& m_vm_lst = MESH->m_VMRefs.back(); + DEFINE_VECTOR(st_VMapPt, VMapPtVec, VMapPtIt); + VMapPtVec vm_lst; - DEFINE_VECTOR (st_VMapPt,VMapPtVec,VMapPtIt); - VMapPtVec vm_lst; - - Mpv.vmref = MESH->m_VMRefs.size()-1; + Mpv.vmref = MESH->m_VMRefs.size() - 1; - // parse uv-map - int vmpl_cnt =Ipv.nvmaps; - st_lwPoint& Ipt =Ilr->point.pt[Mpv.pindex]; - int vmpt_cnt =Ipt.nvmaps; - if (!vmpl_cnt&&!vmpt_cnt){ - ELog.DlgMsg (mtError,"Found mesh without UV's!",0); - bResult = false; + // parse uv-map + int vmpl_cnt = Ipv.nvmaps; + st_lwPoint& Ipt = Ilr->point.pt[Mpv.pindex]; + int vmpt_cnt = Ipt.nvmaps; + if (!vmpl_cnt && !vmpt_cnt) { + ELog.DlgMsg(mtError, "Found mesh without UV's!", 0); + bResult = false; break; } AStringVec names; - if (vmpl_cnt){ - // ����� �� poly - for (int vm_i=0; vm_itype!=ID_TXUV) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipv.vm[vm_i].vmap];// ����� ���� VMap - names.push_back (Ipv.vm[vm_i].vmap->name); - pt.index = Ipv.vm[vm_i].index; - } - } - if (vmpt_cnt){ - // ����� �� points - for (int vm_i=0; vm_itype!=ID_TXUV) continue; - if (std::find(names.begin(),names.end(),Ipt.vm[vm_i].vmap->name)!=names.end()) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap - pt.index = Ipt.vm[vm_i].index; + if (vmpl_cnt) { + // ����� �� poly + for (int vm_i = 0; vm_i < vmpl_cnt; vm_i++) + { + if (Ipv.vm[vm_i].vmap->type != ID_TXUV) continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipv.vm[vm_i].vmap]; // ����� ���� VMap + names.push_back(Ipv.vm[vm_i].vmap->name); + pt.index = Ipv.vm[vm_i].index; + } + } + if (vmpt_cnt) { + // ����� �� points + for (int vm_i = 0; vm_i < vmpt_cnt; vm_i++) + { + if (Ipt.vm[vm_i].vmap->type != ID_TXUV) continue; + if (std::find(names.begin(), names.end(), Ipt.vm[vm_i].vmap->name) != names.end()) + continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap + pt.index = Ipt.vm[vm_i].index; } - } + } - std::sort(vm_lst.begin(),vm_lst.end(),CompareFunc); + std::sort(vm_lst.begin(), vm_lst.end(), CompareFunc); - // parse weight-map - int vm_cnt =Ipt.nvmaps; - for (int vm_i=0; vm_itype!=ID_WGHT) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap - pt.index = Ipt.vm[vm_i].index; + // parse weight-map + int vm_cnt = Ipt.nvmaps; + for (int vm_i = 0; vm_i < vm_cnt; vm_i++) + { + if (Ipt.vm[vm_i].vmap->type != ID_WGHT) continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap + pt.index = Ipt.vm[vm_i].index; } - m_vm_lst.count = vm_lst.size(); - m_vm_lst.pts = xr_alloc(m_vm_lst.count); - Memory.mem_copy (m_vm_lst.pts,&*vm_lst.begin(),m_vm_lst.count*sizeof(st_VMapPt)); + m_vm_lst.count = vm_lst.size(); + m_vm_lst.pts = xr_alloc(m_vm_lst.count); + Memory.mem_copy(m_vm_lst.pts, &*vm_lst.begin(), m_vm_lst.count * sizeof(st_VMapPt)); } if (!bResult) break; - // Ipol.surf->alpha_mode - ��������� ��� ����� ����� surface - surf_ids[i] = Ipol.surf->alpha_mode; + // Ipol.surf->alpha_mode - ��������� ��� ����� ����� surface + surf_ids[i] = Ipol.surf->alpha_mode; } if (!bResult) break; - for (u32 pl_id=0; pl_idGetFCount(); pl_id++) - MESH->m_SurfFaces[m_Surfaces[surf_ids[pl_id]]].push_back(pl_id); - + for (u32 pl_id = 0; pl_id < MESH->GetFCount(); pl_id++) + MESH->m_SurfFaces[m_Surfaces[surf_ids[pl_id]]].push_back(pl_id); + if (!bResult) break; k++; - //MESH->DumpAdjacency(); + // MESH->DumpAdjacency(); if (bNeedOptimize) MESH->Optimize(false); - //MESH->DumpAdjacency(); - MESH->RebuildVMaps(); // !!!!!! + // MESH->DumpAdjacency(); + MESH->RebuildVMaps(); // !!!!!! } - } + } } #ifdef _EDITOR - LWO_CloseFile(I); + LWO_CloseFile(I); #else - lwFreeObject(I); + lwFreeObject(I); #endif -// UI->ProgressEnd(); -// UI->SetStatus(""); - if (bResult) VerifyMeshNames(); - else ELog.DlgMsg(mtError,"Can't parse LWO object."); - if (bResult) m_LoadName = (strext(fname))? strcpy(strext(fname),".object"):strcat(strext(fname),".object"); + // UI->ProgressEnd(); + // UI->SetStatus(""); + if (bResult) + VerifyMeshNames(); + else + ELog.DlgMsg(mtError, "Can't parse LWO object."); + if (bResult) m_LoadName = (strext(fname)) ? strcpy(strext(fname), ".object") : strcat(strext(fname), ".object"); return bResult; - }else - ELog.DlgMsg(mtError,"Can't import LWO object file."); -// UI->ProgressEnd(); -// UI->SetStatus(""); + } + else + ELog.DlgMsg(mtError, "Can't import LWO object file."); + // UI->ProgressEnd(); + // UI->SetStatus(""); return false; } - - diff --git a/src/plugins/lw/Export/EditObjectImportDB.cpp b/src/plugins/lw/Export/EditObjectImportDB.cpp index 924d3f511ae..2a94598f1b6 100644 --- a/src/plugins/lw/Export/EditObjectImportDB.cpp +++ b/src/plugins/lw/Export/EditObjectImportDB.cpp @@ -5,239 +5,276 @@ #include "stdafx.h" #pragma hdrstop -#include "EditObject.h" -#include "EditMesh.h" -#include "scenscan\objectdb.h" #include +#include "EditMesh.h" +#include "EditObject.h" #include "bone.h" +#include "scenscan\objectdb.h" -extern "C" LWMessageFuncs *g_msg; -DEFINE_MAP(void*,int,VMIndexLink,VMIndexLinkIt); +extern "C" LWMessageFuncs* g_msg; +DEFINE_MAP(void*, int, VMIndexLink, VMIndexLinkIt); -bool CEditableObject::Import_LWO(st_ObjectDB *I){ - if (I){ - bool bResult=true; +bool CEditableObject::Import_LWO(st_ObjectDB* I) +{ + if (I) { + bool bResult = true; // parse lwo object { - m_Meshes.resize (1); - m_Surfaces.resize (I->nsurfaces); + m_Meshes.resize(1); + m_Surfaces.resize(I->nsurfaces); // surfaces { - for (int i=0; insurfaces; i++){ - DBSurface* Isf=&I->surf[i]; + for (int i = 0; i < I->nsurfaces; i++) + { + DBSurface* Isf = &I->surf[i]; CSurface* Osf = xr_new(); m_Surfaces[i] = Osf; - Osf->SetName((Isf->name&&Isf->name[0])?Isf->name:"default"); - Osf->m_Flags.set(CSurface::sf2Sided,Isf->side==3); + Osf->SetName((Isf->name && Isf->name[0]) ? Isf->name : "default"); + Osf->m_Flags.set(CSurface::sf2Sided, Isf->side == 3); // fill texture layers - string256 tex_name; - R_ASSERT(Isf->tex_cnt==1); - _splitpath( Isf->textures[0], 0, 0, tex_name, 0 ); - Osf->SetTexture(EFS.UpdateTextureNameWithFolder(tex_name)); - Osf->SetVMap(""); - - if (!Osf->_Texture()||!Osf->_Texture()[0]){ - g_msg->error("Can't create shader. Textures empty. Invalid surface:. ",Osf->_Name()); + string256 tex_name; + R_ASSERT(Isf->tex_cnt == 1); + _splitpath(Isf->textures[0], 0, 0, tex_name, 0); + Osf->SetTexture(EFS.UpdateTextureNameWithFolder(tex_name)); + Osf->SetVMap(""); + + if (!Osf->_Texture() || !Osf->_Texture()[0]) { + g_msg->error("Can't create shader. Textures empty. Invalid surface:. ", Osf->_Name()); bResult = false; break; } - - Osf->SetShader ("model"); - Osf->SetShaderXRLC ("default"); - - Osf->SetFVF(D3DFVF_XYZ|D3DFVF_NORMAL|(Isf->tex_cnt<SetShader("model"); + Osf->SetShaderXRLC("default"); + + Osf->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | (Isf->tex_cnt << D3DFVF_TEXCOUNT_SHIFT)); } - } - if (bResult){ - // mesh - do{ + } + if (bResult) { + // mesh + do + { // create new mesh - CEditableMesh* MESH=xr_new(this); - m_Meshes[0]=MESH; + CEditableMesh* MESH = xr_new(this); + m_Meshes[0] = MESH; - strcpy(MESH->m_Name,"mesh"); + strcpy(MESH->m_Name, "mesh"); // parse mesh data // vmaps - DBVMap* Ivmap=0; - int vmap_count=0; - if (I->nvertmaps==0){ - g_msg->error("Import LWO: Mesh layer must contain UV!",0); - bResult=false; + DBVMap* Ivmap = 0; + int vmap_count = 0; + if (I->nvertmaps == 0) { + g_msg->error("Import LWO: Mesh layer must contain UV!", 0); + bResult = false; break; } - // ������� ������������ ������������� ��� - static VMIndexLink VMIndices; - VMIndices.clear(); - - for (int vm_i=0; vm_invertmaps; vm_i++){ - Ivmap = &I->vmap[vm_i]; - switch(Ivmap->type){ - case LWVMAP_TXUV:{ - if (Ivmap->dim!=2){ - g_msg->error("Import LWO: 'UV Map' must contain 2 value!",0); - bResult=false; + // ������� ������������ ������������� ��� + static VMIndexLink VMIndices; + VMIndices.clear(); + + for (int vm_i = 0; vm_i < I->nvertmaps; vm_i++) + { + Ivmap = &I->vmap[vm_i]; + switch (Ivmap->type) + { + case LWVMAP_TXUV: + { + if (Ivmap->dim != 2) { + g_msg->error("Import LWO: 'UV Map' must contain 2 value!", 0); + bResult = false; break; } - MESH->m_VMaps.push_back(xr_new(Ivmap->name,vmtUV,*Ivmap->vdpol>=0)); - st_VMap* Mvmap=MESH->m_VMaps.back(); - int vcnt=Ivmap->nverts; + MESH->m_VMaps.push_back(xr_new(Ivmap->name, vmtUV, *Ivmap->vdpol >= 0)); + st_VMap* Mvmap = MESH->m_VMaps.back(); + int vcnt = Ivmap->nverts; // VMap, flip uv - for (int vm_i=0; vm_inverts; vm_i++) - Mvmap->appendUV(Ivmap->val[0][vm_i],1.f-Ivmap->val[1][vm_i]); + for (int vm_i = 0; vm_i < Ivmap->nverts; vm_i++) + Mvmap->appendUV(Ivmap->val[0][vm_i], 1.f - Ivmap->val[1][vm_i]); // vmap index VMIndices[Ivmap] = vmap_count++; - }break; - case LWVMAP_WGHT:{ - if (Ivmap->dim!=1){ - g_msg->error("Import LWO: 'Weight' must contain 1 value!",0); - bResult=false; + } + break; + case LWVMAP_WGHT: + { + if (Ivmap->dim != 1) { + g_msg->error("Import LWO: 'Weight' must contain 1 value!", 0); + bResult = false; break; } - R_ASSERT(*Ivmap->vdpol==-1); - MESH->m_VMaps.push_back(xr_new(Ivmap->name,vmtWeight,FALSE)); - st_VMap* Mvmap=MESH->m_VMaps.back(); - int vcnt=Ivmap->nverts; + R_ASSERT(*Ivmap->vdpol == -1); + MESH->m_VMaps.push_back(xr_new(Ivmap->name, vmtWeight, FALSE)); + st_VMap* Mvmap = MESH->m_VMaps.back(); + int vcnt = Ivmap->nverts; // VMap - Mvmap->copyfrom(*Ivmap->val,vcnt); + Mvmap->copyfrom(*Ivmap->val, vcnt); // vmap index VMIndices[Ivmap] = vmap_count++; - }break; - case LWVMAP_PICK: g_msg->error("Found 'PICK' VMAP. Import failed.",0); bResult = false; break; - case LWVMAP_MNVW: g_msg->error("Found 'MNVW' VMAP. Import failed.",0); bResult = false; break; - case LWVMAP_MORF: g_msg->error("Found 'MORF' VMAP. Import failed.",0); bResult = false; break; - case LWVMAP_SPOT: g_msg->error("Found 'SPOT' VMAP. Import failed.",0); bResult = false; break; - case LWVMAP_RGB: g_msg->error("Found 'RGB' VMAP. Import failed.",0); bResult = false; break; - case LWVMAP_RGBA: g_msg->error("Found 'RGBA' VMAP. Import failed.",0); bResult = false; break; } - if (!bResult) break; + break; + case LWVMAP_PICK: + g_msg->error("Found 'PICK' VMAP. Import failed.", 0); + bResult = false; + break; + case LWVMAP_MNVW: + g_msg->error("Found 'MNVW' VMAP. Import failed.", 0); + bResult = false; + break; + case LWVMAP_MORF: + g_msg->error("Found 'MORF' VMAP. Import failed.", 0); + bResult = false; + break; + case LWVMAP_SPOT: + g_msg->error("Found 'SPOT' VMAP. Import failed.", 0); + bResult = false; + break; + case LWVMAP_RGB: + g_msg->error("Found 'RGB' VMAP. Import failed.", 0); + bResult = false; + break; + case LWVMAP_RGBA: + g_msg->error("Found 'RGBA' VMAP. Import failed.", 0); + bResult = false; + break; + } + if (!bResult) break; } if (!bResult) break; // points { MESH->m_Points.resize(I->npoints); MESH->m_Adjs.resize(I->npoints); - for (int i=0; inpoints; i++){ - DBPoint& Ipt = I->pt[i]; - Fvector& Mpt = MESH->m_Points[i]; - IntVec& a_lst = MESH->m_Adjs[i]; - Mpt.set (Ipt.pos[0]); - copy (Ipt.pol,Ipt.pol+Ipt.npols,inserter(a_lst,a_lst.begin())); - sort (a_lst.begin(),a_lst.end()); + for (int i = 0; i < I->npoints; i++) + { + DBPoint& Ipt = I->pt[i]; + Fvector& Mpt = MESH->m_Points[i]; + IntVec& a_lst = MESH->m_Adjs[i]; + Mpt.set(Ipt.pos[0]); + copy(Ipt.pol, Ipt.pol + Ipt.npols, inserter(a_lst, a_lst.begin())); + sort(a_lst.begin(), a_lst.end()); } } if (!bResult) break; // polygons MESH->m_Faces.resize(I->npolygons); - MESH->m_VMRefs.reserve(I->npolygons*3); + MESH->m_VMRefs.reserve(I->npolygons * 3); IntVec surf_ids; surf_ids.resize(I->npolygons); - for (int p_i=0; p_inpolygons; p_i++){ - st_Face& Mpol=MESH->m_Faces[p_i]; - DBPolygon& Ipol=I->pol[p_i]; - if (Ipol.nverts!=3) { - g_msg->error("Import LWO: Face must contain only 3 vertices!",0); - bResult=false; + for (int p_i = 0; p_i < I->npolygons; p_i++) + { + st_Face& Mpol = MESH->m_Faces[p_i]; + DBPolygon& Ipol = I->pol[p_i]; + if (Ipol.nverts != 3) { + g_msg->error("Import LWO: Face must contain only 3 vertices!", 0); + bResult = false; break; } - for (int pv_i=0; pv_i<3; pv_i++){ - DBPolVert& Ipv=Ipol.v[pv_i]; - st_FaceVert& Mpv=Mpol.pv[pv_i]; - Mpv.pindex =Ipv.index; - - MESH->m_VMRefs.push_back(VMapPtSVec()); - VMapPtSVec& vm_lst = MESH->m_VMRefs.back(); - Mpv.vmref = MESH->m_VMRefs.size()-1; - - // parse uv-map - int vmp_cnt =Ipv.nvmaps; - if (vmp_cnt){ - // ����� �� poly - for (int vm_i=0; vm_itype!=LWVMAP_TXUV) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipv.vm[vm_i].vmap];// ����� ���� VMap - pt.index = Ipv.vm[vm_i].index; - } - }else{ - // ����� �� points - DBPoint& Ipt = I->pt[Mpv.pindex]; - int vm_cnt =Ipt.nvmaps; - if (!vm_cnt){ - g_msg->error("Can't find polygon/point UV-map!",0); - bResult = false; + for (int pv_i = 0; pv_i < 3; pv_i++) + { + DBPolVert& Ipv = Ipol.v[pv_i]; + st_FaceVert& Mpv = Mpol.pv[pv_i]; + Mpv.pindex = Ipv.index; + + MESH->m_VMRefs.push_back(VMapPtSVec()); + VMapPtSVec& vm_lst = MESH->m_VMRefs.back(); + Mpv.vmref = MESH->m_VMRefs.size() - 1; + + // parse uv-map + int vmp_cnt = Ipv.nvmaps; + if (vmp_cnt) { + // ����� �� poly + for (int vm_i = 0; vm_i < vmp_cnt; vm_i++) + { + if (Ipv.vm[vm_i].vmap->type != LWVMAP_TXUV) continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipv.vm[vm_i].vmap]; // ����� ���� VMap + pt.index = Ipv.vm[vm_i].index; + } + } + else + { + // ����� �� points + DBPoint& Ipt = I->pt[Mpv.pindex]; + int vm_cnt = Ipt.nvmaps; + if (!vm_cnt) { + g_msg->error("Can't find polygon/point UV-map!", 0); + bResult = false; break; - } - for (int vm_i=0; vm_itype!=LWVMAP_TXUV) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap - pt.index = Ipt.vm[vm_i].index; } - } - - // parse weight-map - DBPoint& Ipt = I->pt[Mpv.pindex]; - int vm_cnt =Ipt.nvmaps; - for (int vm_i=0; vm_itype!=LWVMAP_WGHT) continue; - vm_lst.push_back(st_VMapPt()); - st_VMapPt& pt = vm_lst.back(); - pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap - pt.index = Ipt.vm[vm_i].index; + for (int vm_i = 0; vm_i < vm_cnt; vm_i++) + { + if (Ipt.vm[vm_i].vmap->type != LWVMAP_TXUV) continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap + pt.index = Ipt.vm[vm_i].index; + } } - } + // parse weight-map + DBPoint& Ipt = I->pt[Mpv.pindex]; + int vm_cnt = Ipt.nvmaps; + for (int vm_i = 0; vm_i < vm_cnt; vm_i++) + { + if (Ipt.vm[vm_i].vmap->type != LWVMAP_WGHT) continue; + vm_lst.push_back(st_VMapPt()); + st_VMapPt& pt = vm_lst.back(); + pt.vmap_index = VMIndices[Ipt.vm[vm_i].vmap]; // ����� ���� VMap + pt.index = Ipt.vm[vm_i].index; + } + } if (!bResult) break; - // Ipol.surf->alpha_mode - ��������� ��� ����� ����� surface - surf_ids[p_i] = Ipol.sindex; + // Ipol.surf->alpha_mode - ��������� ��� ����� ����� surface + surf_ids[p_i] = Ipol.sindex; } if (!bResult) break; - int p_idx=0; - for (FaceIt pl_it=MESH->m_Faces.begin(); pl_it!=MESH->m_Faces.end(); pl_it++){ - MESH->m_SurfFaces[m_Surfaces[surf_ids[p_idx]]].push_back(p_idx); + int p_idx = 0; + for (FaceIt pl_it = MESH->m_Faces.begin(); pl_it != MESH->m_Faces.end(); pl_it++) + { + MESH->m_SurfFaces[m_Surfaces[surf_ids[p_idx]]].push_back(p_idx); p_idx++; } - if ((MESH->GetVertexCount()<4)||(MESH->GetFaceCount()<2)) - { - ELog.Msg(mtError,"Invalid mesh: '%s'. Faces<2 or Verts<4",MESH->GetName()); - bResult = false; - } + if ((MESH->GetVertexCount() < 4) || (MESH->GetFaceCount() < 2)) { + ELog.Msg(mtError, "Invalid mesh: '%s'. Faces<2 or Verts<4", MESH->GetName()); + bResult = false; + } if (!bResult) break; - MESH->RecomputeBBox(); - - // check weight maps - if (!m_Bones.empty()){ - for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ - if ((*b_it)->WMap()[0]&&(-1==MESH->FindVMapByName(MESH->m_VMaps,(*b_it)->WMap(),vmtWeight,FALSE))){ - g_msg->error("Can't find weight map:",(*b_it)->Name()); - bResult = false; - break; - } - } - } - if (bResult) MESH->RebuildVMaps(); - }while(0); - } - } - if (!bResult) g_msg->error("Can't parse LWO object.",0); - if (bResult){ - // fill default bone part - m_BoneParts.push_back(SBonePart()); - SBonePart& BP = m_BoneParts.back(); - BP.alias = "default"; - for (DWORD b_i=0; b_iName()); - } - + MESH->RecomputeBBox(); + + // check weight maps + if (!m_Bones.empty()) { + for (BoneIt b_it = m_Bones.begin(); b_it != m_Bones.end(); b_it++) + { + if ((*b_it)->WMap()[0] && + (-1 == MESH->FindVMapByName(MESH->m_VMaps, (*b_it)->WMap(), vmtWeight, FALSE))) + { + g_msg->error("Can't find weight map:", (*b_it)->Name()); + bResult = false; + break; + } + } + } + if (bResult) MESH->RebuildVMaps(); + } while (0); + } + } + if (!bResult) g_msg->error("Can't parse LWO object.", 0); + if (bResult) { + // fill default bone part + m_BoneParts.push_back(SBonePart()); + SBonePart& BP = m_BoneParts.back(); + BP.alias = "default"; + for (DWORD b_i = 0; b_i < m_Bones.size(); b_i++) + BP.bones.push_back(m_Bones[b_i]->Name()); + } + return bResult; - }else - g_msg->error("Can't export LWO object file.",0); + } + else + g_msg->error("Can't export LWO object file.", 0); return false; } - diff --git a/src/plugins/lw/Export/LW_export_keys.cpp b/src/plugins/lw/Export/LW_export_keys.cpp index 46183505e3e..513977c15ed 100644 --- a/src/plugins/lw/Export/LW_export_keys.cpp +++ b/src/plugins/lw/Export/LW_export_keys.cpp @@ -1,106 +1,119 @@ +#include "Globals.hpp" +#include "SMotionLW.hpp" +#include "scenscan\objectdb.h" #include "stdafx.h" -#include "xrCore/FileSystem.h" -#include "xrCore/FS.h" #include "utils/LWO/envelope.h" #include "xrCore/Animation/Bone.hpp" #include "xrCore/Animation/Motion.hpp" -#include "Globals.hpp" -#include "scenscan\objectdb.h" -#include "SMotionLW.hpp" +#include "xrCore/FS.h" +#include "xrCore/FileSystem.h" static SMotionLW* m_Motion; -static void RecurseBone(LWItemID parent){ - LWItemID bone = g_iteminfo->firstChild(parent); - while (bone!=LWITEM_NULL){ - if (g_iteminfo->type(bone)==LWI_BONE){ - m_Motion->ParseBoneMotion(bone); - RecurseBone(bone); - } - bone = g_iteminfo->nextChild(parent,bone); - } +static void RecurseBone(LWItemID parent) +{ + LWItemID bone = g_iteminfo->firstChild(parent); + while (bone != LWITEM_NULL) + { + if (g_iteminfo->type(bone) == LWI_BONE) { + m_Motion->ParseBoneMotion(bone); + RecurseBone(bone); + } + bone = g_iteminfo->nextChild(parent, bone); + } } -static bool ParseObjectMotion(LWItemID object, int& obj_cnt){ - LWItemID bone, parent; - bone = g_iteminfo->first( LWI_BONE, object ); +static bool ParseObjectMotion(LWItemID object, int& obj_cnt) +{ + LWItemID bone, parent; + bone = g_iteminfo->first(LWI_BONE, object); - if (!bone){ - g_msg->error("Can't find bone.",0); - return false; - } + if (!bone) { + g_msg->error("Can't find bone.", 0); + return false; + } - while (true){ - parent = g_iteminfo->parent(bone); - if (!parent){ - g_msg->error("Can't find root bone.",0); - return false; - } - if (g_iteminfo->type(parent)!=LWI_BONE) break; - else bone = parent; - } + while (true) + { + parent = g_iteminfo->parent(bone); + if (!parent) { + g_msg->error("Can't find root bone.", 0); + return false; + } + if (g_iteminfo->type(parent) != LWI_BONE) + break; + else + bone = parent; + } - if (bone){ - if (obj_cnt>0){ - g_msg->error("Can't support multiple objects.",0); - return false; - } - m_Motion->ParseBoneMotion(bone); - RecurseBone (bone); + if (bone) { + if (obj_cnt > 0) { + g_msg->error("Can't support multiple objects.", 0); + return false; + } + m_Motion->ParseBoneMotion(bone); + RecurseBone(bone); - obj_cnt++; - } - return true; + obj_cnt++; + } + return true; } void ReplaceSpaceAndLowerCase(shared_str& s) { - if (*s){ - char* _s = xr_strdup(*s); - char* lp = _s; - while(lp[0]){if (lp[0]==' ') lp[0]='_'; lp++;} - xr_strlwr (_s); - s = _s; - xr_free (_s); - } + if (*s) { + char* _s = xr_strdup(*s); + char* lp = _s; + while (lp[0]) + { + if (lp[0] == ' ') lp[0] = '_'; + lp++; + } + xr_strlwr(_s); + s = _s; + xr_free(_s); + } } extern "C" { //----------------------------------------------------------------------------------------- -void __cdecl SaveSkeletonMotion(GlobalFunc *global) +void __cdecl SaveSkeletonMotion(GlobalFunc* global) { - Core._initialize("XRayPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - // get bone ID - LWItemID object; - bool bErr = true; - - string_path buf=""; - string64 name; + Core._initialize("XRayPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + // get bone ID + LWItemID object; + bool bErr = true; + + string_path buf = ""; + string64 name; + + EFS.GetSaveName("$smotion$", buf); + + if (buf[0]) { + object = g_iteminfo->first(LWI_OBJECT, NULL); + int obj_cnt = 0; + _splitpath(buf, 0, 0, name, 0); + m_Motion = new SMotionLW(); + m_Motion->SetName(name); + while (object) + { + if (g_intinfo->itemFlags(object) & LWITEMF_SELECTED) { + bErr = !ParseObjectMotion(object, obj_cnt); + break; + } + object = g_iteminfo->next(object); + } - EFS.GetSaveName ("$smotion$",buf); + if (!bErr) { + m_Motion->SetParam(g_intinfo->previewStart, g_intinfo->previewEnd, (float)g_lwsi->framesPerSecond); + m_Motion->SaveMotion(buf); + g_msg->info("Export successful.", buf); + } + else + g_msg->error("Export failed.", 0); - if (buf[0]){ - object = g_iteminfo->first( LWI_OBJECT, NULL ); - int obj_cnt = 0; - _splitpath( buf, 0, 0, name, 0 ); - m_Motion = new SMotionLW(); - m_Motion->SetName(name); - while ( object ) { - if(g_intinfo->itemFlags(object)&LWITEMF_SELECTED){ - bErr = !ParseObjectMotion(object,obj_cnt); - break; - } - object = g_iteminfo->next( object ); - } - - if (!bErr){ - m_Motion->SetParam(g_intinfo->previewStart, g_intinfo->previewEnd, (float)g_lwsi->framesPerSecond); - m_Motion->SaveMotion(buf); - g_msg->info ("Export successful.",buf); - }else g_msg->error("Export failed.",0); - - xr_delete(m_Motion); - } + xr_delete(m_Motion); + } } }; \ No newline at end of file diff --git a/src/plugins/lw/Export/LW_export_motion.cpp b/src/plugins/lw/Export/LW_export_motion.cpp index 825692d1b25..448edb0d330 100644 --- a/src/plugins/lw/Export/LW_export_motion.cpp +++ b/src/plugins/lw/Export/LW_export_motion.cpp @@ -1,64 +1,69 @@ +#include "Globals.hpp" +#include "OMotionLW.hpp" +#include "scenscan\objectdb.h" #include "stdafx.h" -#include "xrCore/FileSystem.h" -#include "xrCore/FS.h" #include "utils/LWO/envelope.h" #include "xrCore/Animation/Bone.hpp" #include "xrCore/Animation/Motion.hpp" -#include "Globals.hpp" -#include "scenscan\objectdb.h" -#include "OMotionLW.hpp" +#include "xrCore/FS.h" +#include "xrCore/FileSystem.h" static OMotionLW* m_Motion; void SelectedCount(LWItemType type, int& sel_obj_count, LWItemID& last_sel_obj) { - LWItemID object; - object = g_iteminfo->first( type, NULL ); - while ( object ) { - if(g_intinfo->itemFlags(object)&LWITEMF_SELECTED){ - last_sel_obj = object; - sel_obj_count++; - } - object = g_iteminfo->next( object ); - } + LWItemID object; + object = g_iteminfo->first(type, NULL); + while (object) + { + if (g_intinfo->itemFlags(object) & LWITEMF_SELECTED) { + last_sel_obj = object; + sel_obj_count++; + } + object = g_iteminfo->next(object); + } } extern "C" { //----------------------------------------------------------------------------------------- -void __cdecl SaveObjectMotion(GlobalFunc *global) +void __cdecl SaveObjectMotion(GlobalFunc* global) { Core._initialize("XRayPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - // get bone ID - bool bErr = false; + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + // get bone ID + bool bErr = false; - string_path buf = ""; + string_path buf = ""; - EFS.GetSaveName ("$omotion$",buf); - if (buf[0]){ - int sel_obj_cnt = 0; - LWItemID sel_object; + EFS.GetSaveName("$omotion$", buf); + if (buf[0]) { + int sel_obj_cnt = 0; + LWItemID sel_object; - SelectedCount (LWI_OBJECT,sel_obj_cnt,sel_object); - SelectedCount (LWI_CAMERA,sel_obj_cnt,sel_object); - SelectedCount (LWI_BONE, sel_obj_cnt,sel_object); - SelectedCount (LWI_LIGHT, sel_obj_cnt,sel_object); + SelectedCount(LWI_OBJECT, sel_obj_cnt, sel_object); + SelectedCount(LWI_CAMERA, sel_obj_cnt, sel_object); + SelectedCount(LWI_BONE, sel_obj_cnt, sel_object); + SelectedCount(LWI_LIGHT, sel_obj_cnt, sel_object); - if (sel_obj_cnt==1){ - string_path name; - _splitpath (buf, 0, 0, name, 0); - m_Motion = new OMotionLW(); - m_Motion->SetName (name); - m_Motion->ParseObjectMotion (sel_object); - m_Motion->SetParam (g_intinfo->previewStart, g_intinfo->previewEnd, (float)g_lwsi->framesPerSecond); - m_Motion->SaveMotion (buf); - g_msg->info ("Export motion successful.",g_iteminfo->name(sel_object)); - xr_delete (m_Motion); - }else{ - g_msg->error ("Select one object and try again.",NULL); - } - }else{ - g_msg->error("Export failed. Empty name.",NULL); - } + if (sel_obj_cnt == 1) { + string_path name; + _splitpath(buf, 0, 0, name, 0); + m_Motion = new OMotionLW(); + m_Motion->SetName(name); + m_Motion->ParseObjectMotion(sel_object); + m_Motion->SetParam(g_intinfo->previewStart, g_intinfo->previewEnd, (float)g_lwsi->framesPerSecond); + m_Motion->SaveMotion(buf); + g_msg->info("Export motion successful.", g_iteminfo->name(sel_object)); + xr_delete(m_Motion); + } + else + { + g_msg->error("Select one object and try again.", NULL); + } + } + else + { + g_msg->error("Export failed. Empty name.", NULL); + } } }; \ No newline at end of file diff --git a/src/plugins/lw/Export/LW_export_object.cpp b/src/plugins/lw/Export/LW_export_object.cpp index 2990a1b25df..3ba201ae35e 100644 --- a/src/plugins/lw/Export/LW_export_object.cpp +++ b/src/plugins/lw/Export/LW_export_object.cpp @@ -1,9 +1,9 @@ -#include "stdafx.h" +#include "Globals.hpp" #include "editors/ECore/Editor/editobject.h" -#include "xrCore/FileSystem.h" -#include "xrCore/FS.h" +#include "stdafx.h" #include "xrCore/Animation/Bone.hpp" -#include "Globals.hpp" +#include "xrCore/FS.h" +#include "xrCore/FileSystem.h" class LWBoneParser final { @@ -13,8 +13,7 @@ class LWBoneParser final static void LWBoneParser::Parse(CBone& bone, LWItemID boneId) { LWItemID P = g_iteminfo->parent(boneId); - if (g_iteminfo->type(P) == LWI_BONE) - bone.SetParentName(g_iteminfo->name(P)); + if (g_iteminfo->type(P) == LWI_BONE) bone.SetParentName(g_iteminfo->name(P)); LWDVector vec; g_boneinfo->restParam(boneId, LWIP_POSITION, vec); bone.rest_offset.set((float)vec[0], (float)vec[1], (float)vec[2]); @@ -25,59 +24,63 @@ class LWBoneParser final } }; -static BoneVec* m_LWBones=0; +static BoneVec* m_LWBones = 0; static void AppendBone(LWItemID bone) { - m_LWBones->push_back(new CBone()); - CBone& B = *m_LWBones->back(); - B.SetName(g_iteminfo->name(bone)); + m_LWBones->push_back(new CBone()); + CBone& B = *m_LWBones->back(); + B.SetName(g_iteminfo->name(bone)); LWBoneParser::Parse(B, bone); } static void RecurseBone(LWItemID parent) { - LWItemID bone = g_iteminfo->firstChild(parent); - while (bone!=LWITEM_NULL){ - if (g_iteminfo->type(bone)==LWI_BONE){ - AppendBone(bone); - RecurseBone(bone); - } - bone = g_iteminfo->nextChild(parent,bone); - } + LWItemID bone = g_iteminfo->firstChild(parent); + while (bone != LWITEM_NULL) + { + if (g_iteminfo->type(bone) == LWI_BONE) { + AppendBone(bone); + RecurseBone(bone); + } + bone = g_iteminfo->nextChild(parent, bone); + } } static bool ParseObjectBones(LWItemID object, int& obj_cnt) { - LWItemID bone, parent; - bone = g_iteminfo->first( LWI_BONE, object ); - - if (!bone){ - g_msg->error("Can't find bone.",0); - return false; - } - - while (true){ - parent = g_iteminfo->parent(bone); - if (!parent){ - g_msg->error("Can't find root bone.",0); - return false; - } - if (g_iteminfo->type(parent)!=LWI_BONE) break; - else bone = parent; - } - - if (bone){ - if (obj_cnt>0){ - g_msg->error("Can't support multiple objects.",0); - return false; - } - AppendBone(bone); - RecurseBone (bone); - - obj_cnt++; - } - return true; + LWItemID bone, parent; + bone = g_iteminfo->first(LWI_BONE, object); + + if (!bone) { + g_msg->error("Can't find bone.", 0); + return false; + } + + while (true) + { + parent = g_iteminfo->parent(bone); + if (!parent) { + g_msg->error("Can't find root bone.", 0); + return false; + } + if (g_iteminfo->type(parent) != LWI_BONE) + break; + else + bone = parent; + } + + if (bone) { + if (obj_cnt > 0) { + g_msg->error("Can't support multiple objects.", 0); + return false; + } + AppendBone(bone); + RecurseBone(bone); + + obj_cnt++; + } + return true; } extern void ReplaceSpaceAndLowerCase(shared_str& s); @@ -96,83 +99,91 @@ static void RefineBoneNames(CEditableObject* obj) } extern "C" { - //----------------------------------------------------------------------------------------- - void __cdecl SaveObject(GlobalFunc *global) - { - Core._initialize("XRayPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - - // get bone ID - LWItemID object; - bool bErr = true; - - string_path buf = ""; - object = g_iteminfo->first( LWI_OBJECT, NULL ); - int obj_cnt = 0; - bool bObjSel = false; - - while (object){ - if(g_intinfo->itemFlags(object)&LWITEMF_SELECTED){ - bObjSel = true; - if (EFS.GetSaveName("$import$",buf,0,0)){ - bErr = false; - - char name[1024]; - _splitpath( buf, 0, 0, name, 0 ); - - CEditableObject* obj = new CEditableObject(name); - obj->SetVersionToCurrent(TRUE,TRUE); - - // parse bone if exist - bool bBoneExists=false; - if (g_iteminfo->first( LWI_BONE, object )){ - m_LWBones = &obj->Bones(); - bBoneExists = true; - if (!ParseObjectBones(object,obj_cnt)) bErr = true; - if (bErr){ - // default bone part - obj->BoneParts().push_back(SBonePart()); - SBonePart& BP = obj->BoneParts().back(); - BP.alias = "default"; - for (int b_i=0; b_i<(int)obj->Bones().size(); b_i++) - BP.bones.push_back(obj->Bones()[b_i]->Name()); - } - } - if (!bErr){ - LPCSTR lwo_nm=g_objinfo->filename(object); - {// append path - string_path path,dr,di; - _splitpath (lwo_nm,dr,di,0,0); - strconcat (sizeof(path),path,dr,di); - if (!FS.path_exist(path)) FS.append_path(path,path,0,FALSE); - } - if (FS.exist(lwo_nm)){ - if (!obj->ImportLWO(lwo_nm,false)) bErr = true; - else{ - obj->m_Flags.set(CEditableObject::eoDynamic,TRUE); - obj->Optimize (); - RefineBoneNames(obj); - obj->Save(buf); - } - }else - bErr = true; - } - // ��������� ���� ��� ��������� �� ���������� �� ���� � ������ - - if (bErr) g_msg->error("Export failed.",0); - else g_msg->info ("Export successful.",buf); - bErr = false; - - xr_delete(obj); - m_LWBones = 0; - // freeObjectDB(odb); - break; - } - } - object = g_iteminfo->next( object ); - } - if (!bObjSel) g_msg->error("Select object at first.",0); - else if (bErr) g_msg->error("Export failed.",0); - } +//----------------------------------------------------------------------------------------- +void __cdecl SaveObject(GlobalFunc* global) +{ + Core._initialize("XRayPlugin", LogCallback(ELogCallback, nullptr), FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + + // get bone ID + LWItemID object; + bool bErr = true; + + string_path buf = ""; + object = g_iteminfo->first(LWI_OBJECT, NULL); + int obj_cnt = 0; + bool bObjSel = false; + + while (object) + { + if (g_intinfo->itemFlags(object) & LWITEMF_SELECTED) { + bObjSel = true; + if (EFS.GetSaveName("$import$", buf, 0, 0)) { + bErr = false; + + char name[1024]; + _splitpath(buf, 0, 0, name, 0); + + CEditableObject* obj = new CEditableObject(name); + obj->SetVersionToCurrent(TRUE, TRUE); + + // parse bone if exist + bool bBoneExists = false; + if (g_iteminfo->first(LWI_BONE, object)) { + m_LWBones = &obj->Bones(); + bBoneExists = true; + if (!ParseObjectBones(object, obj_cnt)) bErr = true; + if (bErr) { + // default bone part + obj->BoneParts().push_back(SBonePart()); + SBonePart& BP = obj->BoneParts().back(); + BP.alias = "default"; + for (int b_i = 0; b_i < (int)obj->Bones().size(); b_i++) + BP.bones.push_back(obj->Bones()[b_i]->Name()); + } + } + if (!bErr) { + LPCSTR lwo_nm = g_objinfo->filename(object); + { // append path + string_path path, dr, di; + _splitpath(lwo_nm, dr, di, 0, 0); + strconcat(sizeof(path), path, dr, di); + if (!FS.path_exist(path)) FS.append_path(path, path, 0, FALSE); + } + if (FS.exist(lwo_nm)) { + if (!obj->ImportLWO(lwo_nm, false)) + bErr = true; + else + { + obj->m_Flags.set(CEditableObject::eoDynamic, TRUE); + obj->Optimize(); + RefineBoneNames(obj); + obj->Save(buf); + } + } + else + bErr = true; + } + // ��������� ���� ��� ��������� �� ���������� �� ���� � ������ + + if (bErr) + g_msg->error("Export failed.", 0); + else + g_msg->info("Export successful.", buf); + bErr = false; + + xr_delete(obj); + m_LWBones = 0; + // freeObjectDB(odb); + break; + } + } + object = g_iteminfo->next(object); + } + if (!bObjSel) + g_msg->error("Select object at first.", 0); + else if (bErr) + g_msg->error("Export failed.", 0); +} //----------------------------------------------------------------------------------------- }; \ No newline at end of file diff --git a/src/plugins/lw/Export/OMotionLW.cpp b/src/plugins/lw/Export/OMotionLW.cpp index 6a6642d979f..228154330ff 100644 --- a/src/plugins/lw/Export/OMotionLW.cpp +++ b/src/plugins/lw/Export/OMotionLW.cpp @@ -1,6 +1,6 @@ -#include "StdAfx.h" #include "OMotionLW.hpp" #include "Globals.hpp" +#include "StdAfx.h" #include "Util.hpp" void OMotionLW::ParseObjectMotion(LWItemID object) @@ -12,8 +12,7 @@ void OMotionLW::ParseObjectMotion(LWItemID object) while (chan) { EChannelType t = GetChannelType(chan); - if (t != ctUnsupported) - { + if (t != ctUnsupported) { CEnvelope* env = CreateEnvelope(chan); envs[t] = env; } diff --git a/src/plugins/lw/Export/SMotionLW.cpp b/src/plugins/lw/Export/SMotionLW.cpp index d8a578a4d16..2bf54314c2c 100644 --- a/src/plugins/lw/Export/SMotionLW.cpp +++ b/src/plugins/lw/Export/SMotionLW.cpp @@ -1,6 +1,6 @@ -#include "StdAfx.h" #include "SMotionLW.hpp" #include "Globals.hpp" +#include "StdAfx.h" #include "Util.hpp" // XXX: locate and include @@ -19,7 +19,7 @@ void SMotionLW::ParseBoneMotion(LWItemID bone) LWItemID goal, goal_parent; bone_mots.push_back(st_BoneMotion()); - st_BoneMotion& bm = bone_mots.back(); + st_BoneMotion& bm = bone_mots.back(); group = g_iteminfo->chanGroup(bone); chan = g_chinfo->nextChannel(group, NULL); @@ -30,9 +30,8 @@ void SMotionLW::ParseBoneMotion(LWItemID bone) goal_parent = g_iteminfo->parent(goal); bool bParent = !(goal_parent == LWITEM_NULL); - bool bGoalOrient = !!(g_iteminfo->flags(bone)&LWITEMF_GOAL_ORIENT); - if (bGoalOrient) - { + bool bGoalOrient = !!(g_iteminfo->flags(bone) & LWITEMF_GOAL_ORIENT); + if (bGoalOrient) { group_goal = g_iteminfo->chanGroup(goal); chan_goal = g_chinfo->nextChannel(group_goal, NULL); // flag @@ -42,10 +41,8 @@ void SMotionLW::ParseBoneMotion(LWItemID bone) while (chan) { EChannelType t = GetChannelType(chan); - if (t != ctUnsupported) - { - if (!bGoalOrient || (bGoalOrient && ((t == ctPositionX) || (t == ctPositionY) || (t == ctPositionZ)))) - { + if (t != ctUnsupported) { + if (!bGoalOrient || (bGoalOrient && ((t == ctPositionX) || (t == ctPositionY) || (t == ctPositionZ)))) { CEnvelope* env = CreateEnvelope(chan); bm.envs[t] = env; } @@ -53,18 +50,14 @@ void SMotionLW::ParseBoneMotion(LWItemID bone) chan = g_chinfo->nextChannel(group, chan); } // goal orientation - if (bGoalOrient) - { + if (bGoalOrient) { while (chan_goal) { EChannelType t = GetChannelType(chan_goal); - if (t != ctUnsupported) - { - if ((t == ctRotationH) || (t == ctRotationP) || (t == ctRotationB)) - { + if (t != ctUnsupported) { + if ((t == ctRotationH) || (t == ctRotationP) || (t == ctRotationB)) { // parent (if exist) - if (bParent) - { + if (bParent) { group_goal_parent = g_iteminfo->chanGroup(goal_parent); chan_goal_parent = g_chinfo->nextChannel(group_goal_parent, NULL); while (chan_goal_parent) diff --git a/src/plugins/lw/Export/SceneObject.h b/src/plugins/lw/Export/SceneObject.h index 525b94ba461..0ebfae99d47 100644 --- a/src/plugins/lw/Export/SceneObject.h +++ b/src/plugins/lw/Export/SceneObject.h @@ -6,106 +6,112 @@ #include "customobject.h" //---------------------------------------------------- -class CSceneObject : public CCustomObject { - shared_str m_ReferenceName; - CEditableObject*m_pReference; - int m_Version; - void ReferenceChange (PropValue* sender); +class CSceneObject : public CCustomObject +{ + shared_str m_ReferenceName; + CEditableObject* m_pReference; + int m_Version; + void ReferenceChange(PropValue* sender); + public: - enum{ -// flDynamic = (1<<0), - flFORCE32 = u32(-1) + enum + { + // flDynamic = (1<<0), + flFORCE32 = u32(-1) }; + private: - Fbox m_TBBox; - // options - Flags32 m_Flags; + Fbox m_TBBox; + // options + Flags32 m_Flags; + public: - virtual void SetScale (const Fvector& scale) + virtual void SetScale(const Fvector& scale) { - if (m_pReference&&m_pReference->IsDynamic()){ - ELog.Msg(mtError,"Dynamic object %s - can't scale.", Name); - }else{ - FScale.set(scale); + if (m_pReference && m_pReference->IsDynamic()) { + ELog.Msg(mtError, "Dynamic object %s - can't scale.", Name); + } + else + { + FScale.set(scale); UpdateTransform(); } } + protected: - typedef CCustomObject inherited; - int m_iBlinkTime; - CSurface* m_BlinkSurf; - void RenderBlink (); + typedef CCustomObject inherited; + int m_iBlinkTime; + CSurface* m_BlinkSurf; + void RenderBlink(); + public: // constructor/destructor methods - CSceneObject (LPVOID data, LPCSTR name); - virtual ~CSceneObject (); + CSceneObject(LPVOID data, LPCSTR name); + virtual ~CSceneObject(); - virtual void Select (BOOL flag); - void Construct (LPVOID data); + virtual void Select(BOOL flag); + void Construct(LPVOID data); - IC bool CheckVersion () {return m_pReference?(m_Version==m_pReference->Version()):false;} + IC bool CheckVersion() { return m_pReference ? (m_Version == m_pReference->Version()) : false; } // get object properties methods - IC bool RefCompare (CEditableObject *to){return m_pReference?!!(m_pReference==to):false; } - IC bool RefCompare (LPCSTR ref){return ref&&m_pReference?(strcmp(ref,m_pReference->GetName())==0):false; } - IC CEditableObject* GetReference () {return m_pReference; } - CEditableObject*SetReference (LPCSTR ref_name); - CEditableObject*UpdateReference (); - IC EditMeshVec* Meshes () {return m_pReference?&m_pReference->Meshes():0;} - virtual LPCSTR RefName () {return m_pReference?m_pReference->GetName():0;} - virtual bool CanAttach () {return true;} - + IC bool RefCompare(CEditableObject* to) { return m_pReference ? !!(m_pReference == to) : false; } + IC bool RefCompare(LPCSTR ref) { return ref && m_pReference ? (strcmp(ref, m_pReference->GetName()) == 0) : false; } + IC CEditableObject* GetReference() { return m_pReference; } + CEditableObject* SetReference(LPCSTR ref_name); + CEditableObject* UpdateReference(); + IC EditMeshVec* Meshes() { return m_pReference ? &m_pReference->Meshes() : 0; } + virtual LPCSTR RefName() { return m_pReference ? m_pReference->GetName() : 0; } + virtual bool CanAttach() { return true; } // statistics methods - IC bool IsDynamic () {return (m_pReference?m_pReference->IsDynamic():false); } - IC bool IsStatic () {return (m_pReference?m_pReference->IsStatic():false); } - IC bool IsMUStatic () {return (m_pReference?m_pReference->IsMUStatic():false); } - int GetFaceCount (); - int GetVertexCount (); - int GetSurfFaceCount (const char* surf_name); + IC bool IsDynamic() { return (m_pReference ? m_pReference->IsDynamic() : false); } + IC bool IsStatic() { return (m_pReference ? m_pReference->IsStatic() : false); } + IC bool IsMUStatic() { return (m_pReference ? m_pReference->IsMUStatic() : false); } + int GetFaceCount(); + int GetVertexCount(); + int GetSurfFaceCount(const char* surf_name); // render methods - virtual bool IsRender (); - virtual void Render (int priority, bool strictB2F); - void RenderSelection (u32 color=0x40E64646); - void RenderEdge (CEditableMesh* m=0, u32 color=0xFFC0C0C0); - void RenderBones (); - void RenderSingle (); + virtual bool IsRender(); + virtual void Render(int priority, bool strictB2F); + void RenderSelection(u32 color = 0x40E64646); + void RenderEdge(CEditableMesh* m = 0, u32 color = 0xFFC0C0C0); + void RenderBones(); + void RenderSingle(); // update methods - virtual void OnFrame (); - virtual void OnUpdateTransform (); + virtual void OnFrame(); + virtual void OnUpdateTransform(); // misc - void EvictObject (); + void EvictObject(); // pick methods - bool BoxPick (const Fbox& box, SBoxPickInfoVec& pinf); - virtual bool RayPick (float& dist, const Fvector& S, const Fvector& D, SRayPickInfo* pinf=0); - virtual void RayQuery (SPickQuery& pinf); - virtual void BoxQuery (SPickQuery& pinf); - virtual bool FrustumPick (const CFrustum& frustum); - virtual bool SpherePick (const Fvector& center, float radius); + bool BoxPick(const Fbox& box, SBoxPickInfoVec& pinf); + virtual bool RayPick(float& dist, const Fvector& S, const Fvector& D, SRayPickInfo* pinf = 0); + virtual void RayQuery(SPickQuery& pinf); + virtual void BoxQuery(SPickQuery& pinf); + virtual bool FrustumPick(const CFrustum& frustum); + virtual bool SpherePick(const Fvector& center, float radius); // get orintation/bounding volume methods - virtual bool GetBox (Fbox& box); - virtual bool GetUTBox (Fbox& box); - void GetFullTransformToWorld (Fmatrix& m); - void GetFullTransformToLocal (Fmatrix& m); + virtual bool GetBox(Fbox& box); + virtual bool GetUTBox(Fbox& box); + void GetFullTransformToWorld(Fmatrix& m); + void GetFullTransformToLocal(Fmatrix& m); - // editor integration - virtual void FillProp (LPCSTR pref, PropItemVec& values); - virtual bool GetSummaryInfo (SSceneSummary* inf); + // editor integration + virtual void FillProp(LPCSTR pref, PropItemVec& values); + virtual bool GetSummaryInfo(SSceneSummary* inf); // load/save methods - virtual bool Load (IReader&); - virtual void Save (IWriter&); + virtual bool Load(IReader&); + virtual void Save(IWriter&); - virtual void OnShowHint (AStringVec& dest); + virtual void OnShowHint(AStringVec& dest); - void Blink (CSurface* surf=0); + void Blink(CSurface* surf = 0); - virtual bool Validate (bool bMsg); + virtual bool Validate(bool bMsg); }; //---------------------------------------------------- #endif /*_INCDEF_EditObject_H_*/ - - diff --git a/src/plugins/lw/Export/Util.cpp b/src/plugins/lw/Export/Util.cpp index 5d68fc5baa5..6053f394f9f 100644 --- a/src/plugins/lw/Export/Util.cpp +++ b/src/plugins/lw/Export/Util.cpp @@ -1,22 +1,16 @@ -#include "StdAfx.h" #include "Util.hpp" #include "Globals.hpp" +#include "StdAfx.h" EChannelType GetChannelType(LWChannelID chan) { const char* chname = g_chinfo->channelName(chan); - if (xr_strcmp(chname, "Position.X") == 0) - return ctPositionX; - if (xr_strcmp(chname, "Position.Y") == 0) - return ctPositionY; - if (xr_strcmp(chname, "Position.Z") == 0) - return ctPositionZ; - if (xr_strcmp(chname, "Rotation.H") == 0) - return ctRotationH; - if (xr_strcmp(chname, "Rotation.P") == 0) - return ctRotationP; - if (xr_strcmp(chname, "Rotation.B") == 0) - return ctRotationB; + if (xr_strcmp(chname, "Position.X") == 0) return ctPositionX; + if (xr_strcmp(chname, "Position.Y") == 0) return ctPositionY; + if (xr_strcmp(chname, "Position.Z") == 0) return ctPositionZ; + if (xr_strcmp(chname, "Rotation.H") == 0) return ctRotationH; + if (xr_strcmp(chname, "Rotation.P") == 0) return ctRotationP; + if (xr_strcmp(chname, "Rotation.B") == 0) return ctRotationB; return ctUnsupported; } @@ -25,15 +19,14 @@ CEnvelope* CreateEnvelope(LWChannelID chan, LWChannelID* chan_parent /*= nullptr LWChanGroupID group, group_parent; LWEnvelopeID lwenv, lwenv_parent; LWEnvKeyframeID lwkey, lwkey_parent; - CEnvelope *env; + CEnvelope* env; st_Key *key, *tail = NULL; double val; env = new CEnvelope(); group = g_chinfo->channelParent(chan); lwenv = g_chinfo->channelEnvelope(chan); lwkey = NULL; - if (chan_parent) - { + if (chan_parent) { group_parent = g_chinfo->channelParent(*chan_parent); lwenv_parent = g_chinfo->channelEnvelope(*chan_parent); lwkey_parent = NULL; @@ -41,11 +34,9 @@ CEnvelope* CreateEnvelope(LWChannelID chan, LWChannelID* chan_parent /*= nullptr g_envf->egGet(lwenv, group, LWENVTAG_PREBEHAVE, &env->behavior[0]); g_envf->egGet(lwenv, group, LWENVTAG_POSTBEHAVE, &env->behavior[1]); float val_parent = 0; - if (chan_parent) - { + if (chan_parent) { lwkey_parent = g_envf->nextKey(lwenv_parent, lwkey_parent); - if (lwkey_parent) - { + if (lwkey_parent) { g_envf->keyGet(lwenv_parent, lwkey_parent, LWKEY_VALUE, &val); val_parent = (float)val; } @@ -55,15 +46,24 @@ CEnvelope* CreateEnvelope(LWChannelID chan, LWChannelID* chan_parent /*= nullptr key = new st_Key(); env->keys.push_back(key); g_envf->keyGet(lwenv, lwkey, LWKEY_SHAPE, &key->shape); - g_envf->keyGet(lwenv, lwkey, LWKEY_VALUE, &val); key->value = (float)val + val_parent; - g_envf->keyGet(lwenv, lwkey, LWKEY_TIME, &val); key->time = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_TENSION, &val); key->tension = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_CONTINUITY, &val); key->continuity = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_BIAS, &val); key->bias = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_0, &val); key->param[0] = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_1, &val); key->param[1] = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_2, &val); key->param[2] = (float)val; - g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_3, &val); key->param[3] = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_VALUE, &val); + key->value = (float)val + val_parent; + g_envf->keyGet(lwenv, lwkey, LWKEY_TIME, &val); + key->time = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_TENSION, &val); + key->tension = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_CONTINUITY, &val); + key->continuity = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_BIAS, &val); + key->bias = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_0, &val); + key->param[0] = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_1, &val); + key->param[1] = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_2, &val); + key->param[2] = (float)val; + g_envf->keyGet(lwenv, lwkey, LWKEY_PARAM_3, &val); + key->param[3] = (float)val; } return env; } diff --git a/src/plugins/lw/Export/Util.hpp b/src/plugins/lw/Export/Util.hpp index 2a7c0a5289b..020d7bf7248 100644 --- a/src/plugins/lw/Export/Util.hpp +++ b/src/plugins/lw/Export/Util.hpp @@ -1,8 +1,8 @@ #pragma once #include "StdAfx.h" -#include "xrCore/Animation/Motion.hpp" #include "xrCore/Animation/Envelope.hpp" +#include "xrCore/Animation/Motion.hpp" EChannelType GetChannelType(LWChannelID chan); -//Use the Animation Envelopes global to get the keys of an LWEnvelope and create our own version. +// Use the Animation Envelopes global to get the keys of an LWEnvelope and create our own version. CEnvelope* CreateEnvelope(LWChannelID chan, LWChannelID* chan_parent = nullptr); diff --git a/src/plugins/lw/Export/envtest.c b/src/plugins/lw/Export/envtest.c index 6c759e2f65f..7da90c72106 100644 --- a/src/plugins/lw/Export/envtest.c +++ b/src/plugins/lw/Export/envtest.c @@ -3,108 +3,107 @@ envtest.c A plug-in to test the envelope interpolation routine in interp.c. - + Ernie Wright 31 Aug 00 - + This is what I used to test evalEnvelope(). It reads the Position.X envelope for the camera, then compares what evalEnvelope() returns to what LWEnvelopeFuncs->evaluate() says. ====================================================================== */ -#include -#include -#include -#include #include +#include +#include +#include #include #include +#include +#include #include -#include +#include #include #include #include -#include /* some globals */ -LWChannelInfo *g_chinfo; -LWEnvelopeFuncs *g_envf; -LWItemInfo *g_iteminfo; -LWSceneInfo *g_lwsi; -LWInterfaceInfo *g_intinfo; -LWMessageFuncs *g_msg; -LWBoneInfo *g_boneinfo; -LWObjectFuncs *g_objfunc; -LWObjectInfo *g_objinfo; -LWSurfaceFuncs *g_surff; -HostDisplayInfo *g_hdi; - - -static int get_globals( GlobalFunc *global ) +LWChannelInfo* g_chinfo; +LWEnvelopeFuncs* g_envf; +LWItemInfo* g_iteminfo; +LWSceneInfo* g_lwsi; +LWInterfaceInfo* g_intinfo; +LWMessageFuncs* g_msg; +LWBoneInfo* g_boneinfo; +LWObjectFuncs* g_objfunc; +LWObjectInfo* g_objinfo; +LWSurfaceFuncs* g_surff; +HostDisplayInfo* g_hdi; + +static int get_globals(GlobalFunc* global) { - g_chinfo = global( LWCHANNELINFO_GLOBAL, GFUSE_TRANSIENT ); - g_envf = global( LWENVELOPEFUNCS_GLOBAL, GFUSE_TRANSIENT ); - g_iteminfo = global( LWITEMINFO_GLOBAL, GFUSE_TRANSIENT ); - g_lwsi = global( LWSCENEINFO_GLOBAL, GFUSE_TRANSIENT ); - g_intinfo = global( LWINTERFACEINFO_GLOBAL, GFUSE_TRANSIENT ); - g_msg = global( LWMESSAGEFUNCS_GLOBAL, GFUSE_TRANSIENT ); - g_boneinfo = global( LWBONEINFO_GLOBAL, GFUSE_TRANSIENT ); - g_objfunc = global( LWOBJECTFUNCS_GLOBAL, GFUSE_TRANSIENT ); - g_objinfo = global( LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT ); - g_surff = global( LWSURFACEFUNCS_GLOBAL, GFUSE_TRANSIENT ); - g_hdi = global( LWHOSTDISPLAYINFO_GLOBAL, GFUSE_TRANSIENT ); - - return ( g_chinfo && g_envf && g_iteminfo && g_lwsi && g_intinfo && g_msg && g_boneinfo && g_objfunc && g_objinfo && g_surff); -} + g_chinfo = global(LWCHANNELINFO_GLOBAL, GFUSE_TRANSIENT); + g_envf = global(LWENVELOPEFUNCS_GLOBAL, GFUSE_TRANSIENT); + g_iteminfo = global(LWITEMINFO_GLOBAL, GFUSE_TRANSIENT); + g_lwsi = global(LWSCENEINFO_GLOBAL, GFUSE_TRANSIENT); + g_intinfo = global(LWINTERFACEINFO_GLOBAL, GFUSE_TRANSIENT); + g_msg = global(LWMESSAGEFUNCS_GLOBAL, GFUSE_TRANSIENT); + g_boneinfo = global(LWBONEINFO_GLOBAL, GFUSE_TRANSIENT); + g_objfunc = global(LWOBJECTFUNCS_GLOBAL, GFUSE_TRANSIENT); + g_objinfo = global(LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT); + g_surff = global(LWSURFACEFUNCS_GLOBAL, GFUSE_TRANSIENT); + g_hdi = global(LWHOSTDISPLAYINFO_GLOBAL, GFUSE_TRANSIENT); + return (g_chinfo && g_envf && g_iteminfo && g_lwsi && g_intinfo && g_msg && g_boneinfo && g_objfunc && g_objinfo && + g_surff); +} //====================================================================== -//KeyExport() -//The activation function. +// KeyExport() +// The activation function. //====================================================================== -void __cdecl SaveSkeletonMotion(GlobalFunc *global); -XCALL_( int )SkeletonMotionExport( long version, GlobalFunc *global, LWLayoutGeneric *local, void *serverData ){ - if (version!=LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; - if (!get_globals(global)) return AFUNC_BADGLOBAL; - - SaveSkeletonMotion(global); - - return AFUNC_OK; +void __cdecl SaveSkeletonMotion(GlobalFunc* global); +XCALL_(int) SkeletonMotionExport(long version, GlobalFunc* global, LWLayoutGeneric* local, void* serverData) +{ + if (version != LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; + if (!get_globals(global)) return AFUNC_BADGLOBAL; + + SaveSkeletonMotion(global); + + return AFUNC_OK; } //----------------------------------------------------------------------------------------- //====================================================================== -//KeyExport() -//The activation function. +// KeyExport() +// The activation function. //====================================================================== -void __cdecl SaveObject(GlobalFunc *global); -XCALL_( int )ObjectExport( long version, GlobalFunc *global, LWLayoutGeneric *local, void *serverData ){ - if (version!=LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; - if (!get_globals(global)) return AFUNC_BADGLOBAL; - - SaveObject(global); - - return AFUNC_OK; +void __cdecl SaveObject(GlobalFunc* global); +XCALL_(int) ObjectExport(long version, GlobalFunc* global, LWLayoutGeneric* local, void* serverData) +{ + if (version != LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; + if (!get_globals(global)) return AFUNC_BADGLOBAL; + + SaveObject(global); + + return AFUNC_OK; } //----------------------------------------------------------------------------------------- //====================================================================== -//KeyExport() -//The activation function. +// KeyExport() +// The activation function. //====================================================================== -void __cdecl SaveObjectMotion(GlobalFunc *global); -XCALL_( int )ObjectMotionExport( long version, GlobalFunc *global, LWLayoutGeneric *local, void *serverData ){ - if (version!=LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; - if (!get_globals(global)) return AFUNC_BADGLOBAL; - - SaveObjectMotion(global); - - return AFUNC_OK; +void __cdecl SaveObjectMotion(GlobalFunc* global); +XCALL_(int) ObjectMotionExport(long version, GlobalFunc* global, LWLayoutGeneric* local, void* serverData) +{ + if (version != LWLAYOUTGENERIC_VERSION) return AFUNC_BADVERSION; + if (!get_globals(global)) return AFUNC_BADGLOBAL; + + SaveObjectMotion(global); + + return AFUNC_OK; } -ServerRecord ServerDesc[] = { - { LWLAYOUTGENERIC_CLASS, "XRay_Skeleton_Motion_Export", SkeletonMotionExport }, - { LWLAYOUTGENERIC_CLASS, "XRay_Object_Export", ObjectExport }, - { LWLAYOUTGENERIC_CLASS, "XRay_Object_Motion_Export", ObjectMotionExport }, - { NULL } -}; +ServerRecord ServerDesc[] = {{LWLAYOUTGENERIC_CLASS, "XRay_Skeleton_Motion_Export", SkeletonMotionExport}, + {LWLAYOUTGENERIC_CLASS, "XRay_Object_Export", ObjectExport}, + {LWLAYOUTGENERIC_CLASS, "XRay_Object_Motion_Export", ObjectMotionExport}, {NULL}}; diff --git a/src/plugins/lw/Export/resource.h b/src/plugins/lw/Export/resource.h index a02358ca93a..1d713be98de 100644 --- a/src/plugins/lw/Export/resource.h +++ b/src/plugins/lw/Export/resource.h @@ -2,26 +2,26 @@ // Microsoft Developer Studio generated include file. // Used by resource.rc // -#define IDDEBUG 3 -#define IDD_LOG 101 -#define IDI_ICON 103 -#define IDD_VERIFY 104 -#define IDI_XRAY 105 -#define IDC_LIST 1000 -#define IDC_FILE 1001 -#define IDC_LINE 1002 -#define IDC_DESC 1003 -#define IDSTOP 1004 -#define IDCONTINUE 1005 -#define IDC_STACK 1006 +#define IDDEBUG 3 +#define IDD_LOG 101 +#define IDI_ICON 103 +#define IDD_VERIFY 104 +#define IDI_XRAY 105 +#define IDC_LIST 1000 +#define IDC_FILE 1001 +#define IDC_LINE 1002 +#define IDC_DESC 1003 +#define IDSTOP 1004 +#define IDCONTINUE 1005 +#define IDC_STACK 1006 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1007 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1007 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/lw/Export/scenscan/objectdb.cpp b/src/plugins/lw/Export/scenscan/objectdb.cpp index 4a0a7d6337f..9b29006d6f4 100644 --- a/src/plugins/lw/Export/scenscan/objectdb.cpp +++ b/src/plugins/lw/Export/scenscan/objectdb.cpp @@ -9,7 +9,7 @@ Functions for creating an object database. #include "objectdb.h" #include "vecmat.h" -#pragma warning (disable:4995) +#pragma warning(disable : 4995) /* ====================================================================== @@ -20,31 +20,31 @@ ascending numerical order. This takes only linear time if point IDs arrive in order. ====================================================================== */ -static int pntScan( ObjectDB *odb, LWPntID id ) +static int pntScan(ObjectDB* odb, LWPntID id) { - int j; + int j; - j = odb->npoints; + j = odb->npoints; - if ( j == 0 ) { - odb->pt[ 0 ].id = id; - ++odb->npoints; - return 0; - } + if (j == 0) { + odb->pt[0].id = id; + ++odb->npoints; + return 0; + } - while ( odb->pt[ j - 1 ].id > id ) { - odb->pt[ j ].id = odb->pt[ j - 1 ].id; - --j; - if ( j == 0 ) break; - } + while (odb->pt[j - 1].id > id) + { + odb->pt[j].id = odb->pt[j - 1].id; + --j; + if (j == 0) break; + } - odb->pt[ j ].id = id; - ++odb->npoints; + odb->pt[j].id = id; + ++odb->npoints; - return 0; + return 0; } - /* ====================================================================== polScan() @@ -52,14 +52,13 @@ polScan() Polygon scan callback. Just store the ID. ====================================================================== */ -static int polScan( ObjectDB *odb, LWPolID id ) +static int polScan(ObjectDB* odb, LWPolID id) { - odb->pol[ odb->npolygons ].id = id; - ++odb->npolygons; - return 0; + odb->pol[odb->npolygons].id = id; + ++odb->npolygons; + return 0; } - /* ====================================================================== findVert() @@ -68,19 +67,22 @@ Binary search the point array and return the array index for the given point ID. ====================================================================== */ -int findVert( ObjectDB *odb, LWPntID id ) +int findVert(ObjectDB* odb, LWPntID id) { - int lt = 0, rt = odb->npoints - 1, x; - - while ( rt >= lt ) { - x = ( lt + rt ) / 2; - if ( id < odb->pt[ x ].id ) rt = x - 1; else lt = x + 1; - if ( id == odb->pt[ x ].id ) return x; - } - return -1; + int lt = 0, rt = odb->npoints - 1, x; + + while (rt >= lt) + { + x = (lt + rt) / 2; + if (id < odb->pt[x].id) + rt = x - 1; + else + lt = x + 1; + if (id == odb->pt[x].id) return x; + } + return -1; } - /* ====================================================================== getPolyNormals() @@ -91,31 +93,32 @@ The normal is the cross product of two vectors formed from these points. It's undefined for one- and two-point polygons. ====================================================================== */ -void getPolyNormals( ObjectDB *odb, int i ) +void getPolyNormals(ObjectDB* odb, int i) { - int j, k; - LWFVector p1, p2, pn, v1, v2; - - for ( j = 0; j < odb->npolygons; j++ ) { - if ( odb->pol[ j ].nverts < 3 ) continue; - for ( k = 0; k < 3; k++ ) { - p1[ k ] = odb->pt[ odb->pol[ j ].v[ 0 ].index ].pos[ i ][ k ]; - p2[ k ] = odb->pt[ odb->pol[ j ].v[ 1 ].index ].pos[ i ][ k ]; - pn[ k ] = odb->pt[ odb->pol[ j ].v[ - odb->pol[ j ].nverts - 1 ].index ].pos[ i ][ k ]; - } - - for ( k = 0; k < 3; k++ ) { - v1[ k ] = p2[ k ] - p1[ k ]; - v2[ k ] = pn[ k ] - p1[ k ]; - } - - cross( v1, v2, odb->pol[ j ].norm[ i ] ); - normalize( odb->pol[ j ].norm[ i ] ); - } + int j, k; + LWFVector p1, p2, pn, v1, v2; + + for (j = 0; j < odb->npolygons; j++) + { + if (odb->pol[j].nverts < 3) continue; + for (k = 0; k < 3; k++) + { + p1[k] = odb->pt[odb->pol[j].v[0].index].pos[i][k]; + p2[k] = odb->pt[odb->pol[j].v[1].index].pos[i][k]; + pn[k] = odb->pt[odb->pol[j].v[odb->pol[j].nverts - 1].index].pos[i][k]; + } + + for (k = 0; k < 3; k++) + { + v1[k] = p2[k] - p1[k]; + v2[k] = pn[k] - p1[k]; + } + + cross(v1, v2, odb->pol[j].norm[i]); + normalize(odb->pol[j].norm[i]); + } } - /* ====================================================================== getVertNormals() @@ -127,39 +130,39 @@ smoothing angle for the current polygon's surface, the normal of the adjacent polygon is excluded from the sum. ====================================================================== */ -void getVertNormals( ObjectDB *odb, int i ) +void getVertNormals(ObjectDB* odb, int i) { - int j, k, n, g, h, p; - float a; + int j, k, n, g, h, p; + float a; - for ( j = 0; j < odb->npolygons; j++ ) { - for ( n = 0; n < odb->pol[ j ].nverts; n++ ) { - for ( k = 0; k < 3; k++ ) - odb->pol[ j ].v[ n ].norm[ i ][ k ] - = odb->pol[ j ].norm[ i ][ k ]; + for (j = 0; j < odb->npolygons; j++) + { + for (n = 0; n < odb->pol[j].nverts; n++) + { + for (k = 0; k < 3; k++) + odb->pol[j].v[n].norm[i][k] = odb->pol[j].norm[i][k]; - if ( odb->surf[ odb->pol[ j ].sindex ].sman <= 0 ) continue; + if (odb->surf[odb->pol[j].sindex].sman <= 0) continue; - p = odb->pol[ j ].v[ n ].index; + p = odb->pol[j].v[n].index; - for ( g = 0; g < odb->pt[ p ].npols; g++ ) { - h = odb->pt[ p ].pol[ g ]; - if ( h == j ) continue; + for (g = 0; g < odb->pt[p].npols; g++) + { + h = odb->pt[p].pol[g]; + if (h == j) continue; - a = vecangle( odb->pol[ j ].norm[ i ], odb->pol[ h ].norm[ i ] ); - if ( a > odb->surf[ odb->pol[ j ].sindex ].sman ) continue; + a = vecangle(odb->pol[j].norm[i], odb->pol[h].norm[i]); + if (a > odb->surf[odb->pol[j].sindex].sman) continue; - for ( k = 0; k < 3; k++ ) - odb->pol[ j ].v[ n ].norm[ i ][ k ] - += odb->pol[ h ].norm[ i ][ k ]; - } + for (k = 0; k < 3; k++) + odb->pol[j].v[n].norm[i][k] += odb->pol[h].norm[i][k]; + } - normalize( odb->pol[ j ].v[ n ].norm[ i ] ); - } - } + normalize(odb->pol[j].v[n].norm[i]); + } + } } - /* ====================================================================== freeObjectDB() @@ -167,32 +170,29 @@ freeObjectDB() Free an ObjectDB created by getObjectDB(). ====================================================================== */ -void freeObjectDB( ObjectDB *odb ) +void freeObjectDB(ObjectDB* odb) { - int i; - - if ( odb ) { - freeObjectVMaps( odb ); - freeObjectSurfs( odb ); - freePointSearch( odb ); - - if ( odb->pt ) { - for ( i = 0; i < odb->npoints; i++ ) - if ( odb->pt[ i ].pol ) - free( odb->pt[ i ].pol ); - free( odb->pt ); - } - if ( odb->pol ) { - for ( i = 0; i < odb->npolygons; i++ ) - if ( odb->pol[ i ].v ) - free( odb->pol[ i ].v ); - free( odb->pol ); - } - free( odb ); - } + int i; + + if (odb) { + freeObjectVMaps(odb); + freeObjectSurfs(odb); + freePointSearch(odb); + + if (odb->pt) { + for (i = 0; i < odb->npoints; i++) + if (odb->pt[i].pol) free(odb->pt[i].pol); + free(odb->pt); + } + if (odb->pol) { + for (i = 0; i < odb->npolygons; i++) + if (odb->pol[i].v) free(odb->pol[i].v); + free(odb->pol); + } + free(odb); + } } - /* ====================================================================== getObjectDB() @@ -200,140 +200,138 @@ getObjectDB() Create an ObjectDB for an object. ====================================================================== */ -ObjectDB *getObjectDB( LWItemID id, GlobalFunc *global ) +ObjectDB* getObjectDB(LWItemID id, GlobalFunc* global) { - LWObjectInfo *objinfo; - LWMeshInfo *mesh; - LWPntID ptid; - ObjectDB *odb; - const char *name; - int npts, npols, nverts, i, j, k, ok = 0; - + LWObjectInfo* objinfo; + LWMeshInfo* mesh; + LWPntID ptid; + ObjectDB* odb; + const char* name; + int npts, npols, nverts, i, j, k, ok = 0; - /* get the object info global */ + /* get the object info global */ - objinfo = (st_LWObjectInfo*)global( LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT ); - if ( !objinfo ) return NULL; + objinfo = (st_LWObjectInfo*)global(LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT); + if (!objinfo) return NULL; - /* get the mesh info for the object */ + /* get the mesh info for the object */ - mesh = objinfo->meshInfo( id, 1 ); - if ( !mesh ) return NULL; + mesh = objinfo->meshInfo(id, 1); + if (!mesh) return NULL; - /* alloc the object database */ + /* alloc the object database */ - odb = (st_ObjectDB*)calloc( 1, sizeof( ObjectDB )); - if ( !odb ) goto Finish; + odb = (st_ObjectDB*)calloc(1, sizeof(ObjectDB)); + if (!odb) goto Finish; - odb->id = id; - name = objinfo->filename( id ); - odb->filename = (char*)malloc( xr_strlen( name ) + 1 ); - if ( !odb->filename ) goto Finish; - strcpy( odb->filename, name ); + odb->id = id; + name = objinfo->filename(id); + odb->filename = (char*)malloc(xr_strlen(name) + 1); + if (!odb->filename) goto Finish; + strcpy(odb->filename, name); - /* alloc and init the points array */ + /* alloc and init the points array */ - npts = mesh->numPoints( mesh ); - odb->pt = (st_DBPoint*)calloc( npts, sizeof( DBPoint )); - if ( !odb->pt ) goto Finish; + npts = mesh->numPoints(mesh); + odb->pt = (st_DBPoint*)calloc(npts, sizeof(DBPoint)); + if (!odb->pt) goto Finish; - if ( mesh->scanPoints( mesh, (int (__cdecl *)(void *,struct st_GCoreVertex *))pntScan, odb )) - goto Finish; + if (mesh->scanPoints(mesh, (int(__cdecl*)(void*, struct st_GCoreVertex*))pntScan, odb)) goto Finish; - /* alloc and init the polygons array */ + /* alloc and init the polygons array */ - npols = mesh->numPolygons( mesh ); - odb->pol = (st_DBPolygon*)calloc( npols, sizeof( DBPolygon )); - if ( !odb->pol ) goto Finish; + npols = mesh->numPolygons(mesh); + odb->pol = (st_DBPolygon*)calloc(npols, sizeof(DBPolygon)); + if (!odb->pol) goto Finish; - if ( mesh->scanPolys( mesh, (int (__cdecl *)(void *,struct st_GCorePolygon *))polScan, odb )) - goto Finish; + if (mesh->scanPolys(mesh, (int(__cdecl*)(void*, struct st_GCorePolygon*))polScan, odb)) goto Finish; - /* get the vertices of each polygon */ + /* get the vertices of each polygon */ - for ( i = 0; i < npols; i++ ) { - nverts = mesh->polSize( mesh, odb->pol[ i ].id ); - odb->pol[ i ].v = (st_DBPolVert*)calloc( nverts, sizeof( DBPolVert )); - if ( !odb->pol[ i ].v ) goto Finish; - odb->pol[ i ].nverts = nverts; - for ( j = 0; j < nverts; j++ ) { - ptid = mesh->polVertex( mesh, odb->pol[ i ].id, j ); - odb->pol[ i ].v[ j ].index = findVert( odb, ptid ); - } - } + for (i = 0; i < npols; i++) + { + nverts = mesh->polSize(mesh, odb->pol[i].id); + odb->pol[i].v = (st_DBPolVert*)calloc(nverts, sizeof(DBPolVert)); + if (!odb->pol[i].v) goto Finish; + odb->pol[i].nverts = nverts; + for (j = 0; j < nverts; j++) + { + ptid = mesh->polVertex(mesh, odb->pol[i].id, j); + odb->pol[i].v[j].index = findVert(odb, ptid); + } + } - /* count the number of polygons per point */ + /* count the number of polygons per point */ - for ( i = 0; i < npols; i++ ) - for ( j = 0; j < odb->pol[ i ].nverts; j++ ) - ++odb->pt[ odb->pol[ i ].v[ j ].index ].npols; + for (i = 0; i < npols; i++) + for (j = 0; j < odb->pol[i].nverts; j++) + ++odb->pt[odb->pol[i].v[j].index].npols; - /* alloc per-point polygon arrays */ + /* alloc per-point polygon arrays */ - for ( i = 0; i < npts; i++ ) { - if ( odb->pt[ i ].npols == 0 ) continue; - odb->pt[ i ].pol = (int*)calloc( odb->pt[ i ].npols, sizeof( int )); - if ( !odb->pt[ i ].pol ) goto Finish; - odb->pt[ i ].npols = 0; - } + for (i = 0; i < npts; i++) + { + if (odb->pt[i].npols == 0) continue; + odb->pt[i].pol = (int*)calloc(odb->pt[i].npols, sizeof(int)); + if (!odb->pt[i].pol) goto Finish; + odb->pt[i].npols = 0; + } - /* fill in polygon array for each point */ + /* fill in polygon array for each point */ - for ( i = 0; i < npols; i++ ) { - for ( j = 0; j < odb->pol[ i ].nverts; j++ ) { - k = odb->pol[ i ].v[ j ].index; - odb->pt[ k ].pol[ odb->pt[ k ].npols ] = i; - ++odb->pt[ k ].npols; - } - } + for (i = 0; i < npols; i++) + { + for (j = 0; j < odb->pol[i].nverts; j++) + { + k = odb->pol[i].v[j].index; + odb->pt[k].pol[odb->pt[k].npols] = i; + ++odb->pt[k].npols; + } + } - /* get the base position of each point */ + /* get the base position of each point */ - for ( i = 0; i < npts; i++ ) - mesh->pntBasePos( mesh, odb->pt[ i ].id, odb->pt[ i ].pos[ 0 ] ); + for (i = 0; i < npts; i++) + mesh->pntBasePos(mesh, odb->pt[i].id, odb->pt[i].pos[0]); - /* init the point search array */ - /* do this here if you need to search by base pos, or later if you - need to search by final pos */ + /* init the point search array */ + /* do this here if you need to search by base pos, or later if you + need to search by final pos */ - // if ( !initPointSearch( odb, 0 )) - // goto Finish; + // if ( !initPointSearch( odb, 0 )) + // goto Finish; - /* calculate the base normal of each polygon */ + /* calculate the base normal of each polygon */ - getPolyNormals( odb, 0 ); + getPolyNormals(odb, 0); - /* get the vmaps */ + /* get the vmaps */ - if ( !getObjectVMaps( odb, mesh, global )) - goto Finish; + if (!getObjectVMaps(odb, mesh, global)) goto Finish; - /* get the surfaces */ + /* get the surfaces */ - if ( !getObjectSurfs( odb, mesh, global )) - goto Finish; + if (!getObjectSurfs(odb, mesh, global)) goto Finish; - /* calculate initial vertex normals */ + /* calculate initial vertex normals */ - getVertNormals( odb, 0 ); + getVertNormals(odb, 0); - /* done */ + /* done */ - ok = 1; + ok = 1; Finish: - if ( mesh->destroy ) - mesh->destroy( mesh ); + if (mesh->destroy) mesh->destroy(mesh); - if ( !ok ) { - freeObjectDB( odb ); - return NULL; - } + if (!ok) { + freeObjectDB(odb); + return NULL; + } - return odb; + return odb; } - /* ====================================================================== printObjectDB() @@ -344,135 +342,120 @@ database. The c argument is 0 for initial normals and point positions and 1 for final. ====================================================================== */ -int printObjectDB( ObjectDB *odb, FILE *fp, int c ) +int printObjectDB(ObjectDB* odb, FILE* fp, int c) { - DBVMap *vmap; - char *tag; - int i, j, k, n; - - fprintf( fp, "%08.8x %s\n\n", odb->id, odb->filename ); - - fprintf( fp, "Points (%d)\n\n", odb->npoints ); - for ( i = 0; i < odb->npoints; i++ ) { - fprintf( fp, "%08.8x pos (%g, %g, %g) npols %d:", - odb->pt[ i ].id, - odb->pt[ i ].pos[ c ][ 0 ], - odb->pt[ i ].pos[ c ][ 1 ], - odb->pt[ i ].pos[ c ][ 2 ], - odb->pt[ i ].npols ); - for ( j = 0; j < odb->pt[ i ].npols; j++ ) - fprintf( fp, " %d", odb->pt[ i ].pol[ j ] ); - fprintf( fp, "\n" ); - - for ( j = 0; j < odb->pt[ i ].nvmaps; j++ ) { - vmap = odb->pt[ i ].vm[ j ].vmap; - switch ( vmap->type ) { - case LWVMAP_PICK: tag = "PICK"; break; - case LWVMAP_WGHT: tag = "WGHT"; break; - case LWVMAP_MNVW: tag = "MNVW"; break; - case LWVMAP_TXUV: tag = "TXUV"; break; - case LWVMAP_MORF: tag = "MORF"; break; - case LWVMAP_SPOT: tag = "SPOT"; break; - default: tag = "Unknown type"; break; - } - fprintf( fp, " %s %s:", tag, vmap->name ); - for ( k = 0; k < vmap->dim; k++ ) { - n = odb->pt[ i ].vm[ j ].index; - fprintf( fp, " %g", vmap->val[ k ][ n ] ); - } - fprintf( fp, "\n" ); - } - } - - /* test the point search */ - - if ( initPointSearch( odb, c )) - for ( i = 0; i < odb->npoints; i++ ) - if ( i != pointSearch( odb, odb->pt[ i ].pos[ c ] )) - fprintf( fp, "Point search failed for point %d.\n", i ); - - fprintf( fp, "\n\nPolygons (%d)\n\n", odb->npolygons ); - for ( i = 0; i < odb->npolygons; i++ ) { - fprintf( fp, "%08.8x surf %d norm (%g, %g, %g) nverts %d:\n", - odb->pol[ i ].id, - odb->pol[ i ].sindex, - odb->pol[ i ].norm[ c ][ 0 ], - odb->pol[ i ].norm[ c ][ 1 ], - odb->pol[ i ].norm[ c ][ 2 ], - odb->pol[ i ].nverts ); - for ( j = 0; j < odb->pol[ i ].nverts; j++ ) { - fprintf( fp, " vert %d vnorm (%g, %g, %g)\n", - odb->pol[ i ].v[ j ].index, - odb->pol[ i ].v[ j ].norm[ c ][ 0 ], - odb->pol[ i ].v[ j ].norm[ c ][ 1 ], - odb->pol[ i ].v[ j ].norm[ c ][ 2 ] ); - } - } - - fprintf( fp, "\n\nSurfaces (%d)\n", odb->nsurfaces ); - for ( i = 0; i < odb->nsurfaces; i++ ) { - fprintf( fp, "\n%08.8X \"%s\"\n", - odb->surf[ i ].id, - odb->surf[ i ].name ); - fprintf( fp, " " SURF_COLR " %g %g %g\n", - odb->surf[ i ].colr[ 0 ], - odb->surf[ i ].colr[ 1 ], - odb->surf[ i ].colr[ 2 ] ); - fprintf( fp, " " SURF_LUMI " %g\n", odb->surf[ i ].lumi ); - fprintf( fp, " " SURF_DIFF " %g\n", odb->surf[ i ].diff ); - fprintf( fp, " " SURF_SPEC " %g\n", odb->surf[ i ].spec ); - fprintf( fp, " " SURF_REFL " %g\n", odb->surf[ i ].refl ); - fprintf( fp, " " SURF_RFOP " 0x%X\n", odb->surf[ i ].rfop ); - fprintf( fp, " " SURF_TRAN " %g\n", odb->surf[ i ].tran ); - fprintf( fp, " " SURF_TROP " 0x%X\n", odb->surf[ i ].trop ); - fprintf( fp, " " SURF_TRNL " %g\n", odb->surf[ i ].trnl ); - fprintf( fp, " " SURF_RIND " %g\n", odb->surf[ i ].rind ); - fprintf( fp, " " SURF_BUMP " %g\n", odb->surf[ i ].bump ); - fprintf( fp, " " SURF_GLOS " %g\n", odb->surf[ i ].glos ); - fprintf( fp, " " SURF_SHRP " %g\n", odb->surf[ i ].shrp ); - fprintf( fp, " " SURF_SMAN " %g\n", odb->surf[ i ].sman ); - fprintf( fp, " " SURF_RSAN " %g\n", odb->surf[ i ].rsan ); - fprintf( fp, " " SURF_TSAN " %g\n", odb->surf[ i ].tsan ); - fprintf( fp, " " SURF_CLRF " %g\n", odb->surf[ i ].clrf ); - fprintf( fp, " " SURF_CLRH " %g\n", odb->surf[ i ].clrh ); - fprintf( fp, " " SURF_ADTR " %g\n", odb->surf[ i ].adtr ); - fprintf( fp, " " SURF_ALPH " 0x%X\n", odb->surf[ i ].alph ); - fprintf( fp, " " SURF_AVAL " %g\n", odb->surf[ i ].aval ); - fprintf( fp, " " SURF_GLOW " 0x%X\n", odb->surf[ i ].glow ); - fprintf( fp, " " SURF_GVAL " %g\n", odb->surf[ i ].gval ); - fprintf( fp, " " SURF_LINE " 0x%X\n", odb->surf[ i ].line ); - fprintf( fp, " " SURF_LSIZ " %g\n", odb->surf[ i ].lsiz ); - fprintf( fp, " " SURF_LCOL " %g %g %g\n", - odb->surf[ i ].lcol[ 0 ], - odb->surf[ i ].lcol[ 1 ], - odb->surf[ i ].lcol[ 2 ] ); - fprintf( fp, " " SURF_SIDE " 0x%X\n", odb->surf[ i ].side ); - fprintf( fp, " " SURF_RIMG " %08.8X\n", odb->surf[ i ].rimg ); - fprintf( fp, " " SURF_TIMG " %08.8X\n", odb->surf[ i ].timg ); - } - - fprintf( fp, "\n\nVertex Maps (%d)\n\n", odb->nvertmaps ); - for ( i = 0; i < odb->nvertmaps; i++ ) { - tag = ( char * ) &odb->vmap[ i ].type; - fprintf( fp, "%c%c%c%c \"%s\" dim %d nverts %d\n", + DBVMap* vmap; + char* tag; + int i, j, k, n; + + fprintf(fp, "%08.8x %s\n\n", odb->id, odb->filename); + + fprintf(fp, "Points (%d)\n\n", odb->npoints); + for (i = 0; i < odb->npoints; i++) + { + fprintf(fp, "%08.8x pos (%g, %g, %g) npols %d:", odb->pt[i].id, odb->pt[i].pos[c][0], odb->pt[i].pos[c][1], + odb->pt[i].pos[c][2], odb->pt[i].npols); + for (j = 0; j < odb->pt[i].npols; j++) + fprintf(fp, " %d", odb->pt[i].pol[j]); + fprintf(fp, "\n"); + + for (j = 0; j < odb->pt[i].nvmaps; j++) + { + vmap = odb->pt[i].vm[j].vmap; + switch (vmap->type) + { + case LWVMAP_PICK: tag = "PICK"; break; + case LWVMAP_WGHT: tag = "WGHT"; break; + case LWVMAP_MNVW: tag = "MNVW"; break; + case LWVMAP_TXUV: tag = "TXUV"; break; + case LWVMAP_MORF: tag = "MORF"; break; + case LWVMAP_SPOT: tag = "SPOT"; break; + default: tag = "Unknown type"; break; + } + fprintf(fp, " %s %s:", tag, vmap->name); + for (k = 0; k < vmap->dim; k++) + { + n = odb->pt[i].vm[j].index; + fprintf(fp, " %g", vmap->val[k][n]); + } + fprintf(fp, "\n"); + } + } + + /* test the point search */ + + if (initPointSearch(odb, c)) + for (i = 0; i < odb->npoints; i++) + if (i != pointSearch(odb, odb->pt[i].pos[c])) fprintf(fp, "Point search failed for point %d.\n", i); + + fprintf(fp, "\n\nPolygons (%d)\n\n", odb->npolygons); + for (i = 0; i < odb->npolygons; i++) + { + fprintf(fp, "%08.8x surf %d norm (%g, %g, %g) nverts %d:\n", odb->pol[i].id, odb->pol[i].sindex, + odb->pol[i].norm[c][0], odb->pol[i].norm[c][1], odb->pol[i].norm[c][2], odb->pol[i].nverts); + for (j = 0; j < odb->pol[i].nverts; j++) + { + fprintf(fp, " vert %d vnorm (%g, %g, %g)\n", odb->pol[i].v[j].index, odb->pol[i].v[j].norm[c][0], + odb->pol[i].v[j].norm[c][1], odb->pol[i].v[j].norm[c][2]); + } + } + + fprintf(fp, "\n\nSurfaces (%d)\n", odb->nsurfaces); + for (i = 0; i < odb->nsurfaces; i++) + { + fprintf(fp, "\n%08.8X \"%s\"\n", odb->surf[i].id, odb->surf[i].name); + fprintf(fp, " " SURF_COLR " %g %g %g\n", odb->surf[i].colr[0], odb->surf[i].colr[1], odb->surf[i].colr[2]); + fprintf(fp, " " SURF_LUMI " %g\n", odb->surf[i].lumi); + fprintf(fp, " " SURF_DIFF " %g\n", odb->surf[i].diff); + fprintf(fp, " " SURF_SPEC " %g\n", odb->surf[i].spec); + fprintf(fp, " " SURF_REFL " %g\n", odb->surf[i].refl); + fprintf(fp, " " SURF_RFOP " 0x%X\n", odb->surf[i].rfop); + fprintf(fp, " " SURF_TRAN " %g\n", odb->surf[i].tran); + fprintf(fp, " " SURF_TROP " 0x%X\n", odb->surf[i].trop); + fprintf(fp, " " SURF_TRNL " %g\n", odb->surf[i].trnl); + fprintf(fp, " " SURF_RIND " %g\n", odb->surf[i].rind); + fprintf(fp, " " SURF_BUMP " %g\n", odb->surf[i].bump); + fprintf(fp, " " SURF_GLOS " %g\n", odb->surf[i].glos); + fprintf(fp, " " SURF_SHRP " %g\n", odb->surf[i].shrp); + fprintf(fp, " " SURF_SMAN " %g\n", odb->surf[i].sman); + fprintf(fp, " " SURF_RSAN " %g\n", odb->surf[i].rsan); + fprintf(fp, " " SURF_TSAN " %g\n", odb->surf[i].tsan); + fprintf(fp, " " SURF_CLRF " %g\n", odb->surf[i].clrf); + fprintf(fp, " " SURF_CLRH " %g\n", odb->surf[i].clrh); + fprintf(fp, " " SURF_ADTR " %g\n", odb->surf[i].adtr); + fprintf(fp, " " SURF_ALPH " 0x%X\n", odb->surf[i].alph); + fprintf(fp, " " SURF_AVAL " %g\n", odb->surf[i].aval); + fprintf(fp, " " SURF_GLOW " 0x%X\n", odb->surf[i].glow); + fprintf(fp, " " SURF_GVAL " %g\n", odb->surf[i].gval); + fprintf(fp, " " SURF_LINE " 0x%X\n", odb->surf[i].line); + fprintf(fp, " " SURF_LSIZ " %g\n", odb->surf[i].lsiz); + fprintf(fp, " " SURF_LCOL " %g %g %g\n", odb->surf[i].lcol[0], odb->surf[i].lcol[1], odb->surf[i].lcol[2]); + fprintf(fp, " " SURF_SIDE " 0x%X\n", odb->surf[i].side); + fprintf(fp, " " SURF_RIMG " %08.8X\n", odb->surf[i].rimg); + fprintf(fp, " " SURF_TIMG " %08.8X\n", odb->surf[i].timg); + } + + fprintf(fp, "\n\nVertex Maps (%d)\n\n", odb->nvertmaps); + for (i = 0; i < odb->nvertmaps; i++) + { + tag = (char*)&odb->vmap[i].type; + fprintf(fp, "%c%c%c%c \"%s\" dim %d nverts %d\n", #ifdef _WIN32 - tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ], + tag[3], tag[2], tag[1], tag[0], #else - tag[ 0 ], tag[ 1 ], tag[ 2 ], tag[ 3 ], + tag[0], tag[1], tag[2], tag[3], #endif - odb->vmap[ i ].name, - odb->vmap[ i ].dim, - odb->vmap[ i ].nverts ); - for ( j = 0; j < odb->vmap[ i ].nverts; j++ ) { - fprintf( fp, " %d ", odb->vmap[ i ].vindex[ j ] ); - for ( k = 0; k < odb->vmap[ i ].dim; k++ ) - fprintf( fp, " %g", odb->vmap[ i ].val[ k ][ j ] ); - fprintf( fp, "\n" ); - } - } - - return 1; + odb->vmap[i].name, odb->vmap[i].dim, odb->vmap[i].nverts); + for (j = 0; j < odb->vmap[i].nverts; j++) + { + fprintf(fp, " %d ", odb->vmap[i].vindex[j]); + for (k = 0; k < odb->vmap[i].dim; k++) + fprintf(fp, " %g", odb->vmap[i].val[k][j]); + fprintf(fp, "\n"); + } + } + + return 1; } - -#pragma warning (default:4995) \ No newline at end of file +#pragma warning(default : 4995) \ No newline at end of file diff --git a/src/plugins/lw/Export/scenscan/objectdb.h b/src/plugins/lw/Export/scenscan/objectdb.h index 4b03c53054b..be00de45281 100644 --- a/src/plugins/lw/Export/scenscan/objectdb.h +++ b/src/plugins/lw/Export/scenscan/objectdb.h @@ -8,131 +8,136 @@ Typedefs and function prototypes for an object database. #ifndef OBJECTDB_H #define OBJECTDB_H -#include #include +#include #include #include - -typedef struct st_DBVMapVal { - char *name; // name - LWID type; // type of data (e.g. UVs, weights) - int dim; // dimension (number of values per point) - int nverts; // number of vertices - int *vindex; // array of vertex indexes - int *vdpol; // -1 - point map 0..n-polymap(polygon number) - float **val; // 2D array of vmap values +typedef struct st_DBVMapVal +{ + char* name; // name + LWID type; // type of data (e.g. UVs, weights) + int dim; // dimension (number of values per point) + int nverts; // number of vertices + int* vindex; // array of vertex indexes + int* vdpol; // -1 - point map 0..n-polymap(polygon number) + float** val; // 2D array of vmap values } DBVMap; -typedef struct st_DBVMapPt { - DBVMap *vmap; // where the values are stored - int index; // offset into the vmap value arrays +typedef struct st_DBVMapPt +{ + DBVMap* vmap; // where the values are stored + int index; // offset into the vmap value arrays } DBVMapPt; -typedef struct st_DBPoint { - LWPntID id; // Layout point ID - LWFVector pos[ 2 ]; // initial and final position - int npols; // number of polygons sharing the point - int *pol; // array of polygon indexes - int nvmaps; // number of vmap values - DBVMapPt *vm; // array of vmap values +typedef struct st_DBPoint +{ + LWPntID id; // Layout point ID + LWFVector pos[2]; // initial and final position + int npols; // number of polygons sharing the point + int* pol; // array of polygon indexes + int nvmaps; // number of vmap values + DBVMapPt* vm; // array of vmap values } DBPoint; -typedef struct st_DBPolVert { - int index; // index into the point array - LWFVector norm[ 2 ]; // initial and final normals - int nvmaps; - DBVMapPt *vm; // array of vmap references +typedef struct st_DBPolVert +{ + int index; // index into the point array + LWFVector norm[2]; // initial and final normals + int nvmaps; + DBVMapPt* vm; // array of vmap references } DBPolVert; -typedef struct st_DBPolygon { - LWPolID id; // Layout polygon ID - int sindex; // surface index - LWFVector norm[ 2 ]; // initial and final normals - int nverts; // number of vertices - DBPolVert *v; // vertex array +typedef struct st_DBPolygon +{ + LWPolID id; // Layout polygon ID + int sindex; // surface index + LWFVector norm[2]; // initial and final normals + int nverts; // number of vertices + DBPolVert* v; // vertex array } DBPolygon; -typedef struct st_lwPlugin { - struct st_lwPlugin *next, *prev; - char *ord; - char *name; - int flags; - void *data; +typedef struct st_lwPlugin +{ + struct st_lwPlugin *next, *prev; + char* ord; + char* name; + int flags; + void* data; } lwPlugin; -typedef struct st_DBSurface { - LWSurfaceID id; // surface ID - char *name; // surface name - char textures[8][64]; // textures - int tex_cnt; - float colr[ 3 ]; // color - float lumi; // luminosity - float diff; // diffuse level - float spec; // specularity - float refl; // reflectivity - float tran; // transparency - float trnl; // translucency - float rind; // index of refraction - float bump; // bump - float glos; // glossiness - float shrp; // diffuse sharpness - float sman; // max smoothing angle (radians) - float rsan; // reflection seam angle - float tsan; // refraction seam angle - float clrf; // color filter - float clrh; // color highlight - float adtr; // additive transparency - float aval; // alpha value - float gval; // glow value - float lcol[ 3 ]; // line color - float lsiz; // line size - int alph; // alpha options - int rfop; // reflection options - int trop; // refraction options - int side; // sidedness - int glow; // glow - int line; // render outlines - LWImageID rimg; // reflection image - LWImageID timg; // refraction image - lwPlugin *shader; // linked list of shaders - int nshaders; +typedef struct st_DBSurface +{ + LWSurfaceID id; // surface ID + char* name; // surface name + char textures[8][64]; // textures + int tex_cnt; + float colr[3]; // color + float lumi; // luminosity + float diff; // diffuse level + float spec; // specularity + float refl; // reflectivity + float tran; // transparency + float trnl; // translucency + float rind; // index of refraction + float bump; // bump + float glos; // glossiness + float shrp; // diffuse sharpness + float sman; // max smoothing angle (radians) + float rsan; // reflection seam angle + float tsan; // refraction seam angle + float clrf; // color filter + float clrh; // color highlight + float adtr; // additive transparency + float aval; // alpha value + float gval; // glow value + float lcol[3]; // line color + float lsiz; // line size + int alph; // alpha options + int rfop; // reflection options + int trop; // refraction options + int side; // sidedness + int glow; // glow + int line; // render outlines + LWImageID rimg; // reflection image + LWImageID timg; // refraction image + lwPlugin* shader; // linked list of shaders + int nshaders; } DBSurface; -typedef struct st_ObjectDB { - char *filename; // object filename - LWItemID id; // Layout item ID - int npoints; // number of points - int npolygons; // number of polygons - int nsurfaces; // number of surfaces - int nvertmaps; // number of vertex maps - DBPoint *pt; // point array - int *vsort; // point indexes sorted by point position - int vsortkey; // coordinate for position sort - DBPolygon *pol; // polygon array - DBSurface *surf; // surface array - DBVMap *vmap; // vmap array +typedef struct st_ObjectDB +{ + char* filename; // object filename + LWItemID id; // Layout item ID + int npoints; // number of points + int npolygons; // number of polygons + int nsurfaces; // number of surfaces + int nvertmaps; // number of vertex maps + DBPoint* pt; // point array + int* vsort; // point indexes sorted by point position + int vsortkey; // coordinate for position sort + DBPolygon* pol; // polygon array + DBSurface* surf; // surface array + DBVMap* vmap; // vmap array } ObjectDB; +int findVert(ObjectDB* odb, LWPntID id); -int findVert( ObjectDB *odb, LWPntID id ); - -void getPolyNormals( ObjectDB *odb, int i ); -void getVertNormals( ObjectDB *odb, int i ); - -void freeObjectDB( ObjectDB *odb ); -ObjectDB *getObjectDB( LWItemID id, GlobalFunc *global ); -int printObjectDB( ObjectDB *odb, FILE *fp, int c ); +void getPolyNormals(ObjectDB* odb, int i); +void getVertNormals(ObjectDB* odb, int i); -void freeObjectVMaps( ObjectDB *odb ); -int getObjectVMaps( ObjectDB *odb, LWMeshInfo *mesh, GlobalFunc *global ); +void freeObjectDB(ObjectDB* odb); +ObjectDB* getObjectDB(LWItemID id, GlobalFunc* global); +int printObjectDB(ObjectDB* odb, FILE* fp, int c); -void freeObjectSurfs( ObjectDB *odb ); -int getObjectSurfs( ObjectDB *odb, LWMeshInfo *mesh, GlobalFunc *global ); +void freeObjectVMaps(ObjectDB* odb); +int getObjectVMaps(ObjectDB* odb, LWMeshInfo* mesh, GlobalFunc* global); -int initPointSearch( ObjectDB *odb, int ipos ); -void freePointSearch( ObjectDB *odb ); -int pointSearch( ObjectDB *odb, float pos[ 3 ] ); +void freeObjectSurfs(ObjectDB* odb); +int getObjectSurfs(ObjectDB* odb, LWMeshInfo* mesh, GlobalFunc* global); +int initPointSearch(ObjectDB* odb, int ipos); +void freePointSearch(ObjectDB* odb); +int pointSearch(ObjectDB* odb, float pos[3]); #endif diff --git a/src/plugins/lw/Export/scenscan/ptsearch.cpp b/src/plugins/lw/Export/scenscan/ptsearch.cpp index 56c7e31c985..e75747eccfd 100644 --- a/src/plugins/lw/Export/scenscan/ptsearch.cpp +++ b/src/plugins/lw/Export/scenscan/ptsearch.cpp @@ -17,18 +17,16 @@ of points. ====================================================================== */ #include "objectdb.h" -#define KEY (odb->vsortkey % 3) -#define IPOS (odb->vsortkey / 3) -#define ARRAY( i ) odb->vsort[ i ] +#define KEY (odb->vsortkey % 3) +#define IPOS (odb->vsortkey / 3) +#define ARRAY(i) odb->vsort[i] #undef ARRAYSIZE -#define ARRAYSIZE odb->npoints -#define COORD( p, c ) odb->pt[ odb->vsort[ p ]].pos[ ipos ][ c ] -#define SORTVAL( p ) COORD( p, key ) - -#pragma warning (disable:4995) - +#define ARRAYSIZE odb->npoints +#define COORD(p, c) odb->pt[odb->vsort[p]].pos[ipos][c] +#define SORTVAL(p) COORD(p, key) +#pragma warning(disable : 4995) /* ====================================================================== @@ -39,43 +37,59 @@ falls below SUBARRAYSIZE, beyond which it's somewhat more efficient to let a different kind of sort finish the job. ====================================================================== */ -#define SUBARRAYSIZE 10 -#define PUSH( i ) stack[ ++tos ] = i -#define POP( i ) i = stack[ tos-- ] -#define STACKEMPTY tos < 0 -#define SWAP( i, j ) t = i; i = j; j = t +#define SUBARRAYSIZE 10 +#define PUSH(i) stack[++tos] = i +#define POP(i) i = stack[tos--] +#define STACKEMPTY tos < 0 +#define SWAP(i, j) \ + t = i; \ + i = j; \ + j = t -static void vsortq( ObjectDB *odb ) +static void vsortq(ObjectDB* odb) { - static int stack[ 200 ]; - int i, j, lt, rt, tos = -1, t, key = KEY, ipos = IPOS; - float v; - - lt = 0; - rt = ARRAYSIZE - 1; - - for ( ;; ) { - while ( rt - lt > SUBARRAYSIZE ) { - v = SORTVAL( rt ); i = lt - 1; j = rt; - for ( ;; ) { - while ( SORTVAL( ++i ) < v ) ; - while ( j && SORTVAL( --j ) > v ) ; - if ( i > j ) break; - SWAP( ARRAY( i ), ARRAY( j )); - } - SWAP( ARRAY( i ), ARRAY( rt )); - if ( i - lt > rt - i ) - { PUSH( lt ); PUSH( i - 1 ); lt = i + 1; } - else - { PUSH( i + 1 ); PUSH( rt ); rt = i - 1; } - } - if ( STACKEMPTY ) break; - POP( rt ); - POP( lt ); - } + static int stack[200]; + int i, j, lt, rt, tos = -1, t, key = KEY, ipos = IPOS; + float v; + + lt = 0; + rt = ARRAYSIZE - 1; + + for (;;) + { + while (rt - lt > SUBARRAYSIZE) + { + v = SORTVAL(rt); + i = lt - 1; + j = rt; + for (;;) + { + while (SORTVAL(++i) < v) + ; + while (j && SORTVAL(--j) > v) + ; + if (i > j) break; + SWAP(ARRAY(i), ARRAY(j)); + } + SWAP(ARRAY(i), ARRAY(rt)); + if (i - lt > rt - i) { + PUSH(lt); + PUSH(i - 1); + lt = i + 1; + } + else + { + PUSH(i + 1); + PUSH(rt); + rt = i - 1; + } + } + if (STACKEMPTY) break; + POP(rt); + POP(lt); + } } - /* ====================================================================== vsorti() @@ -84,24 +98,25 @@ Insertion sort the point array. Because the array was preconditioned by a quicksort, it's almost sorted already, a best case for insertion. ====================================================================== */ -static void vsorti( ObjectDB *odb ) +static void vsorti(ObjectDB* odb) { - int i, j, t, key = KEY, ipos = IPOS; - float v; - - for ( i = 1; i < ARRAYSIZE; i++ ) { - t = ARRAY( i ); - v = SORTVAL( i ); - j = i; - while ( j && SORTVAL( j - 1 ) > v ) { - ARRAY( j ) = ARRAY( j - 1 ); - --j; - } - ARRAY( j ) = t; - } + int i, j, t, key = KEY, ipos = IPOS; + float v; + + for (i = 1; i < ARRAYSIZE; i++) + { + t = ARRAY(i); + v = SORTVAL(i); + j = i; + while (j && SORTVAL(j - 1) > v) + { + ARRAY(j) = ARRAY(j - 1); + --j; + } + ARRAY(j) = t; + } } - /* ====================================================================== initPointSearch() @@ -118,42 +133,39 @@ The second argument is 0 to sort on initial positions and 1 to sort on final positions. ====================================================================== */ -int initPointSearch( ObjectDB *odb, int ipos ) +int initPointSearch(ObjectDB* odb, int ipos) { - float m[ 3 ] = { 0.0f }, sd[ 3 ] = { 0.0f }; - int i, j; + float m[3] = {0.0f}, sd[3] = {0.0f}; + int i, j; - if ( odb->npoints <= 0 ) return 1; + if (odb->npoints <= 0) return 1; - for ( i = 0; i < odb->npoints; i++ ) - for ( j = 0; j < 3; j++ ) - m[ j ] += odb->pt[ i ].pos[ ipos ][ j ]; + for (i = 0; i < odb->npoints; i++) + for (j = 0; j < 3; j++) + m[j] += odb->pt[i].pos[ipos][j]; - for ( j = 0; j < 3; j++ ) - m[ j ] /= odb->npoints; + for (j = 0; j < 3; j++) + m[j] /= odb->npoints; - for ( i = 0; i < odb->npoints; i++ ) - for ( j = 0; j < 3; j++ ) - sd[ j ] += odb->pt[ i ].pos[ ipos ][ j ] - m[ j ]; + for (i = 0; i < odb->npoints; i++) + for (j = 0; j < 3; j++) + sd[j] += odb->pt[i].pos[ipos][j] - m[j]; - odb->vsortkey = sd[ 0 ] > sd[ 1 ] ? - ( sd[ 0 ] > sd[ 2 ] ? 0 : 2 ) : - ( sd[ 1 ] > sd[ 2 ] ? 1 : 2 ); - odb->vsortkey += 3 * ipos; + odb->vsortkey = sd[0] > sd[1] ? (sd[0] > sd[2] ? 0 : 2) : (sd[1] > sd[2] ? 1 : 2); + odb->vsortkey += 3 * ipos; - odb->vsort = (int*)calloc( odb->npoints, sizeof( int )); - if ( !odb->vsort ) return 0; + odb->vsort = (int*)calloc(odb->npoints, sizeof(int)); + if (!odb->vsort) return 0; - for ( i = 0; i < odb->npoints; i++ ) - odb->vsort[ i ] = i; + for (i = 0; i < odb->npoints; i++) + odb->vsort[i] = i; - vsortq( odb ); - vsorti( odb ); + vsortq(odb); + vsorti(odb); - return 1; + return 1; } - /* ====================================================================== freePointSearch() @@ -161,17 +173,16 @@ freePointSearch() Free memory allocated by initPointSearch(). ====================================================================== */ -void freePointSearch( ObjectDB *odb ) +void freePointSearch(ObjectDB* odb) { - if ( odb ) { - if ( odb->vsort ) { - free( odb->vsort ); - odb->vsort = NULL; - } - } + if (odb) { + if (odb->vsort) { + free(odb->vsort); + odb->vsort = NULL; + } + } } - /* ====================================================================== pointSearch() @@ -186,25 +197,29 @@ If more than one point has the position, this returns the first point index in the vsort[] array. ====================================================================== */ -int pointSearch( ObjectDB *odb, float pos[ 3 ] ) +int pointSearch(ObjectDB* odb, float pos[3]) { - int lt = 0, rt = ARRAYSIZE - 1, x, key = KEY, ipos = IPOS; - - while ( rt >= lt ) { - x = ( lt + rt ) / 2; - if ( pos[ key ] < SORTVAL( x )) rt = x - 1; else lt = x + 1; - if ( pos[ key ] == SORTVAL( x )) { - lt = rt = x; - while ( lt > 0 && pos[ key ] == SORTVAL( lt - 1 )) --lt; - while ( rt < ARRAYSIZE - 1 && pos[ key ] == SORTVAL( rt + 1 )) ++rt; - for ( x = lt; x <= rt; x++ ) - if ( pos[ 0 ] == COORD( x, 0 ) && - pos[ 1 ] == COORD( x, 1 ) && - pos[ 2 ] == COORD( x, 2 )) return ARRAY( x ); - return -1; - } - } - return -1; + int lt = 0, rt = ARRAYSIZE - 1, x, key = KEY, ipos = IPOS; + + while (rt >= lt) + { + x = (lt + rt) / 2; + if (pos[key] < SORTVAL(x)) + rt = x - 1; + else + lt = x + 1; + if (pos[key] == SORTVAL(x)) { + lt = rt = x; + while (lt > 0 && pos[key] == SORTVAL(lt - 1)) + --lt; + while (rt < ARRAYSIZE - 1 && pos[key] == SORTVAL(rt + 1)) + ++rt; + for (x = lt; x <= rt; x++) + if (pos[0] == COORD(x, 0) && pos[1] == COORD(x, 1) && pos[2] == COORD(x, 2)) return ARRAY(x); + return -1; + } + } + return -1; } -#pragma warning (default:4995) \ No newline at end of file +#pragma warning(default : 4995) \ No newline at end of file diff --git a/src/plugins/lw/Export/scenscan/scenscan.h b/src/plugins/lw/Export/scenscan/scenscan.h index ec17070ab8d..824b3b184cd 100644 --- a/src/plugins/lw/Export/scenscan/scenscan.h +++ b/src/plugins/lw/Export/scenscan/scenscan.h @@ -5,20 +5,21 @@ scenscan.h Typedefs and function prototypes for a scene database. ====================================================================== */ -#include #include +#include -typedef struct st_DBVMapRec { - char *name; - LWID type; - int dim; +typedef struct st_DBVMapRec +{ + char* name; + LWID type; + int dim; } DBVMapRec; -typedef struct st_VertMapDB { - int nvmaps; - DBVMapRec *vmap; +typedef struct st_VertMapDB +{ + int nvmaps; + DBVMapRec* vmap; } VertMapDB; - -void freeVertMapDB( VertMapDB *vmdb ); -VertMapDB *getVertMapDB( GlobalFunc *global ); +void freeVertMapDB(VertMapDB* vmdb); +VertMapDB* getVertMapDB(GlobalFunc* global); diff --git a/src/plugins/lw/Export/scenscan/surface.cpp b/src/plugins/lw/Export/scenscan/surface.cpp index 70fb5a2d9b8..98adfad3561 100644 --- a/src/plugins/lw/Export/scenscan/surface.cpp +++ b/src/plugins/lw/Export/scenscan/surface.cpp @@ -5,13 +5,13 @@ surface.c Functions for examining surfaces. ====================================================================== */ -#include "scenscan.h" -#include "objectdb.h" #include +#include "objectdb.h" +#include "scenscan.h" -#pragma warning (disable:4995) +#pragma warning(disable : 4995) -extern "C" LWMessageFuncs *g_msg; +extern "C" LWMessageFuncs* g_msg; /* ====================================================================== findSurf() @@ -20,17 +20,15 @@ findSurf() matching surface name. ====================================================================== */ -static int findSurf( ObjectDB *odb, const char *tag ) +static int findSurf(ObjectDB* odb, const char* tag) { - int i; - - for ( i = 0; i < odb->nsurfaces; i++ ) - if ( !strcmp( tag, odb->surf[ i ].name )) - return i; - - return -1; -} + int i; + for (i = 0; i < odb->nsurfaces; i++) + if (!strcmp(tag, odb->surf[i].name)) return i; + + return -1; +} /* ====================================================================== @@ -39,22 +37,20 @@ freeObjectSurfs() Free memory allocated by getObjectSurfs(). ====================================================================== */ -void freeObjectSurfs( ObjectDB *odb ) +void freeObjectSurfs(ObjectDB* odb) { - int i; - - if ( odb ) { - if ( odb->surf ) { - for ( i = 0; i < odb->nsurfaces; i++ ) - if ( odb->surf[ i ].name ) - free( odb->surf[ i ].name ); - free( odb->surf ); - odb->surf = 0; - odb->nsurfaces = 0; - } - } -} + int i; + if (odb) { + if (odb->surf) { + for (i = 0; i < odb->nsurfaces; i++) + if (odb->surf[i].name) free(odb->surf[i].name); + free(odb->surf); + odb->surf = 0; + odb->nsurfaces = 0; + } + } +} /* ====================================================================== @@ -63,162 +59,163 @@ getObjectSurfs() Allocate and fill in structures describing the surfaces applied to the object. Updates the ObjectDB and returns 1 if successful. Backs out of any changes to the ObjectDB and returns 0 if an error occurs. - - Currently this isn't very sophisticated. We just get the values. The - SDK also allows us to get the envelopes and textures for most of these - parameters (anything with an E or a T button in the Surface Editor), - so we could do much more here. Given a channel's LWTextureID, for - example, we could use the Texture Functions global to get each texture - layer's parameters, including the image maps. + + Currently this isn't very sophisticated. We just get the values. The + SDK also allows us to get the envelopes and textures for most of these + parameters (anything with an E or a T button in the Surface Editor), + so we could do much more here. Given a channel's LWTextureID, for + example, we could use the Texture Functions global to get each texture + layer's parameters, including the image maps. ====================================================================== */ -int getObjectSurfs( ObjectDB *odb, LWMeshInfo *mesh, GlobalFunc *global ) +int getObjectSurfs(ObjectDB* odb, LWMeshInfo* mesh, GlobalFunc* global) { - LWSurfaceFuncs *surff; - LWSurfaceID *surfid; - LWTextureFuncs *txfunc; - LWImageList *imglist; - double *dval; - int i; - const char* tag; - - - imglist = (st_LWImageList*)global( LWIMAGELIST_GLOBAL, GFUSE_TRANSIENT ); - if ( !imglist ) return 0; - txfunc = (st_LWTextureFuncs*)global( LWTEXTUREFUNCS_GLOBAL, GFUSE_TRANSIENT ); /* get the surface ID array */ - if ( !txfunc ) return 0; - surff = (st_LWSurfaceFuncs*)global( LWSURFACEFUNCS_GLOBAL, GFUSE_TRANSIENT ); - if ( !surff ) return 0; - surfid = surff->byObject( odb->filename ); - if ( !surfid ) return 0; - - /* count the surface IDs and alloc the surface array */ - - for ( odb->nsurfaces = 0; ; odb->nsurfaces++ ) - if ( !surfid[ odb->nsurfaces ] ) break; - odb->surf = (st_DBSurface*)calloc( odb->nsurfaces, sizeof( DBSurface )); - if ( !odb->surf ) { - odb->nsurfaces = 0; - return 0; - } - - /* fill in the surface parameters */ - - for ( i = 0; i < odb->nsurfaces; i++ ) { - odb->surf[ i ].id = surfid[ i ]; - tag = surff->name( surfid[ i ] ); - odb->surf[ i ].name = (char*)malloc( xr_strlen( tag ) + 1 ); - if ( !odb->surf[ i ].name ) { - freeObjectSurfs( odb ); - return 0; - } - strcpy( odb->surf[ i ].name, tag ); - - LWTextureID tid = surff->getTex(surfid[i],SURF_COLR); - if (!tid){ - g_msg->error("Empty texture in surface:",odb->surf[ i ].name); - freeObjectSurfs( odb ); - return 0; - } - for (LWTLayerID tlid=txfunc->firstLayer(tid); tlid; tlid=txfunc->nextLayer(tid,tlid)){ - DWORD imid; - int res = txfunc->getParam(tlid,TXTAG_IMAGE,&imid); - tag = imglist->name((LWImageID)imid); - if (!tag){ - g_msg->error("Invalid texture name.",0); - return 0; - } - strcpy(odb->surf[i].textures[odb->surf[i].tex_cnt],tag); - odb->surf[i].tex_cnt++; - } - - - dval = surff->getFlt( surfid[ i ], SURF_COLR ); - odb->surf[ i ].colr[ 0 ] = ( float ) dval[ 0 ]; - odb->surf[ i ].colr[ 1 ] = ( float ) dval[ 1 ]; - odb->surf[ i ].colr[ 2 ] = ( float ) dval[ 2 ]; - - dval = surff->getFlt( surfid[ i ], SURF_LUMI ); - odb->surf[ i ].lumi = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_DIFF ); - odb->surf[ i ].diff = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_SPEC ); - odb->surf[ i ].spec = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_REFL ); - odb->surf[ i ].refl = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_TRAN ); - odb->surf[ i ].tran = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_TRNL ); - odb->surf[ i ].trnl = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_RIND ); - odb->surf[ i ].rind = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_BUMP ); - odb->surf[ i ].bump = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_GLOS ); - odb->surf[ i ].glos = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_SHRP ); - odb->surf[ i ].shrp = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_SMAN ); - odb->surf[ i ].sman = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_RSAN ); - odb->surf[ i ].rsan = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_TSAN ); - odb->surf[ i ].tsan = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_CLRF ); - odb->surf[ i ].clrf = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_CLRH ); - odb->surf[ i ].clrh = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_ADTR ); - odb->surf[ i ].adtr = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_AVAL ); - odb->surf[ i ].aval = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_GVAL ); - odb->surf[ i ].gval = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_LSIZ ); - odb->surf[ i ].lsiz = ( float ) *dval; - - dval = surff->getFlt( surfid[ i ], SURF_LCOL ); - odb->surf[ i ].lcol[ 0 ] = ( float ) dval[ 0 ]; - odb->surf[ i ].lcol[ 1 ] = ( float ) dval[ 1 ]; - odb->surf[ i ].lcol[ 2 ] = ( float ) dval[ 2 ]; - - odb->surf[ i ].alph = surff->getInt( surfid[ i ], SURF_ALPH ); - odb->surf[ i ].rfop = surff->getInt( surfid[ i ], SURF_RFOP ); - odb->surf[ i ].trop = surff->getInt( surfid[ i ], SURF_TROP ); - odb->surf[ i ].side = surff->getInt( surfid[ i ], SURF_SIDE ); - odb->surf[ i ].glow = surff->getInt( surfid[ i ], SURF_GLOW ); - odb->surf[ i ].line = surff->getInt( surfid[ i ], SURF_LINE ); - - odb->surf[ i ].rimg = surff->getImg( surfid[ i ], SURF_RIMG ); - odb->surf[ i ].timg = surff->getImg( surfid[ i ], SURF_TIMG ); - } - - /* find surface index for each polygon */ - - for ( i = 0; i < odb->npolygons; i++ ) { - tag = mesh->polTag( mesh, odb->pol[ i ].id, LWPTAG_SURF ); - odb->pol[ i ].sindex = findSurf( odb, tag ); - } - - return 1; + LWSurfaceFuncs* surff; + LWSurfaceID* surfid; + LWTextureFuncs* txfunc; + LWImageList* imglist; + double* dval; + int i; + const char* tag; + + imglist = (st_LWImageList*)global(LWIMAGELIST_GLOBAL, GFUSE_TRANSIENT); + if (!imglist) return 0; + txfunc = (st_LWTextureFuncs*)global(LWTEXTUREFUNCS_GLOBAL, GFUSE_TRANSIENT); /* get the surface ID array */ + if (!txfunc) return 0; + surff = (st_LWSurfaceFuncs*)global(LWSURFACEFUNCS_GLOBAL, GFUSE_TRANSIENT); + if (!surff) return 0; + surfid = surff->byObject(odb->filename); + if (!surfid) return 0; + + /* count the surface IDs and alloc the surface array */ + + for (odb->nsurfaces = 0;; odb->nsurfaces++) + if (!surfid[odb->nsurfaces]) break; + odb->surf = (st_DBSurface*)calloc(odb->nsurfaces, sizeof(DBSurface)); + if (!odb->surf) { + odb->nsurfaces = 0; + return 0; + } + + /* fill in the surface parameters */ + + for (i = 0; i < odb->nsurfaces; i++) + { + odb->surf[i].id = surfid[i]; + tag = surff->name(surfid[i]); + odb->surf[i].name = (char*)malloc(xr_strlen(tag) + 1); + if (!odb->surf[i].name) { + freeObjectSurfs(odb); + return 0; + } + strcpy(odb->surf[i].name, tag); + + LWTextureID tid = surff->getTex(surfid[i], SURF_COLR); + if (!tid) { + g_msg->error("Empty texture in surface:", odb->surf[i].name); + freeObjectSurfs(odb); + return 0; + } + for (LWTLayerID tlid = txfunc->firstLayer(tid); tlid; tlid = txfunc->nextLayer(tid, tlid)) + { + DWORD imid; + int res = txfunc->getParam(tlid, TXTAG_IMAGE, &imid); + tag = imglist->name((LWImageID)imid); + if (!tag) { + g_msg->error("Invalid texture name.", 0); + return 0; + } + strcpy(odb->surf[i].textures[odb->surf[i].tex_cnt], tag); + odb->surf[i].tex_cnt++; + } + + dval = surff->getFlt(surfid[i], SURF_COLR); + odb->surf[i].colr[0] = (float)dval[0]; + odb->surf[i].colr[1] = (float)dval[1]; + odb->surf[i].colr[2] = (float)dval[2]; + + dval = surff->getFlt(surfid[i], SURF_LUMI); + odb->surf[i].lumi = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_DIFF); + odb->surf[i].diff = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_SPEC); + odb->surf[i].spec = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_REFL); + odb->surf[i].refl = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_TRAN); + odb->surf[i].tran = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_TRNL); + odb->surf[i].trnl = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_RIND); + odb->surf[i].rind = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_BUMP); + odb->surf[i].bump = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_GLOS); + odb->surf[i].glos = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_SHRP); + odb->surf[i].shrp = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_SMAN); + odb->surf[i].sman = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_RSAN); + odb->surf[i].rsan = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_TSAN); + odb->surf[i].tsan = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_CLRF); + odb->surf[i].clrf = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_CLRH); + odb->surf[i].clrh = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_ADTR); + odb->surf[i].adtr = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_AVAL); + odb->surf[i].aval = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_GVAL); + odb->surf[i].gval = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_LSIZ); + odb->surf[i].lsiz = (float)*dval; + + dval = surff->getFlt(surfid[i], SURF_LCOL); + odb->surf[i].lcol[0] = (float)dval[0]; + odb->surf[i].lcol[1] = (float)dval[1]; + odb->surf[i].lcol[2] = (float)dval[2]; + + odb->surf[i].alph = surff->getInt(surfid[i], SURF_ALPH); + odb->surf[i].rfop = surff->getInt(surfid[i], SURF_RFOP); + odb->surf[i].trop = surff->getInt(surfid[i], SURF_TROP); + odb->surf[i].side = surff->getInt(surfid[i], SURF_SIDE); + odb->surf[i].glow = surff->getInt(surfid[i], SURF_GLOW); + odb->surf[i].line = surff->getInt(surfid[i], SURF_LINE); + + odb->surf[i].rimg = surff->getImg(surfid[i], SURF_RIMG); + odb->surf[i].timg = surff->getImg(surfid[i], SURF_TIMG); + } + + /* find surface index for each polygon */ + + for (i = 0; i < odb->npolygons; i++) + { + tag = mesh->polTag(mesh, odb->pol[i].id, LWPTAG_SURF); + odb->pol[i].sindex = findSurf(odb, tag); + } + + return 1; } -#pragma warning (default:4995) +#pragma warning(default : 4995) diff --git a/src/plugins/lw/Export/scenscan/vecmat.cpp b/src/plugins/lw/Export/scenscan/vecmat.cpp index 431767001df..8327235afbd 100644 --- a/src/plugins/lw/Export/scenscan/vecmat.cpp +++ b/src/plugins/lw/Export/scenscan/vecmat.cpp @@ -7,32 +7,30 @@ Basic vector and matrix functions. ====================================================================== */ #include "vecmat.h" -#pragma warning (disable:4995) +#pragma warning(disable : 4995) -float dot( LWFVector a, LWFVector b ) +float dot(LWFVector a, LWFVector b) { - return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] + a[ 2 ] * b[ 2 ]; + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } - -void cross( LWFVector a, LWFVector b, LWFVector c ) +void cross(LWFVector a, LWFVector b, LWFVector c) { - c[ 0 ] = a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ]; - c[ 1 ] = a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ]; - c[ 2 ] = a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ]; + c[0] = a[1] * b[2] - a[2] * b[1]; + c[1] = a[2] * b[0] - a[0] * b[2]; + c[2] = a[0] * b[1] - a[1] * b[0]; } - -void normalize( LWFVector v ) +void normalize(LWFVector v) { - float r; - - r = ( float ) sqrt( dot( v, v )); - if ( r > 0 ) { - v[ 0 ] /= r; - v[ 1 ] /= r; - v[ 2 ] /= r; - } + float r; + + r = (float)sqrt(dot(v, v)); + if (r > 0) { + v[0] /= r; + v[1] /= r; + v[2] /= r; + } } -#pragma warning (default:4995) +#pragma warning(default : 4995) diff --git a/src/plugins/lw/Export/scenscan/vecmat.h b/src/plugins/lw/Export/scenscan/vecmat.h index ab5a1840c31..298e6b7cd27 100644 --- a/src/plugins/lw/Export/scenscan/vecmat.h +++ b/src/plugins/lw/Export/scenscan/vecmat.h @@ -1,7 +1,6 @@ #ifndef _VECMAT_H_ #define _VECMAT_H_ - /*====================================================================== vecmat.h @@ -10,10 +9,10 @@ Basic vector and matrix functions. #include -#define vecangle(a,b) (float)acos(dot(a,b)) /* a and b must be unit vectors */ +#define vecangle(a, b) (float)acos(dot(a, b)) /* a and b must be unit vectors */ -float dot( LWFVector a, LWFVector b ); -void cross( LWFVector a, LWFVector b, LWFVector c ); -void normalize( LWFVector v ); +float dot(LWFVector a, LWFVector b); +void cross(LWFVector a, LWFVector b, LWFVector c); +void normalize(LWFVector v); -#endif //_VECMAT_H_/* +#endif //_VECMAT_H_/* diff --git a/src/plugins/lw/Export/scenscan/vmap.cpp b/src/plugins/lw/Export/scenscan/vmap.cpp index a2c88417d8f..d9339dde207 100644 --- a/src/plugins/lw/Export/scenscan/vmap.cpp +++ b/src/plugins/lw/Export/scenscan/vmap.cpp @@ -5,10 +5,10 @@ vmap.c Functions for examining vertex maps. ====================================================================== */ -#include "scenscan.h" #include "objectdb.h" +#include "scenscan.h" -#pragma warning (disable:4995) +#pragma warning(disable : 4995) /* ====================================================================== @@ -17,20 +17,17 @@ freeVertMapDB() Frees the VertMapDB created by getVertMapDB(). ====================================================================== */ -void freeVertMapDB( VertMapDB *vmdb ) +void freeVertMapDB(VertMapDB* vmdb) { - int i; - - if ( vmdb ) { - for ( i = 0; i < vmdb->nvmaps; i++ ) - if ( vmdb->vmap[ i ].name ) - free( vmdb->vmap[ i ].name ); - if ( vmdb->vmap ) - free( vmdb->vmap ); - free( vmdb ); - } -} + int i; + if (vmdb) { + for (i = 0; i < vmdb->nvmaps; i++) + if (vmdb->vmap[i].name) free(vmdb->vmap[i].name); + if (vmdb->vmap) free(vmdb->vmap); + free(vmdb); + } +} /* ====================================================================== @@ -40,54 +37,53 @@ getVertMapDB() by getObjectVMaps(), but it can be useful for other purposes. ====================================================================== */ -VertMapDB *getVertMapDB( GlobalFunc *global ) +VertMapDB* getVertMapDB(GlobalFunc* global) { - VertMapDB *vmdb; - LWObjectFuncs *objf; - const char *name; - int j, nvmaps; - - - objf = (st_LWObjectFuncs*)global( LWOBJECTFUNCS_GLOBAL, GFUSE_TRANSIENT ); - if ( !objf ) return NULL; - - /* count vmaps of all types */ - - nvmaps = objf->numVMaps( 0 ); - - if ( !nvmaps ) return NULL; - - /* allocate the VertMapDB */ - - vmdb = (st_VertMapDB*)calloc( 1, sizeof( VertMapDB )); - if ( !vmdb ) return NULL; - vmdb->nvmaps = nvmaps; - - /* allocate the vmap array */ - - vmdb->vmap = (st_DBVMapRec*)calloc( nvmaps, sizeof( DBVMapRec )); - if ( !vmdb->vmap ) { - free( vmdb ); - return NULL; - } - - /* fill in the vmap array */ - - for ( j = 0; j < nvmaps; j++ ) { - vmdb->vmap[ j ].type = objf->vmapType( j ); - vmdb->vmap[ j ].dim = objf->vmapDim( 0, j ); - name = objf->vmapName( 0, j ); - vmdb->vmap[ j ].name = (char*)malloc( xr_strlen( name ) + 1 ); - if ( !vmdb->vmap[ j ].name ) { - freeVertMapDB( vmdb ); - return NULL; - } - strcpy( vmdb->vmap[ j ].name, name ); - } - - return vmdb; -} + VertMapDB* vmdb; + LWObjectFuncs* objf; + const char* name; + int j, nvmaps; + + objf = (st_LWObjectFuncs*)global(LWOBJECTFUNCS_GLOBAL, GFUSE_TRANSIENT); + if (!objf) return NULL; + + /* count vmaps of all types */ + + nvmaps = objf->numVMaps(0); + + if (!nvmaps) return NULL; + + /* allocate the VertMapDB */ + + vmdb = (st_VertMapDB*)calloc(1, sizeof(VertMapDB)); + if (!vmdb) return NULL; + vmdb->nvmaps = nvmaps; + + /* allocate the vmap array */ + + vmdb->vmap = (st_DBVMapRec*)calloc(nvmaps, sizeof(DBVMapRec)); + if (!vmdb->vmap) { + free(vmdb); + return NULL; + } + + /* fill in the vmap array */ + for (j = 0; j < nvmaps; j++) + { + vmdb->vmap[j].type = objf->vmapType(j); + vmdb->vmap[j].dim = objf->vmapDim(0, j); + name = objf->vmapName(0, j); + vmdb->vmap[j].name = (char*)malloc(xr_strlen(name) + 1); + if (!vmdb->vmap[j].name) { + freeVertMapDB(vmdb); + return NULL; + } + strcpy(vmdb->vmap[j].name, name); + } + + return vmdb; +} /* ====================================================================== @@ -96,62 +92,63 @@ freeObjectVMaps() Free memory allocated by getObjectVMaps(). ====================================================================== */ -void freeObjectVMaps( ObjectDB *odb ) +void freeObjectVMaps(ObjectDB* odb) { - int i, j; - - if ( odb ) { - if ( odb->vmap ) { - for ( i = 0; i < odb->nvertmaps; i++ ) { - if ( odb->vmap[ i ].name ) free( odb->vmap[ i ].name ); - if ( odb->vmap[i].vindex ) free( odb->vmap[ i ].vindex ); - if ( odb->vmap[i].vdpol ) free( odb->vmap[ i ].vdpol ); - if ( odb->vmap[ i ].val ) { - for ( j = 0; j < odb->vmap[ i ].dim; j++ ) - if ( odb->vmap[ i ].val[ j ] ) - free( odb->vmap[ i ].val[ j ] ); - free( odb->vmap[ i ].val ); - } - } - free( odb->vmap ); - odb->vmap = NULL; - odb->nvertmaps = 0; - } - // vmap - for ( i = 0; i < odb->npoints; i++ ) { - odb->pt[ i ].nvmaps = 0; - if ( odb->pt[ i ].vm ) { - free( odb->pt[ i ].vm ); - odb->pt[ i ].vm = NULL; - } - } - // vmad - for ( int p = 0; p < odb->npolygons; p++ ) { - st_DBPolygon& P = odb->pol[p]; - for ( j=0; jvmap) { + for (i = 0; i < odb->nvertmaps; i++) + { + if (odb->vmap[i].name) free(odb->vmap[i].name); + if (odb->vmap[i].vindex) free(odb->vmap[i].vindex); + if (odb->vmap[i].vdpol) free(odb->vmap[i].vdpol); + if (odb->vmap[i].val) { + for (j = 0; j < odb->vmap[i].dim; j++) + if (odb->vmap[i].val[j]) free(odb->vmap[i].val[j]); + free(odb->vmap[i].val); + } + } + free(odb->vmap); + odb->vmap = NULL; + odb->nvertmaps = 0; + } + // vmap + for (i = 0; i < odb->npoints; i++) + { + odb->pt[i].nvmaps = 0; + if (odb->pt[i].vm) { + free(odb->pt[i].vm); + odb->pt[i].vm = NULL; + } + } + // vmad + for (int p = 0; p < odb->npolygons; p++) + { + st_DBPolygon& P = odb->pol[p]; + for (j = 0; j < P.nverts; j++) + { + if (P.v[j].vm) { + free(P.v[j].vm); + P.v[j].vm = NULL; + } + } + } + } +} //====================================================================== -//getObjectVMaps() +// getObjectVMaps() // Allocate and fill in structures describing the vertex maps applied to // the object. Updates the ObjectDB and returns 1 if successful. Backs // out of any changes to the ObjectDB and returns 0 if an error occurs. - + // Before calling this function, the ObjectDB must be prepared to receive // vmap data. This means that the point array has been allocated and // filled in, and the references to vmap structures are pristine--all // counts are 0 and all pointers are NULL. - + // We need to work within a peculiarity of the plug-in API for vmaps. // We can't ask for only the vmaps for a particular object. In order to // find the vmaps associated with an object, we need to ask, for each @@ -160,217 +157,242 @@ void freeObjectVMaps( ObjectDB *odb ) // ObjectDB. //====================================================================== -int getObjectVMaps( ObjectDB *odb, LWMeshInfo *mesh, GlobalFunc *global ) +int getObjectVMaps(ObjectDB* odb, LWMeshInfo* mesh, GlobalFunc* global) { - VertMapDB *vmdb; - void *vmid; - int i, j, k, n, p, ismapped, nvmaps, dim, *npts, ok = 0; - float *val = NULL; - - - /* get the list of vmaps in the scene */ - - vmdb = getVertMapDB( global ); - if ( !vmdb ) return 1; - - /* create an array for counting the points with each vmap */ - - npts = (int*)calloc( vmdb->nvmaps, sizeof( int )); - if ( !npts ) goto Finish; - - /* count the object's vmaps and the number of points for each vmap */ - - for ( i = 0, nvmaps = 0; i < vmdb->nvmaps; i++ ) { - vmid = mesh->pntVLookup( mesh, vmdb->vmap[ i ].type, vmdb->vmap[ i ].name ); - - if ( vmid ) { - dim = mesh->pntVSelect( mesh, vmid ); - if ( dim > 0 ) { - val = (float*)calloc( dim, sizeof( float )); - if ( !val ) goto Finish; - }else - val = NULL; - - // vmap - for ( j = 0; j < odb->npoints; j++ ) { - ismapped = mesh->pntVGet( mesh, odb->pt[ j ].id, val ); - if ( ismapped ) ++npts[ i ]; - } - - //vmad - for ( j = 0; j < odb->npolygons; j++ ) { - st_DBPolygon& P = odb->pol[j]; - for ( k =0; kpntVPGet( mesh, odb->pt[P.v[k].index].id, P.id, val ); - if ( ismapped ) ++npts[ i ]; - } - } - - if ( npts[ i ] ) ++nvmaps; - free( val ); - } - } - - /* no vmaps for this object? */ - - if ( nvmaps == 0 ) { - ok = 1; - goto Finish; - } - - /* allocate the vmap array */ - - odb->nvertmaps = nvmaps; - odb->vmap = (st_DBVMapVal*)calloc( nvmaps, sizeof( DBVMap )); - if ( !odb->vmap ) goto Finish; - - for ( i = 0; i < nvmaps; i++ ) { - - /* initialize the vmap info */ - - odb->vmap[ i ].name = (char*)malloc( xr_strlen( vmdb->vmap[ i ].name ) + 1 ); - if ( !odb->vmap[ i ].name ) goto Finish; - strcpy( odb->vmap[ i ].name, vmdb->vmap[ i ].name ); - odb->vmap[ i ].type = vmdb->vmap[ i ].type; - odb->vmap[ i ].dim = vmdb->vmap[ i ].dim; - odb->vmap[ i ].nverts = npts[ i ]; - - /* allocate the point index array */ - odb->vmap[ i ].vindex = (int*)calloc( npts[ i ], sizeof( int )); - if ( !odb->vmap[ i ].vindex ) goto Finish; - - odb->vmap[ i ].vdpol = (int*)calloc( npts[ i ], sizeof(int)); - if ( !odb->vmap[ i ].vdpol ) goto Finish; - - /* allocate the value arrays */ - - if ( vmdb->vmap[ i ].dim > 0 ) { - odb->vmap[ i ].val = (float**)calloc( vmdb->vmap[ i ].dim, sizeof( float * )); - if ( !odb->vmap[ i ].val ) goto Finish; - for ( k = 0; k < vmdb->vmap[ i ].dim; k++ ) { - odb->vmap[ i ].val[ k ] = (float*)calloc( npts[ i ], sizeof( float )); - if ( !odb->vmap[ i ].val[ k ] ) goto Finish; - } - } - - /* fill in the point index and value arrays */ - - vmid = mesh->pntVLookup( mesh, vmdb->vmap[ i ].type, vmdb->vmap[ i ].name ); - if ( vmid ) { - dim = mesh->pntVSelect( mesh, vmid ); - if ( dim > 0 ) { - val = (float*)calloc( dim, sizeof( float )); - if ( !val ) goto Finish; - } - else - val = NULL; - - // vmap - for ( j = 0, n = 0; j < odb->npoints; j++ ) { - ismapped = mesh->pntVGet( mesh, odb->pt[ j ].id, val ); - if ( ismapped ) { - odb->vmap[ i ].vindex[ n ] = j; - odb->vmap[ i ].vdpol[ n ] = -1; - for ( k = 0; k < dim; k++ ) - odb->vmap[ i ].val[ k ][ n ] = val[ k ]; - ++n; - } - } - - // vmad - for ( p = 0; p < odb->npolygons; p++ ) { - st_DBPolygon& P = odb->pol[p]; - for ( j=0; jpntVPGet( mesh, odb->pt[P.v[j].index].id, P.id, val ); - if ( ismapped ){ - odb->vmap[ i ].vindex[ n ] = P.v[j].index; - odb->vmap[ i ].vdpol[ n ] = p; - for ( k = 0; k < dim; k++ ) - odb->vmap[ i ].val[ k ][ n ] = val[ k ]; - ++n; - } - } - } - - free( val ); - } - } - - /* count the number of vmap values for each point */ - - for ( i = 0; i < nvmaps; i++ ){ - for ( j = 0; j < odb->vmap[ i ].nverts; j++ ){ - int pt_idx = odb->vmap[i].vindex[j]; - int vd_pol = odb->vmap[i].vdpol[j]; - st_DBPoint& pt = odb->pt[pt_idx]; - if (vd_pol<=-1) ++pt.nvmaps; - else{ - st_DBPolygon& P = odb->pol[vd_pol]; - for (int pv_i=0; pv_inpoints; i++ ) { - odb->pt[ i ].vm = (st_DBVMapPt*)calloc( odb->pt[ i ].nvmaps, sizeof( DBVMapPt )); - if ( !odb->pt[ i ].vm ) goto Finish; - odb->pt[ i ].nvmaps = 0; - } - /* allocate vmap references for each mapped polypoint */ - for ( p = 0; p < odb->npolygons; p++ ) { - st_DBPolygon& P = odb->pol[p]; - for ( j=0; jvmap[ i ].nverts; j++ ) { - int pt_idx = odb->vmap[i].vindex[j]; - int vd_pol = odb->vmap[i].vdpol[j]; - - if (vd_pol<=-1){ - int vm_cnt = odb->pt[pt_idx].nvmaps; - odb->pt[pt_idx].vm[vm_cnt].vmap = &odb->vmap[ i ]; - odb->pt[pt_idx].vm[vm_cnt].index = j; - ++odb->pt[pt_idx].nvmaps; - }else{ - st_DBPolygon& P = odb->pol[vd_pol]; - for (int pv_i=0; pv_ivmap[i]; - pol_vert.vm[vm_cnt].index = j; - ++pol_vert.nvmaps; - break; - } - } - } - } - } - - // success - - ok = 1; - + VertMapDB* vmdb; + void* vmid; + int i, j, k, n, p, ismapped, nvmaps, dim, *npts, ok = 0; + float* val = NULL; + + /* get the list of vmaps in the scene */ + + vmdb = getVertMapDB(global); + if (!vmdb) return 1; + + /* create an array for counting the points with each vmap */ + + npts = (int*)calloc(vmdb->nvmaps, sizeof(int)); + if (!npts) goto Finish; + + /* count the object's vmaps and the number of points for each vmap */ + + for (i = 0, nvmaps = 0; i < vmdb->nvmaps; i++) + { + vmid = mesh->pntVLookup(mesh, vmdb->vmap[i].type, vmdb->vmap[i].name); + + if (vmid) { + dim = mesh->pntVSelect(mesh, vmid); + if (dim > 0) { + val = (float*)calloc(dim, sizeof(float)); + if (!val) goto Finish; + } + else + val = NULL; + + // vmap + for (j = 0; j < odb->npoints; j++) + { + ismapped = mesh->pntVGet(mesh, odb->pt[j].id, val); + if (ismapped) ++npts[i]; + } + + // vmad + for (j = 0; j < odb->npolygons; j++) + { + st_DBPolygon& P = odb->pol[j]; + for (k = 0; k < P.nverts; k++) + { + ismapped = mesh->pntVPGet(mesh, odb->pt[P.v[k].index].id, P.id, val); + if (ismapped) ++npts[i]; + } + } + + if (npts[i]) ++nvmaps; + free(val); + } + } + + /* no vmaps for this object? */ + + if (nvmaps == 0) { + ok = 1; + goto Finish; + } + + /* allocate the vmap array */ + + odb->nvertmaps = nvmaps; + odb->vmap = (st_DBVMapVal*)calloc(nvmaps, sizeof(DBVMap)); + if (!odb->vmap) goto Finish; + + for (i = 0; i < nvmaps; i++) + { + /* initialize the vmap info */ + + odb->vmap[i].name = (char*)malloc(xr_strlen(vmdb->vmap[i].name) + 1); + if (!odb->vmap[i].name) goto Finish; + strcpy(odb->vmap[i].name, vmdb->vmap[i].name); + odb->vmap[i].type = vmdb->vmap[i].type; + odb->vmap[i].dim = vmdb->vmap[i].dim; + odb->vmap[i].nverts = npts[i]; + + /* allocate the point index array */ + odb->vmap[i].vindex = (int*)calloc(npts[i], sizeof(int)); + if (!odb->vmap[i].vindex) goto Finish; + + odb->vmap[i].vdpol = (int*)calloc(npts[i], sizeof(int)); + if (!odb->vmap[i].vdpol) goto Finish; + + /* allocate the value arrays */ + + if (vmdb->vmap[i].dim > 0) { + odb->vmap[i].val = (float**)calloc(vmdb->vmap[i].dim, sizeof(float*)); + if (!odb->vmap[i].val) goto Finish; + for (k = 0; k < vmdb->vmap[i].dim; k++) + { + odb->vmap[i].val[k] = (float*)calloc(npts[i], sizeof(float)); + if (!odb->vmap[i].val[k]) goto Finish; + } + } + + /* fill in the point index and value arrays */ + + vmid = mesh->pntVLookup(mesh, vmdb->vmap[i].type, vmdb->vmap[i].name); + if (vmid) { + dim = mesh->pntVSelect(mesh, vmid); + if (dim > 0) { + val = (float*)calloc(dim, sizeof(float)); + if (!val) goto Finish; + } + else + val = NULL; + + // vmap + for (j = 0, n = 0; j < odb->npoints; j++) + { + ismapped = mesh->pntVGet(mesh, odb->pt[j].id, val); + if (ismapped) { + odb->vmap[i].vindex[n] = j; + odb->vmap[i].vdpol[n] = -1; + for (k = 0; k < dim; k++) + odb->vmap[i].val[k][n] = val[k]; + ++n; + } + } + + // vmad + for (p = 0; p < odb->npolygons; p++) + { + st_DBPolygon& P = odb->pol[p]; + for (j = 0; j < P.nverts; j++) + { + ismapped = mesh->pntVPGet(mesh, odb->pt[P.v[j].index].id, P.id, val); + if (ismapped) { + odb->vmap[i].vindex[n] = P.v[j].index; + odb->vmap[i].vdpol[n] = p; + for (k = 0; k < dim; k++) + odb->vmap[i].val[k][n] = val[k]; + ++n; + } + } + } + + free(val); + } + } + + /* count the number of vmap values for each point */ + + for (i = 0; i < nvmaps; i++) + { + for (j = 0; j < odb->vmap[i].nverts; j++) + { + int pt_idx = odb->vmap[i].vindex[j]; + int vd_pol = odb->vmap[i].vdpol[j]; + st_DBPoint& pt = odb->pt[pt_idx]; + if (vd_pol <= -1) + ++pt.nvmaps; + else + { + st_DBPolygon& P = odb->pol[vd_pol]; + for (int pv_i = 0; pv_i < P.nverts; pv_i++) + { + st_DBPolVert& pol_vert = P.v[pv_i]; + if (pt_idx == pol_vert.index) { + ++pol_vert.nvmaps; + break; + } + } + } + } + } + + /* allocate vmap references for each mapped point */ + for (i = 0; i < odb->npoints; i++) + { + odb->pt[i].vm = (st_DBVMapPt*)calloc(odb->pt[i].nvmaps, sizeof(DBVMapPt)); + if (!odb->pt[i].vm) goto Finish; + odb->pt[i].nvmaps = 0; + } + /* allocate vmap references for each mapped polypoint */ + for (p = 0; p < odb->npolygons; p++) + { + st_DBPolygon& P = odb->pol[p]; + for (j = 0; j < P.nverts; j++) + { + if (P.v[j].nvmaps) { + P.v[j].vm = (st_DBVMapPt*)calloc(P.v[j].nvmaps, sizeof(DBVMapPt)); + P.v[j].nvmaps = 0; + } + else + { + P.v[j].vm = 0; + } + } + } + + /* fill in vmap references for each mapped point */ + for (i = 0; i < nvmaps; i++) + { + for (j = 0; j < odb->vmap[i].nverts; j++) + { + int pt_idx = odb->vmap[i].vindex[j]; + int vd_pol = odb->vmap[i].vdpol[j]; + + if (vd_pol <= -1) { + int vm_cnt = odb->pt[pt_idx].nvmaps; + odb->pt[pt_idx].vm[vm_cnt].vmap = &odb->vmap[i]; + odb->pt[pt_idx].vm[vm_cnt].index = j; + ++odb->pt[pt_idx].nvmaps; + } + else + { + st_DBPolygon& P = odb->pol[vd_pol]; + for (int pv_i = 0; pv_i < P.nverts; pv_i++) + { + st_DBPolVert& pol_vert = P.v[pv_i]; + int vm_cnt = pol_vert.nvmaps; + if (pt_idx == pol_vert.index) { + pol_vert.vm[vm_cnt].vmap = &odb->vmap[i]; + pol_vert.vm[vm_cnt].index = j; + ++pol_vert.nvmaps; + break; + } + } + } + } + } + + // success + + ok = 1; + Finish: - freeVertMapDB( vmdb ); - if ( npts ) free( npts ); - if ( !ok ) - freeObjectVMaps( odb ); - - return ok; + freeVertMapDB(vmdb); + if (npts) free(npts); + if (!ok) freeObjectVMaps(odb); + + return ok; } -#pragma warning (default:4995) +#pragma warning(default : 4995) diff --git a/src/plugins/lw/Export/stdafx.cpp b/src/plugins/lw/Export/stdafx.cpp index 6ffc703a873..cf524364f72 100644 --- a/src/plugins/lw/Export/stdafx.cpp +++ b/src/plugins/lw/Export/stdafx.cpp @@ -2,4 +2,3 @@ // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" - \ No newline at end of file diff --git a/src/plugins/lw/Export/stdafx.h b/src/plugins/lw/Export/stdafx.h index ab5be739ff7..b42de2f69fc 100644 --- a/src/plugins/lw/Export/stdafx.h +++ b/src/plugins/lw/Export/stdafx.h @@ -11,45 +11,64 @@ #pragma comment(lib, "xrCore.lib") #define _BCL -#define ENGINE_API +#define ENGINE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; - #define ECORE_API -#include "plugins/Shared/ELog.h" #include -#include -#include -#include -#include #include -#include +#include #include +#include +#include #include +#include +#include +#include "plugins/Shared/ELog.h" #define AnsiString std::string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #define THROW R_ASSERT(0) #ifdef _LW_SHADER - #define _EDITOR_FILE_NAME_ "lw_shader" +#define _EDITOR_FILE_NAME_ "lw_shader" +#else +#ifdef _LW_EXPORT +#define _EDITOR_FILE_NAME_ "lw_export" #else - #ifdef _LW_EXPORT - #define _EDITOR_FILE_NAME_ "lw_export" - #else - #ifdef _LW_IMPORT - #define _EDITOR_FILE_NAME_ "lw_import" - #endif - #endif +#ifdef _LW_IMPORT +#define _EDITOR_FILE_NAME_ "lw_import" +#endif +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" -#endif // StdafxH +#endif // StdafxH diff --git a/src/plugins/lw/Server/servdesc.c b/src/plugins/lw/Server/servdesc.c index 213bf7fcdd2..7f0ce267e29 100644 --- a/src/plugins/lw/Server/servdesc.c +++ b/src/plugins/lw/Server/servdesc.c @@ -9,16 +9,9 @@ */ #include +extern char ServerClass[]; +extern char ServerName[]; +extern ServerUserName UserNames[]; +extern XCALL_(int) Activate(long, GlobalFunc*, void*, void*); -extern char ServerClass[]; -extern char ServerName[]; -extern ServerUserName UserNames[]; -extern XCALL_(int) Activate (long, GlobalFunc *, void *, void *); - - - ServerRecord -ServerDesc[] = { - { ServerClass, ServerName, Activate, UserNames }, - { 0 } -}; - +ServerRecord ServerDesc[] = {{ServerClass, ServerName, Activate, UserNames}, {0}}; diff --git a/src/plugins/lw/Server/servmain.c b/src/plugins/lw/Server/servmain.c index d4965d61441..2a6a07337f7 100644 --- a/src/plugins/lw/Server/servmain.c +++ b/src/plugins/lw/Server/servmain.c @@ -4,22 +4,13 @@ */ #include +extern void* Startup(void); +extern void Shutdown(void* serverData); +extern ServerRecord ServerDesc[]; -extern void * Startup (void); -extern void Shutdown (void *serverData); -extern ServerRecord ServerDesc[]; - - - #ifdef __BORLANDC__ +#ifdef __BORLANDC__ ModuleDescriptor mod_descrip = - #else +#else ModuleDescriptor _mod_descrip = - #endif - { - MOD_SYSSYNC, - MOD_SYSVER, - MOD_MACHINE, - Startup, - Shutdown, - ServerDesc - }; +#endif + {MOD_SYSSYNC, MOD_SYSVER, MOD_MACHINE, Startup, Shutdown, ServerDesc}; diff --git a/src/plugins/lw/Server/shutdown.c b/src/plugins/lw/Server/shutdown.c index fa7582da083..018d764819e 100644 --- a/src/plugins/lw/Server/shutdown.c +++ b/src/plugins/lw/Server/shutdown.c @@ -6,9 +6,6 @@ */ #include - - void -Shutdown ( - void *serverData) +void Shutdown(void* serverData) { } diff --git a/src/plugins/lw/Server/startup.c b/src/plugins/lw/Server/startup.c index 70ecd548851..3239839f107 100644 --- a/src/plugins/lw/Server/startup.c +++ b/src/plugins/lw/Server/startup.c @@ -6,9 +6,7 @@ */ #include - - void * -Startup (void) +void* Startup(void) { - return (void *) 4; + return (void*)4; } diff --git a/src/plugins/lw/Server/username.c b/src/plugins/lw/Server/username.c index a46f34cf408..ece748065f7 100644 --- a/src/plugins/lw/Server/username.c +++ b/src/plugins/lw/Server/username.c @@ -7,9 +7,4 @@ */ #include - - ServerUserName -UserNames[] = { - { 0 } -}; - +ServerUserName UserNames[] = {{0}}; diff --git a/src/plugins/lw/Shader/LW_Shader.cpp b/src/plugins/lw/Shader/LW_Shader.cpp index fb6fedcc159..d8e6474abef 100644 --- a/src/plugins/lw/Shader/LW_Shader.cpp +++ b/src/plugins/lw/Shader/LW_Shader.cpp @@ -1,28 +1,32 @@ -#include "stdafx.h" #include "LW_Shader.h" #include "plugins/Shared/BlenderListLoader.h" +#include "stdafx.h" -extern "C" { EShaderList ENShaders; EShaderList LCShaders; EShaderList GameMtls;} +extern "C" { +EShaderList ENShaders; +EShaderList LCShaders; +EShaderList GameMtls; +} extern "C" { - void __cdecl LoadShaders() - { - Core._initialize("XRayPlugin", 0, FALSE, nullptr, true); - FS._initialize (CLocatorAPI::flScanAppRoot,NULL,"xray_path.ltx"); - LPSTRVec lst; - ENShaders.count=LoadBlenderList(lst); - for (LPSTRIt b_it=lst.begin(); b_it!=lst.end(); b_it++) - strcpy(ENShaders.Names[b_it-lst.begin()],*b_it); - ClearList(lst); +void __cdecl LoadShaders() +{ + Core._initialize("XRayPlugin", 0, FALSE, nullptr, true); + FS._initialize(CLocatorAPI::flScanAppRoot, NULL, "xray_path.ltx"); + LPSTRVec lst; + ENShaders.count = LoadBlenderList(lst); + for (LPSTRIt b_it = lst.begin(); b_it != lst.end(); b_it++) + strcpy(ENShaders.Names[b_it - lst.begin()], *b_it); + ClearList(lst); - LCShaders.count=LoadShaderLCList(lst); - for (LPSTRIt c_it=lst.begin(); c_it!=lst.end(); c_it++) - strcpy(LCShaders.Names[c_it-lst.begin()],*c_it); - ClearList(lst); + LCShaders.count = LoadShaderLCList(lst); + for (LPSTRIt c_it = lst.begin(); c_it != lst.end(); c_it++) + strcpy(LCShaders.Names[c_it - lst.begin()], *c_it); + ClearList(lst); - GameMtls.count=LoadGameMtlList(lst); - for (LPSTRIt g_it=lst.begin(); g_it!=lst.end(); g_it++) - strcpy(GameMtls.Names[g_it-lst.begin()],*g_it); - ClearList(lst); - } + GameMtls.count = LoadGameMtlList(lst); + for (LPSTRIt g_it = lst.begin(); g_it != lst.end(); g_it++) + strcpy(GameMtls.Names[g_it - lst.begin()], *g_it); + ClearList(lst); +} }; \ No newline at end of file diff --git a/src/plugins/lw/Shader/LW_Shader.h b/src/plugins/lw/Shader/LW_Shader.h index ba6e58aabff..8ef9c5bc879 100644 --- a/src/plugins/lw/Shader/LW_Shader.h +++ b/src/plugins/lw/Shader/LW_Shader.h @@ -6,9 +6,10 @@ typedef char sh_name[64]; -typedef struct st_EShaderList{ - int count; - sh_name Names[1024]; -}EShaderList; +typedef struct st_EShaderList +{ + int count; + sh_name Names[1024]; +} EShaderList; #endif \ No newline at end of file diff --git a/src/plugins/lw/Shader/blotch.c b/src/plugins/lw/Shader/blotch.c index 949bcec5b4c..f0faa9cfb1a 100644 --- a/src/plugins/lw/Shader/blotch.c +++ b/src/plugins/lw/Shader/blotch.c @@ -13,68 +13,79 @@ is related to xpanel destroy processing. It shouldn't cause loss of data, and it should be resolved in later builds. ====================================================================== */ +#include #include #include #include -#include #include +#include #include -#include #include -#include +#include #include "LW_Shader.h" -#pragma warning (disable:4996) +#pragma warning(disable : 4996) #ifndef PI #define PI 3.1415926535897932384 #endif - + EShaderList ENShaders; EShaderList LCShaders; EShaderList GameMtls; -char* ENList_GetName(int idx){ - return ((idx>=0)&&(idx= 0) && (idx < ENShaders.count)) ? ENShaders.Names[idx] : "(none)"; } -void ENList_Clear(){ - ENShaders.count=0; +int ENList_GetIdx(sh_name n) +{ + int k; + for (k = 0; k < ENShaders.count; k++) + { + if (strcmp(n, ENShaders.Names[k]) == 0) return k; + } + return -1; +} +void ENList_Clear() +{ + ENShaders.count = 0; } - -char* LCList_GetName(int idx){ - return ((idx>=0)&&(idx= 0) && (idx < LCShaders.count)) ? LCShaders.Names[idx] : "(none)"; } -void LCList_Clear(){ - LCShaders.count=0; +int LCList_GetIdx(sh_name n) +{ + int k; + for (k = 0; k < LCShaders.count; k++) + { + if (strcmp(n, LCShaders.Names[k]) == 0) return k; + } + return -1; +} +void LCList_Clear() +{ + LCShaders.count = 0; } -char* GMList_GetName(int idx){ - return ((idx>=0)&&(idx= 0) && (idx < GameMtls.count)) ? GameMtls.Names[idx] : "(none)"; } -void GMList_Clear(){ - GameMtls.count=0; +int GMList_GetIdx(sh_name n) +{ + int k; + for (k = 0; k < GameMtls.count; k++) + { + if (strcmp(n, GameMtls.Names[k]) == 0) return k; + } + return -1; +} +void GMList_Clear() +{ + GameMtls.count = 0; } /* ====================================================================== @@ -84,22 +95,22 @@ Return the number of weight maps, plus 1 for "(none)". An xpanel callback for the vmap popup list, also used by Load(). ====================================================================== */ -XCALL_( static int ) -popCnt_EN( void *data ) +XCALL_(static int) +popCnt_EN(void* data) { - return 1 + ENShaders.count; + return 1 + ENShaders.count; } -XCALL_( static int ) -popCnt_GM( void *data ) +XCALL_(static int) +popCnt_GM(void* data) { - return 1 + GameMtls.count; + return 1 + GameMtls.count; } -XCALL_( static int ) -popCnt_LC( void *data ) +XCALL_(static int) +popCnt_LC(void* data) { - return 1 + LCShaders.count; + return 1 + LCShaders.count; } /* @@ -110,22 +121,22 @@ Return the name of a vmap, given an index. An xpanel callback for the vmap popup list, also used by Load() and Save(). ====================================================================== */ -XCALL_( static const char * ) -popName_EN( void *data, int idx ) +XCALL_(static const char*) +popName_EN(void* data, int idx) { - return ENList_GetName(idx); + return ENList_GetName(idx); } -XCALL_( static const char * ) -popName_GM( void *data, int idx ) +XCALL_(static const char*) +popName_GM(void* data, int idx) { - return GMList_GetName(idx); + return GMList_GetName(idx); } -XCALL_( static const char * ) -popName_LC( void *data, int idx ) +XCALL_(static const char*) +popName_LC(void* data, int idx) { - return LCList_GetName(idx); + return LCList_GetName(idx); } /* @@ -142,30 +153,28 @@ variables are initialized to some default values. ====================================================================== */ void __cdecl LoadShaders(); - -XCALL_( static LWInstance ) -Create( void *priv, LWSurfaceID surf, LWError *err ) +XCALL_(static LWInstance) +Create(void* priv, LWSurfaceID surf, LWError* err) { - XRShader *inst; + XRShader* inst; - inst = calloc( 1, sizeof( XRShader )); - if ( !inst ) { - *err = "Couldn't allocate memory for instance."; - return NULL; - } + inst = calloc(1, sizeof(XRShader)); + if (!inst) { + *err = "Couldn't allocate memory for instance."; + return NULL; + } - strcpy(inst->en_name, "default"); - strcpy(inst->lc_name, "default"); - strcpy(inst->gm_name, "default"); + strcpy(inst->en_name, "default"); + strcpy(inst->lc_name, "default"); + strcpy(inst->gm_name, "default"); - ENList_Clear(); - LCList_Clear(); - LoadShaders(); + ENList_Clear(); + LCList_Clear(); + LoadShaders(); - return inst; + return inst; } - /* ====================================================================== Destroy() @@ -173,13 +182,12 @@ Destroy() Handler callback. Free resources allocated by Create(). ====================================================================== */ -XCALL_( static void ) -Destroy( XRShader *inst ) +XCALL_(static void) +Destroy(XRShader* inst) { - free( inst ); + free(inst); } - /* ====================================================================== Copy() @@ -187,16 +195,15 @@ Copy() Handler callback. Copy instance data. ====================================================================== */ -XCALL_( static LWError ) -Copy( XRShader *to, XRShader *from ) +XCALL_(static LWError) +Copy(XRShader* to, XRShader* from) { - XCALL_INIT; + XCALL_INIT; - *to = *from; - return NULL; + *to = *from; + return NULL; } - /* ====================================================================== Load() @@ -206,19 +213,18 @@ in the SURF chunks of object files, but it isn't necessary to know that to read and write the data. ====================================================================== */ -XCALL_( static LWError ) -Load( XRShader *inst, const LWLoadState *ls ) +XCALL_(static LWError) +Load(XRShader* inst, const LWLoadState* ls) { - ls->read(ls->readData,(char*)inst,sizeof(XRShader)); - if (ENList_GetIdx(inst->en_name)==-1) strcpy(inst->en_name,"default"); - if (LCList_GetIdx(inst->lc_name)==-1) strcpy(inst->lc_name,"default"); - if (GMList_GetIdx(inst->gm_name)==-1) strcpy(inst->gm_name,"default"); - inst->desc = 0; + ls->read(ls->readData, (char*)inst, sizeof(XRShader)); + if (ENList_GetIdx(inst->en_name) == -1) strcpy(inst->en_name, "default"); + if (LCList_GetIdx(inst->lc_name) == -1) strcpy(inst->lc_name, "default"); + if (GMList_GetIdx(inst->gm_name) == -1) strcpy(inst->gm_name, "default"); + inst->desc = 0; - return NULL; + return NULL; } - /* ====================================================================== Save() @@ -229,15 +235,14 @@ transfer our double-precision data to a float variable before calling the LWSAVE_FP() macro. ====================================================================== */ -XCALL_( static LWError ) -Save( XRShader *inst, const LWSaveState *ss ) +XCALL_(static LWError) +Save(XRShader* inst, const LWSaveState* ss) { - ss->write(ss->writeData,(char*)inst,sizeof(XRShader)); + ss->write(ss->writeData, (char*)inst, sizeof(XRShader)); - return NULL; + return NULL; } - /* ====================================================================== DescLn() @@ -247,17 +252,16 @@ data. Since the string must persist after this is called, it's part of the instance. ====================================================================== */ -XCALL_( static const char * ) -DescLn( XRShader *inst ) +XCALL_(static const char*) +DescLn(XRShader* inst) { - char s[1024]; - if (inst->desc) free(inst->desc); - sprintf( s, "ES:'%s', CS:'%s', GM:'%s'", inst->en_name, inst->lc_name, inst->gm_name ); - inst->desc = strdup(s); - return inst->desc; + char s[1024]; + if (inst->desc) free(inst->desc); + sprintf(s, "ES:'%s', CS:'%s', GM:'%s'", inst->en_name, inst->lc_name, inst->gm_name); + inst->desc = strdup(s); + return inst->desc; } - /* ====================================================================== Init() @@ -266,14 +270,13 @@ Handler callback, called at the start of rendering. We do a little precalculation here. ====================================================================== */ -XCALL_( static LWError ) -Init( XRShader *inst, int mode ) +XCALL_(static LWError) +Init(XRShader* inst, int mode) { - inst->desc = 0; - return NULL; + inst->desc = 0; + return NULL; } - /* ====================================================================== Cleanup() @@ -282,14 +285,13 @@ Handler callback, called at the end of rendering. We don't have anything to do, but it's here in case we want to add something later. ====================================================================== */ -XCALL_( static void ) -Cleanup( XRShader *inst ) +XCALL_(static void) +Cleanup(XRShader* inst) { - if (inst->desc) free(inst->desc); - return; + if (inst->desc) free(inst->desc); + return; } - /* ====================================================================== NewTime() @@ -297,13 +299,12 @@ NewTime() Handler callback, called at the start of each sampling pass. ====================================================================== */ -XCALL_( static LWError ) -NewTime( XRShader *inst, LWFrame f, LWTime t ) +XCALL_(static LWError) +NewTime(XRShader* inst, LWFrame f, LWTime t) { - return NULL; + return NULL; } - /* ====================================================================== Flags() @@ -312,13 +313,12 @@ Handler callback. Blotch alters the color of the surface, but nothing else, so we return just the color bit. ====================================================================== */ -XCALL_( static unsigned int ) -Flags( XRShader *inst ) +XCALL_(static unsigned int) +Flags(XRShader* inst) { - return LWSHF_COLOR; + return LWSHF_COLOR; } - /* ====================================================================== Evaluate() @@ -329,12 +329,11 @@ blotch and blend some of the blotch color with the color already computed for that spot. ====================================================================== */ -XCALL_( static void ) -Evaluate( XRShader *inst, LWShaderAccess *sa ) +XCALL_(static void) +Evaluate(XRShader* inst, LWShaderAccess* sa) { } - /* ====================================================================== Handler() @@ -343,38 +342,38 @@ Handler activation function. Check the version and fill in the callback fields of the handler structure. ====================================================================== */ -XCALL_( static int ) -Handler( long version, GlobalFunc *global, LWShaderHandler *local, - void *serverData) +XCALL_(static int) +Handler(long version, GlobalFunc* global, LWShaderHandler* local, void* serverData) { - if ( version != LWSHADER_VERSION ) return AFUNC_BADVERSION; + if (version != LWSHADER_VERSION) return AFUNC_BADVERSION; - local->inst->create = Create; - local->inst->destroy = Destroy; - local->inst->load = Load; - local->inst->save = Save; - local->inst->copy = Copy; - local->inst->descln = DescLn; - local->rend->init = Init; - local->rend->cleanup = Cleanup; - local->rend->newTime = NewTime; - local->evaluate = Evaluate; - local->flags = Flags; + local->inst->create = Create; + local->inst->destroy = Destroy; + local->inst->load = Load; + local->inst->save = Save; + local->inst->copy = Copy; + local->inst->descln = DescLn; + local->rend->init = Init; + local->rend->cleanup = Cleanup; + local->rend->newTime = NewTime; + local->evaluate = Evaluate; + local->flags = Flags; - return AFUNC_OK; + return AFUNC_OK; } - - /* interface stuff ----- */ -static LWXPanelFuncs *xpanf; -static LWColorActivateFunc *colorpick; -static LWInstUpdate *lwupdate; +static LWXPanelFuncs* xpanf; +static LWColorActivateFunc* colorpick; +static LWInstUpdate* lwupdate; -enum { ID_EN = 0x8001, - ID_LC = 0x8002, - ID_GM = 0x8003}; +enum +{ + ID_EN = 0x8001, + ID_LC = 0x8002, + ID_GM = 0x8003 +}; /* ====================================================================== @@ -383,30 +382,29 @@ ui_get() Xpanels callback for LWXP_VIEW panels. Returns a pointer to the data for a given control value. ====================================================================== */ -void *ui_get( XRShader *dat, unsigned long vid ) +void* ui_get(XRShader* dat, unsigned long vid) { - void *result = NULL; - - if ( dat ) - switch ( vid ) { - case ID_EN: - dat->en_idx = ENList_GetIdx(dat->en_name); - result = &dat->en_idx; - break; - case ID_LC: - dat->lc_idx = LCList_GetIdx(dat->lc_name); - result = &dat->lc_idx; - break; - case ID_GM: - dat->gm_idx = GMList_GetIdx(dat->gm_name); - result = &dat->gm_idx; - break; - } - - return result; + void* result = NULL; + + if (dat) switch (vid) + { + case ID_EN: + dat->en_idx = ENList_GetIdx(dat->en_name); + result = &dat->en_idx; + break; + case ID_LC: + dat->lc_idx = LCList_GetIdx(dat->lc_name); + result = &dat->lc_idx; + break; + case ID_GM: + dat->gm_idx = GMList_GetIdx(dat->gm_name); + result = &dat->gm_idx; + break; + } + + return result; } - /* ====================================================================== ui_set() @@ -415,28 +413,27 @@ Xpanels callback for LWXP_VIEW panels. Store a value in our instance data. ====================================================================== */ -LWXPRefreshCode ui_set( XRShader *dat, unsigned long vid, void *value ) +LWXPRefreshCode ui_set(XRShader* dat, unsigned long vid, void* value) { - switch ( vid ) { - case ID_EN: - dat->en_idx = *(( int * ) value ); - if(dat->en_idx>=0) strncpy(dat->en_name, ENList_GetName(dat->en_idx) ,sizeof( dat->en_name )); - break; - case ID_LC: - dat->lc_idx = *(( int * ) value ); - if(dat->lc_idx>=0) strncpy(dat->lc_name, LCList_GetName(dat->lc_idx) ,sizeof( dat->lc_name )); - break; - case ID_GM: - dat->gm_idx = *(( int * ) value ); - if(dat->gm_idx>=0) strncpy(dat->gm_name, GMList_GetName(dat->gm_idx) ,sizeof( dat->gm_name )); - break; - default: - return 0; - } - return 1; + switch (vid) + { + case ID_EN: + dat->en_idx = *((int*)value); + if (dat->en_idx >= 0) strncpy(dat->en_name, ENList_GetName(dat->en_idx), sizeof(dat->en_name)); + break; + case ID_LC: + dat->lc_idx = *((int*)value); + if (dat->lc_idx >= 0) strncpy(dat->lc_name, LCList_GetName(dat->lc_idx), sizeof(dat->lc_name)); + break; + case ID_GM: + dat->gm_idx = *((int*)value); + if (dat->gm_idx >= 0) strncpy(dat->gm_name, GMList_GetName(dat->gm_idx), sizeof(dat->gm_name)); + break; + default: return 0; + } + return 1; } - /* ====================================================================== ui_chgnotify() @@ -446,66 +443,51 @@ the value of one of your controls. We use the instance update global to tell Layout that our instance data has changed. ====================================================================== */ -void ui_chgnotify( LWXPanelID panel, unsigned long cid, unsigned long vid, - int event ) +void ui_chgnotify(LWXPanelID panel, unsigned long cid, unsigned long vid, int event) { - void *dat; + void* dat; - if ( event == LWXPEVENT_VALUE ) - if ( dat = xpanf->getData( panel, 0 )) - lwupdate( LWSHADER_HCLASS, dat ); + if (event == LWXPEVENT_VALUE) + if (dat = xpanf->getData(panel, 0)) lwupdate(LWSHADER_HCLASS, dat); } - /* ====================================================================== get_panel() Create and initialize an LWXP_VIEW panel. Called by Interface(). ====================================================================== */ -#define STR_Type_EN "Engine" -#define STR_Type_LC "Compiler" -#define STR_Type_GM "Game Material" +#define STR_Type_EN "Engine" +#define STR_Type_LC "Compiler" +#define STR_Type_GM "Game Material" static LWXPanelControl ctrl_list[] = { - { ID_EN, STR_Type_EN, "iPopChoice" }, - { ID_LC, STR_Type_LC, "iPopChoice" }, - { ID_GM, STR_Type_GM, "iPopChoice" }, - { 0 } -}; + {ID_EN, STR_Type_EN, "iPopChoice"}, {ID_LC, STR_Type_LC, "iPopChoice"}, {ID_GM, STR_Type_GM, "iPopChoice"}, {0}}; /* matching array of data descriptors */ static LWXPanelDataDesc data_descrip[] = { - { ID_EN, STR_Type_EN, "integer" }, - { ID_LC, STR_Type_LC, "integer" }, - { ID_GM, STR_Type_GM, "integer" }, - { 0 }, + {ID_EN, STR_Type_EN, "integer"}, {ID_LC, STR_Type_LC, "integer"}, {ID_GM, STR_Type_GM, "integer"}, {0}, }; -static LWXPanelID get_xpanel( GlobalFunc *global, XRShader *dat ) +static LWXPanelID get_xpanel(GlobalFunc* global, XRShader* dat) { - LWXPanelID panID = NULL; + LWXPanelID panID = NULL; - static LWXPanelHint hint[] = { - XpLABEL( 0, "Shaders" ), - XpCHGNOTIFY( ui_chgnotify ), - XpPOPFUNCS( ID_EN, popCnt_EN, popName_EN ), - XpPOPFUNCS( ID_LC, popCnt_LC, popName_LC ), - XpPOPFUNCS( ID_GM, popCnt_GM, popName_GM ), - XpEND - }; + static LWXPanelHint hint[] = {XpLABEL(0, "Shaders"), XpCHGNOTIFY(ui_chgnotify), + XpPOPFUNCS(ID_EN, popCnt_EN, popName_EN), XpPOPFUNCS(ID_LC, popCnt_LC, popName_LC), + XpPOPFUNCS(ID_GM, popCnt_GM, popName_GM), XpEND}; - xpanf = global( LWXPANELFUNCS_GLOBAL, GFUSE_TRANSIENT ); - if ( xpanf ) { - panID = xpanf->create( LWXP_VIEW, ctrl_list ); - if ( panID ) { - xpanf->hint( panID, 0, hint ); - xpanf->describe( panID, data_descrip, ui_get, ui_set ); - xpanf->viewInst( panID, dat ); - xpanf->setData( panID, 0, dat ); - } - } + xpanf = global(LWXPANELFUNCS_GLOBAL, GFUSE_TRANSIENT); + if (xpanf) { + panID = xpanf->create(LWXP_VIEW, ctrl_list); + if (panID) { + xpanf->hint(panID, 0, hint); + xpanf->describe(panID, data_descrip, ui_get, ui_set); + xpanf->viewInst(panID, dat); + xpanf->setData(panID, 0, dat); + } + } - return panID; + return panID; } /* @@ -515,29 +497,25 @@ Interface() The interface activation function. ====================================================================== */ -XCALL_( int ) -Interface( long version, GlobalFunc *global, LWInterface *local, - void *serverData ) +XCALL_(int) +Interface(long version, GlobalFunc* global, LWInterface* local, void* serverData) { - if ( version != LWINTERFACE_VERSION ) return AFUNC_BADVERSION; + if (version != LWINTERFACE_VERSION) return AFUNC_BADVERSION; - colorpick = global( LWCOLORACTIVATEFUNC_GLOBAL, GFUSE_TRANSIENT ); - lwupdate = global( LWINSTUPDATE_GLOBAL, GFUSE_TRANSIENT ); - xpanf = global( LWXPANELFUNCS_GLOBAL, GFUSE_TRANSIENT ); - if ( !colorpick || !lwupdate || !xpanf ) return AFUNC_BADGLOBAL; + colorpick = global(LWCOLORACTIVATEFUNC_GLOBAL, GFUSE_TRANSIENT); + lwupdate = global(LWINSTUPDATE_GLOBAL, GFUSE_TRANSIENT); + xpanf = global(LWXPANELFUNCS_GLOBAL, GFUSE_TRANSIENT); + if (!colorpick || !lwupdate || !xpanf) return AFUNC_BADGLOBAL; - local->panel = get_xpanel( global, local->inst ); -// local->panel = get_panel( local->inst ); - local->options = NULL; - local->command = NULL; + local->panel = get_xpanel(global, local->inst); + // local->panel = get_panel( local->inst ); + local->options = NULL; + local->command = NULL; - return local->panel ? AFUNC_OK : AFUNC_BADGLOBAL; + return local->panel ? AFUNC_OK : AFUNC_BADGLOBAL; } ServerRecord ServerDesc[] = { - { LWSHADER_HCLASS, SH_PLUGIN_NAME, Handler }, - { LWSHADER_ICLASS, SH_PLUGIN_NAME, Interface }, - { NULL } -}; + {LWSHADER_HCLASS, SH_PLUGIN_NAME, Handler}, {LWSHADER_ICLASS, SH_PLUGIN_NAME, Interface}, {NULL}}; -#pragma warning (default:4996) +#pragma warning(default : 4996) diff --git a/src/plugins/lw/Shader/resource.h b/src/plugins/lw/Shader/resource.h index a02358ca93a..1d713be98de 100644 --- a/src/plugins/lw/Shader/resource.h +++ b/src/plugins/lw/Shader/resource.h @@ -2,26 +2,26 @@ // Microsoft Developer Studio generated include file. // Used by resource.rc // -#define IDDEBUG 3 -#define IDD_LOG 101 -#define IDI_ICON 103 -#define IDD_VERIFY 104 -#define IDI_XRAY 105 -#define IDC_LIST 1000 -#define IDC_FILE 1001 -#define IDC_LINE 1002 -#define IDC_DESC 1003 -#define IDSTOP 1004 -#define IDCONTINUE 1005 -#define IDC_STACK 1006 +#define IDDEBUG 3 +#define IDD_LOG 101 +#define IDI_ICON 103 +#define IDD_VERIFY 104 +#define IDI_XRAY 105 +#define IDC_LIST 1000 +#define IDC_FILE 1001 +#define IDC_LINE 1002 +#define IDC_DESC 1003 +#define IDSTOP 1004 +#define IDCONTINUE 1005 +#define IDC_STACK 1006 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1007 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1007 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/src/plugins/lw/Shader/stdafx.cpp b/src/plugins/lw/Shader/stdafx.cpp index 6ffc703a873..cf524364f72 100644 --- a/src/plugins/lw/Shader/stdafx.cpp +++ b/src/plugins/lw/Shader/stdafx.cpp @@ -2,4 +2,3 @@ // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" - \ No newline at end of file diff --git a/src/plugins/lw/Shader/stdafx.h b/src/plugins/lw/Shader/stdafx.h index d38c83cb670..43fd5cb426b 100644 --- a/src/plugins/lw/Shader/stdafx.h +++ b/src/plugins/lw/Shader/stdafx.h @@ -10,39 +10,58 @@ #include "xrCore/xrCore.h" #pragma comment(lib, "xrCore.lib") -#define ENGINE_API +#define ENGINE_API -enum TMsgDlgType { mtWarning, mtError, mtInformation, mtConfirmation, mtCustom }; -enum TMsgDlgBtn { mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp }; +enum TMsgDlgType +{ + mtWarning, + mtError, + mtInformation, + mtConfirmation, + mtCustom +}; +enum TMsgDlgBtn +{ + mbYes, + mbNo, + mbOK, + mbCancel, + mbAbort, + mbRetry, + mbIgnore, + mbAll, + mbNoToAll, + mbYesToAll, + mbHelp +}; typedef TMsgDlgBtn TMsgDlgButtons[mbHelp]; - #define ECORE_API -#include "plugins/Shared/ELog.h" #include -#include #include +#include +#include "plugins/Shared/ELog.h" #define AnsiString std::string -DEFINE_VECTOR(AnsiString,AStringVec,AStringIt); +DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); #define THROW R_ASSERT(0) #ifdef _LW_SHADER - #define _EDITOR_FILE_NAME_ "lw_shader" +#define _EDITOR_FILE_NAME_ "lw_shader" +#else +#ifdef _LW_EXPORT +#define _EDITOR_FILE_NAME_ "lw_export" #else - #ifdef _LW_EXPORT - #define _EDITOR_FILE_NAME_ "lw_export" - #else - #ifdef _LW_IMPORT - #define _EDITOR_FILE_NAME_ "lw_import" - #endif - #endif +#ifdef _LW_IMPORT +#define _EDITOR_FILE_NAME_ "lw_import" +#endif +#endif #endif -#define GAMEMTL_NONE u32(-1) +#define GAMEMTL_NONE u32(-1) #define _game_data_ "$game_data$" -#endif // StdafxH +#endif // StdafxH diff --git a/src/plugins/lw/lw_shared/LW_ShaderDef.h b/src/plugins/lw/lw_shared/LW_ShaderDef.h index ee0ce7586c3..62dc42b480f 100644 --- a/src/plugins/lw/lw_shared/LW_ShaderDef.h +++ b/src/plugins/lw/lw_shared/LW_ShaderDef.h @@ -3,15 +3,16 @@ #pragma once /* our instance data */ -#pragma pack(push,1) -typedef struct st_XRShader{ - char en_name[64]; - int en_idx; - char lc_name[64]; - int lc_idx; - char gm_name[64]; - int gm_idx; - char* desc; +#pragma pack(push, 1) +typedef struct st_XRShader +{ + char en_name[64]; + int en_idx; + char lc_name[64]; + int lc_idx; + char gm_name[64]; + int gm_idx; + char* desc; } XRShader; #pragma pack(pop)