.egg Importer for Blender

I am working on a simple .egg importer for Blender.

Any sugestions are welcome!

More information will come.

I have gotten something working!

It might seem a very strange way of doing it, but I have never written an importer before.

Right now it imports vertexes fine, but has problems with faces. Textures, bones, ect. are not yet supported.

import Blender
Vector = Blender.Mathutils.Vector
import string

#Model path:
inputFile = open('MODEL PATH','r')

fileString = inputFile.read()

mesh = Blender.Mesh.New()

vertexNumber = 0
polygonNumber = 0

filledPolygonList = []

currentVertex = 0

vertexes = {}

vertex = fileString.find('<Vertex> ' + str(vertexNumber))
previousVertex = 0

while fileString.find('<Vertex> ' + str(vertexNumber)) != -1:

    vertexNumber += 1

    previousVertex = vertex

    vertex = fileString.find('<Vertex> ' + str(vertexNumber))

    vertexValue = fileString[previousVertex:vertex]

    vertexValueStart = vertexValue.find('{')
    vertexValueEnd = vertexValue.find('}')

    vertexValue = vertexValue[vertexValueStart+8:vertexValueEnd-5]

    vertexValue = string.split(vertexValue)

    vertexes['vertex '+str(vertexNumber)] = vertexValue


while currentVertex < vertexNumber - 1:

    polygon = [Vector(vertexes.get('vertex ' + str(currentVertex + 1))),Vector(vertexes.get('vertex ' + str(currentVertex + 2))),Vector(vertexes.get('vertex ' + str(currentVertex + 3))),Vector(vertexes.get('vertex '  + str(currentVertex + 4)))]
    filledPolygonList.append(polygon)

    filledPolygon = Blender.Geometry.PolyFill(filledPolygonList)

    mesh.verts.extend(polygon)

    print "Wrote vertex " + str(currentVertex + 1)
    print "Wrote vertex " + str(currentVertex + 2)
    print "Wrote vertex " + str(currentVertex + 3)
    print "Wrote vertex " + str(currentVertex + 4)
    #mesh.faces.extend(filledPolygon)

    currentVertex += 4

scene = Blender.Scene.GetCurrent()
ob = scene.objects.new(mesh)
Blender.Redraw

print "Number of vertexes: " + str(vertexNumber)

print "Done."

Uncomment #mesh.faces.extend(filledPolygon) for experimental face support.

Simply run this code in the Blender script window.

I have a new version, and it supports faces!

(Please note: it only supports faces made of triangles, quads will not work.)

Heres the code:

import Blender
Vector = Blender.Mathutils.Vector
import string

#Model path:
inputFile = open('Model Path','r')

fileString = inputFile.read()

mesh = Blender.Mesh.New()

vertexNumber = 0
faces = []

currentVertex = 0

vertexes = {}

vertex = fileString.find('<Vertex> ' + str(vertexNumber))
previousVertex = 0

while fileString.find('<Vertex> ' + str(vertexNumber)) != -1:

    vertexNumber += 1

    previousVertex = vertex

    vertex = fileString.find('<Vertex> ' + str(vertexNumber))

    vertexValue = fileString[previousVertex:vertex]

    vertexValueStart = vertexValue.find('{')
    vertexValueEnd = vertexValue.find('}')

    vertexValue = vertexValue[vertexValueStart+8:vertexValueEnd-5]

    vertexValue = string.split(vertexValue)

    vertexes['vertex '+str(vertexNumber)] = vertexValue


while currentVertex < vertexNumber - 1:

    polygon = [Vector(vertexes.get('vertex ' + str(currentVertex + 1))),Vector(vertexes.get('vertex ' + str(currentVertex + 2))),Vector(vertexes.get('vertex ' + str(currentVertex + 3)))]

    mesh.verts.extend(polygon)

    faces.append([currentVertex,currentVertex+1,currentVertex+2])

    print "Wrote vertex " + str(currentVertex + 1)
    print "Wrote vertex " + str(currentVertex + 2)
    print "Wrote vertex " + str(currentVertex + 3)

    currentVertex += 3

mesh.faces.extend(faces)

scene = Blender.Scene.GetCurrent()
ob = scene.objects.new(mesh)
Blender.Redraw

print "Number of vertexes: " + str(vertexNumber)

print "Done."

If anyone can test this out and let me know how it worked for you that would be perfect.

Im too stupid to start the script. - how do i do that?

Here how to get it working:

First replace ‘Model Path’ with the path of your model.

Then open Blender and go to the Text Editor window. Paste the code into the Text Editor and go to Text>Run Python Script. (Or just press ALT+P)

If everything goes correctly, when you switch back to the 3D window you will see the model!

could you indicate the appropriate indentations?

Thanks!

Should be fixed now, though I no longer support this.

Do what you wish with it.