[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34855] trunk/blender/source/blender/ blenkernel: SVN maintenance.
gsr b3d
gsr.b3d at infernal-iceberg.com
Mon Feb 14 22:20:06 CET 2011
Revision: 34855
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34855
Author: gsrb3d
Date: 2011-02-14 21:20:05 +0000 (Mon, 14 Feb 2011)
Log Message:
-----------
SVN maintenance.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/mikktspace.c
trunk/blender/source/blender/blenkernel/mikktspace.h
Property Changed:
----------------
trunk/blender/source/blender/blenkernel/intern/mikktspace.c
trunk/blender/source/blender/blenkernel/mikktspace.h
Modified: trunk/blender/source/blender/blenkernel/intern/mikktspace.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mikktspace.c 2011-02-14 21:00:49 UTC (rev 34854)
+++ trunk/blender/source/blender/blenkernel/intern/mikktspace.c 2011-02-14 21:20:05 UTC (rev 34855)
@@ -1,1886 +1,1886 @@
-/**
- * Copyright (C) 2011 by Morten S. Mikkelsen
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <float.h>
-#include <malloc.h>
-#include "mikktspace.h"
-
-#define TFALSE 0
-#define TTRUE 1
-
-#ifndef M_PI
-#define M_PI 3.1415926535897932384626433832795
-#endif
-
-#define INTERNAL_RND_SORT_SEED 39871946
-
-// internal structure
-typedef struct
-{
- float x, y, z;
-} SVec3;
-
-tbool veq( const SVec3 v1, const SVec3 v2 )
-{
- return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z);
-}
-
-const SVec3 vadd( const SVec3 v1, const SVec3 v2 )
-{
- SVec3 vRes;
-
- vRes.x = v1.x + v2.x;
- vRes.y = v1.y + v2.y;
- vRes.z = v1.z + v2.z;
-
- return vRes;
-}
-
-
-const SVec3 vsub( const SVec3 v1, const SVec3 v2 )
-{
- SVec3 vRes;
-
- vRes.x = v1.x - v2.x;
- vRes.y = v1.y - v2.y;
- vRes.z = v1.z - v2.z;
-
- return vRes;
-}
-
-const SVec3 vscale(const float fS, const SVec3 v)
-{
- SVec3 vRes;
-
- vRes.x = fS * v.x;
- vRes.y = fS * v.y;
- vRes.z = fS * v.z;
-
- return vRes;
-}
-
-float LengthSquared( const SVec3 v )
-{
- return v.x*v.x + v.y*v.y + v.z*v.z;
-}
-
-float Length( const SVec3 v )
-{
- return sqrtf(LengthSquared(v));
-}
-
-const SVec3 Normalize( const SVec3 v )
-{
- return vscale(1 / Length(v), v);
-}
-
-const float vdot( const SVec3 v1, const SVec3 v2)
-{
- return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
-}
-
-
-tbool NotZero(const float fX)
-{
- // could possibly use FLT_EPSILON instead
- return fabsf(fX) > FLT_MIN;
-}
-
-tbool VNotZero(const SVec3 v)
-{
- // might change this to an epsilon based test
- return NotZero(v.x) || NotZero(v.y) || NotZero(v.z);
-}
-
-
-
-typedef struct
-{
- int iNrFaces;
- int * pTriMembers;
-} SSubGroup;
-
-typedef struct
-{
- int iNrFaces;
- int * pFaceIndices;
- int iVertexRepresentitive;
- tbool bOrientPreservering;
-} SGroup;
-
-//
-#define MARK_DEGENERATE 1
-#define QUAD_ONE_DEGEN_TRI 2
-#define GROUP_WITH_ANY 4
-#define ORIENT_PRESERVING 8
-
-
-
-typedef struct
-{
- int FaceNeighbors[3];
- SGroup * AssignedGroup[3];
-
- // normalized first order face derivatives
- SVec3 vOs, vOt;
- float fMagS, fMagT; // original magnitudes
-
- // determines if the current and the next triangle are a quad.
- int iOrgFaceNumber;
- int iFlag, iTSpacesOffs;
- unsigned char vert_num[4];
-} STriInfo;
-
-typedef struct
-{
- SVec3 vOs;
- float fMagS;
- SVec3 vOt;
- float fMagT;
- int iCounter; // this is to average back into quads.
- tbool bOrient;
-} STSpace;
-
-int GenerateInitialVerticesIndexList(STriInfo pTriInfos[], int piTriList_out[], const SMikkTSpaceContext * pContext, const int iNrTrianglesIn);
-void GenerateSharedVerticesIndexList(int piTriList_in_and_out[], const SMikkTSpaceContext * pContext, const int iNrTrianglesIn);
-void InitTriInfo(STriInfo pTriInfos[], const int piTriListIn[], const SMikkTSpaceContext * pContext, const int iNrTrianglesIn);
-int Build4RuleGroups(STriInfo pTriInfos[], SGroup pGroups[], int piGroupTrianglesBuffer[], const int piTriListIn[], const int iNrTrianglesIn);
-tbool GenerateTSpaces(STSpace psTspace[], const STriInfo pTriInfos[], const SGroup pGroups[],
- const int iNrActiveGroups, const int piTriListIn[], const float fThresCos,
- const SMikkTSpaceContext * pContext);
-
-int MakeIndex(const int iFace, const int iVert)
-{
- assert(iVert>=0 && iVert<4 && iFace>=0);
- return (iFace<<2) | (iVert&0x3);
-}
-
-void IndexToData(int * piFace, int * piVert, const int iIndexIn)
-{
- piVert[0] = iIndexIn&0x3;
- piFace[0] = iIndexIn>>2;
-}
-
-const STSpace AvgTSpace(const STSpace * pTS0, const STSpace * pTS1)
-{
- STSpace ts_res;
-
- // this if is important. Due to floating point precision
- // averaging when ts0==ts1 will cause a slight difference
- // which results in tangent space splits later on
- if(pTS0->fMagS==pTS1->fMagS && pTS0->fMagT==pTS1->fMagT &&
- veq(pTS0->vOs,pTS1->vOs) && veq(pTS0->vOt, pTS1->vOt))
- {
- ts_res.fMagS = pTS0->fMagS;
- ts_res.fMagT = pTS0->fMagT;
- ts_res.vOs = pTS0->vOs;
- ts_res.vOt = pTS0->vOt;
- }
- else
- {
- ts_res.fMagS = 0.5f*(pTS0->fMagS+pTS1->fMagS);
- ts_res.fMagT = 0.5f*(pTS0->fMagT+pTS1->fMagT);
- ts_res.vOs = vadd(pTS0->vOs,pTS1->vOs);
- ts_res.vOt = vadd(pTS0->vOt,pTS1->vOt);
- if( VNotZero(ts_res.vOs) ) ts_res.vOs = Normalize(ts_res.vOs);
- if( VNotZero(ts_res.vOt) ) ts_res.vOt = Normalize(ts_res.vOt);
- }
-
- return ts_res;
-}
-
-
-
-const SVec3 GetPosition(const SMikkTSpaceContext * pContext, const int index);
-const SVec3 GetNormal(const SMikkTSpaceContext * pContext, const int index);
-const SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index);
-
-
-// degen triangles
-void DegenPrologue(STriInfo pTriInfos[], int piTriList_out[], const int iNrTrianglesIn, const int iTotTris);
-void DegenEpilogue(STSpace psTspace[], STriInfo pTriInfos[], int piTriListIn[], const SMikkTSpaceContext * pContext, const int iNrTrianglesIn, const int iTotTris);
-
-
-tbool genTangSpaceDefault(const SMikkTSpaceContext * pContext)
-{
- return genTangSpace(pContext, 180.0f);
-}
-
-tbool genTangSpace(const SMikkTSpaceContext * pContext, const float fAngularThreshold)
-{
- // count nr_triangles
- int * piTriListIn = NULL, * piGroupTrianglesBuffer = NULL;
- STriInfo * pTriInfos = NULL;
- SGroup * pGroups = NULL;
- STSpace * psTspace = NULL;
- int iNrTrianglesIn = 0, f=0, t=0, i=0;
- int iNrTSPaces = 0, iTotTris = 0, iDegenTriangles = 0, iNrMaxGroups = 0;
- int iNrActiveGroups = 0, index = 0;
- const int iNrFaces = pContext->m_pInterface->m_getNumFaces(pContext);
- tbool bRes = TFALSE;
- const float fThresCos = (const float) cos((fAngularThreshold*M_PI)/180);
-
- // verify all call-backs have been set
- if( pContext->m_pInterface->m_getNumFaces==NULL ||
- pContext->m_pInterface->m_getNumVerticesOfFace==NULL ||
- pContext->m_pInterface->m_getPosition==NULL ||
- pContext->m_pInterface->m_getNormal==NULL ||
- pContext->m_pInterface->m_getTexCoord==NULL )
- return TFALSE;
-
- // count triangles on supported faces
- for(f=0; f<iNrFaces; f++)
- {
- const int verts = pContext->m_pInterface->m_getNumVerticesOfFace(pContext, f);
- if(verts==3) ++iNrTrianglesIn;
- else if(verts==4) iNrTrianglesIn += 2;
- }
- if(iNrTrianglesIn<=0) return TFALSE;
-
- // allocate memory for an index list
- piTriListIn = (int *) malloc(sizeof(int)*3*iNrTrianglesIn);
- pTriInfos = (STriInfo *) malloc(sizeof(STriInfo)*iNrTrianglesIn);
- if(piTriListIn==NULL || pTriInfos==NULL)
- {
- if(piTriListIn!=NULL) free(piTriListIn);
- if(pTriInfos!=NULL) free(pTriInfos);
- return TFALSE;
- }
-
- // make an initial triangle --> face index list
- iNrTSPaces = GenerateInitialVerticesIndexList(pTriInfos, piTriListIn, pContext, iNrTrianglesIn);
-
- // make a welded index list of identical positions and attributes (pos, norm, texc)
- //printf("gen welded index list begin\n");
- GenerateSharedVerticesIndexList(piTriListIn, pContext, iNrTrianglesIn);
- //printf("gen welded index list end\n");
-
- // Mark all degenerate triangles
- iTotTris = iNrTrianglesIn;
- iNrTrianglesIn = 0;
- iDegenTriangles = 0;
- for(t=0; t<iTotTris; t++)
- {
- const int i0 = piTriListIn[t*3+0];
- const int i1 = piTriListIn[t*3+1];
- const int i2 = piTriListIn[t*3+2];
- const SVec3 p0 = GetPosition(pContext, i0);
- const SVec3 p1 = GetPosition(pContext, i1);
- const SVec3 p2 = GetPosition(pContext, i2);
- if(veq(p0,p1) || veq(p0,p2) || veq(p1,p2)) // degenerate
- {
- pTriInfos[t].iFlag |= MARK_DEGENERATE;
- ++iDegenTriangles;
- }
- }
- iNrTrianglesIn = iTotTris - iDegenTriangles;
-
- // mark all triangle pairs that belong to a quad with only one
- // good triangle. These need special treatment in DegenEpilogue().
- // Additionally, move all good triangles to the start of
- // pTriInfos[] and piTriListIn[] without changing order and
- // put the degenerate triangles last.
- DegenPrologue(pTriInfos, piTriListIn, iNrTrianglesIn, iTotTris);
-
-
- // evaluate triangle level attributes and neighbor list
- //printf("gen neighbors list begin\n");
- InitTriInfo(pTriInfos, piTriListIn, pContext, iNrTrianglesIn);
- //printf("gen neighbors list end\n");
-
-
- // based on the 4 rules, identify groups based on connectivity
- iNrMaxGroups = iNrTrianglesIn*3;
- pGroups = (SGroup *) malloc(sizeof(SGroup)*iNrMaxGroups);
- piGroupTrianglesBuffer = (int *) malloc(sizeof(int)*iNrTrianglesIn*3);
- if(pGroups==NULL || piGroupTrianglesBuffer==NULL)
- {
- if(pGroups!=NULL) free(pGroups);
- if(piGroupTrianglesBuffer!=NULL) free(piGroupTrianglesBuffer);
- free(piTriListIn);
- free(pTriInfos);
- return TFALSE;
- }
- //printf("gen 4rule groups begin\n");
- iNrActiveGroups =
- Build4RuleGroups(pTriInfos, pGroups, piGroupTrianglesBuffer, piTriListIn, iNrTrianglesIn);
- //printf("gen 4rule groups end\n");
-
- //
-
- psTspace = (STSpace *) malloc(sizeof(STSpace)*iNrTSPaces);
- if(psTspace==NULL)
- {
- free(piTriListIn);
- free(pTriInfos);
- free(pGroups);
- free(piGroupTrianglesBuffer);
- return TFALSE;
- }
- memset(psTspace, 0, sizeof(STSpace)*iNrTSPaces);
- for(t=0; t<iNrTSPaces; t++)
- {
- psTspace[t].vOs.x=1.0f; psTspace[t].vOs.y=0.0f; psTspace[t].vOs.z=0.0f; psTspace[t].fMagS = 1.0f;
- psTspace[t].vOt.x=0.0f; psTspace[t].vOt.y=1.0f; psTspace[t].vOt.z=0.0f; psTspace[t].fMagT = 1.0f;
- }
-
- // make tspaces, each group is split up into subgroups if necessary
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list