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 » Fri Jun 15, 2007 4:56 pm

Hi Maggy, you seem to be a little lost. I'm guessing google brought you here with some keywords. You do realize, I hope, that this is a forum for discussing mods for a computer video game? Have you played Darwinia? You didn't mention it once in your post.

The only reason any of us have tinkered with 3D file formats here is because we want to import or export 3D models into or out of Darwinia -- so we can play more games. It would be great if some of our efforts were to help you, but I'm sure this isn't the best place for you to be seeking help.

If you're fishing to find someone to do some paid programming for you, you should state that up front. There probably are a few regulars here who could do it (not me). But so far you've just listed lots of "good news, bad news" and left us (at least me) kinda confused just what you're after. I mean, these "news" are only "good & bad" for you. Where do we fit in again?

Sorry if this comes across harsh,

-brice
Maggy
level0
Posts: 6
Joined: Fri Jun 15, 2007 3:50 pm

Postby Maggy » Fri Jun 15, 2007 6:52 pm

You are not too harsh. I do know that and that's why I started my first post with
Please forgive me for being a little off topic
.

I wish I could pay a good programmer or better a team of specialists. I have lots of ideas but no money.

The Dassault 3D printscreen utility is probably a very good method to export 3D models from Darwinia as long as Darwinia uses DirectX or OpenGL.
The same 3Dprintscreen utility is probably also a great way to collect models from almost any other source and use them in Darwinia.
Just that one missing link, Darwinia doesn't read 3DXML. THAT is where you fit in. If, just IF you'd want to look into it.

I'm not ordering anything, I'm kindly asking and I honestly do honestly believe that this community can benefit as much as me from a 3DXML converter.
All I can do now is hope that one of these "few regulars" agrees with me.

BTW, the reason that I wrote in this forum, in this thread:
I googled all day, I found several forums with several people discussing 3DXML and the wish to be able to convert it. I didn't find however any other forum where people discussed 3D conversion, especially triangle strips, in so much detail.
I do believe that there would be a niche for a shareware 3DXML converter. If it was available for a reasonable price I would have bought it and so would probably a lot of other 3d printscreen users. And of course I'm still willing to pay for it. I'm just not able to hire a private programmer.
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Fri Jun 15, 2007 10:32 pm

Maggy wrote:The Dassault 3D printscreen utility is probably a very good method to EXPORT 3D models from Darwinia as long as Darwinia uses DirectX or OpenGL.


Darwinia does target OpenGL... but I'm still guessing you haven't played the game. Models in Darwinia are very low poly. Getting model info OUT of Darwinia is less of an issue than getting them in. A text editor and a little determination can get you the coordinate list for *any* Darwinia model since the models are already in text files. Then a little time is all that's needed to rebuild the model in Blender or any other modelling package.

People on this forum care more about IMPORTing INTO Darwinia. The current Blender exporter from PaladinOfKaos allows just that, and with only a few hassles (mandatory vertex painting, learning Blender, etc.)

I'm pointing this out 'cause it still seems like you're in the wrong forum... IMHO, you will have better luck in the Blender forums. In any case, you have yet to make it clear what you actually want to do with an 3DXML converter. You obviously aren't interested in Darwinia, at least not as a modder.
Maggy
level0
Posts: 6
Joined: Fri Jun 15, 2007 3:50 pm

Postby Maggy » Mon Jun 18, 2007 2:06 pm

I'm not at all a gamer, nor did I ever try to give that impression. I really do not know anything at all about Darwinia.

The 3D printscreen software from Dassault CAN indeed help you to IMPORT models from ANY other software that uses OpenGL or DirectX.
Lots of software. especially games, have either the models they use stored in some proprietary binary format or generate their 3D graphics on the fly.
As far as I know Blender is not capable to capture such models. 3D printscreen is.

Coincidentally I AM only interested in low poly, Sketchup and Google Earth to be precise.

NVidia has a freeware high poly to low poly utility called Melody.
http://developer.nvidia.com/object/melody_home.html
User avatar
KingAl
level5
level5
Posts: 4138
Joined: Sun Sep 10, 2006 7:42 am

