Using the script:
- There are some diferences between light information in Gmax and
Blender :
- for the spotlights theta (hotspot) parameter SpotSize - SpotSize * SpotBlend was used.
- for the spotlights phi (falloff) parameter SpotSize was used
- if you want to use light attenuation (only for lamps and spots) enable Quad and use Quad1 and Quad2 for attenuation start and end. To
avoid problems Quad1 should always be smaller than Quad2.
- For global ambient color use Shading -> WorldButtons (AmbR, AmbG, AmbB)
- When working with colors ( both for lights and ambient ) try not to
have any color component value under 0.1. I'll try and fix this in a future
version.
This script is still a beta (and also my first "serious" python script) so sugestions would be apreciated.
Also not related to the script but maybe someone will find this usefull. The Blender -> LMTS workflow(s) :
1) Export to .x, import with lmdx, export to lmts and L)
2) Export to .3ds (no textures), texture in Anim8or, Wings etc., reexport, use "a3ds2lmts filename" to convert to lmts and L)
3) Export to .obj (retains textures),import in Wings, export to .3ds,
use "a3ds2lmts filename" to convert to lmts and L)
L) You can use "LMtools.bat filename" to generate a lightmapped file
using default values or use lmgen and lmpack.
Code: Select all
#!BPY
"""
Name: 'LMTS script (.scr)'
Blender: 241
Group: 'Export'
Tooltip: "'LMTS .scr exporter'
"""
import os
import math
import Blender
from Blender import *
def salveaza_script(fis):
if not fis.endswith('.scr'): fis = "%s.scr" % fis
ef = open(fis,'w')
wrld = Blender.World.Get('World')
ef.write("\
;lightmap_settings \n\
lightmap.lumel_size =12 \n\n\
;Ambient light \n\
ambient_global.color = $" + str(hex(int(wrld.getAmb()[0] * 255))).replace('0x','')+str(hex(int(wrld.getAmb()[1] * 255))).replace('0x','')+str(hex(int(wrld.getAmb()[2] * 255))).replace('0x','') + "\n\n");
lista_obj = Blender.Object.Get()
for obj in lista_obj :
if obj.getType() == "Lamp" :
la = obj.data
if la.type == 0 :
ef.write("; omni ["+ obj.name + "]\n")
ef.write("omni_point.position = "+str(obj.LocX)+", "+str(obj.LocZ)+", "+str(obj.LocY)+"\n")
ef.write("omni_point.color = $"+str(hex(int(la.R*255))).replace('0x','')+str(hex(int(la.G*255))).replace('0x','')+str(hex(int(la.B*255))).replace('0x','')+"\n")
ef.write("omni_point.multiplier = " + str(la.energy)+"\n")
if la.getMode() & la.Modes["Quad"] :
ef.write("omni_point.attenuation = " + str(la.getQuad1()*100)+", "+str(la.getQuad2()*100)+"\n")
else : ef.write("omni_point.attenuation = 0, 0\n")
ef.write("omni_point.cast_shadows = true \nomni_point.enabled = true \nomni_point.add\n\n")
# de rezolvat
#if la.getMode() & la.Modes["Shadows"] :
# ef.write("omni_point.cast_shadows = true \n")
#else : ef.write("omni_point.cast_shadows = false \n")
elif la.type == 2 :
ef.write("; spotlight ["+ obj.name + "]\n")
ef.write("spotlight.position = "+str(obj.LocX)+", "+str(obj.LocZ)+", "+str(obj.LocY)+"\n")
### constructia targetului, are pozitia <=> cu clipendu spotului
empty = Blender.Object.New('Empty')
scene = Blender.Scene.getCurrent()
scene.link(empty)
empty.setLocation(0,0,-la.clipEnd)
empty.setMatrix(empty.getMatrix() * obj.getMatrix())
ef.write("spotlight.target = "+str(empty.LocX)+", "+str(empty.LocY)+", "+str(empty.LocZ)+"\n")
scene.unlink(empty)
Blender.Redraw()
### urmeaza target, theta, pi
ef.write("spotlight.theta = " + str( la.getSpotSize()*(math.pi/180) - la.getSpotSize() * la.getSpotBlend()*(math.pi/180) )+"\n")
ef.write("spotlight.phi = "+ str(la.getSpotSize()*(math.pi/180))+"\n")
ef.write("spotlight.color = $"+str(hex(int(la.R*255))).replace('0x','')+str(hex(int(la.G*255))).replace('0x','')+str(hex(int(la.B*255))).replace('0x','')+"\n")
ef.write("spotlight.multiplier = " + str(la.energy)+"\n")
if la.getMode() & la.Modes["Quad"] :
ef.write("spotlight.attenuation = " + str(la.getQuad1()*100)+", "+str(la.getQuad2()*100)+"\n")
else : ef.write("spotlight.attenuation = 0, 0\n")
ef.write("spotlight.cast_shadows = true \nspotlight.enabled = true \nspotlight.add\n\n")
elif la.type == 4 :
ef.write("; directional ["+ obj.name + "]\n" )
matr = obj.matrixWorld
dir = Mathutils.Vector(0,0,1,1)*matr
dir.resize3D()
ef.write("directional.direction = "+str(dir[0]*(-1))+", "+str(dir[2]*(-1))+", "+str(dir[1]*(-1))+"\n")
ef.write("directional.color = $"+str(hex(int(la.R*255))).replace('0x','')+str(hex(int(la.G*255))).replace('0x','')+str(hex(int(la.B*255))).replace('0x','')+"\n")
ef.write("directional.multiplier = " + str(la.energy)+"\n")
ef.write("directional.cast_shadows = true \ndirectional.enabled = true \ndirectional.add\n\n")
Blender.Redraw()
ef.close()
Window.FileSelector(salveaza_script, "Save script")
Robert