Shape Files: Import & Export Blender Meshes

Talk about your new mod or map here

Moderators: jelco, bert_the_turtle

brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 2:03 am

For the save dialog, here's the code from xsi_export.py:

Code: Select all

fname = bsys.makename(ext=".xsi")
if EXPORT_DIR <> '':
  fname = bsys.join(EXPORT_DIR, bsys.basename(fname))

Blender.Window.FileSelector(export_xsi, "Export SoftImage XSI", fname)


Also, it might be nice to truncate precisions to 3-4 places. If you don't know about it, Python's printf equivalent is here: http://www.python.org/doc/2.3.5/lib/typesseq-strings.html

The console reports:

Code: Select all

Compiled with Python version 2.4.
Checking for installed Python... got it!
  File "<string>", line 196
    elif type == 'Empty':
                         ^
IndentationError: unindent does not match any outer indentation level

Blender quit

Simply deleting one space from that line fixes the problem! Python errors: sometimes more obscure than perl!

..and fwiw, the triangulation code from xsi_export.py:

Code: Select all

# copy of code to triangulate mesh
##################################
def triangulate_face(f):   
  if len(f.v) <= 3:
    #newFaces = [ [f.v[0].index, f.v[1].index, f.v[2].index] ]
    newFaces = [ [f.v[0].index, f.v[2].index, f.v[1].index] ]
    mats.append ( f.materialIndex )
  else:
    #newFaces = [ [f.v[0].index, f.v[1].index, f.v[2].index] ]
    #newFaces.append ( [f.v[3].index, f.v[0].index, f.v[2].index] )
    newFaces = [ [f.v[0].index, f.v[2].index, f.v[1].index] ]
    newFaces.append ( [f.v[3].index, f.v[2].index, f.v[0].index] )
    mats.append ( f.materialIndex )
    mats.append ( f.materialIndex )

  return newFaces
User avatar
The GoldFish
level5
level5
Posts: 3961
Joined: Fri Mar 01, 2002 9:01 pm
Location: Bowl / South UK
Contact:

Postby The GoldFish » Tue May 08, 2007 2:25 am

Since at this stage it seems fairly outclassed and unneeded, I shant bother doing much more in the way of my VB app.

What I've done so far is available here - no up/front implimentation, but then I haven't worked on it at all today or anything (busy busy...), but you might as well get the original 3DS files and import them if they're available for the shape you want, since then you'll get the rotations/colour etc.
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 2:28 am

brice wrote:The console reports:

Code: Select all

Compiled with Python version 2.4.
Checking for installed Python... got it!
  File "<string>", line 196
    elif type == 'Empty':
                         ^
IndentationError: unindent does not match any outer indentation level

Blender quit

Simply deleting one space from that line fixes the problem! Python errors: sometimes more obscure than perl!


That's my one gripe about Python: It uses indentation for blocks, instead of some sort of delimiter. This should fix both that error and the default file-name issue:

Code: Select all

#!BPY

# """
# Name: 'Darwinia Shape File (.shp)'
# Blender: 243
# Group: 'Export'
# Tooltip: 'Export to the Shape format used by Darwinia'
# """
__author__ = 'Branan Riley'
__version__ = '0.9'
__email__ = 'branan@gmail.com'
__bpydoc__ = """\
This script exports to the Shape format used by Darwinia.

Every selected object will be exported as a fragment in
the shape file. If an object has a parent, that parent will
be defined as the parent of its fragment. Otherwise, a
fragment will be parented to 'SceneRoot'. Markers are not
yet supported, but it should be pretty easy, once I get
everything else done.


This program is distributed under the GPL. The complete
text of the GPL is availble at http://www.gnu.org/licenses/gpl.txt
"""

import Blender

mesh_objects = []
empty_objects = []

class shp_object:
  def __init__(self):
    self.ParentName='SceneRoot'
    self.Up=0.0,1.0,0.0
    self.Front=0.0,0.0,1.0
    self.Pos=0.0,0.0,0.0
    self.Name='NewDataChunk'
   
  def setParent(self, parent):
    self.ParentName=parent
 
  def setUp(self, x, y, z):
    self.Up=x,y,z
 
  def setFront(self, x, y, z):
    self.Front=x,y,z
 
  def setPos(self, x, y, z):
    self.Pos=x,y,z
 
  def setName(self, name):
    self.Name=name

