Blender V2.61 - r43446
Classes | Defines | Functions | Variables

mikktspace.c File Reference

#include <assert.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <stdlib.h>
#include "mikktspace.h"

Go to the source code of this file.

Classes

struct  SVec3
struct  SSubGroup
struct  SGroup
struct  STriInfo
struct  STSpace
struct  STmpVert
union  SEdge

Defines

#define TFALSE   0
#define TTRUE   1
#define M_PI   3.1415926535897932384626433832795
#define INTERNAL_RND_SORT_SEED   39871946
#define MARK_DEGENERATE   1
#define QUAD_ONE_DEGEN_TRI   2
#define GROUP_WITH_ANY   4
#define ORIENT_PRESERVING   8
#define NOINLINE   __attribute__ ((noinline))

Functions

static tbool veq (const SVec3 v1, const SVec3 v2)
static SVec3 vadd (const SVec3 v1, const SVec3 v2)
static SVec3 vsub (const SVec3 v1, const SVec3 v2)
static SVec3 vscale (const float fS, const SVec3 v)
static float LengthSquared (const SVec3 v)
static float Length (const SVec3 v)
static SVec3 Normalize (const SVec3 v)
static float vdot (const SVec3 v1, const SVec3 v2)
static tbool NotZero (const float fX)
static tbool VNotZero (const SVec3 v)
static int GenerateInitialVerticesIndexList (STriInfo pTriInfos[], int piTriList_out[], const SMikkTSpaceContext *pContext, const int iNrTrianglesIn)
static void GenerateSharedVerticesIndexList (int piTriList_in_and_out[], const SMikkTSpaceContext *pContext, const int iNrTrianglesIn)
static void InitTriInfo (STriInfo pTriInfos[], const int piTriListIn[], const SMikkTSpaceContext *pContext, const int iNrTrianglesIn)
static int Build4RuleGroups (STriInfo pTriInfos[], SGroup pGroups[], int piGroupTrianglesBuffer[], const int piTriListIn[], const int iNrTrianglesIn)
static tbool GenerateTSpaces (STSpace psTspace[], const STriInfo pTriInfos[], const SGroup pGroups[], const int iNrActiveGroups, const int piTriListIn[], const float fThresCos, const SMikkTSpaceContext *pContext)
static int MakeIndex (const int iFace, const int iVert)
static void IndexToData (int *piFace, int *piVert, const int iIndexIn)
static STSpace AvgTSpace (const STSpace *pTS0, const STSpace *pTS1)
static SVec3 GetPosition (const SMikkTSpaceContext *pContext, const int index)
static SVec3 GetNormal (const SMikkTSpaceContext *pContext, const int index)
static SVec3 GetTexCoord (const SMikkTSpaceContext *pContext, const int index)
static void DegenPrologue (STriInfo pTriInfos[], int piTriList_out[], const int iNrTrianglesIn, const int iTotTris)
static void DegenEpilogue (STSpace psTspace[], STriInfo pTriInfos[], int piTriListIn[], const SMikkTSpaceContext *pContext, const int iNrTrianglesIn, const int iTotTris)
tbool genTangSpaceDefault (const SMikkTSpaceContext *pContext)
tbool genTangSpace (const SMikkTSpaceContext *pContext, const float fAngularThreshold)
NOINLINE int FindGridCell (const float fMin, const float fMax, const float fVal)
static void MergeVertsFast (int piTriList_in_and_out[], STmpVert pTmpVert[], const SMikkTSpaceContext *pContext, const int iL_in, const int iR_in)
static void MergeVertsSlow (int piTriList_in_and_out[], const SMikkTSpaceContext *pContext, const int pTable[], const int iEntries)
static void GenerateSharedVerticesIndexListSlow (int piTriList_in_and_out[], const SMikkTSpaceContext *pContext, const int iNrTrianglesIn)
static void BuildNeighborsFast (STriInfo pTriInfos[], SEdge *pEdges, const int piTriListIn[], const int iNrTrianglesIn)
static void BuildNeighborsSlow (STriInfo pTriInfos[], const int piTriListIn[], const int iNrTrianglesIn)
static float CalcTexArea (const SMikkTSpaceContext *pContext, const int indices[])
static tbool AssignRecur (const int piTriListIn[], STriInfo psTriInfos[], const int iMyTriIndex, SGroup *pGroup)
static void AddTriToGroup (SGroup *pGroup, const int iTriIndex)
static tbool CompareSubGroups (const SSubGroup *pg1, const SSubGroup *pg2)
static void QuickSort (int *pSortBuffer, int iLeft, int iRight, unsigned int uSeed)
static STSpace EvalTspace (int face_indices[], const int iFaces, const int piTriListIn[], const STriInfo pTriInfos[], const SMikkTSpaceContext *pContext, const int iVertexRepresentitive)
static void QuickSortEdges (SEdge *pSortBuffer, int iLeft, int iRight, const int channel, unsigned int uSeed)
static void GetEdge (int *i0_out, int *i1_out, int *edgenum_out, const int indices[], const int i0_in, const int i1_in)

