[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16638] trunk/blender/release/scripts/ bpymodules/colladaImEx/translator.py: collada importer

Remigiusz Fiedler migius at 4d-vectors.de
Sat Sep 20 18:30:55 CEST 2008


Revision: 16638
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16638
Author:   migius
Date:     2008-09-20 18:30:14 +0200 (Sat, 20 Sep 2008)

Log Message:
-----------
collada importer
 - bugfix meshes with more than 16 materials: material index bigger than 15 replaced with 15.

Modified Paths:
--------------
    trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py

Modified: trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py
===================================================================
--- trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py	2008-09-20 15:10:06 UTC (rev 16637)
+++ trunk/blender/release/scripts/bpymodules/colladaImEx/translator.py	2008-09-20 16:30:14 UTC (rev 16638)
@@ -1,3608 +1,3629 @@
-# --------------------------------------------------------------------------
-# Illusoft Collada 1.4 plugin for Blender
-# --------------------------------------------------------------------------
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# Copyright (C) 2006: Illusoft - colladablender at illusoft.com
-#    - 2008.08: multiple bugfixes by migius (AKA Remigiusz Fiedler)
-#
-# 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.
-#
-# ***** END GPL LICENCE BLOCK *****
-# --------------------------------------------------------------------------
-
-# History
-# 2008.08.31 by migius:
-# - added support for import IPOs interpolation type: LINEAR,BEZIER
-# - include patch jointVertexWeight from Dmitri: http://projects.blender.org/tracker/index.php?func=detail&aid=17427
-# - non-armature-animation export/import seams to work
-# - still buggy: armatures-position and armature-animation export&import
-# 2008.08.04 by migius:
-# - bugfix/refactor localTransformMatrix usage in hierarchies:
-#   it preserves local orientation for each child, so imported IPOs are correct working
-# 2008.05.08 by migius: modif. for debug mode
-
-from cutils import *
-import collada
-import Blender
-from Blender.Mathutils import *
-import math
-import datetime
-from helperObjects import *
-
-debprn = 0 #--- print debug "print 'deb: ..."
-dmitri = 0 #switch for testing patch from Dmitri
-
-class Translator(object):
-	isImporter = False
-
-	def __init__(self, isImporter, version, debugM, fileName, _useTriangles, _usePolygons, _bakeMatrices, _exportSelection, _createNewScene, _clearScene, _lookAt, _exportPhysics, _exportCurrentScene, _exportRelativePaths, _useUV, _sampleAnimation, _onlyMainScene):
-		global __version__, debugMode, usePhysics, useTriangles, usePolygons, bakeMatrices, exportSelection, createNewScene, clearScene, lookAt, replaceNames, exportPhysics, exportCurrentScene, useRelativePaths, useUV, sampleAnimation, onlyMainScene
-		#if debprn: print 'deb:class_Translator isImporter=', isImporter #deb---------
-		__version__ = version
-		debugMode = debugM
-		usePhysics = None
-		useTriangles = _useTriangles
-		usePolygons = _usePolygons
-		bakeMatrices = _bakeMatrices
-		exportSelection = _exportSelection
-		createNewScene = _createNewScene
-		clearScene = _clearScene
-		lookAt = _lookAt
-		exportPhysics = _exportPhysics
-		usePhysics = _exportPhysics
-		exportCurrentScene = _exportCurrentScene
-		useRelativePaths = _exportRelativePaths
-		useUV = _useUV
-		sampleAnimation = _sampleAnimation
-		onlyMainScene= _onlyMainScene
-
-		replaceNames = clearScene
-
-		self.isImporter = isImporter
-		self.fileName = ''
-		#if debprn: print 'deb:class_Translator fileName=', fileName #deb---------
-		if self.isImporter:
-			self.__Import(fileName)
-		else:
-			self.__Export(fileName)
-
-	def __Import(self,fileName=''):
-		#if debprn: print 'deb:translator__Import fileName=', fileName #deb---------
-		documentTranslator = DocumentTranslator(fileName)
-		documentTranslator.Import(fileName)
-
-	def __Export(self,filename=''):
-		documentTranslator = DocumentTranslator(filename)
-		documentTranslator.Export(filename)
-
-
-class DocumentTranslator(object):
-	isImport = None
-	ids = []
-	sceneGraph = None
-
-	# Keep track of the layers on import
-	layers = None
-
-	cameraLibrary = None
-##	  geometryLibrary = None
-	controllersLibrary = None
-	animationsLibrary = None
-##	  materialLibrary = None
-	texturesLibrary = None
-	lampsLibrary = None
-	colladaDocument = None
-	scenesLibrary = None
-	fps = 25
-
-	def __init__(self, fileName):
-		global waitingControllers, armatures
-		# Keep track of the controller that are waiting to be applied
-		waitingControllers = dict()
-		# Keep track of the armatures created
-		armatures = dict()
-
-		self.isImport = False
-		self.scenesLibrary = ScenesLibrary(self)
-		self.sceneGraph = SceneGraph(self)
-		self.lampsLibrary = LampsLibrary(self)
-		self.colladaDocument = None
-		self.texturesLibrary = TexturesLibrary(self)
-		self.camerasLibrary = CamerasLibrary(self)
-		self.materialsLibrary = MaterialsLibrary(self)
-		self.meshLibrary = MeshLibrary(self)
-		self.animationsLibrary = AnimationsLibrary(self)
-		self.controllersLibrary = ControllersLibrary(self)
-
-		self.filename = None
-		self.filePath = ''
-
-
-		self.currentBScene = Blender.Scene.GetCurrent()
-
-		self.progressCount = 0.4
-		self.progressField = (1.0 - self.progressCount)
-		self.progressStep = 0.0
-		self.progressPartCount = 0.0
-
-		self.tMatOLD = Matrix()
-		self._zUpMatrix = Matrix()
-		self._yUpMatrix = Matrix(
-		[0,0,1,0],
-		[1,0,0,0],
-		[0,1,0,0],
-		[0,0,0,1])
-
-		self.axisTransformMatrix = Matrix()
-		self.inverseAxisTransformMatrix  = Matrix()
-		self.orgAxiss = ["X","Y","Z"]
-
-	def CreateID(self, name, typeName=None):
-		if len(name) > 0 and not name[0].isalpha():
-			name = "i"+name
-
-		if not (name in self.ids):
-			self.ids.append(name)
-			return name
-		else:
-			tempName = name
-			if not(typeName is None) and name.rfind(typeName) >= 0:
-				# Check for existing number at the end?
-				return self.IncrementString(tempName, True)
-			else:
-				# First check if no Blender Object exists with the name 'tempName + typeName'
-				if (tempName + typeName) in self.allBlenderNames:
-					return self.IncrementString(tempName + typeName, True)
-				else:
-					return self.CreateID(tempName+typeName, typeName)
-
-	def IncrementString(self, name, checkName):
-		tempName = name
-		if name.rfind('.') >= 0:
-			while tempName[-1:].isdigit():
-				tempName =	tempName[:-1]
-			digitStr = name[-(len(name)-len(tempName)):]
-			digit = 1
-			if len(digitStr) > 0 and len(digitStr) != len(name):
-				digit = int(digitStr)+1
-			newName = tempName+str(digit).zfill(3)
-		else:
-			newName = name+'.001'
-
-		if not (newName in self.ids) and (not checkName or not (newName in self.allBlenderNames)):
-			self.ids.append(newName)
-			return newName
-		else:
-			return self.IncrementString(newName, checkName)
-
-
-	def CreateNameForObject(self, name, replace, myType):
-		if not replace:
-			return name
-
-		if myType == 'object':
-			try:
-				ob = Blender.Object.Get(name)
-				ob.name = self.CreateNameForObject(self.IncrementString(ob.name, False), True, 'object')
-			except ValueError:
-				pass
-		elif myType == 'mesh':
-			try:
-				mesh = Blender.Mesh.Get(name)
-				if not mesh is None:
-					mesh.name = self.CreateNameForObject(self.IncrementString(mesh.name, False), True, 'mesh')
-			except ValueError:
-				pass
-		elif myType == 'armature':
-			try:
-				armature = Blender.Armature.Get(str(name))
-				if not armature is None:
-					armature.name = self.CreateNameForObject(self.IncrementString(armature.name, False), True, 'armature')
-			except ValueError:
-				pass
-		elif myType == 'camera':
-			try:
-				camera = Blender.Camera.Get(str(name))
-				if not camera is None:
-					camera.name = self.CreateNameForObject(self.IncrementString(camera.name, False), True, 'camera')
-			except NameError:
-				pass
-		elif myType == 'lamp':
-			try:
-				lamp = Blender.Lamp.Get(str(name))
-				if not lamp is None:
-					lamp.name = self.CreateNameForObject(self.IncrementString(lamp.name, False), True, 'lamp')
-			except NameError:
-				pass
-
-		return name
-
-	def Import(self, fileName):
-		global debugMode, createNewScene
-		#if debprn: print 'deb:DocumentTranslator_Import fileName', fileName #deb---------
-		self.filename = fileName
-		self.filePath = Blender.sys.dirname(self.filename) + Blender.sys.sep
-		self.isImport = True
-		Blender.Window.EditMode(0)
-		Blender.Window.DrawProgressBar(0.0, 'Starting Import')
-
-		# Keep track of the 20 layers
-		self.layers = [None for x in range(20)]
-
-		if createNewScene:
-			self.currentBScene = Blender.Scene.New('Scene')
-			self.currentBScene.makeCurrent()
-		else:
-			self.currentBScene = Blender.Scene.GetCurrent()
-
-		# Create a new Collada document
-		Blender.Window.DrawProgressBar(0.1, 'Get Collada Document')
-		self.colladaDocument = collada.DaeDocument(debugMode)
-
-		# Setup the libraries
-		self.camerasLibrary.SetDaeLibrary(self.colladaDocument.camerasLibrary)
-		self.lampsLibrary.SetDaeLibrary(self.colladaDocument.lightsLibrary)
-		self.texturesLibrary.SetDaeLibrary(self.colladaDocument.imagesLibrary)
-		self.materialsLibrary.SetDaeLibrary(self.colladaDocument.materialsLibrary)
-		self.meshLibrary.SetDaeLibrary(self.colladaDocument.geometriesLibrary)
-		self.animationsLibrary.SetDaeLibrary(self.colladaDocument.animationsLibrary)
-		self.controllersLibrary.SetDaeLibrary(self.colladaDocument.controllersLibrary)
-
-		# Parse the COLLADA file
-		self.colladaDocument.LoadDocumentFromFile(fileName)
-
-		self.axiss = ["X", "Y", "Z"]
-		if self.colladaDocument.asset.upAxis == collada.DaeSyntax.Y_UP:
-			self.tMatOLD[0][0] = 0
-			self.tMatOLD[1][1] = 0
-			self.tMatOLD[2][2] = 0
-			self.tMatOLD[0][1] = 1
-			self.tMatOLD[1][2] = 1
-			self.tMatOLD[2][0] = 1
-			self.axiss = ["Y", "Z", "X"]
-
-		if self.colladaDocument.asset.upAxis == collada.DaeSyntax.Y_UP:
-			self.axisTransformMatrix = Matrix(self._yUpMatrix)
-			self.axiss = ["Y", "Z", "X"]
-
-		self.inverseAxisTransformMatrix = Matrix(self.axisTransformMatrix).invert()
-
-		self.progressStep = self.progressField/(self.colladaDocument.GetItemCount()+1)
-
-		# Get the animation info
-		#TODO: for what is this good? (migius)
-		if 0:	animations = AnimationInfo.CreateAnimations(self.animationsLibrary, self.fps, self.axiss)
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list