[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1250] branches/ io_import_gimp_to_3d_layers.py: GIMPto3DLayers: GIMP Compressed File (XJT) support finished.

Daniel Salazar zanqdo at gmail.com
Tue Dec 7 23:11:38 CET 2010


Revision: 1250
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1250
Author:   zanqdo
Date:     2010-12-07 23:11:38 +0100 (Tue, 07 Dec 2010)

Log Message:
-----------
GIMPto3DLayers: GIMP Compressed File (XJT) support finished. This should
work crossplatform with just python. Needs extensive testing

Modified Paths:
--------------
    branches/io_import_gimp_to_3d_layers.py

Modified: branches/io_import_gimp_to_3d_layers.py
===================================================================
--- branches/io_import_gimp_to_3d_layers.py	2010-12-07 20:54:02 UTC (rev 1249)
+++ branches/io_import_gimp_to_3d_layers.py	2010-12-07 22:11:38 UTC (rev 1250)
@@ -19,7 +19,7 @@
 bl_addon_info = {
 	"name": "Import GIMP Files as 3D Layers (.xcf, .xjt)",
 	"author": "Daniel Salazar (ZanQdo)",
-	"version": (1,1,0),
+	"version": (2,0,0),
 	"blender": (2, 5, 5),
 	"api": 33419,
 	"location": "File > Import > GIMP Images as 3D Layers(.xcf, .xjt)",
@@ -73,7 +73,7 @@
 		
 		for Member in Members:
 			Name = Member.name
-			if Name.startswith('l') and Name.endswith('.jpg') and not Name.startswith('la'): #only color JPGs for now!
+			if Name.startswith('l') and Name.endswith('.jpg'): #only color JPGs for now!
 				IMG.extract(Name, path=PathSaveRaw)
 		
 		#-------------------------------------------------
@@ -87,13 +87,19 @@
 					if Segment.startswith('w/h:'):
 						ResX, ResY = map (int, Segment[4:].split(','))
 			if Line.startswith("b'L") or Line.startswith("b'l"):
+				
+				if Line.startswith("b'L"): HasAlpha = True
+				else: HasAlpha = False
+				
 				md = None
 				op = 1
+				ox, oy = 0,0
 				
 				for Segment in Line.split():
 					
 					if Segment.startswith("b'"):
 						imageFile = 'l' + Segment[3:] + '.jpg'
+						imageFileAlpha ='la'+Segment[3:]+'.jpg'
 						
 						# Get Widht and Height from images
 						data = open(PathSaveRaw+imageFile, "rb").read()
@@ -113,12 +119,9 @@
 						
 					elif Segment.startswith('op:'): # opacity
 						op = float(Segment[3:])*.01
-						
+					
 					elif Segment.startswith('o:'): # origin
 						ox, oy = map(int, Segment[2:].split(','))
-						
-					elif Segment == 'acl': # blank origin layer
-						ox, oy = 0, 0
 					
 					elif Segment.startswith('n:'): # name
 						n = Segment[3:-4]
@@ -134,10 +137,11 @@
 							NameShort = n
 						
 						os.rename(PathSaveRaw+imageFile, PathSaveRaw+NameShort+'.jpg')
+						if HasAlpha: os.rename(PathSaveRaw+imageFileAlpha, PathSaveRaw+NameShort+'_A'+'.jpg')
 						
 				IMGs.append({'LayerMode':md, 'LayerOpacity':op,\
 							'LayerName':n, 'LayerNameShort':NameShort,\
-							'RenderLayer':RenderLayer, 'LayerCoords':[ow, oh, ox, oy]})
+							'RenderLayer':RenderLayer, 'LayerCoords':[ow, oh, ox, oy], 'HasAlpha':HasAlpha})
 	
 	else: # Ext == '.xcf':
 		ExtSave = '.png'
@@ -189,6 +193,7 @@
 					'LayerNameShort':NameShort,\
 					'LayerCoords':list(map(int, Line[1].replace('x', ' ').replace('+', ' +').replace('-', ' -').split())),\
 					'RenderLayer':RenderLayer,\
+					'HasAlpha':True,\
 					})
 			elif Line.startswith('Version'):
 				ResX, ResY = map (int, Line.split()[2].split('x'))
@@ -244,7 +249,7 @@
 	#-------------------------------------------------
 	# 3D LAYERS
 	
-	def Make3DLayer (Name, NameShort, Z, Coords, RenderLayer, LayerMode, LayerOpacity):
+	def Make3DLayer (Name, NameShort, Z, Coords, RenderLayer, LayerMode, LayerOpacity, HasAlpha):
 		
 		# RenderLayer
 		