Variables

const int g_iCells = 2048

Detailed Description

Definition in file mikktspace.c.


Define Documentation

#define GROUP_WITH_ANY   4

Definition at line 139 of file mikktspace.c.

Referenced by AssignRecur(), Build4RuleGroups(), EvalTspace(), GenerateTSpaces(), and InitTriInfo().

#define INTERNAL_RND_SORT_SEED   39871946

Definition at line 40 of file mikktspace.c.

Referenced by BuildNeighborsFast(), and GenerateTSpaces().

#define M_PI   3.1415926535897932384626433832795

Definition at line 37 of file mikktspace.c.

Referenced by genTangSpace().

#define MARK_DEGENERATE   1

Definition at line 137 of file mikktspace.c.

Referenced by DegenPrologue(), genTangSpace(), and InitTriInfo().

#define NOINLINE   __attribute__ ((noinline))

Definition at line 440 of file mikktspace.c.

#define ORIENT_PRESERVING   8

Definition at line 140 of file mikktspace.c.

Referenced by AssignRecur(), Build4RuleGroups(), GenerateTSpaces(), and InitTriInfo().

#define QUAD_ONE_DEGEN_TRI   2

Definition at line 138 of file mikktspace.c.

Referenced by DegenEpilogue(), and DegenPrologue().

#define TFALSE   0

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.

Definition at line 33 of file mikktspace.c.

Referenced by AssignRecur(), Build4RuleGroups(), BuildNeighborsFast(), BuildNeighborsSlow(), CompareSubGroups(), DegenEpilogue(), DegenPrologue(), GenerateInitialVerticesIndexList(), GenerateSharedVerticesIndexListSlow(), GenerateTSpaces(), genTangSpace(), InitTriInfo(), MergeVertsFast(), and MergeVertsSlow().

#define TTRUE   1

Function Documentation

static void AddTriToGroup ( SGroup pGroup,
const int  iTriIndex 
) [static]

Definition at line 1129 of file mikktspace.c.

References SGroup::iNrFaces, and SGroup::pFaceIndices.

Referenced by AssignRecur(), and Build4RuleGroups().

static tbool AssignRecur ( const int  piTriListIn[],
STriInfo  psTriInfos[],
const int  iMyTriIndex,
SGroup pGroup 
) [static]
static STSpace AvgTSpace ( const STSpace pTS0,
const STSpace pTS1 
) [static]

Definition at line 189 of file mikktspace.c.

References STSpace::fMagS, STSpace::fMagT, Normalize(), vadd(), veq(), VNotZero(), STSpace::vOs, and STSpace::vOt.

Referenced by GenerateTSpaces().

static int Build4RuleGroups ( STriInfo  pTriInfos[],
SGroup  pGroups[],
int  piGroupTrianglesBuffer[],
const int  piTriListIn[],
const int  iNrTrianglesIn 
) [static]
static void BuildNeighborsFast ( STriInfo  pTriInfos[],
SEdge pEdges,
const int  piTriListIn[],
const int  iNrTrianglesIn 
) [static]
static void BuildNeighborsSlow ( STriInfo  pTriInfos[],
const int  piTriListIn[],
const int  iNrTrianglesIn 
) [static]

Definition at line 1592 of file mikktspace.c.

References STriInfo::FaceNeighbors, i, TFALSE, and TTRUE.

Referenced by InitTriInfo().

static float CalcTexArea ( const SMikkTSpaceContext pContext,
const int  indices[] 
) [static]

Definition at line 927 of file mikktspace.c.

References GetTexCoord(), SVec3::x, and SVec3::y.

Referenced by InitTriInfo().

static tbool CompareSubGroups ( const SSubGroup pg1,
const SSubGroup pg2 
) [static]

Definition at line 1437 of file mikktspace.c.

References i, SSubGroup::iNrFaces, SSubGroup::pTriMembers, TFALSE, and TTRUE.

Referenced by GenerateTSpaces().

static void DegenEpilogue ( STSpace  psTspace[],
STriInfo  pTriInfos[],
int  piTriListIn[],
const SMikkTSpaceContext pContext,
const int  iNrTrianglesIn,
const int  iTotTris 
) [static]
static void DegenPrologue ( STriInfo  pTriInfos[],
int  piTriList_out[],
const int  iNrTrianglesIn,
const int  iTotTris 
) [static]
static STSpace EvalTspace ( int  face_indices[],
const int  iFaces,
const int  piTriListIn[],
const STriInfo  pTriInfos[],
const SMikkTSpaceContext pContext,
const int  iVertexRepresentitive 
) [static]
NOINLINE int FindGridCell ( const float  fMin,
const float  fMax,
const float  fVal 
)

Definition at line 446 of file mikktspace.c.

References g_iCells.

Referenced by GenerateSharedVerticesIndexList().

