2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** 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 *****
|
|
|
|
|
* CSG operations.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-08-17 13:26:42 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BLI_ghash.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
|
|
#include "CSG_BooleanOps.h"
|
|
|
|
|
|
2005-08-17 13:26:42 +00:00
|
|
|
#include "BKE_booleanops.h"
|
2006-08-28 01:12:36 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
#include "BKE_customdata.h"
|
2005-08-17 13:26:42 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2006-08-28 01:12:36 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_global.h"
|
2005-08-17 13:26:42 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
#include "BKE_object.h"
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
2006-01-28 20:17:48 +00:00
|
|
|
#include "BIF_toolbox.h"
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
#include "BDR_editface.h"
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Here's the vertex iterator structure used to walk through
|
|
|
|
|
* the blender vertex structure.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
Mesh *mesh;
|
2006-11-08 20:14:04 +00:00
|
|
|
Object *ob;
|
2002-10-12 11:37:38 +00:00
|
|
|
int pos;
|
|
|
|
|
} VertexIt;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementations of local vertex iterator functions.
|
|
|
|
|
* These describe a blender mesh to the CSG module.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void VertexIt_Destruct(CSG_VertexIteratorDescriptor * iterator)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
if (iterator->it) {
|
|
|
|
|
// deallocate memory for iterator
|
|
|
|
|
MEM_freeN(iterator->it);
|
|
|
|
|
iterator->it = 0;
|
|
|
|
|
}
|
|
|
|
|
iterator->Done = NULL;
|
|
|
|
|
iterator->Fill = NULL;
|
|
|
|
|
iterator->Reset = NULL;
|
|
|
|
|
iterator->Step = NULL;
|
|
|
|
|
iterator->num_elements = 0;
|
|
|
|
|
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static int VertexIt_Done(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
VertexIt * iterator = (VertexIt *)it;
|
|
|
|
|
return(iterator->pos >= iterator->mesh->totvert);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void VertexIt_Fill(CSG_IteratorPtr it, CSG_IVertex *vert)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
VertexIt * iterator = (VertexIt *)it;
|
|
|
|
|
MVert *verts = iterator->mesh->mvert;
|
|
|
|
|
|
|
|
|
|
float global_pos[3];
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* boolean happens in global space, transform both with obmat */
|
2002-10-12 11:37:38 +00:00
|
|
|
VecMat4MulVecfl(
|
|
|
|
|
global_pos,
|
|
|
|
|
iterator->ob->obmat,
|
|
|
|
|
verts[iterator->pos].co
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
vert->position[0] = global_pos[0];
|
|
|
|
|
vert->position[1] = global_pos[1];
|
|
|
|
|
vert->position[2] = global_pos[2];
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void VertexIt_Step(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
VertexIt * iterator = (VertexIt *)it;
|
|
|
|
|
iterator->pos ++;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void VertexIt_Reset(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
VertexIt * iterator = (VertexIt *)it;
|
|
|
|
|
iterator->pos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void VertexIt_Construct(CSG_VertexIteratorDescriptor *output, Object *ob)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
VertexIt *it;
|
|
|
|
|
if (output == 0) return;
|
|
|
|
|
|
|
|
|
|
// allocate some memory for blender iterator
|
|
|
|
|
it = (VertexIt *)(MEM_mallocN(sizeof(VertexIt),"Boolean_VIt"));
|
|
|
|
|
if (it == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// assign blender specific variables
|
|
|
|
|
it->ob = ob;
|
|
|
|
|
it->mesh = ob->data;
|
|
|
|
|
|
|
|
|
|
it->pos = 0;
|
|
|
|
|
|
|
|
|
|
// assign iterator function pointers.
|
|
|
|
|
output->Step = VertexIt_Step;
|
|
|
|
|
output->Fill = VertexIt_Fill;
|
|
|
|
|
output->Done = VertexIt_Done;
|
|
|
|
|
output->Reset = VertexIt_Reset;
|
|
|
|
|
output->num_elements = it->mesh->totvert;
|
|
|
|
|
output->it = it;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Blender Face iterator
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
Mesh *mesh;
|
|
|
|
|
int pos;
|
2006-11-08 20:14:04 +00:00
|
|
|
int offset;
|
2002-10-12 11:37:38 +00:00
|
|
|
} FaceIt;
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FaceIt_Destruct(CSG_FaceIteratorDescriptor * iterator)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(iterator->it);
|
|
|
|
|
iterator->Done = NULL;
|
|
|
|
|
iterator->Fill = NULL;
|
|
|
|
|
iterator->Reset = NULL;
|
|
|
|
|
iterator->Step = NULL;
|
|
|
|
|
iterator->num_elements = 0;
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static int FaceIt_Done(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
// assume CSG_IteratorPtr is of the correct type.
|
|
|
|
|
FaceIt * iterator = (FaceIt *)it;
|
|
|
|
|
return(iterator->pos >= iterator->mesh->totface);
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FaceIt_Fill(CSG_IteratorPtr it, CSG_IFace *face)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
// assume CSG_IteratorPtr is of the correct type.
|
2006-11-08 20:14:04 +00:00
|
|
|
FaceIt *face_it = (FaceIt *)it;
|
2002-10-12 11:37:38 +00:00
|
|
|
MFace *mfaces = face_it->mesh->mface;
|
2006-11-08 20:14:04 +00:00
|
|
|
MFace *mface = &mfaces[face_it->pos];
|
|
|
|
|
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
face->vertex_index[0] = mface->v1;
|
|
|
|
|
face->vertex_index[1] = mface->v2;
|
|
|
|
|
face->vertex_index[2] = mface->v3;
|
|
|
|
|
if (mface->v4) {
|
|
|
|
|
face->vertex_index[3] = mface->v4;
|
|
|
|
|
face->vertex_number = 4;
|
|
|
|
|
} else {
|
|
|
|
|
face->vertex_number = 3;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
face->orig_face = face_it->offset + face_it->pos;
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FaceIt_Step(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FaceIt * face_it = (FaceIt *)it;
|
|
|
|
|
face_it->pos ++;
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FaceIt_Reset(CSG_IteratorPtr it)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FaceIt * face_it = (FaceIt *)it;
|
|
|
|
|
face_it->pos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FaceIt_Construct(
|
|
|
|
|
CSG_FaceIteratorDescriptor *output, Object *ob, int offset)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FaceIt *it;
|
|
|
|
|
if (output == 0) return;
|
|
|
|
|
|
|
|
|
|
// allocate some memory for blender iterator
|
|
|
|
|
it = (FaceIt *)(MEM_mallocN(sizeof(FaceIt),"Boolean_FIt"));
|
|
|
|
|
if (it == 0) {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
// assign blender specific variables
|
|
|
|
|
it->mesh = ob->data;
|
2006-11-08 20:14:04 +00:00
|
|
|
it->offset = offset;
|
2002-10-12 11:37:38 +00:00
|
|
|
it->pos = 0;
|
|
|
|
|
|
|
|
|
|
// assign iterator function pointers.
|
|
|
|
|
output->Step = FaceIt_Step;
|
|
|
|
|
output->Fill = FaceIt_Fill;
|
|
|
|
|
output->Done = FaceIt_Done;
|
|
|
|
|
output->Reset = FaceIt_Reset;
|
|
|
|
|
output->num_elements = it->mesh->totface;
|
|
|
|
|
output->it = it;
|
2004-02-23 19:14:38 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static Object *AddNewBlenderMesh(Base *base)
|
2005-09-03 17:22:29 +00:00
|
|
|
{
|
2006-11-08 20:14:04 +00:00
|
|
|
// This little function adds a new mesh object to the blender object list
|
|
|
|
|
// It uses ob to duplicate data as this seems to be easier than creating
|
|
|
|
|
// a new one. This new oject contains no faces nor vertices.
|
|
|
|
|
Mesh *old_me;
|
|
|
|
|
Base *basen;
|
|
|
|
|
Object *ob_new;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// now create a new blender object.
|
|
|
|
|
// duplicating all the settings from the previous object
|
|
|
|
|
// to the new one.
|
|
|
|
|
ob_new= copy_object(base->object);
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// Ok we don't want to use the actual data from the
|
|
|
|
|
// last object, the above function incremented the
|
|
|
|
|
// number of users, so decrement it here.
|
|
|
|
|
old_me= ob_new->data;
|
|
|
|
|
old_me->id.us--;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// Now create a new base to add into the linked list of
|
|
|
|
|
// vase objects.
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
basen= MEM_mallocN(sizeof(Base), "duplibase");
|
|
|
|
|
*basen= *base;
|
|
|
|
|
BLI_addhead(&G.scene->base, basen); /* addhead: anders oneindige lus */
|
|
|
|
|
basen->object= ob_new;
|
|
|
|
|
basen->flag &= ~SELECT;
|
|
|
|
|
|
|
|
|
|
// Initialize the mesh data associated with this object.
|
2007-03-11 16:25:17 +00:00
|
|
|
ob_new->data= add_mesh("Mesh");
|
2006-11-08 20:14:04 +00:00
|
|
|
G.totmesh++;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// Finally assign the object type.
|
|
|
|
|
ob_new->type= OB_MESH;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
return ob_new;
|
|
|
|
|
}
|
2005-09-03 17:22:29 +00:00
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
static void InterpCSGFace(
|
2006-11-08 20:14:04 +00:00
|
|
|
DerivedMesh *dm, Mesh *orig_me, int index, int orig_index, int nr,
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
float mapmat[][4])
|
2006-11-08 20:14:04 +00:00
|
|
|
{
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
float obco[3], *co[4], *orig_co[4], w[4][4];
|
2006-11-08 20:14:04 +00:00
|
|
|
MFace *mface, *orig_mface;
|
|
|
|
|
int j;
|
2006-01-01 15:41:20 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
mface = CDDM_get_face(dm, index);
|
|
|
|
|
orig_mface = orig_me->mface + orig_index;
|
2006-01-01 15:41:20 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// get the vertex coordinates from the original mesh
|
|
|
|
|
orig_co[0] = (orig_me->mvert + orig_mface->v1)->co;
|
|
|
|
|
orig_co[1] = (orig_me->mvert + orig_mface->v2)->co;
|
|
|
|
|
orig_co[2] = (orig_me->mvert + orig_mface->v3)->co;
|
|
|
|
|
orig_co[3] = (orig_mface->v4)? (orig_me->mvert + orig_mface->v4)->co: NULL;
|
2006-01-01 15:41:20 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// get the vertex coordinates from the new derivedmesh
|
|
|
|
|
co[0] = CDDM_get_vert(dm, mface->v1)->co;
|
|
|
|
|
co[1] = CDDM_get_vert(dm, mface->v2)->co;
|
|
|
|
|
co[2] = CDDM_get_vert(dm, mface->v3)->co;
|
|
|
|
|
co[3] = (nr == 4)? CDDM_get_vert(dm, mface->v4)->co: NULL;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
for (j = 0; j < nr; j++) {
|
|
|
|
|
// get coordinate into the space of the original mesh
|
|
|
|
|
if (mapmat)
|
|
|
|
|
VecMat4MulVecfl(obco, mapmat, co[j]);
|
|
|
|
|
else
|
|
|
|
|
VecCopyf(obco, co[j]);
|
2005-09-03 17:22:29 +00:00
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
InterpWeightsQ3Dfl(orig_co[0], orig_co[1], orig_co[2], orig_co[3], obco, w[j]);
|
2005-09-03 17:22:29 +00:00
|
|
|
}
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
|
|
|
|
CustomData_interp(&orig_me->fdata, &dm->faceData, &orig_index, NULL, (float*)w, 1, index);
|
2005-09-03 17:22:29 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* Iterate over the CSG Output Descriptors and create a new DerivedMesh
|
|
|
|
|
from them */
|
|
|
|
|
static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
|
|
|
|
|
CSG_FaceIteratorDescriptor *face_it,
|
|
|
|
|
CSG_VertexIteratorDescriptor *vertex_it,
|
|
|
|
|
float parinv[][4],
|
|
|
|
|
float mapmat[][4],
|
|
|
|
|
Material **mat,
|
|
|
|
|
int *totmat,
|
|
|
|
|
Object *ob1,
|
|
|
|
|
Object *ob2)
|
2006-08-28 01:12:36 +00:00
|
|
|
{
|
2006-11-08 20:14:04 +00:00
|
|
|
DerivedMesh *dm;
|
|
|
|
|
GHash *material_hash = NULL;
|
|
|
|
|
Mesh *me1= (Mesh*)ob1->data;
|
|
|
|
|
Mesh *me2= (Mesh*)ob2->data;
|
|
|
|
|
int i;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// create a new DerivedMesh
|
|
|
|
|
dm = CDDM_new(vertex_it->num_elements, 0, face_it->num_elements);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-12-12 21:29:09 +00:00
|
|
|
CustomData_merge(&me1->fdata, &dm->faceData, CD_MASK_DERIVEDMESH,
|
|
|
|
|
CD_DEFAULT, face_it->num_elements);
|
|
|
|
|
CustomData_merge(&me2->fdata, &dm->faceData, CD_MASK_DERIVEDMESH,
|
|
|
|
|
CD_DEFAULT, face_it->num_elements);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// step through the vertex iterators:
|
|
|
|
|
for (i = 0; !vertex_it->Done(vertex_it->it); i++) {
|
|
|
|
|
CSG_IVertex csgvert;
|
|
|
|
|
MVert *mvert = CDDM_get_vert(dm, i);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// retrieve a csg vertex from the boolean module
|
|
|
|
|
vertex_it->Fill(vertex_it->it, &csgvert);
|
|
|
|
|
vertex_it->Step(vertex_it->it);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// we have to map the vertex coordinates back in the coordinate frame
|
|
|
|
|
// of the resulting object, since it was computed in world space
|
|
|
|
|
VecMat4MulVecfl(mvert->co, parinv, csgvert.position);
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// a hash table to remap materials to indices
|
|
|
|
|
if (mat) {
|
|
|
|
|
material_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
|
|
|
|
*totmat = 0;
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// step through the face iterators
|
|
|
|
|
for(i = 0; !face_it->Done(face_it->it); i++) {
|
|
|
|
|
Mesh *orig_me;
|
|
|
|
|
Object *orig_ob;
|
|
|
|
|
Material *orig_mat;
|
|
|
|
|
CSG_IFace csgface;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
MFace *mface;
|
2006-11-08 20:14:04 +00:00
|
|
|
int orig_index, mat_nr;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// retrieve a csg face from the boolean module
|
|
|
|
|
face_it->Fill(face_it->it, &csgface);
|
|
|
|
|
face_it->Step(face_it->it);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// find the original mesh and data
|
2007-01-06 00:25:22 +00:00
|
|
|
orig_ob = (csgface.orig_face < me1->totface)? ob1: ob2;
|
|
|
|
|
orig_me = (orig_ob == ob1)? me1: me2;
|
|
|
|
|
orig_index = (orig_ob == ob1)? csgface.orig_face: csgface.orig_face - me1->totface;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
|
|
|
|
// copy all face layers, including mface
|
|
|
|
|
CustomData_copy_data(&orig_me->fdata, &dm->faceData, orig_index, i, 1);
|
2006-11-08 20:14:04 +00:00
|
|
|
|
|
|
|
|
// set mface
|
|
|
|
|
mface = CDDM_get_face(dm, i);
|
|
|
|
|
mface->v1 = csgface.vertex_index[0];
|
|
|
|
|
mface->v2 = csgface.vertex_index[1];
|
|
|
|
|
mface->v3 = csgface.vertex_index[2];
|
|
|
|
|
mface->v4 = (csgface.vertex_number == 4)? csgface.vertex_index[3]: 0;
|
|
|
|
|
|
|
|
|
|
// set material, based on lookup in hash table
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
orig_mat= give_current_material(orig_ob, mface->mat_nr+1);
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
if (mat && orig_mat) {
|
|
|
|
|
if (!BLI_ghash_haskey(material_hash, orig_mat)) {
|
|
|
|
|
mat[*totmat] = orig_mat;
|
|
|
|
|
mat_nr = mface->mat_nr = (*totmat)++;
|
|
|
|
|
BLI_ghash_insert(material_hash, orig_mat, (void*)mat_nr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
mface->mat_nr = (int)BLI_ghash_lookup(material_hash, orig_mat);
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
2006-11-08 20:14:04 +00:00
|
|
|
else
|
|
|
|
|
mface->mat_nr = 0;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
InterpCSGFace(dm, orig_me, i, orig_index, csgface.vertex_number,
|
|
|
|
|
(orig_me == me2)? mapmat: NULL);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
test_index_face(mface, &dm->faceData, i, csgface.vertex_number);
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
if (material_hash)
|
|
|
|
|
BLI_ghash_free(material_hash, NULL, NULL);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
CDDM_calc_edges(dm);
|
|
|
|
|
CDDM_calc_normals(dm);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
return dm;
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
2004-04-08 18:58:32 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void BuildMeshDescriptors(
|
|
|
|
|
struct Object *ob,
|
|
|
|
|
int face_offset,
|
|
|
|
|
struct CSG_FaceIteratorDescriptor * face_it,
|
|
|
|
|
struct CSG_VertexIteratorDescriptor * vertex_it)
|
|
|
|
|
{
|
|
|
|
|
VertexIt_Construct(vertex_it,ob);
|
|
|
|
|
FaceIt_Construct(face_it,ob,face_offset);
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
static void FreeMeshDescriptors(
|
|
|
|
|
struct CSG_FaceIteratorDescriptor *face_it,
|
|
|
|
|
struct CSG_VertexIteratorDescriptor *vertex_it)
|
|
|
|
|
{
|
|
|
|
|
VertexIt_Destruct(vertex_it);
|
|
|
|
|
FaceIt_Destruct(face_it);
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
DerivedMesh *NewBooleanDerivedMesh_intern(
|
|
|
|
|
struct Object *ob, struct Object *ob_select,
|
|
|
|
|
int int_op_type, Material **mat, int *totmat)
|
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
float inv_mat[4][4];
|
|
|
|
|
float map_mat[4][4];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
DerivedMesh *dm = NULL;
|
|
|
|
|
Mesh *me1 = get_mesh(ob);
|
|
|
|
|
Mesh *me2 = get_mesh(ob_select);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
if (me1 == NULL || me2 == NULL) return 0;
|
|
|
|
|
if (!me1->totface || !me2->totface) return 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// we map the final object back into ob's local coordinate space. For this
|
|
|
|
|
// we need to compute the inverse transform from global to ob (inv_mat),
|
|
|
|
|
// and the transform from ob to ob_select for use in interpolation (map_mat)
|
|
|
|
|
Mat4Invert(inv_mat, ob_select->obmat);
|
|
|
|
|
Mat4MulMat4(map_mat, ob->obmat, inv_mat);
|
|
|
|
|
Mat4Invert(inv_mat, ob->obmat);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
{
|
2006-11-08 20:14:04 +00:00
|
|
|
// interface with the boolean module:
|
|
|
|
|
//
|
|
|
|
|
// the idea is, we pass the boolean module verts and faces using the
|
|
|
|
|
// provided descriptors. once the boolean operation is performed, we
|
|
|
|
|
// get back output descriptors, from which we then build a DerivedMesh
|
|
|
|
|
|
|
|
|
|
CSG_VertexIteratorDescriptor vd_1, vd_2;
|
|
|
|
|
CSG_FaceIteratorDescriptor fd_1, fd_2;
|
|
|
|
|
CSG_OperationType op_type;
|
|
|
|
|
CSG_BooleanOperation *bool_op;
|
|
|
|
|
|
|
|
|
|
// work out the operation they chose and pick the appropriate
|
|
|
|
|
// enum from the csg module.
|
|
|
|
|
switch (int_op_type) {
|
|
|
|
|
case 1 : op_type = e_csg_intersection; break;
|
|
|
|
|
case 2 : op_type = e_csg_union; break;
|
|
|
|
|
case 3 : op_type = e_csg_difference; break;
|
|
|
|
|
case 4 : op_type = e_csg_classify; break;
|
|
|
|
|
default : op_type = e_csg_intersection;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
BuildMeshDescriptors(ob, 0, &fd_1, &vd_1);
|
|
|
|
|
BuildMeshDescriptors(ob_select, me1->totface, &fd_2, &vd_2);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
bool_op = CSG_NewBooleanFunction();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// perform the operation
|
|
|
|
|
if (CSG_PerformBooleanOperation(bool_op, op_type, fd_1, vd_1, fd_2, vd_2)) {
|
2002-10-12 11:37:38 +00:00
|
|
|
CSG_VertexIteratorDescriptor vd_o;
|
|
|
|
|
CSG_FaceIteratorDescriptor fd_o;
|
2005-09-03 17:22:29 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
CSG_OutputFaceDescriptor(bool_op, &fd_o);
|
|
|
|
|
CSG_OutputVertexDescriptor(bool_op, &vd_o);
|
|
|
|
|
|
|
|
|
|
// iterate through results of operation and insert
|
|
|
|
|
// into new object
|
|
|
|
|
dm = ConvertCSGDescriptorsToDerivedMesh(
|
|
|
|
|
&fd_o, &vd_o, inv_mat, map_mat, mat, totmat, ob, ob_select);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
// free up the memory
|
2002-10-12 11:37:38 +00:00
|
|
|
CSG_FreeVertexDescriptor(&vd_o);
|
|
|
|
|
CSG_FreeFaceDescriptor(&fd_o);
|
|
|
|
|
}
|
2006-11-08 20:14:04 +00:00
|
|
|
else
|
|
|
|
|
error("Unknown internal error in boolean");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
CSG_FreeBooleanOperation(bool_op);
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
FreeMeshDescriptors(&fd_1, &vd_1);
|
|
|
|
|
FreeMeshDescriptors(&fd_2, &vd_2);
|
2005-08-14 19:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
return dm;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
int NewBooleanMesh(Base *base, Base *base_select, int int_op_type)
|
2006-08-28 01:12:36 +00:00
|
|
|
{
|
2006-11-08 20:14:04 +00:00
|
|
|
Mesh *me_new;
|
|
|
|
|
int a, maxmat, totmat= 0;
|
|
|
|
|
Object *ob_new, *ob, *ob_select;
|
|
|
|
|
Material **mat;
|
|
|
|
|
DerivedMesh *dm;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
ob= base->object;
|
|
|
|
|
ob_select= base_select->object;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
maxmat= ob->totcol + ob_select->totcol;
|
|
|
|
|
mat= (Material**)MEM_mallocN(sizeof(Material*)*maxmat, "NewBooleanMeshMat");
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
dm= NewBooleanDerivedMesh_intern(ob, ob_select, int_op_type, mat, &totmat);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
if (dm == NULL) {
|
|
|
|
|
MEM_freeN(mat);
|
|
|
|
|
return 0;
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* create a new blender mesh object - using 'base' as a template */
|
|
|
|
|
ob_new= AddNewBlenderMesh(base);
|
|
|
|
|
me_new= ob_new->data;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
DM_to_mesh(dm, me_new);
|
|
|
|
|
dm->release(dm);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* add materials to object */
|
|
|
|
|
for (a = 0; a < totmat; a++)
|
|
|
|
|
assign_material(ob_new, mat[a], a+1);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
MEM_freeN(mat);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* update dag */
|
|
|
|
|
DAG_object_flush_update(G.scene, ob_new, OB_RECALC_DATA);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-11-08 20:14:04 +00:00
|
|
|
|
|
|
|
|
DerivedMesh *NewBooleanDerivedMesh(struct Object *ob, struct Object *ob_select,
|
|
|
|
|
int int_op_type)
|
|
|
|
|
{
|
|
|
|
|
return NewBooleanDerivedMesh_intern(ob, ob_select, int_op_type, NULL, NULL);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|