Merge lp:~sirver/widelands-media/automask-material-improvement into lp:widelands-media

Proposed by SirVer
Status: Merged
Merged at revision: not available
Proposed branch: lp:~sirver/widelands-media/automask-material-improvement
Merge into: lp:widelands-media
Diff against target: 162 lines (+156/-0)
1 file modified
graphics/stock_sources/blender_set_templates/automask.py (+156/-0)
To merge this branch: bzr merge lp:~sirver/widelands-media/automask-material-improvement
Reviewer Review Type Date Requested Status
Widelands Media Developers Pending
Review via email: mp+22364@code.launchpad.net

Description of the change

Additional to objects in the PlayerGroup, a material named "PlayerColor" will also be set to ShadelessWhite. This allows for VertexGroups in Objects to be masked as well (there is an example in the graphics/stock_sources/blender_set_templates/automask.blend. I also added the .py file for itself, because I am not a king in packaging stuff into blender.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'graphics/stock_sources/blender_set_templates/automask.blend'
2Binary files graphics/stock_sources/blender_set_templates/automask.blend 2009-05-27 18:04:22 +0000 and graphics/stock_sources/blender_set_templates/automask.blend 2010-03-29 11:48:23 +0000 differ
3=== added file 'graphics/stock_sources/blender_set_templates/automask.py'
4--- graphics/stock_sources/blender_set_templates/automask.py 1970-01-01 00:00:00 +0000
5+++ graphics/stock_sources/blender_set_templates/automask.py 2010-03-29 11:48:23 +0000
6@@ -0,0 +1,156 @@
7+#automask python script (unstable)
8+#Needs Blender 2.43 or release candidates
9+#tested on linux build
10+
11+#CAUTION: Be sure to have saved/copied your model before
12+#running this. No undo available.
13+
14+#HOWTO: Add your player color objects to a group named
15+#PlayerColor in the 'Object and Links' Panel (F7).
16+#Press Alt-P with mouse cursor over this window.
17+
18+#Note: This Code is awful.
19+#Don't know why, but with any other attempt to relink materials
20+#for more than 300 objects/meshes blender 243 segfaults unevitably.
21+#Under 200 objects it seems to be no problem to change materials
22+#with NMesh.setMaterials/Object.setMaterials.
23+#So if you want to improve this code, use at
24+#least helmsmith-animation for testing.
25+
26+#Nevertheless...
27+
28+import Blender as BL
29+
30+objects = BL.Object.Get()
31+
32+def blackout_materials():
33+ materials = BL.Material.Get()
34+ for material in materials:
35+ print material.name
36+
37+ #delete all material ipos
38+ mipo = material.getIpo()
39+ if mipo != None:
40+ material.clearIpo()
41+
42+ #clear all material texture channels
43+ for i in [0,1,2,3,4,5,6,7,8,9]:
44+ material.clearTexture(i)
45+
46+ #change all present materials to shadeless black
47+ material.setRGBCol(0.0,0.0,0.0)
48+ material.setMode("Shadeless")
49+ material.setAlpha(1.0)
50+
51+
52+def blackout_objects():
53+ #define new shadeless materials (black/white)
54+ shadelessblack = BL.Material.New()
55+ shadelessblack.setRGBCol(0.0,0.0,0.0)
56+ shadelessblack.setMode("Shadeless")
57+
58+ #apply shadeless materials to objects with no materials
59+ for object in objects:
60+ objtype = object.getType()
61+ if objtype == "Mesh":
62+ nmesh = object.getData()
63+ if not nmesh.getMaterials():
64+ if not object.getMaterials():
65+ nmesh.materials.append( shadelessblack )
66+ nmesh.update()
67+ else:
68+ nmesh.hasVertexColours(0)
69+ nmesh.hasFaceUV(0)
70+ nmesh.hasVertexUV(0)
71+ #nmesh.update()
72+
73+ #remove all mesh color/uv layers
74+ meshes = BL.Mesh.Get()
75+ for mesh in meshes:
76+ collayers = mesh.getColorLayerNames()
77+ for coll in collayers:
78+ mesh.removeColorLayer(coll)
79+ mesh.update()
80+ uvlayers = mesh.getUVLayerNames()
81+ for uvl in uvlayers:
82+ mesh.removeUVLayer(uvl)
83+ mesh.update()
84+
85+def whiteout_objects_in_playercolor_group():
86+ shadelesswhite = BL.Material.New()
87+ shadelesswhite.setRGBCol(1.0,1.0,1.0)
88+ shadelesswhite.setMode("Shadeless")
89+
90+ #search for player color objects and make them shadeless white
91+ groups = BL.Group.Get()
92+
93+ havepcgrp = 0
94+ havepcobj = 0
95+ for pcgroup in groups:
96+ if pcgroup.name == "PlayerColor":
97+ havepcgrp = 1
98+ break
99+
100+ if havepcgrp == 0:
101+ print "Please add group 'PlayerColor'"
102+ print "Use 'Object and Links' Panel (F7)"
103+ else:
104+ for obj in list(pcgroup.objects):
105+ if obj.getType() == "Mesh":
106+ havepcobj = 1
107+ nmesh = obj.getData(0,0)
108+ if obj.getMaterials():
109+ obj.setMaterials([shadelesswhite])
110+ #FIXME: it sometimes happens, that faces
111+ #must be assigned to lower material indices.
112+ #Without that faces are rendered invisible
113+ #Should do this automatically here
114+ nmesh.setMaterials([shadelesswhite])
115+ obj.colbits = (1<<0)+(1<<0)#...
116+ nmesh.update()
117+ else:
118+ print "Warning 'PlayerColor' object must be mesh type"
119+ if havepcobj == 0:
120+ print "Warning: no 'PlayerColor' object found"
121+
122+def whiteout_player_color_material():
123+ """
124+ This searches for a Material calles PlayerColor and makes it shadeless
125+ white
126+ """
127+ try:
128+ m = BL.Material.Get("PlayerColor")
129+ m.setRGBCol(1.,1.,1.)
130+ m.setMode("Shadeless")
131+ except NameError:
132+ pass
133+
134+
135+def setup_world():
136+ #world and render settings
137+ world = BL.World.GetCurrent()
138+ world.setSkytype(0x04)
139+ world.setHor([0.0,0.0,0.0])
140+ scene = BL.Scene.GetCurrent()
141+ context = scene.getRenderingContext()
142+ context.enableKey()
143+ context.enableOversampling(0)
144+ context.enableRGBColor()
145+ context.setImageType(BL.Scene.Render.PNG)
146+
147+def main():
148+ # leave edit mode
149+ if BL.Window.EditMode():
150+ BL.Window.EditMode(0)
151+
152+ blackout_materials()
153+ blackout_objects()
154+
155+ whiteout_objects_in_playercolor_group()
156+ whiteout_player_color_material()
157+ setup_world()
158+
159+
160+if __name__ == '__main__':
161+ main()
162+

Subscribers

People subscribed via source and target branches

to status/vote changes: