Author: ArcRiley Date: 2008-03-22 05:14:03 -0400 (Sat, 22 Mar 2008) New Revision: 1201
Modified: trunk/pysoy/examples/CollideBlocks.py trunk/pysoy/examples/TexBlocks.py trunk/pysoy/examples/blocks.py Log: Ticket #949 : * separated code out better to allow dynamic materials for blocks Modified: trunk/pysoy/examples/CollideBlocks.py =================================================================== --- trunk/pysoy/examples/CollideBlocks.py 2008-03-22 09:12:44 UTC (rev 1200) +++ trunk/pysoy/examples/CollideBlocks.py 2008-03-22 09:14:03 UTC (rev 1201) @@ -8,7 +8,25 @@ cam.position = (0.0, 0.0, 15.0) lig = soy.bodies.Light(sce) lig.position = (-10.0,10.0,2.0) -bks = blocks.blocks(sce) + +black = soy.materials.Material() +black.ambient = soy.colors.black +black.diffuse = soy.colors.Color('#222') +black.specular= soy.colors.Color('#444') +black.shininess = 5.0 +colors = { + 'Aventurine' : (soy.materials.Aventurine(), black, ( 0, 0, 0)), + 'Basalt' : (soy.materials.Basalt(), black, ( 4,-1,-4)), + 'Copper' : (soy.materials.Copper(), black, (-3,-2,-2)), + 'CopperSulfate' : (soy.materials.CopperSulfate(), black, ( 0,-2,-1)), + 'DarkWood' : (soy.materials.DarkWood(), black, ( 5, 3,-6)), + 'Pearl' : (soy.materials.Pearl(), black, (-1, 2,-3)), + 'Rhodonite' : (soy.materials.Rhodonite(), black, (-4, 1,-5)), + 'VelvetyRed' : (soy.materials.VelvetyRed(), black, ( 3, 0,-8)), +} + +bks = blocks.blocks(sce, colors) + fps = soy.textures.Print() scr = soy.Screen() Modified: trunk/pysoy/examples/TexBlocks.py =================================================================== --- trunk/pysoy/examples/TexBlocks.py 2008-03-22 09:12:44 UTC (rev 1200) +++ trunk/pysoy/examples/TexBlocks.py 2008-03-22 09:14:03 UTC (rev 1201) @@ -7,12 +7,24 @@ cam = soy.bodies.Camera(sce) cam.position = (0.0, 0.0, 3.0) lig = soy.bodies.Light(sce) -lig.position = (-5.0,5.0,5.0) -bks = blocks.blocks(sce) +lig.position = (-10.0,10.0,2.0) + +black = soy.materials.Material() +black.ambient = soy.colors.black +black.diffuse = soy.colors.Color('#222') +black.specular= soy.colors.Color('#444') +black.shininess = 5.0 +mrbl = soy.transports.File('media/marble.soy')['gimp'] +dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp'] +colors = { + 'Marble' : (soy.materials.Material(color=mrbl, normal=dot3), black, (0,0,0)), +} +bks = blocks.blocks(sce, colors) + fps = soy.textures.Print() scr = soy.Screen() -win = soy.Window(scr, 'CollideBlocks', background=soy.colors.gray) +win = soy.Window(scr, 'TexBlocks', background=soy.colors.cyan) pro = soy.widgets.Projector(win, camera=cam) can = soy.widgets.Canvas(win, texture=fps) Modified: trunk/pysoy/examples/blocks.py =================================================================== --- trunk/pysoy/examples/blocks.py 2008-03-22 09:12:44 UTC (rev 1200) +++ trunk/pysoy/examples/blocks.py 2008-03-22 09:14:03 UTC (rev 1201) @@ -1,18 +1,9 @@ import soy from random import random -mrbl = soy.transports.File('media/marble.soy')['gimp'] -dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp'] - class BlockMesh(soy.models.Mesh) : - def __init__(self, mycol) : - black = soy.materials.Material() - black.ambient = soy.colors.black - black.diffuse = soy.colors.Color('#222') - black.specular= soy.colors.Color('#222') - black.shininess = 5.0 + def __init__(self, mats) : Vert = VertexGroup(self) - # Create Faces # 2 Halves for a in (1.0, -1.0) : @@ -21,10 +12,7 @@ # 4 Quarters in each side for c in (1.0, -1.0) : for d in (1.0, -1.0) : - if a*c*d > 0 : - material = mycol - else : - material = black + material = mats[a*c*d > 0] points = (Vert(b, (.500*a, .000*c, .000*d), (a, 0, 0)), # 0 Vert(b, (.500*a, .000*c, .450*d), (a, 0, 0)), # 1 Vert(b, (.500*a, .450*c, .450*d), (a, 0, 0)), # 2 @@ -74,23 +62,12 @@ def srand() : return random()-.5 -def blocks(sce): - colors = { - 'Marble' : (soy.materials.Material(color=mrbl, normal=dot3), (0,0,0)), - 'Aventurine' : (soy.materials.Aventurine(), ( 0, 0, 0)), - 'Basalt' : (soy.materials.Basalt(), ( 4,-1,-4)), - 'Copper' : (soy.materials.Copper(), (-3,-2,-2)), - 'CopperSulfate' : (soy.materials.CopperSulfate(), ( 0,-2,-1)), - 'DarkWood' : (soy.materials.DarkWood(), ( 5, 3,-6)), - 'Pearl' : (soy.materials.Pearl(), (-1, 2,-3)), - 'Rhodonite' : (soy.materials.Rhodonite(), (-4, 1,-5)), - 'VelvetyRed' : (soy.materials.VelvetyRed(), ( 3, 0,-8)), - } +def blocks(sce, colors): blocks = {} for color in colors : blocks[color] = soy.bodies.Body(sce, - model=BlockMesh(colors[color][0]), - position=colors[color][1]) + model=BlockMesh(colors[color][:2]), + position=colors[color][2]) blocks[color].rotation = (srand(), srand(), srand()) blocks[color].shape = soy.shapes.Box(1,1,1) t = -0.5 _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn