Re: dino and aliens msh files
Posted: Wed Aug 29, 2012 8:57 am
Just print out the index you're trying to get and the size of your list...
Maybe you're just parsing the file wrong.
Maybe you're just parsing the file wrong.
Code: Select all
# read triangles
faces = []
uvs = []
for i in xrange(numTriangles):
# skip flags
file.read(2)
# read indices (faces)
faces.append(struct.unpack("HHH", file.read(3*2)))
# read normals
normals = struct.unpack("fffffffff", file.read(3*3*4))
# read texture coordinates
s = struct.unpack("fff", file.read(3*4))
t = struct.unpack("fff", file.read(3*4))
# store texture coordinates
uvs.append([[s[0], 1-t[0]], [s[1], 1-t[1]], [s[2], 1-t[2]]])
if faces[-1][2] == 0: # Cant have zero at the third index
faces[-1] = faces[-1][1], faces[-1][2], faces[-1][0]
uvs[-1] = uvs[-1][1], uvs[-1][2], uvs[-1][0]
# skip smooth group
file.read(1)
# skip group
file.read(1)
# add the faces to the mesh
mesh.faces.extend(faces)
# set texture coordinates
for i in xrange(numTriangles):
mesh.faces[i].uv = [Vector(uvs[i][0]), Vector(uvs[i][1]), Vector(uvs[i][2])]
Code: Select all
#!BPY
"""
Name: 'Dino and Aliens2 (.msh)...'
Blender: 249
Group: 'Import'
"""
__author= "Boguslaw Radomski"
__version__= "0.01"
__bpydoc__ = """\
Dino and Aliens msh importer by Boguslaw Radomski
This script imports a Dino and Aliens msh files to Blender.
Note, This loads mesh objects only, materials and animations are not supported yet.
I do not know how to read material from a file and add support to Blender.
"""
# ***** GPL LICENSE *****
#
# 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,
#
# --------------------------------------------------------------------------
# importing modules
import Blender
import struct
from Blender.Mathutils import Vector
# imports a msh file to the current scene
def load_msh(filename):
# get scene
scn = Blender.Scene.GetCurrent()
if scn == None:
return "No scene to import to!"
Blender.Window.WaitCursor(1)
# open the file
file = open(filename, 'rb')
# read id to check if the file is a dino and aliens msh file
id = file.read(3)
if id != 'MSH':
print 'this is not MSH file'
return
file.seek(29,0)
# Create the mesh
scn.objects.selected = []
mesh = Blender.Mesh.New("name")
meshOb = scn.objects.new(mesh)
# read the number of vertices
numVerts = struct.unpack('L', file.read(4))[0]
# read number of triangles
numTriangles = struct.unpack('L', file.read(4))[0]
# read vertices
verts = []
for i in xrange(numVerts):
verts.append(struct.unpack('fff', file.read(3*4)))
# add the vertices to the mesh
mesh.verts.extend(verts)
# read triangles
faces = []
for i in xrange(numTriangles):
# read indices (faces)
faces.append(struct.unpack('iii', file.read(3*4)))
# add the faces to the mesh
mesh.faces.extend(faces)
#--- shakotay2 start ----------------------------
uvs = []
# read texture coordinates
for i in xrange(numTriangles):
s = struct.unpack("ff", file.read(2*4))
t = struct.unpack("ff", file.read(2*4))
u = struct.unpack("ff", file.read(2*4))
print s
print t
print u
print '\n'
# store texture coordinates
uvs.append([[s[0], s[1]], [t[0], t[1]], [u[0], u[1]]])
# set texture coordinates
for i in xrange(numTriangles):
mesh.faces[i].uv = [Vector(uvs[i][0]), Vector(uvs[i][1]), Vector(uvs[i][2])]
print i
print Vector(uvs[i][0])
print Vector(uvs[i][1])
print Vector(uvs[i][2])
print '\n'
#--- shakotay2 end ---------------------------------
Blender.Window.WaitCursor(0)
# refresh the view
Blender.Redraw()
# close the file
file.close()
Blender.Window.FileSelector(load_msh, 'import msh', '*.msh')
I don't think so;Bogus wrote:whether this possible that at the beginning msh files is bone?