Postby KingAl » Mon Jun 18, 2007 2:09 pm

Unless I'm misunderstanding you, I think you're missing brice's point:

The difficulty is not importing models into 3D programs from Darwinia, but importing models into Darwinia from 3D programs. The term 'import' can be used (with varying validity) in both cases, which is where some of the misunderstanding probably stems from.

That is, we don't need existing models, we're trying to create new ones.
Gentlemen, you can't fight in here: this is the War Room!
Ultimate Uplink Guide
Latest Patch
Maggy
level0
Posts: 6
Joined: Fri Jun 15, 2007 3:50 pm

Postby Maggy » Mon Jun 18, 2007 3:11 pm

I'm talking about importing into Darwinia as well:

1. SEE any model in any other program
2. use 3D printscreen to capture it
3. use the not yet existing conversion to turn the capture into an editable format
4. if it's high poly, use melody or any other method to turn it into low poly
5. edit it till you like it
6. import it into Darwinia

or import it into Sketchup, that's what I personally want. That's not a crime, is it?
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Mon Jun 18, 2007 7:27 pm

Maggy wrote:or import it into Sketchup, that's what I personally want. That's not a crime, is it?


Nope, certainly not, and no one here is persecuting you, certainly not me. Nice of you to finally tell us what you're really after. I still think you're in the wrong forum, but that's just my opinion, and who knows, maybe I'm wrong. I wish you the best of luck.

-brice
Maggy
level0
Posts: 6
Joined: Fri Jun 15, 2007 3:50 pm

Postby Maggy » Tue Jun 19, 2007 7:14 am

c'mon, in my first post I said:
All I want is a way to capture shapes and import them into Sketchup.


And I did apologise twice for being off topic and in the wrong forum.
User avatar
Levi
level1
level1
Posts: 17
Joined: Fri Jun 08, 2007 6:14 am
Contact:

Postby Levi » Tue Jun 19, 2007 10:32 pm

Sheesh.
infowars.com
User avatar
Lowell
level3
level3
Posts: 428
Joined: Mon Jan 02, 2006 8:03 pm
Location: Atlanta, Georgia
Contact:

Postby Lowell » Wed Jun 20, 2007 5:56 pm

Sooo...if I use 3D Printscreen for capture and mesh, Melody from high to low, then Sketchup....will sketchup export in .SHP format? Darwinia also uses a stripped down version of the shp format...we have been using perl to convert in the past.

I mean I have a ton of 3D art programs that I can make models in...that's no biggie...what I want is a simple method of export of my models into the games format.
...current project is an oil tanker, cruise ship and large container ship for a train game...the trains have to offload and load at terminals next to the models...aside from Darwinia I have five mods running... This model is "flattened" with a UVW unwrap. then turned into DIFF.DDS, EMSK.DDS, NORM.DDS, SPEC.DDS, plus make the NIF and KFM files. Then you get a super detailed sort-of higher poly model in game. Just a tad too much for ole Darwinia...


Image

I'll try using the set of apps you mentioned and see what happens...I have four models for The_Particles that I need to finish.
brice
level2
level2
Posts: 167
Joined: Fri Feb 23, 2007 6:04 am

Postby brice » Wed Jun 20, 2007 7:22 pm

Not to rain on anyone's parade, but I can't see how anyone can get models "into" Darwinia without a dedicated .shp file exporter. Maybe some of these "printscreen" utilities can reach into the OpenGL pipeline and rip the 3D data for models... and maybe, just maybe, they can do the reverse and stuff models back into a *running* copy of Darwinia... I'll believe it when I see it... BUT just remember that Darwinia does not write it's own shape file format. Repeat: even if you can stuff the model into the OpenGL session, there is no way to make Darwinia write it out to a .shp file. Therefore your effort is wasted in the long run since Darwinia only loads models from .shp text files. It's a one way street.