class shp_fragment(shp_object):
  def __init__(self):
    shp_object.__init__(self)
    self.Positions=[]
    self.Colours=[]
    self.Vertices=[]
    self.Triangles=[]
 
  def addPosition(self, x, y, z):
    if self.Positions.count((x,y,z)) == 0:
      self.Positions.append((x,y,z))
    return self.Positions.index((x,y,z))
 
  def addColour(self, r, g, b):
    if self.Colours.count((r,g,b)) == 0:
      self.Colours.append((r,g,b))
    return self.Colours.index((r,g,b))
 
  def addVertex(self, pos, col):
    if self.Vertices.count((pos,col)) == 0:
      self.Vertices.append((pos,col))
    return self.Vertices.index((pos,col))
 
  def addTriangle(self, pos0, pos1, pos2):
    self.Triangles.append((pos0,pos1,pos2))
 
  def write(self, file):
    file.write('Fragment: '+self.Name+'\n')
   
    file.write('\tParentName: '+self.ParentName+'\n')
   
    s = '\tUp:'
    for i in range(3):
      s = s+' '+str(self.Up[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tFront:'
    for i in range(3):
      s = s+' '+str(self.Front[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPos:'
    for i in range(3):
      s = s+' '+str(self.Pos[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPositions: '+str(len(self.Positions))+'\n'
    file.write(s)
    for i in range(len(self.Positions)):
      s = '\t\t'+str(i)+':'
      for j in range(3):
        s = s+' '+str(self.Positions[i][j])
      s = s+'\n'
      file.write(s)
   
    file.write('\tNormals: 0\n')
   
    s = '\tColours: '+str(len(self.Colours))+'\n'
    file.write(s)
    for i in range(len(self.Colours)):
      s = '\t\t'+str(i)+':'
      for j in range(3):
        s = s+' '+str(self.Colours[i][j])
      s = s+'\n'
      file.write(s)
   
    s = '\tVertices: '+str(len(self.Vertices))+'\n'
    file.write(s)
    for i in range(len(self.Vertices)):
      s = '\t\t'+str(i)+':'
      for j in range(2):
        s = s+' '+str(self.Vertices[i][j])
      s = s+'\n'
      file.write(s)
   
    s = '\tTriangles: '+str(len(self.Triangles))+'\n'
    file.write(s)
    for i in range(len(self.Triangles)):
      s = '\t\t'
      for j in range(2):
        s = s+str(self.Triangles[i][j])+' '
      s = s+str(self.Triangles[i][2])+'\n'
      file.write(s)

class shp_marker(shp_object):
  def __init__(self):
    shp_object.__init__(self)
    self.Depth = 1
 
  def setDepth(self, depth):
    self.Depth = depth
 
  def write(self, file):
    file.write('Marker: '+self.Name+'\n')
   
    file.write('\tParentName'+self.ParentName+'\n')
   
    s = '\tDepth: '+str(self.Depth)+'\n'
    file.write(s)
   
    s = '\tUp:'
    for i in range(3):
      s = s+' '+str(self.Up[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tFront:'
    for i in range(3):
      s = s+' '+str(self.Front[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPos:'
    for i in range(3):
      s = s+' '+str(self.Pos[i])
    s = s+'\n'
    file.write(s)
   
    file.write('MarkerEnd\n')
 
def getObjects():
  global mesh_objects
 
  selected_obs = Blender.Object.GetSelected()
  for obj in selected_obs:
    type = obj.getType()
    if type == 'Mesh':
      mesh_objects.append(obj)
    elif type == 'Empty':
      empty_objects.append(obj)

def createShpFragment(obj):
  new_shp = shp_fragment()
  new_shp.setName(obj.getName())
  parent = obj.getParent()
  if parent:
    new_shp.setParent(parent.getName())
  matrix = obj.getMatrix('localspace')
  new_shp.setPos(matrix[3][1],matrix[3][2],matrix[3][0])
  msh_name = obj.getData(name_only=True)
  msh = Blender.Mesh.Get(msh_name)
  for f in msh.faces:
    verts=[0,0,0]
    for i in range(3):
      col = new_shp.addColour(f.col[i].r,f.col[i].g,f.col[i].b)
      pos = new_shp.addPosition(f.verts[i].co.y,f.verts[i].co.z,f.verts[i].co.x)
      verts[i]=new_shp.addVertex(pos,col)
    new_shp.addTriangle(verts[0],verts[1],verts[2])
  return new_shp

def countParent(obj,count):
  parent = obj.getParent()
  if parent:
    return countParent(parent, count+1)
  else:
    return count   

def createShpMarker(obj):
  new_shp = shp_marker()
  new_shp.setName(obj.getName())
  parent = obj.getParent()
  if parent:
    new_shp.setParent(parent.getName())
  new_shp.setDepth(countParent(obj,1))
  matrix = obj.getMatrix('localspace')
  new_shp.setPos(matrix[3][1],matrix[3][2],matrix[3][0])
  return new_shp

def mainFunc(filename):
  file = open(filename, 'w')
  getObjects()
  shp_fragments = []
  shp_markers = []
  for obj in mesh_objects:
    shp_fragments.append(createShpFragment(obj))
  for obj in empty_objects:
    shp_markers.append(createShpMarker(obj))
  for frag in shp_fragments:
    frag.write(file)
  file.write('\n')
  for mrk in shp_markers:
    mrk.write(file)
  file.close()

fname = Blender.sys.makename(ext='.shp')
Blender.Window.FileSelector(mainFunc, "Export SHP File", fname)


Of course, it might not work at all... I'm at the library at school right now, so I can't even test it in Blender to make sure it works.

Changes:
  • Should now default to a *.shp name
  • Replaced all tabs with spaces. Sometimes I hate Python...
  • Added a GPL notice. A proper GPL notice and a COPYING file will be added once a proper ZIPped release is made.


EDIT: Fixed another indentation bug
Last edited by PaladinOfKaos on Tue May 08, 2007 2:36 am, edited 1 time in total.
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 2:33 am

Nope:

Code: Select all

Compiled with Python version 2.4.
Checking for installed Python... got it!
  File "<string>", line 134
    file.write(s)
    ^
SyntaxError: invalid syntax
Saved session recovery to /tmp/quit.blend

Blender quit


Looks like you had mixed spaces and tabs before you "converted".

Probably best to wait to post until you can test? After all, Darwinia as been out for how many years? There's no urgent rush. Although this IS exciting!
Last edited by brice on Tue May 08, 2007 2:36 am, edited 1 time in total.
User avatar
xander
level5
level5
Posts: 16869
Joined: Thu Oct 21, 2004 11:41 pm
Location: Highland, CA, USA
Contact:

Postby xander » Tue May 08, 2007 2:36 am

The GoldFish wrote:Since at this stage it seems fairly outclassed and unneeded, I shant bother doing much more in the way of my VB app.

I still love you, TGF. ImageImageImage

xander
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 2:40 am

xander wrote:
The GoldFish wrote:Since at this stage it seems fairly outclassed and unneeded, I shant bother doing much more in the way of my VB app.

I still love you, TGF. ImageImageImage

xander


...and if you don't mind it coming from a stranger, that goes for me too! We wouldn't be here if everyone hadn't contributed something.

-brice
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 2:47 am

Grabbed the ZIP file of Blender (I've been in the Zone on this thing since I started it, so I may as well take advantage of it while it lasts). It's working now, so it looks like I've cleaned up all the indentation errors. I've updated my last post with the changes.

EDIT: As soon as the exporter is doing everything, I'll start on the importer. I believe that triangulation and Up/Front is all that's left. Any other requests?
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 3:15 am

I have a question about using Empties as placeholders for the Markers. There are a few Marker types that can have repeats: Ports, Lights, Status. Usually they end up in a circle around the main building shape, with possibly some gaps.

I'm not a Blender pro, and I can't figure out how to easily duplicate an Empty into a circle. Dupliverts doesn't seem to work with Empties. I can get dupliverts to work fine with cube children around a circle.

Darwinia imposes a maximum port number of about 80 -- somewher between 80 - 100 the game starts crashing. Now how would I go about making a circle of 80 Empties in Blender?

And would the exporter know about the dupliverts if they are the way to go?

EDIT: In any case, it is easy enough to write a simple perl script to generate circles of ports. That's what I do now. But TGF was hoping for a no-text-edit solution in the long run. Probably most people would appreciate it too.


...and if I have the child of a duplivert selected when I export I get the following errors:

Code: Select all

Compiled with Python version 2.4.
Checking for installed Python... got it!
Traceback (most recent call last):
  File "<string>", line 232, in mainFunc
  File "<string>", line 202, in createShpFragment
ValueError: face has no vertex colors
Traceback (most recent call last):
  File "<string>", line 232, in mainFunc
  File "<string>", line 202, in createShpFragment
ValueError: face has no vertex colors
Saved session recovery to /tmp/quit.blend

Blender quit

The parent circle exports fine as an empty fragment.
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 3:26 am

I don't think Dupliverts works with Empties. Even if it did work, I'm not sure it's possible to capture it in a way I could use to export nicely.

What you can do is place the cursor at the centre of where you want your circle, and tell it to rotate around the cursor. Then your empties should end up where you need them to be.

EDIT: That crash is known, I figured no-one would try to export with no vertex colors. I know, I know... "Never make assumptions about your users". Shall I make the default a horific shade of purple so people realize they forgot to collor their vertices?
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 3:35 am

... then here's my suggestion. Maybe use a small generic shape instead of Empties? Then if someone wants to duplivert the shape, they can do a Make Dupliverts Real to get all the Markers exported. Plus a real shape would convey orientation better than the axes of the Empty. Maybe something as simple as a cube with one face pulled out into a pyramid for the front? or a small wireframe like the camera in blender?

I mean, I wouldn't want to have to rotate 80 Empties into positon individually... there's no spinDup for Objects is there?


EDIT: That crash is known, I figured no-one would try to export with no vertex colors. I know, I know... "Never make assumptions about your users". Shall I make the default a horific shade of purple so people realize they forgot to collor their vertices?


yes! No... 128 128 128 would be a fine default.
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 3:44 am

That will work nicely, so long as there is a standard mesh name for the marker mesh - something like 'Marker'.

The workflow would end up something like:
  1. Create your circle, or whatever other shape you want
  2. Create your object. Give it whatever object name you feel, and a mesh name of 'Marker'
  3. Make circle parent of marker shape
  4. Dupliverts
  5. Select circle
  6. Make Duplicates Real (ctrl-shift-a)
  7. Re-Parent each duplicate if needed, or leave them children of SceneRoot


You now have a several objects, each with a unique object name, each a child of SceneRoot (Or whatever you re-parented them to), and each using the 'Marker' mesh. The script just has to check that the mesh is named 'Marker' to create a marker, otherwise it creates a fragment. A bit more complex, but it lets DupliVerts work, and you can represent markers however you like.
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 3:50 am

I like it! But if you're still planning on doing an importer for the original game shapes, you're going to have to choose a Marker Object mesh yourself, aren't you? People can change it if they like.

If you use linked duplicates, will your exporter find all the copies? And when you do a Make Real, can you choose to use linked duplicates instead of literal dups?
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 4:01 am

I'm not certain if I can use linked duplicates. I'll have to examine the API a bit more.

On an entirely different subject, I think I know how the front, up, and pos vectors map to a transformation matrix... Something like this:

Code: Select all

[[Fx,*x,Ux,Px]
 [Fy,*y,Uy,Py]
 [Fz,*z,Uz,Pz]
 [00,00,00,01]]


The numbers labeled '*' can be calculated with a cross product. The columns might be wrong, but I'm almost certain that this is the general idea.
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Tue May 08, 2007 4:13 am

brice wrote:If you use linked duplicates, will your exporter find all the copies? And when you do a Make Real, can you choose to use linked duplicates instead of literal dups?

... I just tried, and it looks like Make Duplicate Real does make a cluster of linked duplicates. They all follow the edits on any one of them. So if you can access the linked mesh data for all the Objects, then you're home. Just choose some little wireframe for your Marker object and inject a single copy during import. Then link all markers to that one and impose a naming scheme to segregate them during export.


PaladinOfKaos wrote:I'm not certain if I can use linked duplicates. I'll have to examine the API a bit more.

...well your current exporter will export any subset of the cubes after a Make Duplis Real op. Adding vertex colors to one adds to all. So they behave like regular Objects for the BPython API.
PaladinOfKaos
level1
level1
Posts: 40
Joined: Mon May 07, 2007 4:35 pm

Postby PaladinOfKaos » Tue May 08, 2007 4:26 am

I thought you meant linked as in 'not made real'. I'd like to support that, but it would be a lot of work...

In other news, I've got another test build. This should create a mesh that appears exactly as it did before, but with different Front/Up vectors and no swizzling of the vertices. Also, please check that a mesh that isn't centered on the origin doesn't come out in a way wrong location. (translation then rotation versus rotation then translation...)

Code: Select all

#!BPY

# """
# Name: 'Darwinia Shape File (.shp)'
# Blender: 243
# Group: 'Export'
# Tooltip: 'Export to the Shape format used by Darwinia'
# """
__author__ = 'Branan Riley'
__version__ = '0.9'
__email__ = 'branan@gmail.com'
__bpydoc__ = """\
This script exports to the Shape format used by Darwinia.

Every selected object will be exported as a fragment in
the shape file. If an object has a parent, that parent will
be defined as the parent of its fragment. Otherwise, a
fragment will be parented to 'SceneRoot'. Markers are not
yet supported, but it should be pretty easy, once I get
everything else done.


This program is distributed under the GPL. The complete
text of the GPL is availble at http://www.gnu.org/licenses/gpl.txt
"""

import Blender

mesh_objects = []
empty_objects = []

class shp_object:
  def __init__(self):
    self.ParentName='SceneRoot'
    self.Up=0.0,0.0,1.0
    self.Front=1.0,0.0,0.0
    self.Pos=0.0,0.0,0.0
    self.Name='NewDataChunk'
 
  def setParent(self, parent):
    self.ParentName=parent
 
  def setUp(self, x, y, z):
    self.Up=x,y,z
 
  def setFront(self, x, y, z):
    self.Front=x,y,z
 
  def setPos(self, x, y, z):
    self.Pos=x,y,z
 
  def setName(self, name):
    self.Name=name

class shp_fragment(shp_object):
  def __init__(self):
    shp_object.__init__(self)
    self.Positions=[]
    self.Colours=[]
    self.Vertices=[]
    self.Triangles=[]
 
  def addPosition(self, x, y, z):
    if self.Positions.count((x,y,z)) == 0:
      self.Positions.append((x,y,z))
    return self.Positions.index((x,y,z))
 
  def addColour(self, r, g, b):
    if self.Colours.count((r,g,b)) == 0:
      self.Colours.append((r,g,b))
    return self.Colours.index((r,g,b))
 
  def addVertex(self, pos, col):
    if self.Vertices.count((pos,col)) == 0:
      self.Vertices.append((pos,col))
    return self.Vertices.index((pos,col))
 
  def addTriangle(self, pos0, pos1, pos2):
    self.Triangles.append((pos0,pos1,pos2))
 
  def write(self, file):
    file.write('Fragment: '+self.Name+'\n')
   
    file.write('\tParentName: '+self.ParentName+'\n')
   
    s = '\tUp:'
    for i in range(3):
      s = s+' '+str(self.Up[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tFront:'
    for i in range(3):
      s = s+' '+str(self.Front[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPos:'
    for i in range(3):
      s = s+' '+str(self.Pos[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPositions: '+str(len(self.Positions))+'\n'
    file.write(s)
    for i in range(len(self.Positions)):
      s = '\t\t'+str(i)+':'
      for j in range(3):
        s = s+' '+str(self.Positions[i][j])
      s = s+'\n'
      file.write(s)
   
    file.write('\tNormals: 0\n')
   
    s = '\tColours: '+str(len(self.Colours))+'\n'
    file.write(s)
    for i in range(len(self.Colours)):
      s = '\t\t'+str(i)+':'
      for j in range(3):
        s = s+' '+str(self.Colours[i][j])
      s = s+'\n'
      file.write(s)
   
    s = '\tVertices: '+str(len(self.Vertices))+'\n'
    file.write(s)
    for i in range(len(self.Vertices)):
      s = '\t\t'+str(i)+':'
      for j in range(2):
        s = s+' '+str(self.Vertices[i][j])
      s = s+'\n'
      file.write(s)
   
    s = '\tTriangles: '+str(len(self.Triangles))+'\n'
    file.write(s)
    for i in range(len(self.Triangles)):
      s = '\t\t'
      for j in range(2):
        s = s+str(self.Triangles[i][j])+' '
      s = s+str(self.Triangles[i][2])+'\n'
      file.write(s)

class shp_marker(shp_object):
  def __init__(self):
    shp_object.__init__(self)
    self.Depth = 1
 
  def setDepth(self, depth):
    self.Depth = depth
 
  def write(self, file):
    file.write('Marker: '+self.Name+'\n')
   
    file.write('\tParentName'+self.ParentName+'\n')
   
    s = '\tDepth: '+str(self.Depth)+'\n'
    file.write(s)
   
    s = '\tUp:'
    for i in range(3):
      s = s+' '+str(self.Up[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tFront:'
    for i in range(3):
      s = s+' '+str(self.Front[i])
    s = s+'\n'
    file.write(s)
   
    s = '\tPos:'
    for i in range(3):
      s = s+' '+str(self.Pos[i])
    s = s+'\n'
    file.write(s)
   
    file.write('MarkerEnd\n')
 
def getObjects():
  global mesh_objects
 
  selected_obs = Blender.Object.GetSelected()
  for obj in selected_obs:
    type = obj.getType()
    if type == 'Mesh':
      mesh_objects.append(obj)
    elif type == 'Empty':
      empty_objects.append(obj)

def createShpFragment(obj):
  new_shp = shp_fragment()
  new_shp.setName(obj.getName())
  parent = obj.getParent()
  if parent:
    new_shp.setParent(parent.getName())
  matrix = obj.getMatrix('localspace')
  new_shp.setPos(matrix[3][2],matrix[3][0],matrix[3][1])
  msh_name = obj.getData(name_only=True)
  msh = Blender.Mesh.Get(msh_name)
  for f in msh.faces:
    verts=[0,0,0]
    for i in range(3):
      col = new_shp.addColour(f.col[i].r,f.col[i].g,f.col[i].b)
      pos = new_shp.addPosition(f.verts[i].co.z,f.verts[i].co.x,f.verts[i].co.y)
      verts[i]=new_shp.addVertex(pos,col)
    new_shp.addTriangle(verts[0],verts[1],verts[2])
  return new_shp

def countParent(obj,count):
  parent = obj.getParent()
  if parent:
    return countParent(parent, count+1)
  else:
    return count

def createShpMarker(obj):
  new_shp = shp_marker()
  new_shp.setName(obj.getName())
  parent = obj.getParent()
  if parent:
    new_shp.setParent(parent.getName())
  new_shp.setDepth(countParent(obj,1))
  matrix = obj.getMatrix('localspace')
  new_shp.setPos(matrix[3][2],matrix[3][0],matrix[3][1])
  return new_shp

def mainFunc(filename):
  file = open(filename, 'w')
  getObjects()
  shp_fragments = []
  shp_markers = []
  for obj in mesh_objects:
    shp_fragments.append(createShpFragment(obj))
  for obj in empty_objects:
    shp_markers.append(createShpMarker(obj))
  for frag in shp_fragments:
    frag.write(file)
  file.write('\n')
  for mrk in shp_markers:
    mrk.write(file)
  file.close()

fname = Blender.sys.makename(ext='.shp')
Blender.Window.FileSelector(mainFunc, "Export SHP File", fname)


EDIT: Swizzle code finally works! YAY!
Last edited by PaladinOfKaos on Tue May 08, 2007 5:18 am, edited 2 times in total.

Return to “Mod Projects”

Who is online

Users browsing this forum: No registered users and 13 guests