[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30037] branches/soc-2010-jwilkins/release /scripts/io/import_scene_obj.py:

Jason Wilkins Jason.A.Wilkins at gmail.com
Tue Jul 6 14:51:14 CEST 2010


Revision: 30037
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30037
Author:   jwilkins
Date:     2010-07-06 14:51:14 +0200 (Tue, 06 Jul 2010)

Log Message:
-----------


Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/io/import_scene_obj.py

Modified: branches/soc-2010-jwilkins/release/scripts/io/import_scene_obj.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/io/import_scene_obj.py	2010-07-06 12:45:40 UTC (rev 30036)
+++ branches/soc-2010-jwilkins/release/scripts/io/import_scene_obj.py	2010-07-06 12:51:14 UTC (rev 30037)
@@ -18,21 +18,105 @@
 
 # <pep8 compliant>
 
-__author__= "Campbell Barton", "Jiri Hnidek", "Paolo Ciccone"
-__url__= ['http://wiki.blender.org/index.php/Scripts/Manual/Import/wavefront_obj', 'blender.org', 'blenderartists.org']
-__version__= "2.11"
+__author__= ['Bob Holcomb', 'Richard L?rk?ng', 'Damien McGinnes', 'Campbell Barton', 'Mario Lapin']
+__url__ = ("blenderartists.org", "www.blender.org", "www.gametutorials.com", "lib3ds.sourceforge.net/")
+__version__= '0.996'
+__bpydoc__= '''\
 
-__bpydoc__= """\
-This script imports a Wavefront OBJ files to Blender.
+3ds Importer
 
-Usage:
-Run this script from "File->Import" menu and then load the desired OBJ file.
-Note, This loads mesh objects and materials only, nurbs and curves are not supported.
-"""
+This script imports a 3ds file and the materials into Blender for editing.
 
+Loader is based on 3ds loader from www.gametutorials.com (Thanks DigiBen).
+
+0.996 by Mario Lapin (mario.lapin at gmail.com) 13/04/200 <br>
+ - Implemented workaround to correct association between name, geometry and materials of
+   imported meshes.
+
+   Without this patch, version 0.995 of this importer would associate to each mesh object the
+   geometry and the materials of the previously parsed mesh object. By so, the name of the
+   first mesh object would be thrown away, and the name of the last mesh object would be
+   automatically merged with a '.001' at the end. No object would desappear, however object's
+   names and materials would be completely jumbled.
+
+0.995 by Campbell Barton<br>
+- workaround for buggy mesh vert delete
+- minor tweaks
+
+0.99 by Bob Holcomb<br>
+- added support for floating point color values that previously broke on import.
+
+0.98 by Campbell Barton<br>
+- import faces and verts to lists instead of a mesh, convert to a mesh later
+- use new index mapping feature of mesh to re-map faces that were not added.
+
+0.97 by Campbell Barton<br>
+- Strip material names of spaces
+- Added import as instance to import the 3ds into its own
+  scene and add a group instance to the current scene
+- New option to scale down imported objects so they are within a limited bounding area.
+
+0.96 by Campbell Barton<br>
+- Added workaround for bug in setting UV's for Zero vert index UV faces.
+- Removed unique name function, let blender make the names unique.
+
+0.95 by Campbell Barton<br>
+- Removed workarounds for Blender 2.41
+- Mesh objects split by material- many 3ds objects used more then 16 per mesh.
+- Removed a lot of unneeded variable creation.
+
+0.94 by Campbell Barton<br>
+- Face import tested to be about overall 16x speedup over 0.93.
+- Material importing speedup.
+- Tested with more models.
+- Support some corrupt models.
+
+0.93 by Campbell Barton<br>
+- Tested with 400 3ds files from turbosquid and samples.
+- Tactfully ignore faces that used the same verts twice.
+- Rollback to 0.83 sloppy un-reorganized code, this broke UV coord loading.
+- Converted from NMesh to Mesh.
+- Faster and cleaner new names.
+- Use external comprehensive image loader.
+- Re intergrated 0.92 and 0.9 changes
+- Fixes for 2.41 compat.
+- Non textured faces do not use a texture flag.
+
+0.92<br>
+- Added support for diffuse, alpha, spec, bump maps in a single material
+
+0.9<br>
+- Reorganized code into object/material block functions<br>
+- Use of Matrix() to copy matrix data<br>
+- added support for material transparency<br>
+
+0.83 2005-08-07: Campell Barton
+-  Aggressive image finding and case insensitivy for posisx systems.
+
+0.82a 2005-07-22
+- image texture loading (both for face uv and renderer)
+
+0.82 - image texture loading (for face uv)
+
+0.81a (fork- not 0.9) Campbell Barton 2005-06-08
+- Simplified import code
+- Never overwrite data
+- Faster list handling
+- Leaves import selected
+
+0.81 Damien McGinnes 2005-01-09
+- handle missing images better
+
+0.8 Damien McGinnes 2005-01-08
+- copies sticky UV coords to face ones
+- handles images better
+- Recommend that you run 'RemoveDoubles' on each imported mesh after using this script
+
+'''
+
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
-# Script copyright (C) Campbell J Barton 2007
+# Script copyright (C) Bob Holcomb
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -51,1551 +135,889 @@
 # ***** END GPL LICENCE BLOCK *****
 # --------------------------------------------------------------------------
 
+# Importing modules
+
 import os
 import time
+import struct
+
+from import_scene_obj import unpack_face_list, load_image
+
 import bpy
 import mathutils
-from geometry import PolyFill
 
-# from Blender import Mesh, Draw, Window, Texture, Material, sys
-# # import BPyMesh
-# import BPyImage
-# import BPyMessages
+BOUNDS_3DS = []
 
-# try:		import os
-# except:		os= False
 
-def stripExt(name): # name is a string
-    '''Strips the prefix off the name before writing'''
-    index= name.rfind('.')
-    if index != -1:
-        return name[ : index ]
-    else:
-        return name
-# end path funcs
+######################################################
+# Data Structures
+######################################################
 
-def unpack_list(list_of_tuples):
-    l = []
-    for t in list_of_tuples:
-        l.extend(t)
-    return l
+#Some of the chunks that we will see
+#----- Primary Chunk, at the beginning of each file
+PRIMARY = int('0x4D4D',16)
 
-# same as above except that it adds 0 for triangle faces
-def unpack_face_list(list_of_tuples):
-    l = []
-    for t in list_of_tuples:
-        face = [i for i in t]
+#------ Main Chunks
+OBJECTINFO   =      int('0x3D3D',16);      #This gives the version of the mesh and is found right before the material and object information
+VERSION      =      int('0x0002',16);      #This gives the version of the .3ds file
+EDITKEYFRAME=      int('0xB000',16);      #This is the header for all of the key frame info
 
-        if len(face) != 3 and len(face) != 4:
-            raise RuntimeError("{0} vertices in face.".format(len(face)))
+#------ sub defines of OBJECTINFO
+MATERIAL = 45055		#0xAFFF				// This stored the texture info
+OBJECT = 16384		#0x4000				// This stores the faces, vertices, etc...
 
-        # rotate indices if the 4th is 0
-        if len(face) == 4 and face[3] == 0:
-            face = [face[3], face[0], face[1], face[2]]
+#>------ sub defines of MATERIAL
+#------ sub defines of MATERIAL_BLOCK
+MAT_NAME		=	int('0xA000',16)	# This holds the material name
+MAT_AMBIENT		=	int('0xA010',16)	# Ambient color of the object/material
+MAT_DIFFUSE		=	int('0xA020',16)	# This holds the color of the object/material
+MAT_SPECULAR	=	int('0xA030',16)	# SPecular color of the object/material
+MAT_SHINESS		=	int('0xA040',16)	# ??
+MAT_TRANSPARENCY=	int('0xA050',16)	# Transparency value of material
+MAT_SELF_ILLUM	=	int('0xA080',16)	# Self Illumination value of material
+MAT_WIRE		=	int('0xA085',16)	# Only render's wireframe
 