static int GenerateInitialVerticesIndexList ( STriInfo  pTriInfos[],
int  piTriList_out[],
const SMikkTSpaceContext pContext,
const int  iNrTrianglesIn 
) [static]
static void GenerateSharedVerticesIndexList ( int  piTriList_in_and_out[],
const SMikkTSpaceContext pContext,
const int  iNrTrianglesIn 
) [static]
static void GenerateSharedVerticesIndexListSlow ( int  piTriList_in_and_out[],
const SMikkTSpaceContext pContext,
const int  iNrTrianglesIn 
) [static]

Definition at line 727 of file mikktspace.c.

References assert, GetNormal(), GetPosition(), GetTexCoord(), i, offs, TFALSE, TTRUE, and veq().

Referenced by GenerateSharedVerticesIndexList().

static tbool GenerateTSpaces ( STSpace  psTspace[],
const STriInfo  pTriInfos[],
const SGroup  pGroups[],
const int  iNrActiveGroups,
const int  piTriListIn[],
const float  fThresCos,
const SMikkTSpaceContext pContext 
) [static]
tbool genTangSpace ( const SMikkTSpaceContext pContext,
const float  fAngularThreshold 
)
tbool genTangSpaceDefault ( const SMikkTSpaceContext pContext)

Definition at line 229 of file mikktspace.c.

References genTangSpace().

Referenced by calc_vertexnormals(), and DM_add_tangent_layer().

static void GetEdge ( int *  i0_out,
int *  i1_out,
int *  edgenum_out,
const int  indices[],
const int  i0_in,
const int  i1_in 
) [static]

Definition at line 1698 of file mikktspace.c.

Referenced by BuildNeighborsFast().

static SVec3 GetNormal ( const SMikkTSpaceContext pContext,
const int  index 
) [static]
static SVec3 GetPosition ( const SMikkTSpaceContext pContext,
const int  index 
) [static]
static SVec3 GetTexCoord ( const SMikkTSpaceContext pContext,
const int  index 
) [static]
static void IndexToData ( int *  piFace,
int *  piVert,
const int  iIndexIn 
) [static]

Definition at line 183 of file mikktspace.c.

Referenced by GetNormal(), GetPosition(), and GetTexCoord().

static void InitTriInfo ( STriInfo  pTriInfos[],
const int  piTriListIn[],
const SMikkTSpaceContext pContext,
const int  iNrTrianglesIn 
) [static]
static float Length ( const SVec3  v) [static]

Definition at line 92 of file mikktspace.c.

References LengthSquared(), and sqrtf.

Referenced by InitTriInfo(), and Normalize().

static float LengthSquared ( const SVec3  v) [static]

Definition at line 87 of file mikktspace.c.

References SVec3::x, SVec3::y, and SVec3::z.

Referenced by GenerateInitialVerticesIndexList(), and Length().

static int MakeIndex ( const int  iFace,
const int  iVert 
) [static]

Definition at line 177 of file mikktspace.c.

References assert.

Referenced by DegenEpilogue(), and GenerateInitialVerticesIndexList().

static void MergeVertsFast ( int  piTriList_in_and_out[],
STmpVert  pTmpVert[],
const SMikkTSpaceContext pContext,
const int  iL_in,
const int  iR_in 
) [static]
static void MergeVertsSlow ( int  piTriList_in_and_out[],
const SMikkTSpaceContext pContext,
const int  pTable[],
const int  iEntries 
) [static]
static SVec3 Normalize ( const SVec3  v) [static]

Definition at line 97 of file mikktspace.c.

References Length(), and vscale().

static tbool NotZero ( const float  fX) [static]

Definition at line 108 of file mikktspace.c.

References fabsf.

Referenced by InitTriInfo(), and VNotZero().

static void QuickSort ( int *  pSortBuffer,
int  iLeft,
int  iRight,
unsigned int  uSeed 
) [static]

Definition at line 1450 of file mikktspace.c.

References assert.

Referenced by GenerateTSpaces().

static void QuickSortEdges ( SEdge pSortBuffer,
int  iLeft,
int  iRight,
const int  channel,
unsigned int  uSeed 
) [static]

Definition at line 1641 of file mikktspace.c.

References SEdge::array, and assert.

Referenced by BuildNeighborsFast().

static SVec3 vadd ( const SVec3  v1,
const SVec3  v2 
) [static]
static float vdot ( const SVec3  v1,
const SVec3  v2 
) [static]

Definition at line 102 of file mikktspace.c.

References SVec3::x, SVec3::y, and SVec3::z.

Referenced by closestPtPtSeg(), EvalTspace(), GenerateTSpaces(), and processSamples().

static tbool veq ( const SVec3  v1,
const SVec3  v2 
) [static]
static tbool VNotZero ( const SVec3  v) [static]

Definition at line 114 of file mikktspace.c.

References NotZero(), SVec3::x, SVec3::y, and SVec3::z.

Referenced by AvgTSpace(), EvalTspace(), and GenerateTSpaces().

static SVec3 vscale ( const float  fS,
const SVec3  v 
) [static]
static SVec3 vsub ( const SVec3  v1,
const SVec3  v2 
) [static]

Variable Documentation

const int g_iCells = 2048

Definition at line 435 of file mikktspace.c.

Referenced by FindGridCell(), and GenerateSharedVerticesIndexList().