Page 2 of 2

Re: dino and aliens msh files

Posted: Wed Aug 29, 2012 8:57 am
by finale00
Just print out the index you're trying to get and the size of your list...
Maybe you're just parsing the file wrong.

Re: dino and aliens msh files

Posted: Wed Aug 29, 2012 11:47 am
by Bogus
this how shakotay2 imported texture coordinates?

for ms3d files is yes:

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])]
as it will be for .msh files?
just do not know how to write it in a script

Re: dino and aliens msh files

Posted: Thu Aug 30, 2012 9:33 am
by shakotay2
1) did you integrate some debugging lines into your script like recommended by finale00?

2) I'm not very familiar with python script but I made some changes to your script
(including some "print" commands for a debug output to the blender console).

Tested box.msh: 4 of the 6 textured sides of the cube are ok, two are not.

Don't have more time to solve this but I think you should do it. :wink:

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')


Re: dino and aliens msh files

Posted: Thu Aug 30, 2012 11:01 am
by Bogus
thanks it works
can in this way i will be know how to do
animation can for the time being leave
but topic yet not closed

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 6:29 am
by Bogus
whether this possible that at the beginning msh files is bone?
because i know that fruits rotate

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 9:39 am
by shakotay2
Bogus wrote:whether this possible that at the beginning msh files is bone?
I don't think so;
could you please give an example?

You can find strings like "Bip01", "Spine", "L ForeArm", "R Foot" etc. in the *.skl files.

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 11:00 am
by Bogus
ananas.msh, yabloko_0,25.msh, yabloko_0,5.msh and yabloko_1.msh
the characters are also animated, but are in skl files
i do not know where they are vertices and faces a little i was looking for
script can alone write

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 11:41 am
by shakotay2
The structure of ananas.msh looks like this:

# 120 vertices
# 1. 0x25:
v 0.353530 0.739885 2.152248
v 0.641311 0.889165 3.350888
v 1.046994 0.941949 4.351346
...
v -1.456776 0.804483 -3.482513
v -0.897434 1.574350 -3.482513
v 0.007599 1.868413 -3.482513
v 0.007599 0.328678 -3.888980

# 591 face Indices (197 faces)
# 2. 0x5c5:
f 48 57 56
f 58 57 49
f 49 59 58
...
f 80 81 95
f 97 90 82
f 81 82 90
# (vertex related) face index min/max: 1 / 120
# texture related face indices: 1..591 (not in the file)

# Texture coords
# 0xf01
vt 0.676453 0.304822
vt 0.469777 0.162897
vt 0.677072 0.072721
...
vt 0.620055 0.368678
vt 0.452570 0.264222
vt 0.676453 0.304822

# last address= 0x2178

File size is 0x2179;
so no animation/skinning related data in there.

Same with yabloko_1.msh.

The fruits are rotating only?
This doesn't require an animation file; perhaps they're just changing
the angle of the fruits via its rotation matrix .

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 12:01 pm
by Bogus
this how it is that oneself rotate?
this i know because alone I started to write the script
I'm talking about this this what marked:
Image

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 12:16 pm
by shakotay2
There is only one way to prove this: you'll have to change some bytes (the 0x80 for example)
and look whether the rotation of the corresponding fruits slows down or accelerates.

(I would be surprised - but you know: "you never know..." :D )

And you'll have to repack the *.msh to a *.dat file again, I think.

(Didn't try this so far; so don't know whether it works.)

Re: dino and aliens msh files

Posted: Sat Sep 01, 2012 12:40 pm
by Bogus
quite nice joke
i do not know whether in this way not spoil the game
edit:
I think nothing has changed at the same speed of a rotate