If you already have models, you are better off trying to import them into Blender, and then using PaladinOfKaos' .shp exporter. Blender imports lots of popular formats. The exporter may mangle your shadings becuase Darwinia expects flat shading, but you can always learn enough Blender to re-paint the model in Face Paint Mode. In that mode, Blender coloring is WYSIWYG for Darwinia exports. Blender runs on any OS and is free, so it'll only cost you your time to try it. And PaladinOfKaos' exporter works like a charm as long as the model is fully painted (no unpainted vertices). One click export to .shp ... I've done it dozens and dozens of times and never had any problems. The latest version is stickied in this forum and instructions are in this thread. Someday we'll make a real tutorial for the DL thread. If you have problems, post here and I'll try to help.
Maggy
level0
Posts: 6
Joined: Fri Jun 15, 2007 3:50 pm

Postby Maggy » Wed Jun 20, 2007 9:31 pm

3D Printscreen writes 3DXML. And unfortunately there is currently no program, neither freeware, nor shareware, nor commercial that is able to convert these files. That's why I came here in the first place.

So no, Melody is not yet able to read 3Dprintscreens.

Sketchup does not write .SHP but .SKP, although the extensions look more or less alike, they are not related. But Sketchup does import and export common formats like .DXF, .3DS and .OBJ. As far as I know Blender is capable of importing these common formats.
User avatar
Lowell
level3
level3
Posts: 428
Joined: Mon Jan 02, 2006 8:03 pm
Location: Atlanta, Georgia
Contact:

Postby Lowell » Fri Jun 22, 2007 8:54 pm

You mean Google's Sketchup version6? 3Dxml is back from 2005...I thought that was used mostly for web applications. Canoma will do a better job of pulling 3d buildings from screenshots.
revcompgeek+
level1
level1
Posts: 11
Joined: Sat Oct 13, 2007 1:57 am

Postby revcompgeek+ » Thu Nov 22, 2007 8:08 am

I have decided to work on a SHP importer for Blender. I am pretty fluent in Python, and I have been playing around with Blender for a while, and looking through the other import/export scripts for it, it doesn't seem like it should be that hard.
revcompgeek+
level1
level1
Posts: 11
Joined: Sat Oct 13, 2007 1:57 am

Postby revcompgeek+ » Thu Nov 22, 2007 10:00 am

Ok, I have fixed a lot of the problems, and it loads a few shapes ok (armour), and all the parents are created correctly.
TODO:
Fix a couple of triangle problems (look at incubator.shp)
Add color support. (There is code that is supposed to work in shp_fragment.create, but it crashes Blender)
Test thoroughly.

Code: Select all

#!BPY

