[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2931] contrib/py/scripts/addons: . initial commit in addons of bel and io_directx_bel
Jerome Neo
jerome.le.chat at free.fr
Mon Jan 23 08:38:47 CET 2012
Revision: 2931
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2931
Author: littleneo
Date: 2012-01-23 07:38:34 +0000 (Mon, 23 Jan 2012)
Log Message:
-----------
. initial commit in addons of bel and io_directx_bel
. corrected a bug about referenced token parenting
. corrected a bug about non parented meshes
. armatures/empties importation enabled by default
. last run importer options are saved in a 'last_run' preset,
so it can be replayed or saved under another name once a
particular .x profile has been defined
. tagged script for 2.6.1
Added Paths:
-----------
contrib/py/scripts/addons/bel/
contrib/py/scripts/addons/bel/__init__.py
contrib/py/scripts/addons/bel/fs.py
contrib/py/scripts/addons/bel/image.py
contrib/py/scripts/addons/bel/material.py
contrib/py/scripts/addons/bel/mesh.py
contrib/py/scripts/addons/bel/ob.py
contrib/py/scripts/addons/bel/uv.py
contrib/py/scripts/addons/io_directx_bel/
contrib/py/scripts/addons/io_directx_bel/README
contrib/py/scripts/addons/io_directx_bel/__init__.py
contrib/py/scripts/addons/io_directx_bel/import_x.py
contrib/py/scripts/addons/io_directx_bel/templates_x.py
Added: contrib/py/scripts/addons/bel/__init__.py
===================================================================
--- contrib/py/scripts/addons/bel/__init__.py (rev 0)
+++ contrib/py/scripts/addons/bel/__init__.py 2012-01-23 07:38:34 UTC (rev 2931)
@@ -0,0 +1,23 @@
+# set a given name to a unique
+# blender data name in its collection
+def bpyname(name,collection,suffix=4) :
+ name = name[:20-suffix]
+ tpl = '%s.%.'+str(suffix)+'d'
+ bname = name
+ id = 0
+ while bname in collection :
+ id += 1
+ bname = tpl%(name,id)
+ return bname
+
+## check if there's nested lists in a list. used by functions that need
+# list(s) of vertices/faces/edges etc as input
+# @param lst a list of vector or a list of list of vectors
+# @returns always nested list(s)
+# a boolean True if was nested, False if was not
+def nested(lst) :
+ try :
+ t = lst[0][0][0]
+ return lst, True
+ except :
+ return [lst], False
\ No newline at end of file
Added: contrib/py/scripts/addons/bel/fs.py
===================================================================
--- contrib/py/scripts/addons/bel/fs.py (rev 0)
+++ contrib/py/scripts/addons/bel/fs.py 2012-01-23 07:38:34 UTC (rev 2931)
@@ -0,0 +1,71 @@
+# v0.1
+import bpy
+from os import path as os_path, listdir as os_listdir
+from bpy import path as bpy_path
+
+# cross platform paths (since ms conform to / path ;) )
+# maybe add utf8 replace to old ascii blender builtin
+# // can be omitted for relative
+def clean(path) :
+ path = path.strip().replace('\\','/')
+ if ('/') not in path : path = '//'+path
+ return path
+
+## test for existence of a file or a dir
+def exist(path) :
+ if isfile(path) or isdir(path) : return True
+ return False
+
+## test for existence of a file
+def isfile(path) :
+ if os_path.isfile(path) : return True
+ # could be blender relative
+ path = bpy_path.abspath(path)
+ if os_path.isfile(path) : return True
+ return False
+
+## test for existence of a dir
+def isdir(path) :
+ if os_path.isdir(path) : return True
+ # could be blender relative
+ path = bpy_path.abspath(path)
+ if os_path.isdir(path) : return True
+ return False
+
+## returns a list of every absolute filepath
+# to each file within the 'ext' extensions
+# from a folder and its subfolders
+def scanDir(path,ext='all') :
+ files = []
+ fields = os_listdir(path)
+ if ext != 'all' and type(ext) != list : ext = [ext]
+ for item in fields :
+ if os_path.isfile(path + '/' + item) and (ext == 'all' or item.split('.')[-1] in ext) :
+ #print(' file %s'%item)
+ files.append(path + '/' + item)
+ elif os_path.isdir(path + '/' + item) :
+ print('folder %s/%s :'%(path,item))
+ files.extend(scanDir(path + '/' + item))
+ return files
+
+def saveOptions(operator_name, tokens, filename='last_run'):
+ target_path = os_path.join("operator", operator_name)
+ target_path = os_path.join("presets", target_path)
+ target_path = bpy.utils.user_resource('SCRIPTS',target_path,create=True)
+ if target_path:
+ filepath = os_path.join(target_path, filename) + ".py"
+ file_preset = open(filepath, 'w')
+ file_preset.write("import bpy\nop = bpy.context.active_operator\n\n")
+ properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
+ for key, value in tokens.items() :
+ if key not in properties_blacklist :
+ # convert thin wrapped sequences to simple lists to repr()
+ try:
+ value = value[:]
+ except:
+ pass
+
+ file_preset.write("op.%s = %r\n" % (key, value))
+
+ file_preset.close()
+
Added: contrib/py/scripts/addons/bel/image.py
===================================================================
--- contrib/py/scripts/addons/bel/image.py (rev 0)
+++ contrib/py/scripts/addons/bel/image.py 2012-01-23 07:38:34 UTC (rev 2931)
@@ -0,0 +1,264 @@
+import bpy
+import bpy.path
+import bel
+import bel.fs
+
+debuglevel = 0
+
+def dprint(str,l=2) :
+ if l <= debuglevel :
+ print(str)
+
+# create or retrieve a bdata image
+# given its path
+def new(path, name=False, relative = True, premul = True) :
+ path = bel.fs.clean(path)
+ # check file
+ if bel.fs.isfile(path) == False :
+ dprint('Texture image not found')
+ return False
+
+ if relative :
+ try :
+ path = bpy.path.relpath(path)
+ path = bel.fs.clean(path)
+ except :
+ print('cant turn path into relative one (.blend and img path drive letters ?) ')
+
+ # retrieve paths to image file from existing image slot
+ # returns img if paths match
+ for img in bpy.data.images :
+ if img.filepath != '' :
+ if bpy.path.abspath(path) == bpy.path.abspath(bel.fs.clean(img.filepath)) :
+ return img
+
+ # create a unique name in image slot
+ if name == False :
+ name = bpy.path.basename(path)
+ name = bel.bpyname(name,bpy.data.images.keys())
+
+ # finally :
+ img = bpy.data.images.load(filepath=path)
+ img.name = name
+ img.use_premultiply = premul
+ return img
+
+
+def applyShader(mat,config) :
+
+ # matslot.link = 'DATA'
+ #mat = bpy.data.materials['Female_Body']
+
+ texslot = mat.texture_slots[0]
+ tex = texslot.texture
+ img = tex.image
+
+ #config = shaders[shadername]
+ alpha = True if 'alpha' in config else False
+
+ ## MAT
+
+ mat.type = 'SURFACE'
+ # diffuse
+ mat.diffuse_color = Color((0.6, 0.6, 0.6))
+ mat.diffuse_intensity = 0.8
+ mat.diffuse_shader = 'LAMBERT'
+ mat.use_diffuse_ramp = False
+
+ # specular
+ mat.specular_color = Color((1.0, 1.0, 1.0))
+ mat.specular_intensity = 0.25
+ mat.specular_shader = 'COOKTORR'
+ mat.use_specular_ramp = False
+ mat.specular_hardness = 1.0
+
+ # shading
+ mat.emit = 0.0
+ mat.ambient = 0.5
+ mat.translucency = 0.0
+ mat.use_shadeless = False
+ mat.use_tangent_shading = False
+ mat.use_cubic = False
+
+ # transparency
+ mat.use_transparency = alpha
+ mat.transparency_method = 'Z_TRANSPARENCY'
+ mat.alpha = not(alpha)
+ mat.specular_alpha = not(alpha)
+ mat.raytrace_transparency.fresnel = 0.0
+ mat.raytrace_transparency.fresnel_factor = 1.25
+
+ # mirror
+ mat.raytrace_mirror.use = False
+
+ # subsurface_scattering
+ mat.subsurface_scattering.use
+
+ # strand
+ # options
+ # shadow
+ mat.use_shadows = True
+ mat.use_transparent_shadows = True
+ mat.use_cast_shadows_only = False
+ mat.shadow_cast_alpha = 1.0
+ mat.use_only_shadow = False
+ mat.shadow_only_type = 'SHADOW_ONLY_OLD'
+ mat.use_cast_buffer_shadows = True
+ mat.shadow_buffer_bias = 0.0
+ mat.use_ray_shadow_bias = True
+ mat.shadow_ray_bias = 0.0
+ mat.use_cast_approximate = True
+
+ # TEXTURE SLOT 0
+
+ # diffuse
+ texslot.diffuse_factor = 1.0
+ texslot.use_map_diffuse = True
+ texslot.diffuse_color_factor = 1.0
+ texslot.use_map_color_diffuse = True
+ texslot.alpha_factor = 1.0
+ texslot.use_map_alpha = alpha
+ texslot.translucency_factor = 0.0
+ texslot.use_map_translucency = False
+
+ # specular
+ texslot.specular_factor = 0.3
+ texslot.use_map_specular = True
+ texslot.specular_color_factor = 1.0
+ texslot.use_map_color_spec = True
+ texslot.hardness_factor = 0.1
+ texslot.use_map_hardness = True
+
+ # shading
+ texslot.ambient_factor = 0.0
+ texslot.use_map_ambient = False
+ texslot.emit_factor = 0.1
+ texslot.use_map_emit = True
+ texslot.mirror_factor = 0.0
+ texslot.use_map_mirror = False
+ texslot.raymir_factor = 0.0
+ texslot.use_map_raymir = False
+
+ # geometry
+ texslot.normal_factor = 0.0
+ texslot.use_map_normal = False
+ texslot.warp_factor = 0.1
+ texslot.use_map_warp = False
+ texslot.displacement_factor = 0.0
+ texslot.use_map_displacement = False
+
+ texslot.blend_type = 'MIX'
+ texslot.invert = False
+ texslot.use_rgb_to_intensity = False
+ texslot.color = Color((1.0, 0.0, 1.0)) # default
+ texslot.use_stencil = False
+ texslot.default_value = 1.0
+
+ # TEXTURE
+ tex.use_alpha = alpha
+ tex.use_preview_alpha = alpha
+
+ # IMAGE
+ if type(img) != type(None) :
+ img.use_premultiply = True
+
+def BSshader(nodes,pointer) :
+ tkm = bpy.context.scene.tkm
+ typ, nodename = pointer.split(' ')
+ RenderShader = nodes[typ][nodename]
+ name = BSname(nodename,RenderShader['Object.Name'])
+ if name in bpy.data.materials :
+ mat = bpy.data.materials[name]
+ else :
+ mat = bpy.data.materials.new(name=name)
+ # Unused
+ DepthWriteEnable = RenderShader['DepthWriteEnable'] if 'DepthWriteEnable' in RenderShader else False # an integer
+ ShaderTransparency = RenderShader['MultiDrawLayer'] if 'MultiDrawLayer' in RenderShader else False # an integer
+ LightEnable = RenderShader['LightEnable'] if 'LightEnable' in RenderShader else False # an integer
+
+ ShaderPhong = BSnode(nodes,RenderShader['Surface'])
+ #print('mat : %s'%ShaderPhong['Material'])
+ RenderMaterial = BSnode(nodes,ShaderPhong['Material'])
+ DiffuseColor = RenderMaterial['DiffuseColor'] if 'DiffuseColor' in RenderMaterial else False
+ SpecularColor = RenderMaterial['SpecularColor'] if 'SpecularColor' in RenderMaterial else False
+ AmbientColor = RenderMaterial['AmbientColor'] if 'AmbientColor' in RenderMaterial else False
+ EmissionColor = RenderMaterial['Shininess'] if 'EmissionColor' in RenderMaterial else False
+ Shininess = RenderMaterial['Shininess'] if 'Shininess' in RenderMaterial else False
+ Transparency = RenderMaterial['Transparency'] if 'Transparency' in RenderMaterial else False
+ for key in RenderMaterial.keys() :
+ if key not in ['DiffuseColor','SpecularColor','AmbientColor','EmissionColor','Shininess','Transparency'] :
+ print('NEW RENDERMATERIAL PROP ! : %s'%key)
+
+ #print(AmbientColor)
+ if DiffuseColor : mat.diffuse_color = Color(DiffuseColor) #[0][0],DiffuseColor[0][1],DiffuseColor[0][2])
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list