[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26758] trunk/blender: Bugfix: 3DS Importer not settings UV's correctly
Joshua Leung
aligorith at gmail.com
Wed Feb 10 02:55:45 CET 2010
Revision: 26758
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26758
Author: aligorith
Date: 2010-02-10 02:55:45 +0100 (Wed, 10 Feb 2010)
Log Message:
-----------
Bugfix: 3DS Importer not settings UV's correctly
Thanks to example .3ds file and bug report from stridernzl.
1) The API function for adding textures to meshes was not working correctly, resulting in a Null texture slot being created (i.e. a texture slot was created, but the given texture could never be assigned to this).
Fixed by making the function always require a texture as input (as with other places that use pointers as arguments).
2) In "Textured" draw mode, the imported meshes were shown white (i.e. without any textures).
It appears that that the old old setting (mesh.faceUV) is no longer valid/wrapped in RNA, so worked around this by setting the 'tex' setting for UV-faces on. From the UI, this seems to do the same thing as entering editmode and assigning an image to the faces from the image editor.
---
I've also removed a few lines of commented 2.4x code that is no longer valid. Hopefully there wasn't anything too valuable that I accidentally removed in this process ;)
Modified Paths:
--------------
trunk/blender/release/scripts/io/import_scene_3ds.py
trunk/blender/source/blender/makesrna/intern/rna_material_api.c
Modified: trunk/blender/release/scripts/io/import_scene_3ds.py
===================================================================
--- trunk/blender/release/scripts/io/import_scene_3ds.py 2010-02-10 01:54:32 UTC (rev 26757)
+++ trunk/blender/release/scripts/io/import_scene_3ds.py 2010-02-10 01:55:45 UTC (rev 26758)
@@ -146,41 +146,9 @@
import bpy
import Mathutils
-# import Blender
-# from Blender import Mesh, Object, Material, Image, Texture, Lamp, Mathutils
-# from Blender.Mathutils import Vector
-# import BPyImage
-
-# import BPyMessages
-
-# try:
-# from struct import calcsize, unpack
-# except:
-# calcsize= unpack= None
-
-
-
-# # If python version is less than 2.4, try to get set stuff from module
-# try:
-# set
-# except:
-# from sets import Set as set
-
BOUNDS_3DS = []
-#this script imports uvcoords as sticky vertex coords
-#this parameter enables copying these to face uv coords
-#which shold be more useful.
-
-def createBlenderTexture(material, name, image):
- texture = bpy.data.textures.new(name)
- texture.setType('Image')
- texture.image = image
- material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)
-
-
-
######################################################
# Data Structures
######################################################
@@ -294,11 +262,8 @@
def read_string(file):
#read in the characters till we get a null character
s = b''
-# s = ''
while not s.endswith(b'\x00'):
-# while not s.endswith('\x00'):
s += struct.unpack('<c', file.read(1))[0]
-# s += struct.unpack( '<c', file.read(1) )[0]
#print 'string: ',s
s = str(s[:-1], 'ASCII')
@@ -327,29 +292,17 @@
def add_texture_to_material(image, texture, material, mapto):
-# if mapto=='DIFFUSE':
-# map = Texture.MapTo.COL
-# elif mapto=='SPECULAR':
-# map = Texture.MapTo.SPEC
-# elif mapto=='OPACITY':
-# map = Texture.MapTo.ALPHA
-# elif mapto=='BUMP':
-# map = Texture.MapTo.NOR
-# else:
+ #print('assigning %s to %s' % (texture, material))
+
if mapto not in ("COLOR", "SPECULARITY", "ALPHA", "NORMAL"):
print('/tError: Cannot map to "%s"\n\tassuming diffuse color. modify material "%s" later.' % (mapto, material.name))
mapto = "COLOR"
-# map = Texture.MapTo.COL
- if image: texture.image = image
+ if image:
+ texture.image = image
# if image: texture.setImage(image) # double check its an image.
material.add_texture(texture, "UV", mapto)
-# free_tex_slots = [i for i, tex in enumerate( material.getTextures() ) if tex == None]
-# if not free_tex_slots:
-# print('/tError: Cannot add "%s" map. 10 Texture slots alredy used.' % mapto)
-# else:
-# material.setTexture(free_tex_slots[0],texture,Texture.TexCo.UV,map)
def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
@@ -436,7 +389,6 @@
if bmesh.faces and (contextMeshUV or img):
bmesh.add_uv_texture()
-# bmesh.faceUV = 1
for ii, i in enumerate(faces):
# Mapped index- faces may have not been added- if so, then map to the correct index
@@ -461,7 +413,9 @@
# targetFace.uv = [contextMeshUV[vindex] for vindex in myContextMesh_facels[i]]
if img:
uf.image = img
-# targetFace.image = img
+
+ # to get this image to show up in 'Textured' shading mode
+ uf.tex = True
# bmesh.transform(contextMatrix)
ob = bpy.data.objects.new(tempName, 'MESH')
@@ -507,7 +461,7 @@
return [float(col)/255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb
def read_texture(new_chunk, temp_chunk, name, mapto):
- new_texture = bpy.data.textures.new('Diffuse')
+ new_texture = bpy.data.textures.new(name)
new_texture.type = 'IMAGE'
new_texture = new_texture.recast_type()
@@ -657,97 +611,16 @@
elif (new_chunk.ID == MAT_TEXTURE_MAP):
read_texture(new_chunk, temp_chunk, "Diffuse", "COLOR")
-# #print 'elif (new_chunk.ID==MAT_TEXTURE_MAP):'
-# new_texture= bpy.data.textures.new('Diffuse')
-# new_texture.setType('Image')
-# img = None
-# while (new_chunk.bytes_read<new_chunk.length):
-# #print 'MAT_TEXTURE_MAP..while', new_chunk.bytes_read, new_chunk.length
-# read_chunk(file, temp_chunk)
-# if (temp_chunk.ID==MAT_MAP_FILENAME):
-# texture_name=read_string(file)
-# #img= TEXTURE_DICT[contextMaterial.name]= BPyImage.comprehensiveImageLoad(texture_name, FILENAME)
-# img= TEXTURE_DICT[contextMaterial.name]= BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER= False, RECURSIVE= IMAGE_SEARCH)
-# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
-
-# else:
-# skip_to_end(file, temp_chunk)
-
-# new_chunk.bytes_read+= temp_chunk.bytes_read
-
-# #add the map to the material in the right channel
-# if img:
-# add_texture_to_material(img, new_texture, contextMaterial, 'DIFFUSE')
-
elif (new_chunk.ID == MAT_SPECULAR_MAP):
read_texture(new_chunk, temp_chunk, "Specular", "SPECULARITY")
-# #print 'elif (new_chunk.ID == MAT_SPECULAR_MAP):'
-# new_texture = bpy.data.textures.new('Specular')
-# new_texture.setType('Image')
-# img = None
-# while (new_chunk.bytes_read < new_chunk.length):
-# read_chunk(file, temp_chunk)
-# if (temp_chunk.ID == MAT_MAP_FILENAME):
-# texture_name = read_string(file)
-# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME)
-# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH)
-# new_chunk.bytes_read+= (len(texture_name)+1) #plus one for the null character that gets removed
-# else:
-# skip_to_end(file, temp_chunk)
-
-# new_chunk.bytes_read += temp_chunk.bytes_read
-
-# #add the map to the material in the right channel
-# if img:
-# add_texture_to_material(img, new_texture, contextMaterial, 'SPECULAR')
-
elif (new_chunk.ID == MAT_OPACITY_MAP):
read_texture(new_chunk, temp_chunk, "Opacity", "ALPHA")
-# #print 'new_texture = Blender.Texture.New('Opacity')'
-# new_texture = bpy.data.textures.new('Opacity')
-# new_texture.setType('Image')
-# img = None
-# while (new_chunk.bytes_read < new_chunk.length):
-# read_chunk(file, temp_chunk)
-# if (temp_chunk.ID == MAT_MAP_FILENAME):
-# texture_name = read_string(file)
-# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME)
-# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH)
-# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
-# else:
-# skip_to_end(file, temp_chunk)
-
-# new_chunk.bytes_read += temp_chunk.bytes_read
-# #add the map to the material in the right channel
-# if img:
-# add_texture_to_material(img, new_texture, contextMaterial, 'OPACITY')
-
elif (new_chunk.ID == MAT_BUMP_MAP):
read_texture(new_chunk, temp_chunk, "Bump", "NORMAL")
-# #print 'elif (new_chunk.ID == MAT_BUMP_MAP):'
-# new_texture = bpy.data.textures.new('Bump')
-# new_texture.setType('Image')
-# img = None
-# while (new_chunk.bytes_read < new_chunk.length):
-# read_chunk(file, temp_chunk)
-# if (temp_chunk.ID == MAT_MAP_FILENAME):
-# texture_name = read_string(file)
-# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME)
-# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH)
-# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
-# else:
-# skip_to_end(file, temp_chunk)
-
-# new_chunk.bytes_read += temp_chunk.bytes_read
-
-# #add the map to the material in the right channel
-# if img:
-# add_texture_to_material(img, new_texture, contextMaterial, 'BUMP')
-
elif (new_chunk.ID == MAT_TRANSPARENCY):
#print 'elif (new_chunk.ID == MAT_TRANSPARENCY):'
read_chunk(file, temp_chunk)
@@ -852,7 +725,6 @@
temp_data = file.read(STRUCT_SIZE_2FLOAT)
new_chunk.bytes_read += STRUCT_SIZE_2FLOAT #2 float x 4 bytes each
return Mathutils.Vector( struct.unpack('<2f', temp_data) )
-# return Vector( struct.unpack('<2f', temp_data) )
contextMeshUV = [ getuv() for i in range(num_uv) ]
@@ -863,7 +735,6 @@
new_chunk.bytes_read += STRUCT_SIZE_4x3MAT
contextMatrix_rot = Mathutils.Matrix(\
-# contextMatrix_rot = Blender.Mathutils.Matrix(\
data[:3] + [0],\
data[3:6] + [0],\
data[6:9] + [0],\
@@ -1089,16 +960,9 @@
print('finished importing: "%s" in %.4f sec.' % (filename, (time.clock()-time1)))
# print('finished importing: "%s" in %.4f sec.' % (filename, (Blender.sys.time()-time1)))
file.close()
-# Blender.Window.WaitCursor(0)
DEBUG = False
-# if __name__=='__main__' and not DEBUG:
-# if calcsize == None:
-# Blender.Draw.PupMenu('Error%t|a full python installation not found')
-# else:
-# Blender.Window.FileSelector(load_3ds, 'Import 3DS', '*.3ds')
-
# For testing compatibility
#load_3ds('/metavr/convert/vehicle/truck_002/TruckTanker1.3DS', False)
#load_3ds('/metavr/archive/convert/old/arranged_3ds_to_hpx-2/only-need-engine-trains/Engine2.3DS', False)
Modified: trunk/blender/source/blender/makesrna/intern/rna_material_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_material_api.c 2010-02-10 01:54:32 UTC (rev 26757)
+++ trunk/blender/source/blender/makesrna/intern/rna_material_api.c 2010-02-10 01:55:45 UTC (rev 26758)
@@ -55,10 +55,10 @@
break;
}
}
-
+
if (slot == -1)
slot= 0;
-
+
if (ma->mtex[slot]) {
ma->mtex[slot]->tex->id.us--;
}
@@ -69,8 +69,9 @@
mtex= ma->mtex[slot];
mtex->tex= tex;
- id_us_plus(&tex->id);
-
+ if (tex)
+ id_us_plus(&tex->id);
+
mtex->texco= mapto;
mtex->mapto= texco;
}
@@ -117,7 +118,8 @@
func= RNA_def_function(srna, "add_texture", "rna_Material_add_texture");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list