[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14477] trunk/blender/release/scripts/ export_cal3d.py: [#6932] Cal3D Exporter Distort Vertex
Campbell Barton
ideasman42 at gmail.com
Sat Apr 19 19:38:40 CEST 2008
Revision: 14477
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14477
Author: campbellbarton
Date: 2008-04-19 19:38:40 +0200 (Sat, 19 Apr 2008)
Log Message:
-----------
[#6932] Cal3D Exporter Distort Vertex
Removing cal3d importer, since the soya3d maintain their own and I could not fix a bug in weird bone exporting.
Removed Paths:
-------------
trunk/blender/release/scripts/export_cal3d.py
Deleted: trunk/blender/release/scripts/export_cal3d.py
===================================================================
--- trunk/blender/release/scripts/export_cal3d.py 2008-04-19 11:44:09 UTC (rev 14476)
+++ trunk/blender/release/scripts/export_cal3d.py 2008-04-19 17:38:40 UTC (rev 14477)
@@ -1,1112 +0,0 @@
-#!BPY
-"""
-Name: 'Cal3D (.cfg .xaf .xsf .xmf .xrf)...'
-Blender: 243
-Group: 'Export'
-Tip: 'Export armature/bone/mesh/action data to the Cal3D format.'
-"""
-
-# export_cal3d.py
-# Copyright (C) 2003-2004 Jean-Baptiste LAMY -- jibalamy at free.fr
-# Copyright (C) 2004 Matthias Braun -- matze at braunis.de
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-__version__ = '0.9f'
-__author__ = 'Jean-Baptiste, Jiba, Lamy, Campbell Barton (Ideasman42)'
-__email__ = ['Authors email, jibalamy:free*fr']
-__url__ = ['Soya3ds homepage, http://home.gna.org/oomadness/en/soya/', 'Cal3d, http://cal3d.sourceforge.net']
-__bpydoc__ =\
-'''This script is a Blender => Cal3D converter.
-(See http://blender.org and http://cal3d.sourceforge.net)
-
-USAGE:
-
-To install it, place the script in your $HOME/.blender/scripts directory.
-
-Then open the File->Export->Cal3d v0.9 menu. And select the filename of the .cfg file.
-The exporter will create a set of other files with same prefix (ie. bla.cfg, bla.xsf,
-bla_Action1.xaf, bla_Action2.xaf, ...).
-
-You should be able to open the .cfg file in cal3d_miniviewer.
-
-
-NOT (YET) SUPPORTED:
-
- - Rotation, translation, or stretching Blender objects is still quite
-buggy, so AVOID MOVING / ROTATING / RESIZE OBJECTS (either mesh or armature) !
-Instead, edit the object (with tab), select all points / bones (with "a"),
-and move / rotate / resize them.<br>
- - no support for exporting springs yet<br>
- - no support for exporting material colors (most games should only use images
-I think...)
-
-
-KNOWN ISSUES:
-
- - Cal3D versions <=0.9.1 have a bug where animations aren't played when the root bone
-is not animated;<br>
- - Cal3D versions <=0.9.1 have a bug where objects that aren't influenced by any bones
-are not drawn (fixed in Cal3D CVS).
-
-
-NOTES:
-
-It requires a very recent version of Blender (>= 2.44).
-
-Build a model following a few rules:<br>
- - Use only a single armature;<br>
- - Use only a single rootbone (Cal3D doesn't support floating bones);<br>
- - Use only locrot keys (Cal3D doesn't support bone's size change);<br>
- - Don't try to create child/parent constructs in blender object, that gets exported
-incorrectly at the moment;<br>
- - Objects or animations whose names start by "_" are not exported (hidden object).
-
-You can pass as many parameters as you want at the end, "EXPORT_FOR_SOYA=1" is just an
-example. The parameters are the same as below.
-'''
-
-# True (=1) to export for the Soya 3D engine
-# (http://oomadness.tuxfamily.org/en/soya).
-# (=> rotate meshes and skeletons so as X is right, Y is top and -Z is front)
-# EXPORT_FOR_SOYA = 0
-
-# Enables LODs computation. LODs computation is quite slow, and the algo is
-# surely not optimal :-(
-LODS = 0
-
-# Scale the model (not supported by Soya).
-
-# See also BASE_MATRIX below, if you want to rotate/scale/translate the model at
-# the exportation.
-
-#########################################################################################
-# Code starts here.
-# The script should be quite re-useable for writing another Blender animation exporter.
-# Most of the hell of it is to deal with Blender's head-tail-roll bone's definition.
-
-import math
-import Blender
-import BPyMesh
-import BPySys
-import BPyArmature
-import BPyObject
-import bpy
-
-def best_armature_root(armature):
- '''
- Find the armature root bone with the most children, return that bone
- '''
-
- bones = [bone for bone in armature.bones.values() if bone.hasChildren() == True]
- if len(bones) == 1:
- return bones[0]
-
- # Get the best root since we have more then 1
- bones = [(len(bone.getAllChildren()), bone) for bone in bones]
- bones.sort()
- return bones[-1][1] # bone with most children
-
-
-Vector = Blender.Mathutils.Vector
-Quaternion = Blender.Mathutils.Quaternion
-Matrix = Blender.Mathutils.Matrix
-
-# HACK -- it seems that some Blender versions don't define sys.argv,
-# which may crash Python if a warning occurs.
-# if not hasattr(sys, 'argv'): sys.argv = ['???']
-
-def matrix_multiply(b, a):
- return [ [
- a[0][0] * b[0][0] + a[0][1] * b[1][0] + a[0][2] * b[2][0],
- a[0][0] * b[0][1] + a[0][1] * b[1][1] + a[0][2] * b[2][1],
- a[0][0] * b[0][2] + a[0][1] * b[1][2] + a[0][2] * b[2][2],
- 0.0,
- ], [
- a[1][0] * b[0][0] + a[1][1] * b[1][0] + a[1][2] * b[2][0],
- a[1][0] * b[0][1] + a[1][1] * b[1][1] + a[1][2] * b[2][1],
- a[1][0] * b[0][2] + a[1][1] * b[1][2] + a[1][2] * b[2][2],
- 0.0,
- ], [
- a[2][0] * b[0][0] + a[2][1] * b[1][0] + a[2][2] * b[2][0],
- a[2][0] * b[0][1] + a[2][1] * b[1][1] + a[2][2] * b[2][1],
- a[2][0] * b[0][2] + a[2][1] * b[1][2] + a[2][2] * b[2][2],
- 0.0,
- ], [
- a[3][0] * b[0][0] + a[3][1] * b[1][0] + a[3][2] * b[2][0] + b[3][0],
- a[3][0] * b[0][1] + a[3][1] * b[1][1] + a[3][2] * b[2][1] + b[3][1],
- a[3][0] * b[0][2] + a[3][1] * b[1][2] + a[3][2] * b[2][2] + b[3][2],
- 1.0,
- ] ]
-
-# multiplies 2 quaternions in x,y,z,w notation
-def quaternion_multiply(q1, q2):
- return Quaternion(\
- q2[3] * q1[0] + q2[0] * q1[3] + q2[1] * q1[2] - q2[2] * q1[1],
- q2[3] * q1[1] + q2[1] * q1[3] + q2[2] * q1[0] - q2[0] * q1[2],
- q2[3] * q1[2] + q2[2] * q1[3] + q2[0] * q1[1] - q2[1] * q1[0],
- q2[3] * q1[3] - q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2],\
- )
-
-def matrix_translate(m, v):
- m[3][0] += v[0]
- m[3][1] += v[1]
- m[3][2] += v[2]
- return m
-
-def matrix2quaternion(m):
- s = math.sqrt(abs(m[0][0] + m[1][1] + m[2][2] + m[3][3]))
- if s == 0.0:
- x = abs(m[2][1] - m[1][2])
- y = abs(m[0][2] - m[2][0])
- z = abs(m[1][0] - m[0][1])
- if (x >= y) and (x >= z): return Quaternion(1.0, 0.0, 0.0, 0.0)
- elif (y >= x) and (y >= z): return Quaternion(0.0, 1.0, 0.0, 0.0)
- else: return Quaternion(0.0, 0.0, 1.0, 0.0)
-
- q = Quaternion([
- -(m[2][1] - m[1][2]) / (2.0 * s),
- -(m[0][2] - m[2][0]) / (2.0 * s),
- -(m[1][0] - m[0][1]) / (2.0 * s),
- 0.5 * s,
- ])
- q.normalize()
- #print q
- return q
-
-def vector_by_matrix_3x3(p, m):
- return [p[0] * m[0][0] + p[1] * m[1][0] + p[2] * m[2][0],
- p[0] * m[0][1] + p[1] * m[1][1] + p[2] * m[2][1],
- p[0] * m[0][2] + p[1] * m[1][2] + p[2] * m[2][2]]
-
-def vector_add(v1, v2):
- return [v1[0]+v2[0], v1[1]+v2[1], v1[2]+v2[2]]
-
-def vector_sub(v1, v2):
- return [v1[0]-v2[0], v1[1]-v2[1], v1[2]-v2[2]]
-
-def quaternion2matrix(q):
- xx = q[0] * q[0]
- yy = q[1] * q[1]
- zz = q[2] * q[2]
- xy = q[0] * q[1]
- xz = q[0] * q[2]
- yz = q[1] * q[2]
- wx = q[3] * q[0]
- wy = q[3] * q[1]
- wz = q[3] * q[2]
- return Matrix([1.0 - 2.0 * (yy + zz), 2.0 * (xy + wz), 2.0 * (xz - wy), 0.0],
- [ 2.0 * (xy - wz), 1.0 - 2.0 * (xx + zz), 2.0 * (yz + wx), 0.0],
- [ 2.0 * (xz + wy), 2.0 * (yz - wx), 1.0 - 2.0 * (xx + yy), 0.0],
- [0.0 , 0.0 , 0.0 , 1.0])
-
-def matrix_invert(m):
- det = (m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])
- - m[1][0] * (m[0][1] * m[2][2] - m[2][1] * m[0][2])
- + m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]))
- if det == 0.0: return None
- det = 1.0 / det
- r = [ [
- det * (m[1][1] * m[2][2] - m[2][1] * m[1][2]),
- - det * (m[0][1] * m[2][2] - m[2][1] * m[0][2]),
- det * (m[0][1] * m[1][2] - m[1][1] * m[0][2]),
- 0.0,
- ], [
- - det * (m[1][0] * m[2][2] - m[2][0] * m[1][2]),
- det * (m[0][0] * m[2][2] - m[2][0] * m[0][2]),
- - det * (m[0][0] * m[1][2] - m[1][0] * m[0][2]),
- 0.0
- ], [
- det * (m[1][0] * m[2][1] - m[2][0] * m[1][1]),
- - det * (m[0][0] * m[2][1] - m[2][0] * m[0][1]),
- det * (m[0][0] * m[1][1] - m[1][0] * m[0][1]),
- 0.0,
- ] ]
- r.append([
- -(m[3][0] * r[0][0] + m[3][1] * r[1][0] + m[3][2] * r[2][0]),
- -(m[3][0] * r[0][1] + m[3][1] * r[1][1] + m[3][2] * r[2][1]),
- -(m[3][0] * r[0][2] + m[3][1] * r[1][2] + m[3][2] * r[2][2]),
- 1.0,
- ])
- return r
-
-
-def point_by_matrix(p, m):
- return [p[0] * m[0][0] + p[1] * m[1][0] + p[2] * m[2][0] + m[3][0],
- p[0] * m[0][1] + p[1] * m[1][1] + p[2] * m[2][1] + m[3][1],
- p[0] * m[0][2] + p[1] * m[1][2] + p[2] * m[2][2] + m[3][2]]
-
-# Hack for having the model rotated right.
-# Put in BASE_MATRIX your own rotation if you need some.
-
-BASE_MATRIX = None
-
-
-# Cal3D data structures
-
-CAL3D_VERSION = 910
-MATERIALS = {} # keys are (mat.name, img.name)
-
-class Cal3DMaterial(object):
- __slots__ = 'amb', 'diff', 'spec', 'shininess', 'maps_filenames', 'id'
- def __init__(self, blend_world, blend_material, blend_images):
-
- # Material Settings
- if blend_world: amb = [ int(c*255) for c in blend_world.amb ]
- else: amb = [0,0,0] # Default value
-
- if blend_material:
- self.amb = tuple([int(c*blend_material.amb) for c in amb] + [255])
- self.diff = tuple([int(c*255) for c in blend_material.rgbCol] + [int(blend_material.alpha*255)])
- self.spec = tuple([int(c*255) for c in blend_material.rgbCol] + [int(blend_material.alpha*255)])
- self.shininess = (float(blend_material.hard)-1)/5.10
- else:
- self.amb = tuple(amb + [255])
- self.diff = (255,255,255,255)
- self.spec = (255,255,255,255)
- self.shininess = 1.0
-
- self.maps_filenames = []
- for image in blend_images:
- if image:
- self.maps_filenames.append( image.filename.split('\\')[-1].split('/')[-1] )
-
- self.id = len(MATERIALS)
- MATERIALS[blend_material, blend_images] = self
-
- # new xml format
- def writeCal3D(self, file):
- file.write('<?xml version="1.0"?>\n')
- file.write('<HEADER MAGIC="XRF" VERSION="%i"/>\n' % CAL3D_VERSION)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list