diff options
Diffstat (limited to 'intern/boolop')
-rw-r--r-- | intern/boolop/extern/BOP_Interface.h | 9 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_Interface.cpp | 142 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_Material.cpp | 176 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_Material.h | 80 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_MaterialContainer.cpp | 244 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_MaterialContainer.h | 72 | ||||
-rw-r--r-- | intern/boolop/intern/BOP_Mesh.h | 2 |
7 files changed, 21 insertions, 704 deletions
diff --git a/intern/boolop/extern/BOP_Interface.h b/intern/boolop/extern/BOP_Interface.h index 446dd1b79f7..7fe7ae226fd 100644 --- a/intern/boolop/extern/BOP_Interface.h +++ b/intern/boolop/extern/BOP_Interface.h @@ -36,18 +36,11 @@ typedef enum EnumBoolOpState {BOP_OK, BOP_NO_SOLID, BOP_ERROR} BoolOpState; typedef enum EnumBoolOpType {BOP_INTERSECTION=e_csg_intersection, BOP_UNION=e_csg_union, BOP_DIFFERENCE=e_csg_difference} BoolOpType; -// extern interpolator. -typedef int (*CSG_InterpolateUserFaceVertexDataFunc)(void *d1, void * d2, void *dnew, float epsilon); - BoolOpState BOP_performBooleanOperation(BoolOpType opType, - CSG_MeshPropertyDescriptor outputProps, BSP_CSGMesh** outputMesh, - CSG_MeshPropertyDescriptor obAProps, CSG_FaceIteratorDescriptor obAFaces, CSG_VertexIteratorDescriptor obAVertices, - CSG_MeshPropertyDescriptor obBProps, CSG_FaceIteratorDescriptor obBFaces, - CSG_VertexIteratorDescriptor obBVertices, - CSG_InterpolateUserFaceVertexDataFunc interpFunc); + CSG_VertexIteratorDescriptor obBVertices); #endif diff --git a/intern/boolop/intern/BOP_Interface.cpp b/intern/boolop/intern/BOP_Interface.cpp index d069c9d4664..6d1ae56da2d 100644 --- a/intern/boolop/intern/BOP_Interface.cpp +++ b/intern/boolop/intern/BOP_Interface.cpp @@ -36,7 +36,6 @@ #include "BOP_Mesh.h" #include "BOP_Face2Face.h" #include "BOP_Merge.h" -#include "BOP_MaterialContainer.h" #include "BOP_Chrono.h" //#define DEBUG @@ -50,18 +49,14 @@ BOP_Face3* BOP_createFace(BOP_Mesh* mesh, BOP_Index vertex1, BOP_Index vertex2, BOP_Index vertex3, - BOP_Index idxFace); + BOP_Index origFace); void BOP_addMesh(BOP_Mesh* mesh, BOP_Faces* meshFacesId, - BOP_MaterialContainer* materials, - CSG_MeshPropertyDescriptor props, CSG_FaceIteratorDescriptor& face_it, CSG_VertexIteratorDescriptor& vertex_it, bool invert); -BSP_CSGMesh* BOP_newEmptyMesh(CSG_MeshPropertyDescriptor props); +BSP_CSGMesh* BOP_newEmptyMesh(); BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* inputMesh, - BOP_MaterialContainer* materials, - CSG_MeshPropertyDescriptor props, bool invert); void BOP_meshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp); void BOP_simplifiedMeshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp, bool inverted); @@ -70,27 +65,20 @@ void BOP_meshClassify(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp); /** * Performs a generic booleam operation, the entry point for external modules. * @param opType Boolean operation type BOP_INTERSECTION, BOP_UNION, BOP_DIFFERENCE - * @param outputProps Output mesh properties * @param outputMesh Output mesh, the final result (the object C) - * @param obAProps Object A properties * @param obAFaces Object A faces list * @param obAVertices Object A vertices list - * @param obBProps Object B properties * @param obBFaces Object B faces list * @param obBVertices Object B vertices list * @param interpFunc Interpolating function * @return operation state: BOP_OK, BOP_NO_SOLID, BOP_ERROR */ BoolOpState BOP_performBooleanOperation(BoolOpType opType, - CSG_MeshPropertyDescriptor outputProps, BSP_CSGMesh** outputMesh, - CSG_MeshPropertyDescriptor obAProps, CSG_FaceIteratorDescriptor obAFaces, CSG_VertexIteratorDescriptor obAVertices, - CSG_MeshPropertyDescriptor obBProps, CSG_FaceIteratorDescriptor obBFaces, - CSG_VertexIteratorDescriptor obBVertices, - CSG_InterpolateUserFaceVertexDataFunc interpFunc) + CSG_VertexIteratorDescriptor obBVertices) { #ifdef DEBUG cout << "BEGIN BOP_performBooleanOperation" << endl; @@ -111,15 +99,11 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType, // Build C-mesh, the output mesh BOP_Mesh meshC; - // Prepare the material container - BOP_MaterialContainer materials; - materials.setInterpFunc(interpFunc); - // Add A-mesh into C-mesh - BOP_addMesh(&meshC, &meshAFacesId, &materials, obAProps, obAFaces, obAVertices, invertMeshA); + BOP_addMesh(&meshC, &meshAFacesId, obAFaces, obAVertices, invertMeshA); // Add B-mesh into C-mesh - BOP_addMesh(&meshC, &meshBFacesId, &materials, obBProps, obBFaces, obBVertices, invertMeshB); + BOP_addMesh(&meshC, &meshBFacesId, obBFaces, obBVertices, invertMeshB); // for now, allow operations on non-manifold (non-solid) meshes #if 0 @@ -132,7 +116,7 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType, invertMeshA, invertMeshB); // Invert the output mesh if is required - *outputMesh = BOP_exportMesh(&meshC, &materials, outputProps, invertMeshC); + *outputMesh = BOP_exportMesh(&meshC, invertMeshC); #ifdef DEBUG cout << "END BOP_performBooleanOperation" << endl; @@ -324,37 +308,33 @@ void BOP_meshClassify(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp) * @param vertex1 first vertex of the new face * @param vertex2 second vertex of the new face * @param vertex3 third vertex of the new face - * @param idxFace identifier of the new face + * @param origFace identifier of the new face * @return new the new face */ BOP_Face3 *BOP_createFace3(BOP_Mesh* mesh, BOP_Index vertex1, BOP_Index vertex2, BOP_Index vertex3, - BOP_Index idxFace) + BOP_Index origFace) { MT_Point3 p1 = mesh->getVertex(vertex1)->getPoint(); MT_Point3 p2 = mesh->getVertex(vertex2)->getPoint(); MT_Point3 p3 = mesh->getVertex(vertex3)->getPoint(); MT_Plane3 plane(p1,p2,p3); - return new BOP_Face3(vertex1, vertex2, vertex3, plane, idxFace); + return new BOP_Face3(vertex1, vertex2, vertex3, plane, origFace); } /** * Adds mesh information into destination mesh. * @param mesh input/output mesh, destination for the new mesh data * @param meshFacesId output mesh faces, contains an added faces list - * @param materials used to store material data - * @param props Properties of the input mesh data * @param face_it faces iterator * @param vertex_it vertices iterator * @param inverted if TRUE adding inverted faces, non-inverted otherwise */ void BOP_addMesh(BOP_Mesh* mesh, BOP_Faces* meshFacesId, - BOP_MaterialContainer* materials, - CSG_MeshPropertyDescriptor props, CSG_FaceIteratorDescriptor& face_it, CSG_VertexIteratorDescriptor& vertex_it, bool invert) @@ -374,46 +354,12 @@ void BOP_addMesh(BOP_Mesh* mesh, // now for the polygons. // we may need to decalare some memory for user defined face properties. - unsigned int sizeFace = props.user_data_size; - if (sizeFace) { - face.user_face_data = new char[sizeFace]; - } - else { - face.user_face_data = NULL; - } - - unsigned int sizeVertex = props.user_face_vertex_data_size; - if (sizeVertex) { - char * fv_data2 = NULL; - fv_data2 = new char[4 * sizeVertex]; - - face.user_face_vertex_data[0] = fv_data2; - face.user_face_vertex_data[1] = fv_data2 + sizeVertex; - face.user_face_vertex_data[2] = fv_data2 + 2*sizeVertex; - face.user_face_vertex_data[3] = fv_data2 + 3*sizeVertex; - } - else { - face.user_face_vertex_data[0] = NULL; - face.user_face_vertex_data[1] = NULL; - face.user_face_vertex_data[2] = NULL; - face.user_face_vertex_data[3] = NULL; - } - unsigned int idFaceMaterial; - BOP_Material faceMaterial(sizeFace,sizeVertex); - BOP_Material* materialHandler; BOP_Face3 *newface; while (!face_it.Done(face_it.it)) { face_it.Fill(face_it.it,&face); - faceMaterial.setFaceMaterial((char *)face.user_face_data); - faceMaterial.setFaceVertexMaterial((char *)face.user_face_vertex_data[0]); - faceMaterial.setOriginalFace(mesh->getNumFaces()); - faceMaterial.setIsQuad(face.vertex_number == 4); - idFaceMaterial = materials->addMaterial(faceMaterial); - materialHandler = materials->getMaterial(idFaceMaterial); - // Let's not rely on quads being coplanar - especially if they // are coming out of that soup of code from blender... if (face.vertex_number == 4){ @@ -423,40 +369,32 @@ void BOP_addMesh(BOP_Mesh* mesh, face.vertex_index[2] + vtxIndexOffset, face.vertex_index[0] + vtxIndexOffset, face.vertex_index[3] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(0),2); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),0); - materialHandler->setOriginalFaceVertex(newface->getVertex(2),3); newface = BOP_createFace3(mesh, face.vertex_index[2] + vtxIndexOffset, face.vertex_index[1] + vtxIndexOffset, face.vertex_index[0] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),1); } else { newface = BOP_createFace3(mesh, face.vertex_index[0] + vtxIndexOffset, face.vertex_index[2] + vtxIndexOffset, face.vertex_index[3] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(0),0); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),2); - materialHandler->setOriginalFaceVertex(newface->getVertex(2),3); newface = BOP_createFace3(mesh, face.vertex_index[0] + vtxIndexOffset, face.vertex_index[1] + vtxIndexOffset, face.vertex_index[2] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),1); } } else { @@ -466,54 +404,37 @@ void BOP_addMesh(BOP_Mesh* mesh, face.vertex_index[2] + vtxIndexOffset, face.vertex_index[1] + vtxIndexOffset, face.vertex_index[0] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(0),2); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),1); - materialHandler->setOriginalFaceVertex(newface->getVertex(2),0); } else { newface = BOP_createFace3(mesh, face.vertex_index[0] + vtxIndexOffset, face.vertex_index[1] + vtxIndexOffset, face.vertex_index[2] + vtxIndexOffset, - idFaceMaterial); + face.orig_face); meshFacesId->push_back(newface); mesh->addFace(newface); - materialHandler->setOriginalFaceVertex(newface->getVertex(0),0); - materialHandler->setOriginalFaceVertex(newface->getVertex(1),1); - materialHandler->setOriginalFaceVertex(newface->getVertex(2),2); } } face_it.Step(face_it.it); } - - // delete temporal material data - if (face.user_face_data) - delete[] static_cast<char *>(face.user_face_data); - if (face.user_face_vertex_data) - delete[] static_cast<char *>(face.user_face_vertex_data[0]); } /** * Returns an empty mesh with the specified properties. - * @param props Output mesh properties * @return a new empty mesh */ -BSP_CSGMesh* BOP_newEmptyMesh(CSG_MeshPropertyDescriptor props) +BSP_CSGMesh* BOP_newEmptyMesh() { BSP_CSGMesh* mesh = BSP_CSGMesh::New(); if (mesh == NULL) return mesh; vector<BSP_MVertex>* vertices = new vector<BSP_MVertex>; - BSP_CSGUserData* faceData = new BSP_CSGUserData(props.user_data_size); - BSP_CSGUserData* faceVtxData = new BSP_CSGUserData(props.user_face_vertex_data_size); mesh->SetVertices(vertices); - mesh->SetFaceData(faceData); - mesh->SetFaceVertexData(faceVtxData); return mesh; } @@ -521,24 +442,16 @@ BSP_CSGMesh* BOP_newEmptyMesh(CSG_MeshPropertyDescriptor props) /** * Exports a BOP_Mesh to a BSP_CSGMesh. * @param mesh Input mesh - * @param materials used to reconstruct original faces materials - * @param props Properties of output mesh * @param invert if TRUE export with inverted faces, no inverted otherwise * @return the corresponding new BSP_CSGMesh */ BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh, - BOP_MaterialContainer* materials, - CSG_MeshPropertyDescriptor props, bool invert) { - BSP_CSGMesh* outputMesh = BOP_newEmptyMesh(props); + BSP_CSGMesh* outputMesh = BOP_newEmptyMesh(); if (outputMesh == NULL) return NULL; - // User data handlers - BSP_CSGUserData* outputFaceVtxData = &(outputMesh->FaceVertexData()); - BSP_CSGUserData* outputFaceData = &(outputMesh->FaceData()); - // vtx index dictionary, to translate indeces from input to output. map<int,unsigned int> dic; map<int,unsigned int>::iterator itDic; @@ -549,9 +462,6 @@ BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh, BOP_Faces faces = mesh->getFaces(); BOP_Vertexs vertexs = mesh->getVertexs(); - // Reserve temporal memory - char* tmpFaceVtxData = new char[props.user_face_vertex_data_size]; - for (BOP_IT_Faces face = faces.begin(); face != faces.end(); face++) { if ((*face)->getTAG()!=BROKEN){ // Add output face @@ -560,11 +470,8 @@ BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh, // Copy face outFace.m_verts.clear(); - outFace.m_fv_data.clear(); outFace.m_plane = (*face)->getPlane(); - - // Copy face user data from input mesh - outputFaceData->Duplicate(materials->getFaceMaterial((*face)->getOriginalFace())); + outFace.m_orig_face = (*face)->getOriginalFace(); // invert face if is required if (invert) (*face)->invert(); @@ -587,22 +494,11 @@ BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh, // The vertex is added outVtxId = BSP_VertexInd(itDic->second); } - - // Add vertex to output face - outFace.m_verts.push_back(outVtxId); - // Add face vertex user data - char* faceVtxData = materials->getFaceVertexMaterial(mesh, - (*face)->getOriginalFace(), - (mesh->getVertex(idVertex))->getPoint(), - tmpFaceVtxData); - BSP_UserFVInd userFVInd(outputFaceVtxData->Duplicate((void*) faceVtxData)); - outFace.m_fv_data.push_back(userFVInd); + outFace.m_verts.push_back(outVtxId); } } } - // free temporal memory - delete[] tmpFaceVtxData; // Build the mesh edges using topological informtion outputMesh->BuildEdges(); diff --git a/intern/boolop/intern/BOP_Material.cpp b/intern/boolop/intern/BOP_Material.cpp deleted file mode 100644 index 01892d2accc..00000000000 --- a/intern/boolop/intern/BOP_Material.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#include "BOP_Material.h" -#include <iostream> -using namespace std; - -/** - * Constructs a new material. - * @param faceWidth face material size in bytes. - * @param faceVertexWidth verex face material size in bytes. - */ -BOP_Material::BOP_Material(int faceWidth, int faceVertexWidth) -{ - m_faceWidth = faceWidth; - m_faceVertexWidth = faceVertexWidth; - - m_faceMaterial = new char[m_faceWidth]; - m_faceVertexMaterial = new char[N_FACE_VERTEX*m_faceVertexWidth]; -} - -/** - * Constructs a new material duplicating the other object data. - * @param other the other object to copy the data. - */ -BOP_Material::BOP_Material(const BOP_Material& other) -{ - m_faceWidth = other.getFaceWidth(); - m_faceVertexWidth = other.getFaceVertexWidth(); - - m_faceMaterial = new char[m_faceWidth]; - m_faceVertexMaterial = new char[N_FACE_VERTEX*m_faceVertexWidth]; - - duplicate(other); -} - -/** - * Destroys a material. - */ -BOP_Material::~BOP_Material() -{ - delete[] m_faceMaterial; - delete[] m_faceVertexMaterial; -} - -/** - * Duplicates the face material passed by argument. - * @param faceMaterial pointer to face material data. - */ -void BOP_Material::setFaceMaterial(char* faceMaterial) -{ - memcpy(m_faceMaterial, faceMaterial, m_faceWidth); -} - -/** - * Duplicates the all face vertex materials passed by argument. It's supossed - * that all face vertex materials positions are consecutive. - * @param faceVertexMaterial pointer to firts vertex face material. - */ -void BOP_Material::setFaceVertexMaterial(char* faceVertexMaterial) -{ - memcpy(m_faceVertexMaterial, faceVertexMaterial, N_FACE_VERTEX*m_faceVertexWidth); -} - -/** - * Duplicates on i-position the face vertex material passed by argument. - * @param faceMaterial pointer to face vertex material. - * @param i destination position of new face vertex material (0<=i<4) - */ -void BOP_Material::setFaceVertexMaterial(char* faceVertexMaterial, int i) -{ - if (i>=0&&i<N_FACE_VERTEX) - memcpy(m_faceVertexMaterial+i*m_faceVertexWidth, faceVertexMaterial, m_faceVertexWidth); -} - -/** - * Duplicates the other material object data. - * @param other the other material object. - */ -void BOP_Material::duplicate(const BOP_Material& other) -{ - setOriginalFace(other.getOriginalFace()); - setIsQuad(other.isQuad()); - for (int i=0;i<N_FACE_VERTEX;++i) - setOriginalFaceVertex(other.getOriginalFaceVertex(i),i); - setFaceMaterial(other.getFaceMaterial()); - setFaceVertexMaterial(other.getFaceVertexMaterial(0)); -} - -/** - * Implements operator = - */ -BOP_Material& BOP_Material::operator = (const BOP_Material& other) -{ - if (other.getFaceWidth() == m_faceWidth && other.getFaceVertexWidth() == m_faceVertexWidth) - duplicate(other); - return (*this); -} - -/** - * Returns the original face vertex material using a input vtx id. The input vtx IDs - * are mapped to output ids, this one is used to obtain the original face vertex - * material. - * @param originalFaceVertex input vertex id (0..3) - * @return pointer to original face vertex material if it exist, NULL otherwise. - */ -char* BOP_Material::getOriginalFaceVertexMaterial(int originalFaceVertex) -{ - int N = isQuad() ? 4 : 3; - int i = 0; - bool b = false; - while (i<N&&!b){ - if (m_originalFaceVertices[i]==originalFaceVertex) b = true; - else i++; - } - return b ? getFaceVertexMaterial(i) : m_faceVertexMaterial; /* ton: NULL return crashes... */ -} - -/** - * Returns the face material pointer. - * @return pointer to face material. - */ -char* BOP_Material::getFaceMaterial() const -{ - return m_faceMaterial; -} - -/** - * Returns the face vertex material at i position. - * @param i index of face vertex material. - * @return pointer to face vertex material. - */ -inline char* BOP_Material::getFaceVertexMaterial(int i) const -{ - return i>=0&&i<N_FACE_VERTEX ? m_faceVertexMaterial + i*m_faceVertexWidth : NULL; -} - -/** - * Implements operator << - */ -ostream &operator<<(ostream &stream, BOP_Material *m) -{ - cout << "(" << m->getOriginalFace() << ") < "; - int N = m->isQuad() ? 4 : 3; - for (int i=0;i<N;++i) cout << m->getOriginalFaceVertex(i) << " "; - cout << ">" << endl; - - return stream; -} diff --git a/intern/boolop/intern/BOP_Material.h b/intern/boolop/intern/BOP_Material.h deleted file mode 100644 index 079cc614410..00000000000 --- a/intern/boolop/intern/BOP_Material.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef BOP_MATERIAL_H -#define BOP_MATERIAL_H - -#include <iostream> -using namespace std; - -#define N_FACE_VERTEX 4 - -class BOP_Material -{ -private: - char* m_faceMaterial; - char* m_faceVertexMaterial; - int m_faceWidth; - int m_faceVertexWidth; - int m_originalFace; - int m_originalFaceVertices[N_FACE_VERTEX]; - bool m_isQuad; - -public: - BOP_Material(int faceWidth, int faceVertexWidth); - BOP_Material(const BOP_Material& other); - ~BOP_Material(); - void setFaceMaterial(char* faceMaterial); - void setFaceVertexMaterial(char* faceVertexMaterial); - void setFaceVertexMaterial(char* faceVertexMaterial, int i); - void duplicate(const BOP_Material& other); - BOP_Material& operator = (const BOP_Material& other); - char* getFaceMaterial() const; - char* getFaceVertexMaterial(int i) const; - int getFaceWidth() const { return m_faceWidth; }; - int getFaceVertexWidth() const { return m_faceVertexWidth; }; - - void setOriginalFace(int originalFace) {m_originalFace = originalFace;}; - int getOriginalFace() const {return m_originalFace;}; - void setOriginalFaceVertex(int originalFaceVertex, int i) { - if (0<=i&&i<N_FACE_VERTEX) m_originalFaceVertices[i] = originalFaceVertex; - }; - int getOriginalFaceVertex(int i) const { - if (0<=i&&i<N_FACE_VERTEX) return m_originalFaceVertices[i]; - else return -1; - }; - char* getOriginalFaceVertexMaterial(int originalFaceVertex); - void setIsQuad(bool quad) {m_isQuad = quad;}; - bool isQuad() const {return m_isQuad;}; - - friend ostream &operator<<(ostream &stream, BOP_Material *m); -}; - -#endif diff --git a/intern/boolop/intern/BOP_MaterialContainer.cpp b/intern/boolop/intern/BOP_MaterialContainer.cpp deleted file mode 100644 index 6ade5b0649f..00000000000 --- a/intern/boolop/intern/BOP_MaterialContainer.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/** - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#include <iostream> -#include "BOP_MaterialContainer.h" -#include "BOP_MathUtils.h" -#include "MEM_SmartPtr.h" - -/** - * Constructs a new material container. - */ -BOP_MaterialContainer::BOP_MaterialContainer() -{ - m_interpFunc = NULL; -} - -/** - * Destroys a material container. - */ -BOP_MaterialContainer::~BOP_MaterialContainer() -{ -} - -/** - * Adds a new material to this container. - * @param m material material object to add. - * @return the new material index. - */ -BOP_Index BOP_MaterialContainer::addMaterial(BOP_Material m) -{ - m_materialList.push_back(m); - return m_materialList.size()-1; -} - -/** - * Updates the interpolation function of this container. - * @param interpFunc the interpolation function. - */ -void BOP_MaterialContainer::setInterpFunc(CSG_InterpolateUserFaceVertexDataFunc interpFunc) -{ - m_interpFunc = interpFunc; -} - -/** - * Returns the material list. - * @return - */ -BOP_Materials& BOP_MaterialContainer::getMaterialList() -{ - return m_materialList; -} - -/** - * Returns the material with the specified index. - * @param index material index. - * @return material with the specified index. - */ -BOP_Material* BOP_MaterialContainer::getMaterial(BOP_Index index) -{ - return index < m_materialList.size() ? &(m_materialList[index]) : NULL; -} - -/** - * Returns the pointer to face material specified by index. - * @param index material index. - * @return pointer to face material. - */ -char* BOP_MaterialContainer::getFaceMaterial(BOP_Index index) -{ - if (index < m_materialList.size()) - return m_materialList[index].getFaceMaterial(); - else return NULL; -} - -/** - * Returns a pointer to face vertex material, if is the material not exist, then - * returns an interpoled material. - * @param mesh original mesh data. - * @param originalFaceIndex index to the original mesh face. - * @param point point who needs a material. - * @param faceVertexMaterial pointer to mem region where the material will be - * saved. - * @return pointer to the face vertex material. - */ -char* BOP_MaterialContainer::getFaceVertexMaterial(BOP_Mesh *mesh, - BOP_Index originalFaceIndex, - MT_Point3 point, - char* faceVertexMaterial) -{ - unsigned int i; - - if (originalFaceIndex>=m_materialList.size()) return NULL; - - BOP_Material& material = m_materialList[originalFaceIndex]; - - if (material.isQuad()) { - - BOP_Face *face1 = mesh->getFace(material.getOriginalFace()); - BOP_Face *face2 = mesh->getFace(material.getOriginalFace()+1); - - if (!face1 || !face2) return NULL; - - // Search original point - for (i=0;i<face1->size();i++) { - if (point == mesh->getVertex(face1->getVertex(i))->getPoint()) { - return material.getOriginalFaceVertexMaterial(face1->getVertex(i)); - } - } - for (i=0;i<face2->size();i++) { - if (point == mesh->getVertex(face2->getVertex(i))->getPoint()) { - return material.getOriginalFaceVertexMaterial(face2->getVertex(i)); - } - } - // wich is the half quad where the point is? - MT_Vector3 N = face1->getPlane().Normal(); - MT_Point3 p0 = mesh->getVertex(face1->getVertex(0))->getPoint(); - MT_Point3 q(p0.x()+N.x(),p0.y()+N.y(),p0.z()+N.z()); - MT_Point3 p2 = mesh->getVertex(face1->getVertex(1))->getPoint(); - MT_Plane3 plane(p0,p2,q); - - if (BOP_sign(plane.signedDistance(point))==-1) { - // first half quad - faceVertexMaterial = interpolateMaterial(mesh, face1, material, point, faceVertexMaterial); - } - else { - // second half quad - faceVertexMaterial = interpolateMaterial(mesh, face2, material, point, faceVertexMaterial); - } - } - else { - BOP_Face *face1 = mesh->getFace(material.getOriginalFace()); - - if (!face1) return NULL; - - // Search original point - for (i=0;i<face1->size();i++) { - if (point == mesh->getVertex(face1->getVertex(i))->getPoint()) - return material.getOriginalFaceVertexMaterial(face1->getVertex(i)); - } - - faceVertexMaterial = interpolateMaterial(mesh, face1, material, point, faceVertexMaterial); - } - - return faceVertexMaterial; -} - -/** - * Performs vertex data interpolation. - * @param mesh original mesh data. - * @param face face used to interpolate an interior face point material - * @param material face material, input data for implementation. - * @param point interpolated point. - * @param faceVertexMaterial pointer to memory region. - * @return pointer to face vertex material. - */ -char* BOP_MaterialContainer::interpolateMaterial(BOP_Mesh* mesh, - BOP_Face* face, - BOP_Material& material, - MT_Point3 point, - char* faceVertexMaterial) -{ - // (p1)-----(I)------(p2) - // \ | / - // \ | / - // \ | / - // \ (point) / - // \ | / - // \ | / - // \ | / - // (p3) - - MT_Point3 p1 = mesh->getVertex(face->getVertex(0))->getPoint(); - MT_Point3 p2 = mesh->getVertex(face->getVertex(1))->getPoint(); - MT_Point3 p3 = mesh->getVertex(face->getVertex(2))->getPoint(); - MT_Point3 I = BOP_4PointIntersect(p1, p2, p3, point); - MT_Scalar epsilon0 = 1.0-BOP_EpsilonDistance(p1, p2, I); - MT_Scalar epsilon1 = 1.0-BOP_EpsilonDistance(I, p3, point); - - // Interpolate data - if (m_interpFunc) { - // temporal data - char* faceVertexMaterialTemp = new char[material.getFaceVertexWidth()]; - - (*m_interpFunc)(material.getOriginalFaceVertexMaterial(face->getVertex(0)), - material.getOriginalFaceVertexMaterial(face->getVertex(1)), - faceVertexMaterialTemp, - epsilon0); - - (*m_interpFunc)(faceVertexMaterialTemp, - material.getOriginalFaceVertexMaterial(face->getVertex(2)), - faceVertexMaterial, - epsilon1); - - // free temporal data - delete[] faceVertexMaterialTemp; - - } - else faceVertexMaterial = NULL; - - // return the result - return (char*) faceVertexMaterial; -} - -/** - * Implements operator << - */ -ostream &operator<<(ostream &stream, BOP_MaterialContainer *mc) -{ - stream << "***[ Material List ]***********************************************" << endl; - BOP_IT_Materials it; - for (it=mc->getMaterialList().begin();it!=mc->getMaterialList().end();++it) { - stream << "[" << it - mc->getMaterialList().begin() << "] "; - stream << &(*it); - } - stream << "*******************************************************************" << endl; - return stream; -} diff --git a/intern/boolop/intern/BOP_MaterialContainer.h b/intern/boolop/intern/BOP_MaterialContainer.h deleted file mode 100644 index c6de4cd96e5..00000000000 --- a/intern/boolop/intern/BOP_MaterialContainer.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. The Blender - * Foundation also sells licenses for use in proprietary software under - * the Blender License. See http://www.blender.org/BL/ for information - * about this. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL/BL DUAL LICENSE BLOCK ***** - */ - -#ifndef BOP_MATERIALCONTAINER_H -#define BOP_MATERIALCONTAINER_H - -#include "BOP_Mesh.h" -#include "BOP_Material.h" -#include "BOP_Interface.h" -#include <vector> -using namespace std; - -typedef vector<BOP_Material> BOP_Materials; -typedef vector<BOP_Material>::iterator BOP_IT_Materials; - -class BOP_MaterialContainer -{ -private: - BOP_Materials m_materialList; - CSG_InterpolateUserFaceVertexDataFunc m_interpFunc; - -public: - BOP_MaterialContainer(); - ~BOP_MaterialContainer(); - BOP_Index addMaterial(BOP_Material m); - void setInterpFunc(CSG_InterpolateUserFaceVertexDataFunc interpFunc); - BOP_Materials& getMaterialList(); - BOP_Material* getMaterial(BOP_Index index); - char* getFaceMaterial(BOP_Index index); - char* getFaceVertexMaterial(BOP_Mesh *mesh, - BOP_Index originalFaceIndex, - MT_Point3 point, - char* faceVertexMaterial); - - friend ostream &operator<<(ostream &stream, BOP_MaterialContainer *mc); - -private: - char* interpolateMaterial(BOP_Mesh* mesh, - BOP_Face* face, - BOP_Material& material, - MT_Point3 point, - char* faceVertexMaterial); -}; - -#endif diff --git a/intern/boolop/intern/BOP_Mesh.h b/intern/boolop/intern/BOP_Mesh.h index 557939441fc..f671b9a96c9 100644 --- a/intern/boolop/intern/BOP_Mesh.h +++ b/intern/boolop/intern/BOP_Mesh.h @@ -78,7 +78,7 @@ private: bool testFace(BOP_Face *face); public: - BOP_Mesh (); + BOP_Mesh(); ~BOP_Mesh(); BOP_Index addVertex(MT_Point3 point); |