diff options
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 606 |
1 files changed, 0 insertions, 606 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 2aeef91538c..f056d1fa61b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -80,10 +80,6 @@ #include "BLO_sys_types.h" // for intptr_t support -#ifdef WITH_VERSE -#include "BKE_verse.h" -#endif - #include "BIF_gl.h" #include "BIF_glutil.h" @@ -1388,573 +1384,6 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob, return (DerivedMesh*) emdm; } -#ifdef WITH_VERSE - -/* verse derived mesh */ -typedef struct { - struct DerivedMesh dm; - struct VNode *vnode; - struct VLayer *vertex_layer; - struct VLayer *polygon_layer; - struct ListBase *edges; - float (*vertexCos)[3]; -} VDerivedMesh; - -/* this function set up border points of verse mesh bounding box */ -static void vDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3]) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert; - - if(!vdm->vertex_layer) return; - - vvert = (VerseVert*)vdm->vertex_layer->dl.lb.first; - - if(vdm->vertex_layer->dl.da.count > 0) { - while(vvert) { - DO_MINMAX(vdm->vertexCos ? vvert->cos : vvert->co, min_r, max_r); - vvert = vvert->next; - } - } - else { - min_r[0] = min_r[1] = min_r[2] = max_r[0] = max_r[1] = max_r[2] = 0.0; - } -} - -/* this function return number of vertexes in vertex layer */ -static int vDM_getNumVerts(DerivedMesh *dm) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - - if(!vdm->vertex_layer) return 0; - else return vdm->vertex_layer->dl.da.count; -} - -/* this function return number of 'fake' edges */ -static int vDM_getNumEdges(DerivedMesh *dm) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - - return BLI_countlist(vdm->edges); -} - -/* this function returns number of polygons in polygon layer */ -static int vDM_getNumFaces(DerivedMesh *dm) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - - if(!vdm->polygon_layer) return 0; - else return vdm->polygon_layer->dl.da.count; -} - -/* this function doesn't return vertex with index of access array, - * but it return 'indexth' vertex of dynamic list */ -void vDM_getVert(DerivedMesh *dm, int index, MVert *vert_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert; - int i; - - if(!vdm->vertex_layer) return; - - for(vvert = vdm->vertex_layer->dl.lb.first, i=0 ; i<index; i++) vvert = vvert->next; - - if(vvert) { - VECCOPY(vert_r->co, vvert->co); - - vert_r->no[0] = vvert->no[0] * 32767.0; - vert_r->no[1] = vvert->no[1] * 32767.0; - vert_r->no[2] = vvert->no[2] * 32767.0; - - /* TODO what to do with vert_r->flag and vert_r->mat_nr? */ - vert_r->mat_nr = 0; - vert_r->flag = 0; - } -} - -/* this function returns fake verse edge */ -void vDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseEdge *vedge; - struct VLayer *vert_vlayer = vdm->vertex_layer; - struct VerseVert *vvert; - int j; - - if(!vdm->vertex_layer || !vdm->edges) return; - - if(vdm->edges->first) { - struct VerseVert *vvert1, *vvert2; - - /* store vert indices in tmp union */ - for(vvert = vdm->vertex_layer->dl.lb.first, j = 0; vvert; vvert = vvert->next, j++) - vvert->tmp.index = j; - - for(vedge = vdm->edges->first; vedge; vedge = vedge->next) { - if(vedge->tmp.index==index) { - vvert1 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v0); - vvert2 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v1); - - if(vvert1 && vvert2) { - edge_r->v1 = vvert1->tmp.index; - edge_r->v2 = vvert2->tmp.index; - } - else { - edge_r->v1 = 0; - edge_r->v2 = 0; - } - /* not supported yet */ - edge_r->flag = 0; - edge_r->crease = 0; - edge_r->bweight = 0; - break; - } - } - } -} - -/* this function doesn't return face with index of access array, - * but it returns 'indexth' vertex of dynamic list */ -void vDM_getFace(DerivedMesh *dm, int index, MFace *face_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseFace *vface; - struct VerseVert *vvert; - struct VerseVert *vvert0, *vvert1, *vvert2, *vvert3; - int i; - - if(!vdm->vertex_layer || !vdm->polygon_layer) return; - - for(vface = vdm->polygon_layer->dl.lb.first, i = 0; i < index; ++i) vface = vface->next; - - face_r->mat_nr = 0; - face_r->flag = 0; - - /* goddamn, we have to search all verts to find indices */ - vvert0 = vface->vvert0; - vvert1 = vface->vvert1; - vvert2 = vface->vvert2; - vvert3 = vface->vvert3; - if(!vvert3) face_r->v4 = 0; - - for(vvert = vdm->vertex_layer->dl.lb.first, i = 0; vvert0 || vvert1 || vvert2 || vvert3; i++, vvert = vvert->next) { - if(vvert == vvert0) { - face_r->v1 = i; - vvert0 = NULL; - } - if(vvert == vvert1) { - face_r->v2 = i; - vvert1 = NULL; - } - if(vvert == vvert2) { - face_r->v3 = i; - vvert2 = NULL; - } - if(vvert == vvert3) { - face_r->v4 = i; - vvert3 = NULL; - } - } - - test_index_face(face_r, NULL, 0, vface->vvert3?4:3); -} - -/* fill array of mvert */ -void vDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert; - - if(!vdm->vertex_layer) return; - - for(vvert = vdm->vertex_layer->dl.lb.first ; vvert; vvert = vvert->next, ++vert_r) { - VECCOPY(vert_r->co, vvert->co); - - vert_r->no[0] = vvert->no[0] * 32767.0; - vert_r->no[1] = vvert->no[1] * 32767.0; - vert_r->no[2] = vvert->no[2] * 32767.0; - - vert_r->mat_nr = 0; - vert_r->flag = 0; - } -} - -/* dummy function, edges arent supported in verse mesh */ -void vDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - - if(!vdm->vertex_layer || !vdm->edges) return; - - if(vdm->edges->first) { - struct VerseEdge *vedge; - struct VLayer *vert_vlayer = vdm->vertex_layer; - struct VerseVert *vvert, *vvert1, *vvert2; - int j; - - /* store vert indices in tmp union */ - for(vvert = vdm->vertex_layer->dl.lb.first, j = 0; vvert; vvert = vvert->next, ++j) - vvert->tmp.index = j; - - for(vedge = vdm->edges->first, j=0 ; vedge; vedge = vedge->next, ++edge_r, j++) { - /* create temporary edge index */ - vedge->tmp.index = j; - vvert1 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v0); - vvert2 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v1); - if(vvert1 && vvert2) { - edge_r->v1 = vvert1->tmp.index; - edge_r->v2 = vvert2->tmp.index; - } - else { - printf("error: vDM_copyEdgeArray: %d, %d\n", vedge->v0, vedge->v1); - edge_r->v1 = 0; - edge_r->v2 = 0; - } - /* not supported yet */ - edge_r->flag = 0; - edge_r->crease = 0; - edge_r->bweight = 0; - } - } -} - -/* fill array of mfaces */ -void vDM_copyFaceArray(DerivedMesh *dm, MFace *face_r) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseFace *vface; - struct VerseVert *vvert; - int i; - - if(!vdm->vertex_layer || !vdm->polygon_layer) return; - - /* store vertexes indices in tmp union */ - for(vvert = vdm->vertex_layer->dl.lb.first, i = 0; vvert; vvert = vvert->next, ++i) - vvert->tmp.index = i; - - for(vface = vdm->polygon_layer->dl.lb.first; vface; vface = vface->next, ++face_r) { - face_r->mat_nr = 0; - face_r->flag = 0; - - face_r->v1 = vface->vvert0->tmp.index; - face_r->v2 = vface->vvert1->tmp.index; - face_r->v3 = vface->vvert2->tmp.index; - if(vface->vvert3) face_r->v4 = vface->vvert3->tmp.index; - else face_r->v4 = 0; - - test_index_face(face_r, NULL, 0, vface->vvert3?4:3); - } -} - -/* return coordination of vertex with index */ -static void vDM_getVertCo(DerivedMesh *dm, int index, float co_r[3]) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert = NULL; - - if(!vdm->vertex_layer) return; - - vvert = BLI_dlist_find_link(&(vdm->vertex_layer->dl), index); - - if(vvert) { - VECCOPY(co_r, vdm->vertexCos ? vvert->cos : vvert->co); - } - else { - co_r[0] = co_r[1] = co_r[2] = 0.0; - } -} - -/* return array of vertex coordiantions */ -static void vDM_getVertCos(DerivedMesh *dm, float (*cos_r)[3]) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert; - int i = 0; - - if(!vdm->vertex_layer) return; - - vvert = vdm->vertex_layer->dl.lb.first; - while(vvert) { - VECCOPY(cos_r[i], vdm->vertexCos ? vvert->cos : vvert->co); - i++; - vvert = vvert->next; - } -} - -/* return normal of vertex with index */ -static void vDM_getVertNo(DerivedMesh *dm, int index, float no_r[3]) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert = NULL; - - if(!vdm->vertex_layer) return; - - vvert = BLI_dlist_find_link(&(vdm->vertex_layer->dl), index); - if(vvert) { - VECCOPY(no_r, vvert->no); - } - else { - no_r[0] = no_r[1] = no_r[2] = 0.0; - } -} - -/* draw all VerseVertexes */ -static void vDM_drawVerts(DerivedMesh *dm) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseVert *vvert; - - if(!vdm->vertex_layer) return; - - vvert = vdm->vertex_layer->dl.lb.first; - - //XXX bglBegin(GL_POINTS); - while(vvert) { - //XXX bglVertex3fv(vdm->vertexCos ? vvert->cos : vvert->co); - vvert = vvert->next; - } - //XXX bglEnd(); -} - -/* draw all edges of VerseFaces ... it isn't optimal, because verse - * specification doesn't support edges :-( ... bother eskil ;-) - * ... some edges (most of edges) are drawn twice */ -static void vDM_drawEdges(DerivedMesh *dm, int drawLooseEdges) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseEdge *vedge; - struct VLayer *vert_vlayer = vdm->vertex_layer; - - if(vert_vlayer && vdm->edges && (BLI_countlist(vdm->edges) > 0)) { - struct VerseVert *vvert1, *vvert2; - - glBegin(GL_LINES); - for(vedge = vdm->edges->first; vedge; vedge = vedge->next) { - vvert1 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v0); - vvert2 = BLI_dlist_find_link(&(vert_vlayer->dl), (unsigned int)vedge->v1); - if(vvert1 && vvert2) { - glVertex3fv(vdm->vertexCos ? vvert1->cos : vvert1->co); - glVertex3fv(vdm->vertexCos ? vvert2->cos : vvert2->co); - } - } - glEnd(); - } -} - -/* verse spec doesn't support edges ... loose edges can't exist */ -void vDM_drawLooseEdges(DerivedMesh *dm) -{ -} - -/* draw uv edges, not supported yet */ -static void vDM_drawUVEdges(DerivedMesh *dm) -{ -} - -/* draw all VerseFaces */ -static void vDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *attribs)) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseFace *vface; - - if(!vdm->polygon_layer) return; - - vface = vdm->polygon_layer->dl.lb.first; - - glShadeModel(GL_FLAT); - while(vface) { - glBegin(vface->vvert3?GL_QUADS:GL_TRIANGLES); - glNormal3fv(vface->no); - glVertex3fv(vdm->vertexCos ? vface->vvert0->cos : vface->vvert0->co); - glVertex3fv(vdm->vertexCos ? vface->vvert1->cos : vface->vvert1->co); - glVertex3fv(vdm->vertexCos ? vface->vvert2->cos : vface->vvert2->co); - if(vface->vvert3) - glVertex3fv(vdm->vertexCos ? vface->vvert3->cos : vface->vvert3->co); - glEnd(); - vface = vface->next; - } -} - -/* this function should draw mesh with mapped texture, but it isn't supported yet */ -static void vDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseFace *vface; - - if(!vdm->polygon_layer) return; - - vface = vdm->polygon_layer->dl.lb.first; - - while(vface) { - glBegin(vface->vvert3?GL_QUADS:GL_TRIANGLES); - glVertex3fv(vdm->vertexCos ? vface->vvert0->cos : vface->vvert0->co); - glVertex3fv(vdm->vertexCos ? vface->vvert1->cos : vface->vvert1->co); - glVertex3fv(vdm->vertexCos ? vface->vvert2->cos : vface->vvert2->co); - if(vface->vvert3) - glVertex3fv(vdm->vertexCos ? vface->vvert3->cos : vface->vvert3->co); - glEnd(); - - vface = vface->next; - } -} - -/* this function should draw mesh with colored faces (weight paint, vertex - * colors, etc.), but it isn't supported yet */ -static void vDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned char *col1, unsigned char *col2) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - struct VerseFace *vface; - - if(!vdm->polygon_layer) return; - - vface = vdm->polygon_layer->dl.lb.first; - - while(vface) { - glBegin(vface->vvert3?GL_QUADS:GL_TRIANGLES); - glVertex3fv(vdm->vertexCos ? vface->vvert0->cos : vface->vvert0->co); - glVertex3fv(vdm->vertexCos ? vface->vvert1->cos : vface->vvert1->co); - glVertex3fv(vdm->vertexCos ? vface->vvert2->cos : vface->vvert2->co); - if(vface->vvert3) - glVertex3fv(vdm->vertexCos ? vface->vvert3->cos : vface->vvert3->co); - glEnd(); - - vface = vface->next; - } -} - -/**/ -static void vDM_foreachMappedVert( - DerivedMesh *dm, - void (*func)(void *userData, int index, float *co, float *no_f, short *no_s), - void *userData) -{ -} - -/**/ -static void vDM_foreachMappedEdge( - DerivedMesh *dm, - void (*func)(void *userData, int index, float *v0co, float *v1co), - void *userData) -{ -} - -/**/ -static void vDM_foreachMappedFaceCenter( - DerivedMesh *dm, - void (*func)(void *userData, int index, float *cent, float *no), - void *userData) -{ -} - -/**/ -static void vDM_drawMappedFacesTex( - DerivedMesh *dm, - int (*setDrawParams)(void *userData, int index), - void *userData) -{ - /* not supported yet */ - vDM_drawFacesTex(dm, NULL); -} - -/**/ -static void vDM_drawMappedFaces( - DerivedMesh *dm, - int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), - void *userData, - int useColors) -{ -} - -/**/ -static void vDM_drawMappedEdges( - DerivedMesh *dm, - int (*setDrawOptions)(void *userData, int index), - void *userData) -{ -} - -/**/ -static void vDM_drawMappedEdgesInterp( - DerivedMesh *dm, - int (*setDrawOptions)(void *userData, int index), - void (*setDrawInterpOptions)(void *userData, int index, float t), - void *userData) -{ -} - -/* free all DerivedMesh data */ -static void vDM_release(DerivedMesh *dm) -{ - VDerivedMesh *vdm = (VDerivedMesh*)dm; - - if (DM_release(dm)) { - if(vdm->vertexCos) MEM_freeN(vdm->vertexCos); - MEM_freeN(vdm); - } -} - -/* create derived mesh from verse mesh ... it is used in object mode, when some other client can - * change shared data and want to see this changes in real time too */ -DerivedMesh *derivedmesh_from_versemesh(VNode *vnode, float (*vertexCos)[3]) -{ - VDerivedMesh *vdm = MEM_callocN(sizeof(*vdm), "vdm"); - - vdm->vnode = vnode; - vdm->vertex_layer = find_verse_layer_type((VGeomData*)vnode->data, VERTEX_LAYER); - vdm->polygon_layer = find_verse_layer_type((VGeomData*)vnode->data, POLYGON_LAYER); - vdm->edges = &((VGeomData*)vnode->data)->edges; - - /* vertex and polygon layer has to exist */ - if(vdm->vertex_layer && vdm->polygon_layer) - DM_init(&vdm->dm, vdm->vertex_layer->dl.da.count, BLI_countlist(vdm->edges), vdm->polygon_layer->dl.da.count); - else - DM_init(&vdm->dm, 0, 0, 0); - - vdm->dm.getMinMax = vDM_getMinMax; - - vdm->dm.getNumVerts = vDM_getNumVerts; - vdm->dm.getNumEdges = vDM_getNumEdges; - vdm->dm.getNumFaces = vDM_getNumFaces; - - vdm->dm.getVert = vDM_getVert; - vdm->dm.getEdge = vDM_getEdge; - vdm->dm.getFace = vDM_getFace; - vdm->dm.copyVertArray = vDM_copyVertArray; - vdm->dm.copyEdgeArray = vDM_copyEdgeArray; - vdm->dm.copyFaceArray = vDM_copyFaceArray; - - vdm->dm.foreachMappedVert = vDM_foreachMappedVert; - vdm->dm.foreachMappedEdge = vDM_foreachMappedEdge; - vdm->dm.foreachMappedFaceCenter = vDM_foreachMappedFaceCenter; - - vdm->dm.getVertCos = vDM_getVertCos; - vdm->dm.getVertCo = vDM_getVertCo; - vdm->dm.getVertNo = vDM_getVertNo; - - vdm->dm.drawVerts = vDM_drawVerts; - - vdm->dm.drawEdges = vDM_drawEdges; - vdm->dm.drawLooseEdges = vDM_drawLooseEdges; - vdm->dm.drawUVEdges = vDM_drawUVEdges; - - vdm->dm.drawFacesSolid = vDM_drawFacesSolid; - vdm->dm.drawFacesTex = vDM_drawFacesTex; - vdm->dm.drawFacesColored = vDM_drawFacesColored; - - vdm->dm.drawMappedFacesTex = vDM_drawMappedFacesTex; - vdm->dm.drawMappedFaces = vDM_drawMappedFaces; - vdm->dm.drawMappedEdges = vDM_drawMappedEdges; - vdm->dm.drawMappedEdgesInterp = vDM_drawMappedEdgesInterp; - - vdm->dm.release = vDM_release; - - vdm->vertexCos = vertexCos; - - return (DerivedMesh*) vdm; -} - -#endif - /***/ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, ModifierData *md) @@ -1973,12 +1402,7 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, Modifier float (*deformedVerts)[3] = mesh_getVertexCos(me, &numVerts); mti->deformVerts(md, ob, NULL, deformedVerts, numVerts); -#ifdef WITH_VERSE - if(me->vnode) dm = derivedmesh_from_versemesh(me->vnode, deformedVerts); - else dm = getMeshDerivedMesh(me, ob, deformedVerts); -#else dm = getMeshDerivedMesh(me, ob, deformedVerts); -#endif MEM_freeN(deformedVerts); } else { @@ -2163,22 +1587,11 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos * coordinates (vpaint, etc.) */ if (deform_r) { -#ifdef WITH_VERSE - if(me->vnode) *deform_r = derivedmesh_from_versemesh(me->vnode, deformedVerts); - else { - *deform_r = CDDM_from_mesh(me, ob); - if(deformedVerts) { - CDDM_apply_vert_coords(*deform_r, deformedVerts); - CDDM_calc_normals(*deform_r); - } - } -#else *deform_r = CDDM_from_mesh(me, ob); if(deformedVerts) { CDDM_apply_vert_coords(*deform_r, deformedVerts); CDDM_calc_normals(*deform_r); } -#endif } } else { /* default behaviour for meshes */ @@ -2195,13 +1608,6 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos dm = NULL; orcodm = NULL; -#ifdef WITH_VERSE - /* hack to make sure modifiers don't try to use mesh data from a verse - * node - */ - if(me->vnode) dm = derivedmesh_from_versemesh(me->vnode, deformedVerts); -#endif - for(;md; md = md->next, curr = curr->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -2333,23 +1739,11 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos } else if(dm) { finaldm = dm; } else { -#ifdef WITH_VERSE - if(me->vnode) - finaldm = derivedmesh_from_versemesh(me->vnode, deformedVerts); - else { - finaldm = CDDM_from_mesh(me, ob); - if(deformedVerts) { - CDDM_apply_vert_coords(finaldm, deformedVerts); - CDDM_calc_normals(finaldm); - } - } -#else finaldm = CDDM_from_mesh(me, ob); if(deformedVerts) { CDDM_apply_vert_coords(finaldm, deformedVerts); CDDM_calc_normals(finaldm); } -#endif } /* add an orco layer if needed */ |