Blender script for exporting LMTS .scr files

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
Iaro
Posts: 45
Joined: Sat Feb 05, 2005 7:01 am

Blender script for exporting LMTS .scr files

Post by Iaro »

Lately I've been playing around with Lord Trancos Pulsar Lmtools. The package includes a Gmax script for exporting light information. Because I mostly use Blender for 3D work, I made a script that atempts to mimic the original one's functionalty.
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")

Copy the above code into filename.py and place it in ../Blender_dir/.Blender/Scripts. The script is written for Blender 2.41 but might work for older versions.

Robert
juliusctw
Posts: 392
Joined: Fri Apr 21, 2006 6:56 am
Contact:

Question

Post by juliusctw »

Hello

I'm kinda confused about what your py code does, are you saying that it can export .blend files into .x format for irrlicht, if so, that would be amazing because so many people have been griefing over that problem
Iaro
Posts: 45
Joined: Sat Feb 05, 2005 7:01 am

Post by Iaro »

No, the script is for exporting .scr files containing information about lights in the scene. This information can then be used when lightmapping lmts files.
If you are looking for a Blender .x exporter this thread might interest you : http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11690
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Your approach is very interesting Iaro. Pulsar LMtools is a good alternative for lightmapping and being bale to export from blender is surely a very good alternative. I thought people had forgotten of this format. :wink: Gonna get my LMtools again and try it out!

good work! :D
@juiliusctw: you can read about the pulsar lmtools here:
http://personal.telefonica.terra.es/web/afx/lmtools/
Post Reply