# """
# Name: 'Darwinia Shape File (.shp)'
# Blender: 243
# Group: 'Import'
# Tooltip: 'Import from the Shape format used by Darwinia'
# """
__author__ = 'Matt Peterson'
__version__ = '0.2'
__email__ = 'revcompgeek@gmail.com'
__bpydoc__ = """\
This script imports from the Shape format used by Darwinia.

This is the first version of the Darwinia importer. It will
probably have many bugs in it.

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,sys,re
from string import *

class CorruptedFileException(Exception):
   def __init__(self,value):
      self.parameter=value
   def __str__(self):
      return repr(self.parameter)

def corruptionCheck(value, exceptionString):
   if not value:
      raise CorruptedFileException(exceptionString)

def mysplit(temp,delim=""):
   if temp == "":
      return []
   if delim != "":
      l=split(temp,delim)
   else:
      l=split(temp)
   return l


eof = 0

def readlinene(file):
   line = file.readline()
   while line == "\n":
      line = file.readline()
   if len(line) == 0:
      eof = 1
   return line

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 create(self):
      print "Creating fragment %s..." % self.Name
      scn = Blender.Scene.GetCurrent()
      e = Blender.Mesh.New(self.Name)
   
      vertslist = []
      for i in range(len(self.Vertices)):
         vertslist.append(self.Positions[self.Vertices[i][0]])
      e.verts.extend(vertslist)
      e.faces.extend(self.Triangles)
   
#   print self.Vertices
   
   #e.addColorLayer()
   
#   for i in range(len(self.Triangles)):
#      for x in range(3):
#         e.faces[i].col[x].r, e.faces[i].col[x].g, e.faces[i].col[x].b = self.Colours[self.Vertices[i*3+x][1]]
      
      p=""
      if lower(self.ParentName) != "sceneroot":
         p = self.ParentName
      
      for ob in scn.objects:
         ob.sel=0
      
      o = Blender.Object.New("Mesh", self.Name)
      
      m = o.getMatrix('localspace')
      m[3][0] = self.Pos[0]
      m[3][1] = self.Pos[1]
      m[3][2] = self.Pos[2]
      
#      m[1][0] = self.Front[0]
#      m[1][1] = self.Front[1]
#      m[1][2] = self.Front[2]
      
      m[2][0] = self.Up[0]
      m[2][1] = self.Up[1]
      m[2][2] = self.Up[2]
      o.setMatrix(m)
      
      o.link(e)
      scn.objects.link(o)
      
      return o,p

def readFragment(file):
   frag = shp_fragment()
   data = mysplit(readlinene(file)) # Fragment: name
   corruptionCheck(lower(data[0]) == "fragment:", "First line of fragment does not start with 'Fragment:'")
   frag.Name = data[1]
   
   data = mysplit(readlinene(file)) # ParentName: parentname
   corruptionCheck(lower(data[0]) == "parentname:", "Second line of fragment does not start with 'ParentName:'")
   frag.ParentName = data[1]
   
   line = readlinene(file)
   data = mysplit(line)
   type = lower(data[0])
   data = data[1:]
   while type != "fragment:" and type != "marker:" and eof == 0:
      if type == "up:":
         frag.setUp(-float(data[0]),float(data[2]),float(data[1]))
      if type == "front:":
         frag.setFront(-float(data[0]),float(data[2]),float(data[1]))
      if type == "pos:":
         frag.setPos(-float(data[0]),float(data[2]),float(data[1]))
      if type == "positions:":
         for i in range(int(data[0])):
            n,x,y,z = mysplit(readlinene(file))
            frag.addPosition(-float(x),float(z),float(y))
      if type == "normals:":
         pass # not used
      if type == "colours:":
         for i in range(int(data[0])):
            n,r,g,b = mysplit(readlinene(file))
            frag.Colours.append([int(r),int(g),int(b)])
      if type == "vertices:":
         for i in range(int(data[0])):
            n,p,c = mysplit(readlinene(file))
            frag.addVertex(int(p),int(c))
      if type == "triangles:":
         buf = []
         total = int(data[0])
         while len(buf) < total:
            data = mysplit(readlinene(file),",")
            buf = buf + data
         buf = map(int,buf)
         while len(buf) > 2:
            frag.addTriangle(buf[0],buf[1],buf[2])
            buf = buf[3:]
      
      if type == "strips:":
         numStrips = int(data[0])
         for num in range(numStrips):
            data = mysplit(readlinene(file))
            corruptionCheck(lower(data[0]) == "strip:", "Line after Strips is not Strip")
            data = mysplit(readlinene(file))
            if lower(data[0]) == "material:":
               data = mysplit(readlinene(file))
            corruptionCheck(lower(data[0]) == "verts:", "Verts not in strip")
            numverts = int(data[1])
            vertslist = []
            p = re.compile(r'[\s,.]*v(?=\d+)')
            line = readlinene(file)
            while p.match(line):
               l = p.split(line)
               vertslist += l[1:]
               line = readlinene(file)
            file.seek(-len(line), 1)
            if len(vertslist) != numverts:
               print "Warning: The number after Verts: does not match the number of vertices. The actual number of vertices is %i" % numverts
            vertslist = map(int, vertslist)
            reverse = 0
            while len(vertslist) > 2:
               if reverse:
                  frag.addTriangle(vertslist[0],vertslist[1],vertslist[2])
               else:
                  frag.addTriangle(vertslist[2],vertslist[1],vertslist[0])
               reverse = not reverse
               vertslist = vertslist[1:]
               
      line = readlinene(file)
      data = mysplit(line)
      if len(data) > 0:
         type = lower(data[0])
         data = data[1:]
      else:
         break
      
   if not eof:
      file.seek(-len(line),1)
   return frag

class shp_marker(shp_object):
   def __init__(self):
      shp_object.__init__(self)
      self.Depth = 1
   
   def setDepth(self, depth):
      self.Depth = depth
   
   def create(self):
      print "Creating marker %s..." % self.Name
      scn = Blender.Scene.GetCurrent()
      e = Blender.Object.New('Empty',self.Name)
      
      m = e.getMatrix('localspace')
      m[3][0] = self.Pos[0]
      m[3][1] = self.Pos[1]
      m[3][2] = self.Pos[2]
      
      m[1][0] = self.Front[0]
      m[1][1] = self.Front[1]
      m[1][2] = self.Front[2]
      
      m[2][0] = self.Up[0]
      m[2][1] = self.Up[1]
      m[2][2] = self.Up[2]
      e.setMatrix(m)
      
      p=""
      if lower(self.ParentName) != "sceneroot":
         p = self.ParentName
      
      for ob in scn.objects:
         ob.sel=0
      
      scn.objects.link(e)
      
      return e,p
   
def readMarker(file):
   mark = shp_marker()
   data = mysplit(readlinene(file))
   mark.Name = data[1]
#   print mark.Name
   data = mysplit(readlinene(file))
   mark.ParentName = data[1]
#   print mark.ParentName
   
   line = readlinene(file)
   data = mysplit(line)
   type = lower(data[0])
   data = data[1:]
   while type != "markerend" and type != "fragment:" and type != "marker:" and eof == 0:
      if type == "depth:": # Not needed
#         mark.setDepth(int(data[0]))
         pass
      if type == "up:":
         mark.setUp(-float(data[0]),float(data[2]),float(data[1]))
      if type == "front:":
         mark.setFront(-float(data[0]),float(data[2]),float(data[1]))
      if type == "pos:":
         mark.setPos(-float(data[0]),float(data[2]),float(data[1]))
      line = readlinene(file)
      data = mysplit(line)
      type = lower(data[0])
      data = data[1:]
   if type != "markerend":
      print "Warning: Marker %s does not have an ending MarkerEnd" % mark.Name
   return mark

def read(filename):
   fragments = {}
   markers = {}
   objects = {}
   parents = {}
#   corrupted = 0
   
   Blender.Window.WaitCursor(1)
   file = open(filename, "rU")
   
   start = Blender.sys.time()
   
   try:
      line = readlinene(file)
      #print line
      data = mysplit(line)
      type = lower(data[0])
      data = data[1:]
      while eof == 0 or type == "":
         if lower(type) == "fragment:":
            file.seek(0-len(line),1)
            print "Read fragment: %s" % data[0]
            frag = readFragment(file)
            print "Done"
            fragments[frag.Name] = frag
         if lower(type) == "marker:":
            file.seek(0-len(line),1)
            print "Read marker: %s" % data[0]
            mark = readMarker(file)
            print "Done"
            markers[mark.Name] = mark
         line = readlinene(file)
         data = mysplit(line)
         if len(data) > 0:
            type = lower(data[0])
            data = data[1:]
         else:
            break
   except CorruptedFileException, e:
      print "File corrupted: %s" % str(e)
      return
   finally:
      file.close()
   
   
   print "Creating fragments..."
   for obj in fragments.values():
      o,p = obj.create()
      objects[obj.Name] = o
      if p != "":
         if not parents.has_key(p):
            parents[p] = []
         parents[p].append(o)
   print "Done"
   
   print "Creating markers..."
   for obj in markers.values():
      o,p = obj.create()
      objects[obj.Name] = o
      if p != "":
         if not parents.has_key(p):
            parents[p] = []
         parents[p].append(o)
   print "Done"
   
   print "Making parents..."
   for objs in parents:
      print "%s: %s" % (objs, parents[objs])
      objects[objs].makeParent(parents[objs])
   print "Done"
   
   print "Imported SHP file in %.4f seconds." % (Blender.sys.time()-start)
   
   sys.stdout.flush()
   
   Blender.Window.WaitCursor(0)
   Blender.Window.RedrawAll()

Blender.Window.FileSelector(read, 'Import SHP file', "*.shp")
Last edited by revcompgeek+ on Fri Nov 23, 2007 9:02 am, edited 1 time in total.

Return to “Mod Projects”

Who is online

Users browsing this forum: No registered users and 6 guests