Revision: 31663 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31663 Author: aligorith Date: 2010-08-30 15:07:28 +0200 (Mon, 30 Aug 2010)
Log Message: ----------- Bullet SoC - Improved "Wall" template Changes: * Made dimensions of the bricks more realistic. They were previously 3m x 1m x 1m monsters weighing only 1 kg * Alternating rows are "offset" by half-a-brick, and shorter by 1-brick to compensate. On by default. * Alternating rows can have 'half-bricks' to fill in the spaces left by the offsets. Off by default, and only useful when the previous option is enabled. * Initial/source brick is no longer kept, removing the problem where one column of bricks were always seen to explode (due to overlapping bricks). * Code reshuffle... See http://aligorith.blogspot.com/2010/08/bullet-soc-experiments-fixes-and-more.html for visual illustrations of most of these. Modified Paths: -------------- branches/soc-2010-aligorith-2/release/scripts/op/add_rigidbody_wall.py Modified: branches/soc-2010-aligorith-2/release/scripts/op/add_rigidbody_wall.py =================================================================== --- branches/soc-2010-aligorith-2/release/scripts/op/add_rigidbody_wall.py 2010-08-30 12:27:34 UTC (rev 31662) +++ branches/soc-2010-aligorith-2/release/scripts/op/add_rigidbody_wall.py 2010-08-30 13:07:28 UTC (rev 31663) @@ -18,6 +18,8 @@ import bpy +############################## + # add 'brick' mesh def add_brick(context, major_radius, minor_radius, mass): # add new brick as a cube @@ -42,6 +44,101 @@ return brick; +# ---------------- + +# add most of the objects representing the wall - fullsized bricks +# < wall: (Object) dummy object acting as 'owner' of entire wall +def addWallBricks(context, props, wall): + # add single brick + # - this will end up being the source brick from which + # all other 'normal' bricks are derived + # - assume that this is added at (0,0,0) + # - set parent to 'wall' object so that all can be moved at once + brick = add_brick(context, props.major_length, props.minor_length, props.mass) + brick.parent = wall + + # construct the wall by duplicating the brick as many times as needed + for row in range(props.rows): + # number of bricks per row varies if we're using offsetted rows + # on that row, as the offsets are have half-brick lengths which constitute to one less "whole" + # brick less needed for that row + if props.use_row_offsets and (row % 2) != 0: + rowCols = props.columns - 1 + else: + rowCols = props.columns + + # create bricks for this row + for col in range(rowCols): + # make a copy of the active brick + bpy.ops.object.duplicate(linked=True) + curBrick = context.active_object + + # calculate the positions based on the row and column + # 1) "+ minor_length" factor makes sure wall will be nicely + # off a standard ground plane (at z=0) + rowLoc = (2 * props.minor_length) * row + props.minor_length + # 2) offset depends on whether this is on a row with half-bricks + if rowCols == props.columns: + # normal case - no offset + colLoc = (2 * props.major_length) * col + else: + # half-brick row - offset by half width + colLoc = (2 * props.major_length) * col + props.major_length + + curBrick.location = (colLoc, 0.0, rowLoc) + + # get rid of starting brick + bpy.ops.object.select_all(action='DESELECT') + brick.selected = True + bpy.ops.object.delete() + +# add the half bricks on alternating rows +# < wall: (Object) dummy object acting as 'owner' of entire wall +def addWallHalfBricks(context, props, wall): + # half-brick major length + hlen = props.major_length / 2.0 + + # add single brick + # - this will end up being the source brick from which + # all other 'half' bricks are derived + # - halve the length and mass, but leave the other dimensions alone + # - assume that this is added at (0,0,0) + # - set parent to 'wall' object so that all can be moved at once + brick = add_brick(context, hlen, props.minor_length, props.mass/2.0) + brick.parent = wall + + # calculate horizontal positions + # 1) slightly offset to account for shorter length + xL1 = -hlen + # 2) last normal brick position, plus an extra half-brick length + xL2 = (2*props.major_length)*(props.columns-1) + hlen + # as a tuple for simpler code (but slightly more mem) + xLocs = (xL1, xL2) + + # construct the wall by duplicating the brick as many times as needed + # - only do every second row, adding two bricks; one to each end + for row in range(1, props.rows+1, 2): + # calculate vertical positon: + # + minor_length" factor makes sure wall will be nicely + # off a standard ground plane (at z=0) + rowLoc = (2 * props.minor_length) * row + props.minor_length + + # create the two bricks needed + for xLoc in xLocs: + # make a copy of the active brick + bpy.ops.object.duplicate(linked=True) + curBrick = context.active_object + + # move into position + curBrick.location = (xLoc, 0.0, rowLoc) + + # get rid of starting brick + bpy.ops.object.select_all(action='DESELECT') + brick.selected = True + bpy.ops.object.delete() + +############################## + from bpy.props import * class AddRbWall(bpy.types.Operator): @@ -56,13 +153,20 @@ columns = IntProperty(name="Columns", description="Number of bricks per row", default=5, min=1, max=256) + + use_row_offsets = BoolProperty(name="Use Row Offsets", + description="Every second row is offsetted by a half-brick and shortened to create an alternating pattern", + default=True) + use_half_bricks = BoolProperty(name="Use Half Bricks", + description="When 'Use Row Offsets' is enabled, add half-sized bricks in the offset spaces", + default=False) major_length = FloatProperty(name="Major Length", description="Distance from center to edge along widest axis", - default=1.5, min=0.01, max=100.0) + default=0.15, min=0.01, max=100.0) minor_length = FloatProperty(name="Minor Length", description="Distance from center to edge along all other axes", - default=0.5, min=0.01, max=100.0) + default=0.05, min=0.01, max=100.0) mass = FloatProperty(name="Mass", description="How much each brick weighs (same as for Rigid Bodies)", @@ -74,35 +178,24 @@ def execute(self, context): props = self.properties - # add single brick - # - this will end up being the source brick from which - # all other bricks are derived - # - it will also be the lower-left brick in the wall... - # - assume that this is added at (0,0,0) - brick = add_brick(context, props.major_length, props.minor_length, props.mass) + # add empty to add as dummy wall control + bpy.ops.object.add(type='EMPTY') - # duplicate this brick as many times as needed - for row in range(props.rows): - for col in range(props.columns): - # make a copy of the active brick - bpy.ops.object.duplicate() - curBrick = context.active_object - - # set parent to original brick so they can all be moved at once - curBrick.parent = brick - - # calculate the positions based on the row and column - rowLoc = (2 * props.minor_length) * row - colLoc = (2 * props.major_length) * col - - curBrick.location = (colLoc, 0.0, rowLoc) - - # select only the starting brick + wall = context.active_object + wall.name = "RbWallOb" + + # add half-bricks + if props.use_row_offsets and props.use_half_bricks: + addWallHalfBricks(context, props, wall) + + # add bricks of the wall + addWallBricks(context, props, wall) + + # set wall owner as only selected object bpy.ops.object.select_all(action='DESELECT') + wall.selected = True + context.scene.objects.active = wall - brick.selected = True - context.scene.objects.active = brick - return {'FINISHED'} _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs