Topic: Blender to .mod scripts are there any working?  (Read 32998 times)

0 Members and 1 Guest are viewing this topic.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #160 on: November 11, 2010, 02:26:56 pm »
could be why you choked on the materials with some of the blocks missing.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #161 on: November 11, 2010, 02:27:42 pm »
xactly my suspicion too! :)

Gonna take a little break and watch some TV. Pretty good progress today (for me).

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #162 on: November 11, 2010, 02:29:36 pm »
Alright - assume that the model above is the Control. I'll make as few changes from that at a time - give me five minutes and I'll have a Non-Texture version and a version with Hardpoints/DamagePoints. I've NEVER used LODs before, so I feel a little bit of trepidation, but I'll post the LOD settings when I make it.

EDIT: if you are hung on the materials and want to tackle the Hardpoints/Damagepoints without the material, I'll make the double-change version, too.
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #163 on: November 11, 2010, 02:32:35 pm »
No hurry, take your time and get it right (working out the LODs, and the other variations) As we have stock models with LODs to work from. I'm gonna take a bit of a break right now anyway as I've been at it all day.

Your initial model may be too simple (too few faces?) to be reduced to 4 additional LODs? (not really sure, did not look close enough to see...)

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #164 on: November 11, 2010, 02:34:28 pm »
 ;D ;D my script reads in the cube, but have to work on textures yet.  That is where I got stopped before.  With the 3DS one, should be able to work on that some.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #165 on: November 11, 2010, 02:44:35 pm »
