Hello,
It's a try to support raydium multitexturing import with blender.
This is a new import script.
It have been quite all rewritten, and indent are Tabs and no more mixed between tabs and space (code was quite unreadable with blender font).
It is possible to specify several texture on a mesh using several uvtexture in mesh properties:
Uv texture name are not important, during import they are defined to the name of the image file.
Blender did not show the multitextuing effect in the 3D view. But you can swap texture visibility using
The code is a bit slow (for cocorobrix.tri at least).
Please try it and don't hesitate to report bugs or enhancement.
It allows to render texture and ambiant occlusion (after this one has been baked to a new texture).
I'll detail the steps further because this is wip.
Code:
#!BPY
"""
Name: 'Raydium Import (.tri format)'
blender: 2.31
Group: 'Import'
Tooltip: 'Import a .tri'
"""
#import rpdb2;
#rpdb2.start_embedded_debugger("test",True)
try:
import nt
os=nt
os.sep='\\'
except:
import posix
os=posix
os.sep='/'
import sys
import Blender
from Blender import Mesh
# This script will include .tri files (Raydium mesh files)
# Do not supports multitexturing yet.
# Python puxxor :)
def fileExists(f):
try:
file = open(f)
except IOError:
exists = 0
else:
exists = 1
return exists
class source:
def __init__(self,filename):
self.filename=filename
self.file=open(filename,"r")
def readFaces(self):
lines = self.file.readlines();
#p,f = os.path.split(self.filename)
#p,f = Blender.sys.splitext(self.filename)
p = Blender.sys.dirname(self.filename)
#f = Blender.sys.basename(self.filename)
os.chdir(p)
print "CWD is now %s" % (p)
scene=Blender.Scene.GetCurrent()
mesh = Blender.Mesh.New()
words = lines[0].split()
if len(words) <>1 :
print "Not a raydium .tri file (first line must be 0 or 1)"
return -1
version = float(words[0])
if version <0 or version >1:
print "Not a supported (0 or 1) file format"
return -1
n = 0
vi = 0
fi = 0
ntot = len(lines)-1
naff = ntot /20
ncour = 0
lfilename =[]
ltexname =["tex01","tex02","tex03"]
for line in lines[1:]:
ncour=ncour+1
if (ncour >= naff):
print (vi*100/ntot)+1
ncour=0
if (n==3):
n=0
vi = vi+3
fi = fi+1
if (n==0):
mesh.verts.extend(0,0,0)
mesh.verts.extend(0,0,0)
mesh.verts.extend(0,0,0)
mesh.faces.extend(vi,vi+1,vi+2)
face=mesh.faces[fi]
words = line.split()
vx = float(words[0])
vy = float(words[1])
vz = float(words[2])
if version==1:
bu = float(words[6])
bv = float(words[7])
texname=words[8]
if version==0:
bu = float(words[3])
bv = float(words[4])
texname=words[5]
mesh.verts[vi+n].co[0] = vx
mesh.verts[vi+n].co[1] = vy
mesh.verts[vi+n].co[2] = vz
if texname[0:4] == "rgb(":
temp=texname[4:-1].split(")")
texname=temp[0]
textured = 0
couls=texname.split(",")
r= float(couls[0])*255
g= float(couls[1])*255
b= float(couls[2])*255
try:
mesh.activeColorLayer = "rgb"
except:
mesh.addColorLayer("rgb")
mesh.activeColorLayer = "rgb"
face.col[n].r=int(r)
face.col[n].g=int(g)
face.col[n].b=int(b)
face.col[n].a=255
else:
filename = texname.split(";")
i=0
for file in filename:
param = file.split("|")
if (len(param)==1):
texname = param[0]
if (len(param)==3):
texname = param[2]
bu = float(param[0]) ; bv = float(param[1])
try:
mesh.activeUVLayer = ltexname[i]
except:
mesh.addUVLayer(ltexname[i])
if fileExists(texname) == 0:
print "Cannot access to %s" % (texname)
mesh.activeUVLayer = ltexname[i]
face.image = Blender.Image.Load(texname)
face.mode |= Blender.Mesh.FaceModes['TEX']
face.mode |= Blender.Mesh.FaceModes['TWOSIDE']
face.uv[n][0] = bu
face.uv[n][1] = bv
i=i+1
n = n + 1
scn = Blender.Scene.GetCurrent()
ob = scn.objects.new(mesh)
ob.setLocation(0,0,0)
Blender.Redraw()
return 0
ob = Blender.Object.New("Mesh")
ob.link(mesh)
mesh.name = "tri"
print "end."
return 0
def close(self):
#self.file.flush()
self.file.close()
def importTRI(filename):
if filename.find('.tri', -4) <= 0: filename += '.tri'
obj=source(filename)
ret = obj.readFaces()
obj.close
if ret>0:
print "Imported."
else:
Blender.Draw.PupMenu("Bad File type not imported See console.")
def filesel_callback(filename):
test = importTRI(filename)
Blender.Window.FileSelector(filesel_callback, 'Import TRI','*.tri')
#importTRI("test1.tri")
Waiting for feedback.
Have a nice day
Ouille
P.S.: Is there a blender pro that can detail steps to show this multitexturing directly under blender ?
I try adding a lamp and a camera, but scene is not always textured.
Combining the textures using node editor is a solution but too complex !
Help welcome.
Edit: petite correction du script.