[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34861] trunk/blender: Move mikktspace code to own library, so it is clear that it is also

Nathan Letwory nathan at letworyinteractive.com
Tue Feb 15 10:24:37 CET 2011


Revision: 34861
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34861
Author:   jesterking
Date:     2011-02-15 09:24:35 +0000 (Tue, 15 Feb 2011)
Log Message:
-----------
Move mikktspace code to own library, so it is clear that it is also
intended as a standalone library for use in other applications that
want the same tangent space as Blender.

This also keeps blenkernel clean(er) from extra math functions.

Modified Paths:
--------------
    trunk/blender/intern/CMakeLists.txt
    trunk/blender/intern/SConscript
    trunk/blender/source/blender/blenkernel/CMakeLists.txt
    trunk/blender/source/blender/blenkernel/SConscript
    trunk/blender/source/blender/render/CMakeLists.txt
    trunk/blender/source/blender/render/SConscript

Added Paths:
-----------
    trunk/blender/intern/mikktspace/
    trunk/blender/intern/mikktspace/CMakeLists.txt
    trunk/blender/intern/mikktspace/SConscript
    trunk/blender/intern/mikktspace/mikktspace.c
    trunk/blender/intern/mikktspace/mikktspace.h

Removed Paths:
-------------
    trunk/blender/source/blender/blenkernel/intern/mikktspace.c
    trunk/blender/source/blender/blenkernel/mikktspace.h

Modified: trunk/blender/intern/CMakeLists.txt
===================================================================
--- trunk/blender/intern/CMakeLists.txt	2011-02-15 04:06:13 UTC (rev 34860)
+++ trunk/blender/intern/CMakeLists.txt	2011-02-15 09:24:35 UTC (rev 34861)
@@ -33,6 +33,7 @@
 add_subdirectory(iksolver)
 add_subdirectory(opennl)
 add_subdirectory(smoke)
+add_subdirectory(mikktspace)
 
 if(WITH_MOD_FLUID)
 	add_subdirectory(elbeem)

Modified: trunk/blender/intern/SConscript
===================================================================
--- trunk/blender/intern/SConscript	2011-02-15 04:06:13 UTC (rev 34860)
+++ trunk/blender/intern/SConscript	2011-02-15 09:24:35 UTC (rev 34861)
@@ -13,6 +13,7 @@
             'itasc/SConscript',
             'boolop/SConscript',
             'opennl/SConscript',
+            'mikktspace/SConscript',
             'smoke/SConscript'])
 
 # NEW_CSG was intended for intern/csg, but

Added: trunk/blender/intern/mikktspace/CMakeLists.txt
===================================================================
--- trunk/blender/intern/mikktspace/CMakeLists.txt	                        (rev 0)
+++ trunk/blender/intern/mikktspace/CMakeLists.txt	2011-02-15 09:24:35 UTC (rev 34861)
@@ -0,0 +1,36 @@
+# $Id$
+# ***** BEGIN GPL 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.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Daniel Genrich
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+	.
+)
+
+set(SRC
+	mikktspace.c
+)
+
+blender_add_lib(bf_intern_mikktspace "${SRC}" "${INC}")
+


Property changes on: trunk/blender/intern/mikktspace/CMakeLists.txt
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: trunk/blender/intern/mikktspace/SConscript
===================================================================
--- trunk/blender/intern/mikktspace/SConscript	                        (rev 0)
+++ trunk/blender/intern/mikktspace/SConscript	2011-02-15 09:24:35 UTC (rev 34861)
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+Import ('env')
+
+sources = ['mikktspace.c']
+
+incs = ''
+defs = ''
+
+env.BlenderLib ('bf_intern_mikktspace', sources, Split(incs), Split(defs), libtype=['intern'], priority=[100] )


Property changes on: trunk/blender/intern/mikktspace/SConscript
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: trunk/blender/intern/mikktspace/mikktspace.c
===================================================================
--- trunk/blender/intern/mikktspace/mikktspace.c	                        (rev 0)
+++ trunk/blender/intern/mikktspace/mikktspace.c	2011-02-15 09:24:35 UTC (rev 34861)
@@ -0,0 +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;
+
+static tbool			veq( const SVec3 v1, const SVec3 v2 )
+{
+	return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z);
+}
+
+static 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;
+}
+
+
+static 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;
+}
+
+static 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;
+}
+
+static float			LengthSquared( const SVec3 v )
+{
+	return v.x*v.x + v.y*v.y + v.z*v.z;
+}
+
+static float			Length( const SVec3 v )
+{
+	return sqrtf(LengthSquared(v));
+}
+
+static const SVec3		Normalize( const SVec3 v )
+{
+	return vscale(1 / Length(v), v);
+}
+
+static const float		vdot( const SVec3 v1, const SVec3 v2)
+{
+	return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
+}
+
+
+static tbool NotZero(const float fX)
+{
+	// could possibly use FLT_EPSILON instead
+	return fabsf(fX) > FLT_MIN;
+}
+
+static 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);
+
+static int MakeIndex(const int iFace, const int iVert)
+{
+	assert(iVert>=0 && iVert<4 && iFace>=0);
+	return (iFace<<2) | (iVert&0x3);
+}
+
+static void IndexToData(int * piFace, int * piVert, const int iIndexIn)
+{
+	piVert[0] = iIndexIn&0x3;
+	piFace[0] = iIndexIn>>2;
+}
+
+static 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++)
+	{

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list