Version 2 Includes the following

 - Control.mod (basic features)
 - NoTex.mod (stripped of material)
 - hardpoint.mod (has basic Hardpoints and damagepoints)
 - NoTexHardpoint.mod (has basic hardpoints and damagepoints; no material)
 - Information.txt (has an outline of what I've guessed as being relevant information about the file)
 - UVChecker.bmp (The bitmap file used)
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #166 on: November 11, 2010, 02:47:19 pm »
Not sure what you mean about the reduction to LODs, Bonk. There is only 1 LOD included in the model - can the script handle less than 3 LODs?
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #167 on: November 11, 2010, 04:07:47 pm »
Pretty sure the maximum # of LODs in the mod file are 5. Ideally one of the sample models would have 5 meshes in it of decreasing complexity (LODs). The script, when complete will be able to handle from 1-5. (thanks again...)

(in case anyone is wondering LOD = Level Of Detail)

Offline Tus-XC

  • Capt
  • XenoCorp® Member
  • Commander
  • *
  • Posts: 2782
  • Gender: Male
Re: Blender to .mod scripts are there any working?
« Reply #168 on: November 11, 2010, 05:41:45 pm »
modelname_1, modelname_2, modelname_3, etc. for LODs.  there doesn't actually have to be anything different really between the models, the exporter from what i can surmise doesn't care only that things are properly named

edit: well you have to select that option.  the exporter has the option to check level of detail... but i wouldn't go that route ever.  Also i went ahead and modified FoaS base model and added 5 LOD (base model + 4 other levels).  Each level is exactly the same as the base model.
Rob

"Elige Sortem Tuam"

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #169 on: November 11, 2010, 07:46:52 pm »
Thanks Tus,

Did you happen to document the numbers you used on the LODs?, distances, etc?
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Tus-XC

  • Capt
  • XenoCorp® Member
  • Commander
  • *
  • Posts: 2782
  • Gender: Male
Re: Blender to .mod scripts are there any working?
« Reply #170 on: November 11, 2010, 08:44:36 pm »
i used the default settings, which are

5LOD_1: 0
5LOD_2: 100
5LOD_3: 200
5LOD_4: 300
5LOD_5: 400
« Last Edit: November 11, 2010, 08:59:23 pm by Tus-XC »
Rob

"Elige Sortem Tuam"

Offline Kreeargh

  • Retired.
  • Lt. Commander
  • *
  • Posts: 1476
  • Gender: Male
  • Life is as is worth only what you learn from it!
Re: Blender to .mod scripts are there any working?
« Reply #171 on: November 11, 2010, 09:46:03 pm »
Damn its not dead yet JIM   ;D  :thumbsup:
I wish i could help but i am worthless. Modeling is just a hobby to me. Here is some way to late and out of date most likey not true info that im sure you already know by now but i will share anyway. LODs {Level of detail models}  The max/ gmax exporter can do 5 or more but the game engine uses 3.  I am not sure thats true but from what the stock models show its 3. The models are seperate meshes that use 1 set of hardpoints for all 3meshes. So for the cube test use 3 cubes each cube a higher poly than the next.
 I belive for the lod system to work each model must be a single object either attached seperate parts or a welded hollow mesh i think a groupe lock would work also but i never botherd to try that. I wish all my models to open in m6/sfced editor so my ways are not normal. :crazy2: I have exported a model i forgot to weld the mesh after maping. That model showed atleast 5 mesh parts in m6sfced but in the game engine only 3 showed up from the LOD system. I think the 0 :100 200 300 400 500 thingy is for the scale system frigets might use the closer setings larger ships span the distance more ie for a frig use 0 100 and 300 for the 3 meshes but thats my guess i have always exported the default for the 5 designs i have botherd to make lods for cause i didnt care at the time. The model should be maped by a seperate lower rez texture set fit for the lower poly model or the game engine may show lag in multiplayer play.   Im sure this is a WOP waist of post but i try to help  :angel:
Time for life!

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #172 on: November 12, 2010, 07:00:26 am »
I know... look what you (re)started Kreeargh!  ;D  and your input is still useful. Got me thinking... this script wil handle five (or 500...) but if all we ever use normally (and if that is all the game uses) is 3 then that is fine... I can add those restrictions and settings as we firmly establish them.

That will do Tus, thanks for the effort! :thumbsup:  (though ideally, each LOD should have fewer polys for a "standard" sample model)
... aha the 5 tansitions were the max3 exporter defaults... thought so.

... a little shopping then I'm back at this. All these test models will definitely help the process. I suspect marstone may be updating his 2.49 importer while I work out the start of my 2.5 importer. Either way, one way or another we will have a working import soon. I'm not far off and neither is marstone.

I'm starting to think the export may not be so difficult since we have worked out so much already.

It occurs to me that we'll have to watch what happens to the rather large library of SFC models when this importer is complete. Would we want to add some kind of model "watermarker" or "brander" as I've previously discussed with DarkDrone? Or just stick to our mostly working honour system?   ... bah - scratch the watermarking idea... fraught with issues and complications... pretty much have to leave it up to the individual modeler...

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #173 on: November 13, 2010, 07:31:58 pm »
Thanks again for the test models guys, helped bunches. I've got all the data in correctly for all the test cases. Or as Jim would say... "Is everybody in? The ceremony is about to begin..."

I might get serious on this tonight and try and get the models built. That should be the fun part. Another look at marstone's blender 2.4 version should help. (and the stock lwo and 3ds imports...)

the data import (may need tidying up as I build the model... its simple enough not to need its own classes and object oriented design... I think I can get away with a one, two procedural punch for this task):
Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "The universe may implode at any moment.",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
# import array

import bpy
import math
import mathutils

def decodeAsc(byteStr):
    print (byteStr.decode("ascii"))

def import_mod(filename,context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    if modHdrTag != b'MDLS':
        print("Error parsing file header. Boo!")
        file.close()
        return   
   
    modMeshesParsed = 0
    modMeshes = list()
   
    while modMeshesParsed < modHdrTotalLODs:
       
        modChnkTag, \
        modChnkSize \
        = struct.unpack("<4si", file.read(8))
       
        # Strings
        if modChnkTag == b'STRS':
            modStrSizePadded = 4*(math.ceil(modChnkSize/4))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modStrSizePadded: %d" % modStrSizePadded)
            modStrPool \
            = struct.unpack("<%ds" % modStrSizePadded, file.read(modStrSizePadded))
            modStrStrings = modStrPool[0].split(b'\x00')
            modStrList = [x.decode("ascii") for x in modStrStrings]
            print ("modStrList: ")
            print (modStrList)
       
        # Named Points
        elif modChnkTag == b'PNTS':
            modPtsStart = file.tell()
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modPtsNum = modChnkSize / 16
            print ("modPtsNum: %d" % modPtsNum)
            modPts = list()
            while (file.tell() - modPtsStart < modChnkSize):
                modPts.append(struct.unpack("<fffi", file.read(16)))
            print ("(last)modPts:")
            print (modPts[-1])
       
        # Materials (aieee!)
        elif modChnkTag == b'MATS':
            modMtsStart = file.tell()   
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modMtsFlags = list()
            modMts = list()     
            while (file.tell() - modMtsStart < modChnkSize):
                modMtsFlags.append(struct.unpack("<i", file.read(4)))
                if modMtsFlags[-1][0] > 20:
                    modMts.append(struct.unpack("<Ifffiiii", file.read(32)))
                else:
                    modMts.append(struct.unpack("<Ifffii", file.read(24)))
            print ("modMtsFlags:")
            print (modMtsFlags)
            print ("(last)modMts:")
            print (modMts[-1]) 

        # Geometries
        elif modChnkTag == b'MOD0':
            modModVerticesNum, \
            modModFacesNum \
            = struct.unpack("<ii", file.read(8))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modModVerticesNum: %d" % modModVerticesNum)   
            print ("modModFacesNum: %d" % modModFacesNum) 
           
            modVtxTag, \
            modVtxSize \
            = struct.unpack("<4si", file.read(8))
            modVtxStart = file.tell() 
            print ("modVtxTag: " + modVtxTag.decode("ascii"))
            print ("modVtxSize: %d" % modVtxSize)
           
            modVtx = list()
            while (file.tell() - modVtxStart < modVtxSize):
                modVtx.append(struct.unpack("<fff", file.read(12)))
            print ("(last)modVtx: ")
            print (modVtx[-1])
           
            modPlysStart = file.tell()
            modPlys = list()
            modPlysCount = 0
            while (modPlysCount < modModFacesNum):
                modPly = list()
                modPlyTag, \
                modPlySize, \
                modPlyVtxCount, \
                modPlyMtlIdx \
                = struct.unpack("<4siii", file.read(16))
                # print ("modPlyTag: " + modPlyTag.decode("ascii"))
                # print ("modPlySize: %d" % modPlySize)
                # print ("modPlyVtxCount: %d" % modPlyVtxCount)
                # print ("modPlyMtlIdx: %d" % modPlyMtlIdx)
                modPlyNorm \
                = struct.unpack("<fff", file.read(12))
                # print ("modPlyNorm:")
                # print (modPlyNorm)
                modPlyVtxsStart = file.tell()
                modPlyVtxs = list()
                while (file.tell() - modPlyVtxsStart < modPlyVtxCount*28):
                    modPlyVtxs.append(struct.unpack("<HHffffff", file.read(28)))
                # print ("modPlyVtxs:")
                # print (modPlyVtxs)
                modPly.append(modPlyTag)
                modPly.append(modPlySize)
                modPly.append(modPlyVtxCount)
                modPly.append(modPlyMtlIdx)
                modPly.append(modPlyNorm)
                modPly.append(modPlyVtxs)
                modPlys.append(modPly)
                modPlysCount += 1
           
            modMeshes.append(modModVerticesNum)
            modMeshes.append(modModFacesNum)
            modMeshes.append(modVtx)
            modMeshes.append(modPlys)
           
            print ("(last)modPlys:")
            print (modMeshes[-1][3][-1])
            print (file.tell())
           
            modMeshesParsed += 1
       
    file.close()
       
       
from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()

Offline Kreeargh

  • Retired.
  • Lt. Commander
  • *
  • Posts: 1476
  • Gender: Male
  • Life is as is worth only what you learn from it!
Re: Blender to .mod scripts are there any working?
« Reply #174 on: November 13, 2010, 09:40:57 pm »
I know... look what you (re)started Kreeargh!  ;D  and your input is still useful. Got me thinking... this script wil handle five (or 500...) but if all we ever use normally (and if that is all the game uses) is 3 then that is fine... I can add those restrictions and settings as we firmly establish them.

That will do Tus, thanks for the effort! :thumbsup:  (though ideally, each LOD should have fewer polys for a "standard" sample model)
... aha the 5 tansitions were the max3 exporter defaults... thought so.

... a little shopping then I'm back at this. All these test models will definitely help the process. I suspect marstone may be updating his 2.49 importer while I work out the start of my 2.5 importer. Either way, one way or another we will have a working import soon. I'm not far off and neither is marstone.

I'm starting to think the export may not be so difficult since we have worked out so much already.

It occurs to me that we'll have to watch what happens to the rather large library of SFC models when this importer is complete. Would we want to add some kind of model "watermarker" or "brander" as I've previously discussed with DarkDrone? Or just stick to our mostly working honour system?   ... bah - scratch the watermarking idea... fraught with issues and complications... pretty much have to leave it up to the individual modeler...

Sorry about that :P but gmax kinda blows even though i use it mainly. Lack of renderer and good uvw stuff make the program 1/2 arse usefull. Blender is supported and used by alot so i figured what the hell ask  :-X.   A import .mod to blender plugin isnt needed near as much as a export to mod plugin. Work on that first and take a poll or something from the sfc modelers about the import version. That is true more can be riped if that option is avalable. I myself dont care my work has been riped for many stuff i cant stop that or want to waist my time trying. { my thoughs if one dont want ones work riped dont release it to public}   
Time for life!

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #175 on: November 14, 2010, 12:44:54 am »
Making progress... seems the y and z coordinates are flipped. Typical... flying sideways at 2:30 am!  ;D

The unreal psk importer has been most helpful. I'm as far as getting the first LOD mesh in. Looks like the UV mappings are up next... ? Then apply the mats... I expect to get hung up there a bit as I have not quite sorted the materials flags in my head, flag values that store multiple settings in one int that add in binary always make my head hurt a bit...

And the question is shoud I correct the axes before or after applying the materials? Hmmm maybe the named points... but what blender object to use for those? I seem to recall blender had a better suited object for .mod hardpoints than the milkshape solution...  :-\

Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "The universe may implode at any moment.",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
# import array

import bpy
import math
import mathutils

def decodeAsc(byteStr):
    print (byteStr.decode("ascii"))

def import_mod(filename,context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    if modHdrTag != b'MDLS':
        print("Error parsing file header. Boo!")
        file.close()
        return   
   
    modMeshesParsed = 0
    modMeshes = list()
   
    while modMeshesParsed < modHdrTotalLODs:
       
        modChnkTag, \
        modChnkSize \
        = struct.unpack("<4si", file.read(8))
       
        # Strings
        if modChnkTag == b'STRS':
            modStrSizePadded = 4*(math.ceil(modChnkSize/4))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modStrSizePadded: %d" % modStrSizePadded)
            modStrPool \
            = struct.unpack("<%ds" % modStrSizePadded, file.read(modStrSizePadded))
            modStrStrings = modStrPool[0].split(b'\x00')
            modStrList = [x.decode("ascii") for x in modStrStrings]
            print ("modStrList: ")
            print (modStrList)
       
        # Named Points
        elif modChnkTag == b'PNTS':
            modPtsStart = file.tell()
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modPtsNum = modChnkSize / 16
            print ("modPtsNum: %d" % modPtsNum)
            modPts = list()
            while (file.tell() - modPtsStart < modChnkSize):
                modPts.append(struct.unpack("<fffi", file.read(16)))
            print ("(last)modPts:")
            print (modPts[-1])
       
        # Materials (aieee!)
        elif modChnkTag == b'MATS':
            modMtsStart = file.tell()   
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modMtsFlags = list()
            modMts = list()     
            while (file.tell() - modMtsStart < modChnkSize):
                modMtsFlags.append(struct.unpack("<i", file.read(4)))
                if modMtsFlags[-1][0] > 20:
                    modMts.append(struct.unpack("<Ifffiiii", file.read(32)))
                else:
                    modMts.append(struct.unpack("<Ifffii", file.read(24)))
            print ("modMtsFlags:")
            print (modMtsFlags)
            print ("(last)modMts:")
            print (modMts[-1]) 

        # Geometries
        elif modChnkTag == b'MOD0':
            modMesh = list()
            modFaces = list()
            modModVerticesNum, \
            modModFacesNum \
            = struct.unpack("<ii", file.read(8))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modModVerticesNum: %d" % modModVerticesNum)   
            print ("modModFacesNum: %d" % modModFacesNum) 
           
            modVtxTag, \
            modVtxSize \
            = struct.unpack("<4si", file.read(8))
            modVtxStart = file.tell() 
            print ("modVtxTag: " + modVtxTag.decode("ascii"))
            print ("modVtxSize: %d" % modVtxSize)
           
            modVtx = list()
            modVt = list()
            while (file.tell() - modVtxStart < modVtxSize):
                modVt = struct.unpack("<fff", file.read(12))
                modVtx.extend(modVt)
            # print ("(last)modVtx: ")
            # print (modVtx[-1])
           
            modPlysStart = file.tell()
            modPlys = list()
            modPlysCount = 0
            while (modPlysCount < modModFacesNum):
                modPly = list()
                modPlyTag, \
                modPlySize, \
                modPlyVtxCount, \
                modPlyMtlIdx \
                = struct.unpack("<4siii", file.read(16))
                # print ("modPlyTag: " + modPlyTag.decode("ascii"))
                # print ("modPlySize: %d" % modPlySize)
                # print ("modPlyVtxCount: %d" % modPlyVtxCount)
                # print ("modPlyMtlIdx: %d" % modPlyMtlIdx)
                modPlyNorm \
                = struct.unpack("<fff", file.read(12))
                # print ("modPlyNorm:")
                # print (modPlyNorm)
                modPlyVtxsStart = file.tell()
                modPlyVtxs = list()
                modPlyFace = list()
                while (file.tell() - modPlyVtxsStart < modPlyVtxCount*28):
                    modPlyVtxs.append(struct.unpack("<HHffffff", file.read(28)))
                    modPlyFace.append(modPlyVtxs[-1][0])
                    # print (modPlyVtxs[-1][0])
                modPlyFace.append(0)
                # print ("modPlyVtxs:")
                # print (modPlyVtxs)
                modPly.append(modPlyTag)
                modPly.append(modPlySize)
                modPly.append(modPlyVtxCount)
                modPly.append(modPlyMtlIdx)
                modPly.append(modPlyNorm)
                modPly.append(modPlyVtxs)
                # modPly.append(modPlyFace)
                modFaces.extend(modPlyFace)
                modPlys.append(modPly)
                modPlysCount += 1
           
            modMesh.append(modModVerticesNum)
            modMesh.append(modModFacesNum)
            modMesh.append(modVtx)
            modMesh.append(modPlys)
            modMesh.append(modFaces)
           
            modMeshes.append(modMesh)
           
            print ("(last)modPlys:")
            print (modMesh[-1][3])
            # print (modMeshes[0])
            print (file.tell())
           
            modMeshesParsed += 1
       
    file.close()
   
    mod_obj = bpy.data.meshes.new(name)
    mod_obj.vertices.add(modMeshes[0][0])
    print (modMeshes[0][0])
    mod_obj.vertices.foreach_set("co", modMeshes[0][2])
    print (modMeshes[0][2])
    mod_obj.faces.add(modMeshes[0][1])
    print (modMeshes[0][1])
    mod_obj.faces.foreach_set("vertices_raw", modMeshes[0][4])
    mod_obj.update()
    modmesh = bpy.data.objects.new(name,mod_obj)
    bpy.context.scene.objects.link(modmesh)
    bpy.context.scene.update()
 
    # print (modFaces)
   
    # print (modMeshes[0][0])
    # print (modMeshes[0][2])
   
    return

       
       
from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()


« Last Edit: November 14, 2010, 01:00:59 am by Bonk »

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #176 on: November 14, 2010, 01:18:41 am »
Sorry about that :P but gmax kinda blows even though i use it mainly. Lack of renderer and good uvw stuff make the program 1/2 arse usefull. Blender is supported and used by alot so i figured what the hell ask  :-X.   A import .mod to blender plugin isnt needed near as much as a export to mod plugin. Work on that first and take a poll or something from the sfc modelers about the import version. That is true more can be riped if that option is avalable. I myself dont care my work has been riped for many stuff i cant stop that or want to waist my time trying. { my thoughs if one dont want ones work riped dont release it to public}

Yeah, about releases... Ozzy has a song about it. Basically I am with you.  (actually, Sabbath, Technical Ecstasy, It's Alright)

Definitely getting SFC material into blender will help its future. (watch people start playing with SFC models in the blender game engine... see your models in the movies! ;))

Of course the goal is to get an exporter made so we have a nice new modern open source modelling program to use with existing SFC products. At this point it is a question of when, not if. We're not far off finishing the importer. Once that is done I'll need to figure out how to grab the normals in  the blender environment for storage in the exported .mod file.  (as I see no need (or mechanism) to import them and I expect blender can generate them on the fly, I should be able to jsut grab them inthe exposrt script... but I get ahead...)


Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #177 on: November 14, 2010, 11:05:22 am »
Was the test cube meant to be this huge? (That's a little orange fca mesh back there... I have yet to apply the stored model radius value... ack!)

edit: actually looking at the stored radius vaules they look about right (fca radius ~= 8.5, Control radius ~= 122.5) looks like the radius is just calculated and stored for the engine, as for the normals.

I wonder if one could optimise the file format by normalising the data and using a center and scale value. ? (scale all x,y,z data to 0-1) That would make the most sense to me. I expect other 3d file formats may do so. You'd have to have apretty high poly mesh to lose precision, and moving to 64 bit ints would probably cover even that for some time... hmmm... It would also facilitate mesh manipulation and analysis.
« Last Edit: November 14, 2010, 11:17:54 am by Bonk »

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #178 on: November 14, 2010, 11:24:19 am »
It was 100 maxunits tall - of course I dont know how big an FCA model is in max >.<
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #179 on: November 14, 2010, 11:30:55 am »
*giggle* you said "maxunits"  hehe hehe hehe ...  :crazy2: 

Lol, sorry, figuring out the materials is getting deep and putting my mind in a strange place.