@@ -321,30 +326,72 @@
 		Mat.use_shadows = False
 		Mat.use_cast_buffer_shadows = False
 		Mat.use_cast_approximate = False
-		Mat.use_transparency = True
+		if HasAlpha:
+			Mat.use_transparency = True
+			if OpacityMode == 'MAT': Mat.alpha = LayerOpacity
+			else: Mat.alpha = 0
 		if ShadelessMats: Mat.use_shadeless = True
-		if OpacityMode == 'MAT': Mat.alpha = LayerOpacity
-		else: Mat.alpha = 0
 		
-		Tex = bpy.data.textures.new(NameShort, 'IMAGE')
-		Tex.extension = 'CLIP'
-		Tex.use_preview_alpha = True
+		if Ext == '.xcf':
+			# Color & Alpha PNG
+			Tex = bpy.data.textures.new(NameShort, 'IMAGE')
+			Tex.extension = 'CLIP'
+			Tex.use_preview_alpha = True
+			
+			Img = bpy.data.images.new(NameShort)
+			Img.source = 'FILE'
+			if PremulAlpha: Img.use_premultiply = True
+			Img.filepath = '%s%s%s' % (PathSaveRaw, Name, ExtSave)
+			
+			Tex.image = Img
+			
+			Mat.texture_slots.add()
+			TexSlot = Mat.texture_slots[0]
+			TexSlot.texture = Tex
+			TexSlot.use_map_alpha = True
+			TexSlot.texture_coords = 'UV'
+			if OpacityMode == 'TEX': TexSlot.alpha_factor = LayerOpacity
+			elif OpacityMode == 'MAT': TexSlot.blend_type = 'MULTIPLY'
 		
-		Img = bpy.data.images.new(NameShort)
-		Img.source = 'FILE'
-		if PremulAlpha: Img.use_premultiply = True
-		Img.filepath = '%s%s%s' % (PathSaveRaw, Name, ExtSave)
+		else: # Ext == '.xjt'
+			# Color JPG
+			Tex = bpy.data.textures.new(NameShort, 'IMAGE')
+			Tex.extension = 'CLIP'
+			
+			Img = bpy.data.images.new(NameShort)
+			Img.source = 'FILE'
+			Img.filepath = '%s%s%s' % (PathSaveRaw, Name, ExtSave)
+			
+			Tex.image = Img
+			
+			Mat.texture_slots.add()
+			TexSlot = Mat.texture_slots[0]
+			TexSlot.texture = Tex
+			TexSlot.texture_coords = 'UV'
+			
+			if HasAlpha:
+				# Alpha JPG
+				Tex = bpy.data.textures.new(NameShort+'_A', 'IMAGE')
+				Tex.extension = 'CLIP'
+				Tex.use_preview_alpha = True
+				Tex.use_alpha = False
+				
+				Img = bpy.data.images.new(NameShort)
+				Img.source = 'FILE'
+				if PremulAlpha: Img.use_premultiply = True
+				Img.filepath = '%s%s_A%s' % (PathSaveRaw, Name, ExtSave)
+				
+				Tex.image = Img
+				
+				Mat.texture_slots.add()
+				TexSlot = Mat.texture_slots[1]
+				TexSlot.texture = Tex
+				TexSlot.use_map_alpha = True
+				TexSlot.use_map_color_diffuse = False
+				TexSlot.texture_coords = 'UV'
+				if OpacityMode == 'TEX': TexSlot.alpha_factor = LayerOpacity
+				elif OpacityMode == 'MAT': TexSlot.blend_type = 'MULTIPLY'
 		
-		Tex.image = Img
-		
-		Mat.texture_slots.add()
-		TexSlot = Mat.texture_slots[0]
-		TexSlot.texture = Tex
-		TexSlot.use_map_alpha = True
-		TexSlot.texture_coords = 'UV'
-		if OpacityMode == 'TEX': TexSlot.alpha_factor = LayerOpacity
-		elif OpacityMode == 'MAT': TexSlot.blend_type = 'MULTIPLY'
-		
 		if not Active.material_slots:
 			bpy.ops.object.material_slot_add()
 		
@@ -366,6 +413,7 @@
 		Layer['RenderLayer'],\
 		Layer['LayerMode'],\
 		Layer['LayerOpacity'],\
+		Layer['HasAlpha'],\
 		)
 		
 		Z -= LayerOffset




More information about the Bf-extensions-cvs mailing list