-        if len(face) == 3:
-            face.append(0)
+MAT_TEXTURE_MAP	=	int('0xA200',16)	# This is a header for a new texture map
+MAT_SPECULAR_MAP=	int('0xA204',16)	# This is a header for a new specular map
+MAT_OPACITY_MAP	=	int('0xA210',16)	# This is a header for a new opacity map
+MAT_REFLECTION_MAP=	int('0xA220',16)	# This is a header for a new reflection map
+MAT_BUMP_MAP	=	int('0xA230',16)	# This is a header for a new bump map
+MAT_MAP_FILENAME =      int('0xA300',16)      # This holds the file name of the texture
 
-        l.extend(face)
+MAT_FLOAT_COLOR = int ('0x0010', 16) #color defined as 3 floats
+MAT_24BIT_COLOR	= int ('0x0011', 16) #color defined as 3 bytes
 
-    return l
+#>------ sub defines of OBJECT
+OBJECT_MESH  =      int('0x4100',16);      # This lets us know that we are reading a new object
+OBJECT_LAMP =      int('0x4600',16);      # This lets un know we are reading a light object
+OBJECT_LAMP_SPOT = int('0x4610',16);		# The light is a spotloght.
+OBJECT_LAMP_OFF = int('0x4620',16);		# The light off.
+OBJECT_LAMP_ATTENUATE = int('0x4625',16);
+OBJECT_LAMP_RAYSHADE = int('0x4627',16);
+OBJECT_LAMP_SHADOWED = int('0x4630',16);
+OBJECT_LAMP_LOCAL_SHADOW = int('0x4640',16);
+OBJECT_LAMP_LOCAL_SHADOW2 = int('0x4641',16);
+OBJECT_LAMP_SEE_CONE = int('0x4650',16);
+OBJECT_LAMP_SPOT_RECTANGULAR = int('0x4651',16);
+OBJECT_LAMP_SPOT_OVERSHOOT = int('0x4652',16);
+OBJECT_LAMP_SPOT_PROJECTOR = int('0x4653',16);
+OBJECT_LAMP_EXCLUDE = int('0x4654',16);
+OBJECT_LAMP_RANGE = int('0x4655',16);
+OBJECT_LAMP_ROLL = int('0x4656',16);
+OBJECT_LAMP_SPOT_ASPECT = int('0x4657',16);
+OBJECT_LAMP_RAY_BIAS = int('0x4658',16);
+OBJECT_LAMP_INNER_RANGE = int('0x4659',16);
+OBJECT_LAMP_OUTER_RANGE = int('0x465A',16);
+OBJECT_LAMP_MULTIPLIER = int('0x465B',16);
+OBJECT_LAMP_AMBIENT_LIGHT = int('0x4680',16);
 
-def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True):
-    '''
-    Takes a polyline of indices (fgon)
-    and returns a list of face indicie lists.
-    Designed to be used for importers that need indices for an fgon to create from existing verts.
 
-    from_data: either a mesh, or a list/tuple of vectors.
-    indices: a list of indicies to use this list is the ordered closed polyline to fill, and can be a subset of the data given.
-    PREF_FIX_LOOPS: If this is enabled polylines that use loops to make multiple polylines are delt with correctly.
-    '''
 
-    if not set: # Need sets for this, otherwise do a normal fill.
-        PREF_FIX_LOOPS= False
+OBJECT_CAMERA=      int('0x4700',16);      # This lets un know we are reading a camera object
 
-    Vector= mathutils.Vector
-    if not indices:
-        return []
+#>------ sub defines of CAMERA
+OBJECT_CAM_RANGES=   int('0x4720',16);      # The camera range values
 
-    #	return []
-    def rvec(co): return round(co.x, 6), round(co.y, 6), round(co.z, 6)
-    def mlen(co): return abs(co[0])+abs(co[1])+abs(co[2]) # manhatten length of a vector, faster then length
+#>------ sub defines of OBJECT_MESH
+OBJECT_VERTICES =   int('0x4110',16);      # The objects vertices
+OBJECT_FACES    =   int('0x4120',16);      # The objects faces

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list