Esempio n. 1
0
def processSolid(doc, parent, worldspawn, sf, offset, solid):
    '''Note: uses style set in parent hollow.'''
    global style
    o = utils.getPoint(solid.getAttribute('origin')) + offset
    e = utils.getPoint(solid.getAttribute('extent'))
    t = solid.getAttribute('texture')
    type = solid.getAttribute('type')
    if not t:
        if not type:
            utils.error('solid with no type also has no texture attribute set')
    f = solid.getAttribute('holeface')
    # Get holes info...
    # FIXME this is repeated code from the hollow one -- any way we can
    # refactor it?
    props = {}
    holes = []
    # Check if the solid has children (holes).
    # If so, split it up.
    # If not, just add it.
    if solid.hasChildNodes():
        for hole in solid.childNodes:
            ho_x, ho_y = hole.getAttribute('origin').split()
            he_x, he_y = hole.getAttribute('extent').split()
            type = hole.getAttribute('type')
            if not type:
                pass
            elif type == connector.DOOR:
                props['key'] = hole.getAttribute('key')
            else:
                utils.warning(
                    'only doors allowed as hole types; not plats or others.')
            # FIXME deal with other types
            holes.append(
                utils.Hole2D(utils.Point2D(float(ho_x), float(ho_y)),
                             utils.Point2D(float(he_x), float(he_y)), type,
                             props))
        # Built split (2D) parts into 3D brushes; mapping of coords to 3D
        # depends on which direction/face the hole was constructed in.
        if f == dcp.NORTH:
            parts = split.splitWall(
                utils.Region2D(utils.Point2D(o.x, o.z),
                               utils.Point2D(e.x, e.z)), holes)
            for part in parts:
                part3d = utils.addDim(part, dims.Y, o.y, e.y)
                utils.makeBrush(doc, worldspawn, sf, style, part3d, f, t)
        elif f == dcp.UP:
            parts = split.splitWall(
                utils.Region2D(utils.Point2D(o.x, o.y),
                               utils.Point2D(e.x, e.y)), holes)
            for part in parts:
                part3d = utils.addDim(part, dims.Z, o.z + prog.lip_small,
                                      e.z - prog.lip_small * 2)
                utils.makeBrush(doc, worldspawn, sf, style, part3d, f, t)
            else:
                utils.error('Unsupported holeface ' + f +
                            ' requested for hole in solid.')
    else:
        # Doesn't have child nodes...
        if not type or type == connector.STEP:
            pass  # no properties to set
        elif type == connector.DOOR:
            props['key'] = solid.getAttribute('key')
        elif type == connector.PLAT:
            props['position'] = solid.getAttribute('position')
        else:
            utils.warning('unknown type ' + type + ' specifed.')

        brush = utils.Region3D(Point(o.x, o.y, o.z), Point(e.x, e.y, e.z),
                               type, props)
        utils.makeBrush(doc, worldspawn, sf, style, brush, type, t)
    # We can't remove the child or we screw over tree traversal (urgh)...
    utils.insertPlaceholder(doc, parent, solid)
Esempio n. 2
0
def makeHollow(doc, worldspawn, sf, origin, extent, absentwalls, holes, style):
    '''Makes a hollow object (room/corridor) with the given paramaters.
	Works out the brushes, textures.
	Returns the origin and extent of the inner area.
	The north and south walls cover the entire width of the hollow.  The east and west ones fit inbetween the north and south ones.  However...
	To avoid leaks, when some walls are absent, the others must be made longer to cover the possible holes.  For example, if there is no north wall, the east and west ones need to be ldl.lip units longer in case them not being so would cause a leak.'''
    inner_origin = origin + lip
    inner_abslut_extent = (origin + extent) - lip

    # down (floor)
    if not DCP_DOWN in absentwalls:
        brush_start = origin
        brush_extent = Point(extent.x, extent.y, lip)
    parts = split.splitWall(
        Region2D(Point2D(brush_start.x, brush_start.y),
                 Point2D(brush_extent.x, brush_extent.y)),
        getHoles(holes, DCP_DOWN))
    for part in parts:
        part3d = addDim(part, DIM_Z, brush_start.z)
        #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
        makeBrush(doc, worldspawn, sf, style, part3d, DCP_DOWN)
    # up (ceiling)
    if not DCP_UP in absentwalls:
        brush_start = origin + Point(0, 0, extent.z - lip)
        brush_extent = Point(extent.x, extent.y, lip)
    parts = split.splitWall(
        Region2D(Point2D(brush_start.x, brush_start.y),
                 Point2D(brush_extent.x, brush_extent.y)),
        getHoles(holes, DCP_UP))
    for part in parts:
        part3d = addDim(part, DIM_Z, brush_start.z)
        #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
        makeBrush(doc, worldspawn, sf, style, part3d, DCP_UP)
    # north wall; y represents depth
    if not DCP_NORTH in absentwalls:
        brush_start = origin + Point(0, extent.y - lip, lip)
        brush_extent = Point(extent.x, lip, extent.z - lip * 2)
        wall_holes = getHoles(holes, DCP_NORTH)
        parts = split.splitWall(
            Region2D(Point2D(brush_start.x, brush_start.z),
                     Point2D(brush_extent.x, brush_extent.z)),
            getHoles(holes, DCP_NORTH))
        for part in parts:
            part3d = addDim(part, DIM_Y, brush_start.y)
            #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
            makeBrush(doc, worldspawn, sf, style, part3d, DCP_NORTH)
    # south wall
    # FIXME holes need to be expressed the other way 'round (i.e. 0 is at RHS not LHS)?
    if not DCP_SOUTH in absentwalls:
        brush_start = origin + Point(0, 0, lip)
        brush_extent = Point(extent.x, lip, extent.z - lip * 2)
        wall_holes = getHoles(holes, DCP_SOUTH)
        parts = split.splitWall(
            Region2D(Point2D(brush_start.x, brush_start.z),
                     Point2D(brush_extent.x, brush_extent.z)),
            getHoles(holes, DCP_SOUTH))
        for part in parts:
            part3d = addDim(part, DIM_Y, brush_start.y)
            #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
            makeBrush(doc, worldspawn, sf, style, part3d, DCP_SOUTH)
    # west wall
    if not DCP_WEST in absentwalls:
        if DCP_NORTH not in absentwalls and DCP_SOUTH not in absentwalls:
            brush_start = origin + Point(0, lip, lip)
            brush_extent = Point(lip, extent.y - lip * 2, extent.z - lip * 2)
        elif DCP_NORTH in absentwalls and DCP_SOUTH in absentwalls:
            brush_start = origin + Point(0, lip, lip)
            brush_extent = Point(lip, extent.y - lip * 2, extent.z - lip * 2)
        elif DCP_NORTH in absentwalls:
            brush_start = origin + Point(0, lip, lip)
            brush_extent = Point(lip, extent.y - lip, extent.z - lip * 2)
        elif DCP_SOUTH in absentwalls:
            brush_start = origin + Point(0, 0, lip)
            brush_extent = Point(lip, extent.y - lip, extent.z - lip * 2)
        else:
            error('absentwalls')
        wall_holes = getHoles(holes, DCP_WEST)
        parts = split.splitWall(
            Region2D(Point2D(brush_start.y, brush_start.z),
                     Point2D(brush_extent.y, brush_extent.z)),
            getHoles(holes, DCP_WEST))
        for part in parts:
            part3d = addDim(part, DIM_X, brush_start.x)
            #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
            makeBrush(doc, worldspawn, sf, style, part3d, DCP_WEST)
    # east wall
    if not DCP_EAST in absentwalls:
        if DCP_NORTH not in absentwalls and DCP_SOUTH not in absentwalls:
            brush_start = origin + Point(extent.x - lip, lip, lip)
            brush_extent = Point(lip, extent.y - lip * 2, extent.z - lip * 2)
        elif DCP_NORTH in absentwalls and DCP_SOUTH in absentwalls:
            brush_start = origin + Point(extent.x - lip, 0, lip)
            brush_extent = Point(lip, extent.y, extent.z - lip * 2)
        elif DCP_NORTH in absentwalls:
            brush_start = origin + Point(extent.x - lip, lip, lip)
            brush_extent = Point(lip, extent.y - lip, extent.z - lip * 2)
        elif DCP_SOUTH in absentwalls:
            brush_start = origin + Point(extent.x - lip, 0, lip)
            brush_extent = Point(lip, extent.y - lip, extent.z - lip * 2)
        else:
            error('absentwalls')
        parts = split.splitWall(
            Region2D(Point2D(brush_start.y, brush_start.z),
                     Point2D(brush_extent.y, brush_extent.z)),
            getHoles(holes, DCP_EAST))
        for part in parts:
            part3d = addDim(part, DIM_X, brush_start.x)
            #uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
            makeBrush(doc, worldspawn, sf, style, part3d, DCP_EAST)
    # Return inner extents...
    return inner_origin, inner_abslut_extent
Esempio n. 3
0
def makeHollow(doc, worldspawn, sf, origin, extent, absentwalls, holes, style):
	'''Makes a hollow object (room/corridor) with the given paramaters.

	Works out the brushes, textures.

	Returns the origin and extent of the inner area.

	The north and south walls cover the entire width of the hollow. The east
	and west ones fit inbetween the north and south ones. However...

	To avoid leaks, when some walls are absent, the others must be made longer
	to cover the possible holes. For example, if there is no north wall, the
	east and west ones need to be utils.prog.lip units longer in case them not
	being so would cause a leak.'''
	inner_origin = origin + prog.lip
	inner_abslut_extent = (origin + extent) - prog.lip

	# down (floor)
	if dcp.DOWN not in absentwalls:
		brush_start = origin
		brush_extent = Point(extent.x, extent.y, prog.lip)
	parts = split.splitWall(
		Region2D(
			Point2D(brush_start.x, brush_start.y),
			Point2D(brush_extent.x, brush_extent.y)
		),
		getHoles(holes, dcp.DOWN))
	for part in parts:
		part3d = addDim(part, dims.Z, brush_start.z)
		makeBrush(doc, worldspawn, sf, style, part3d, dcp.DOWN)
	# up (ceiling)
	if dcp.UP not in absentwalls:
		brush_start = origin + Point(0, 0, extent.z - prog.lip)
		brush_extent = Point(extent.x, extent.y, prog.lip)
	parts = split.splitWall(
		Region2D(
			Point2D(brush_start.x, brush_start.y),
			Point2D(brush_extent.x, brush_extent.y)
		),
		getHoles(holes, dcp.UP))
	for part in parts:
		part3d = addDim(part, dims.Z, brush_start.z)
		makeBrush(doc, worldspawn, sf, style, part3d, dcp.UP)
	# north wall; y represents depth
	if dcp.NORTH not in absentwalls:
		brush_start = origin + Point(0, extent.y - prog.lip, prog.lip)
		brush_extent = Point(extent.x, prog.lip, extent.z - prog.lip * 2)
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.x, brush_start.z),
				Point2D(brush_extent.x, brush_extent.z)
			),
			getHoles(holes, dcp.NORTH))
		for part in parts:
			part3d = addDim(part, dims.Y, brush_start.y)
			makeBrush(doc, worldspawn, sf, style, part3d, dcp.NORTH)
	# south wall
	# FIXME holes need to be expressed the other way 'round (i.e. 0 is at RHS
	# not LHS)?
	if dcp.SOUTH not in absentwalls:
		brush_start = origin + Point(0, 0, prog.lip)
		brush_extent = Point(extent.x, prog.lip, extent.z - prog.lip * 2)
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.x, brush_start.z),
				Point2D(brush_extent.x, brush_extent.z)
			),
			getHoles(holes, dcp.SOUTH))
		for part in parts:
			part3d = addDim(part, dims.Y, brush_start.y)
			makeBrush(doc, worldspawn, sf, style, part3d, dcp.SOUTH)
	# west wall
	if dcp.WEST not in absentwalls:
		if dcp.NORTH not in absentwalls and dcp.SOUTH not in absentwalls:
			brush_start = origin + Point(0, prog.lip, prog.lip)
			brush_extent = \
				Point(prog.lip, extent.y - prog.lip * 2, extent.z - prog.lip * 2)
		elif dcp.NORTH in absentwalls and dcp.SOUTH in absentwalls:
			brush_start = origin + Point(0, prog.lip, prog.lip)
			brush_extent = \
				Point(prog.lip, extent.y - prog.lip * 2, extent.z - prog.lip * 2)
		elif dcp.NORTH in absentwalls:
			brush_start = origin + Point(0, prog.lip, prog.lip)
			brush_extent = Point(prog.lip, extent.y - prog.lip, extent.z - prog.lip * 2)
		elif dcp.SOUTH in absentwalls:
			brush_start = origin + Point(0, 0, prog.lip)
			brush_extent = Point(prog.lip, extent.y - prog.lip, extent.z - prog.lip * 2)
		else:
			error('absentwalls')
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.y, brush_start.z),
				Point2D(brush_extent.y, brush_extent.z)
			),
			getHoles(holes, dcp.WEST))
		for part in parts:
			part3d = addDim(part, dims.X, brush_start.x)
			makeBrush(doc, worldspawn, sf, style, part3d, dcp.WEST)
	# east wall
	if dcp.EAST not in absentwalls:
		if dcp.NORTH not in absentwalls and dcp.SOUTH not in absentwalls:
			brush_start = origin + Point(extent.x - prog.lip, prog.lip, prog.lip)
			brush_extent = \
				Point(prog.lip, extent.y - prog.lip * 2, extent.z - prog.lip * 2)
		elif dcp.NORTH in absentwalls and dcp.SOUTH in absentwalls:
			brush_start = origin + Point(extent.x - prog.lip, 0, prog.lip)
			brush_extent = Point(prog.lip, extent.y, extent.z - prog.lip * 2)
		elif dcp.NORTH in absentwalls:
			brush_start = origin + Point(extent.x - prog.lip, prog.lip, prog.lip)
			brush_extent = Point(prog.lip, extent.y - prog.lip, extent.z - prog.lip * 2)
		elif dcp.SOUTH in absentwalls:
			brush_start = origin + Point(extent.x - prog.lip, 0, prog.lip)
			brush_extent = Point(prog.lip, extent.y - prog.lip, extent.z - prog.lip * 2)
		else:
			error('absentwalls')
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.y, brush_start.z),
				Point2D(brush_extent.y, brush_extent.z)
			),
			getHoles(holes, dcp.EAST))
		for part in parts:
			part3d = addDim(part, dims.X, brush_start.x)
			makeBrush(doc, worldspawn, sf, style, part3d, dcp.EAST)
	# Return inner extents...
	return inner_origin, inner_abslut_extent
Esempio n. 4
0
def processSolid(doc, parent, worldspawn, sf, offset, solid):
	'''Note: uses style set in parent hollow.'''
	global style
	o = ldl.getPoint(solid.getAttribute('origin')) + offset
	e = ldl.getPoint(solid.getAttribute('extent'))
	t = solid.getAttribute('texture')
	type = solid.getAttribute('type')
	if not t:
		if not type:
			ldl.error('solid with no type also has no texture attribute set')
	f = solid.getAttribute('holeface')
	# Get holes info...
	# FIXME this is repeated code from the hollow one -- any way we can refactor it?
	props = {}
	holes = []
	# Check if the solid has children (holes).
	# If so, split it up.
	# If not, just add it.
	if solid.hasChildNodes():
		for hole in solid.childNodes:
			ho_x, ho_y = hole.getAttribute('origin').split()
			he_x, he_y = hole.getAttribute('extent').split()
			type = hole.getAttribute('type')
			if not type:
				pass
			elif type == ldl.RT_DOOR:
				props[ldl.PROPS_K_KEY] = hole.getAttribute('key')
			else:
				ldl.warning('only doors allowed as hole types; not plats or others.')
			# FIXME deal with other types
			holes.append(ldl.Hole2D(ldl.Point2D(float(ho_x), float(ho_y)), ldl.Point2D(float(he_x), float(he_y)), type, props))
		# Built split (2D) parts into 3D brushes; mapping of coords to 3D depends on which direction/face the hole was constructed in.
		if f == ldl.DCP_NORTH:
			parts = split.splitWall(
				ldl.Region2D(
					ldl.Point2D(o.x, o.z),
					ldl.Point2D(e.x, e.z)
				),
				holes)
			for part in parts:
				part3d = ldl.addDim(part, ldl.DIM_Y, o.y, e.y)
				#ldl.uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
				ldl.makeBrush(doc, worldspawn, sf, style, part3d, f, t)
		elif f == ldl.DCP_UP:
			parts = split.splitWall(
				ldl.Region2D(
					ldl.Point2D(o.x, o.y),
					ldl.Point2D(e.x, e.y)
				),
				holes)
			for part in parts:
				part3d = ldl.addDim(part, ldl.DIM_Z, o.z+ldl.lip_small, e.z-ldl.lip_small*2)
				#ldl.uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
				ldl.makeBrush(doc, worldspawn, sf, style, part3d, f, t)
			else:
				ldl.error('Unsupported holeface ' + f + ' requested for hole in solid.')
	else:
		# Doesn't have child nodes...
		if not type or type == ldl.RT_STEP:
			pass  # no properties to set
		elif type == ldl.RT_DOOR:
			props[ldl.PROPS_K_KEY] = solid.getAttribute('key')
		elif type == ldl.RT_PLAT:
			props[ldl.PROPS_K_POS] = solid.getAttribute('position')
		else:
			ldl.warning('unknown type ' + type + ' specifed.')

		brush = ldl.Region3D(
			Point(o.x, o.y, o.z),
			Point(e.x, e.y, e.z),
			type,
			props
		)
		ldl.makeBrush(doc, worldspawn, sf, style, brush, type, t)
	# We can't remove the child or we screw over tree traversal (urgh)...
	ldl.insertPlaceholder(doc, parent, solid)
Esempio n. 5
0
File: ldl.py Progetto: matatk/agrip
def makeHollow(doc, worldspawn, sf, origin, extent, absentwalls, holes, style):
	'''Makes a hollow object (room/corridor) with the given paramaters.
	Works out the brushes, textures.
	Returns the origin and extent of the inner area.
	The north and south walls cover the entire width of the hollow.  The east and west ones fit inbetween the north and south ones.  However...
	To avoid leaks, when some walls are absent, the others must be made longer to cover the possible holes.  For example, if there is no north wall, the east and west ones need to be ldl.lip units longer in case them not being so would cause a leak.'''
	inner_origin = origin + lip
	inner_abslut_extent = (origin + extent) - lip

	# down (floor)
	if not DCP_DOWN in absentwalls:
		brush_start = origin
		brush_extent = Point(extent.x, extent.y, lip)
	parts = split.splitWall(
		Region2D(
			Point2D(brush_start.x, brush_start.y),
			Point2D(brush_extent.x, brush_extent.y)
		),
		getHoles(holes, DCP_DOWN))
	for part in parts:
		part3d = addDim(part, DIM_Z, brush_start.z)
		#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
		makeBrush(doc, worldspawn, sf, style, part3d, DCP_DOWN)
	# up (ceiling)
	if not DCP_UP in absentwalls:
		brush_start = origin + Point(0, 0, extent.z - lip)
		brush_extent = Point(extent.x, extent.y, lip)
	parts = split.splitWall(
		Region2D(
			Point2D(brush_start.x, brush_start.y),
			Point2D(brush_extent.x, brush_extent.y)
		),
		getHoles(holes, DCP_UP))
	for part in parts:
		part3d = addDim(part, DIM_Z, brush_start.z)
		#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
		makeBrush(doc, worldspawn, sf, style, part3d, DCP_UP)
	# north wall; y represents depth
	if not DCP_NORTH in absentwalls:
		brush_start = origin + Point(0, extent.y - lip, lip)
		brush_extent = Point(extent.x, lip, extent.z - lip*2)
		wall_holes = getHoles(holes, DCP_NORTH)
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.x, brush_start.z),
				Point2D(brush_extent.x, brush_extent.z)
			),
			getHoles(holes, DCP_NORTH))
		for part in parts:
			part3d = addDim(part, DIM_Y, brush_start.y)
			#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
			makeBrush(doc, worldspawn, sf, style, part3d, DCP_NORTH)
	# south wall
	# FIXME holes need to be expressed the other way 'round (i.e. 0 is at RHS not LHS)?
	if not DCP_SOUTH in absentwalls:
		brush_start = origin + Point(0, 0, lip)
		brush_extent = Point(extent.x, lip, extent.z - lip*2)
		wall_holes = getHoles(holes, DCP_SOUTH)
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.x, brush_start.z),
				Point2D(brush_extent.x, brush_extent.z)
			),
			getHoles(holes, DCP_SOUTH))
		for part in parts:
			part3d = addDim(part, DIM_Y, brush_start.y)
			#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
			makeBrush(doc, worldspawn, sf, style, part3d, DCP_SOUTH)
	# west wall
	if not DCP_WEST in absentwalls:
		if DCP_NORTH not in absentwalls and DCP_SOUTH not in absentwalls:
			brush_start = origin + Point(0, lip, lip)
			brush_extent = Point(lip, extent.y - lip*2, extent.z - lip*2)
		elif DCP_NORTH in absentwalls and DCP_SOUTH in absentwalls:
			brush_start = origin + Point(0, lip, lip)
			brush_extent = Point(lip, extent.y - lip*2, extent.z - lip*2)
		elif DCP_NORTH in absentwalls:
			brush_start = origin + Point(0, lip, lip)
			brush_extent = Point(lip, extent.y - lip, extent.z - lip*2)
		elif DCP_SOUTH in absentwalls:
			brush_start = origin + Point(0, 0, lip)
			brush_extent = Point(lip, extent.y - lip, extent.z - lip*2)
		else:
			error('absentwalls')
		wall_holes = getHoles(holes, DCP_WEST)
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.y, brush_start.z),
				Point2D(brush_extent.y, brush_extent.z)
			),
			getHoles(holes, DCP_WEST))
		for part in parts:
			part3d = addDim(part, DIM_X, brush_start.x)
			#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
			makeBrush(doc, worldspawn, sf, style, part3d, DCP_WEST)
	# east wall
	if not DCP_EAST in absentwalls:
		if DCP_NORTH not in absentwalls and DCP_SOUTH not in absentwalls:
			brush_start = origin + Point(extent.x - lip, lip, lip)
			brush_extent = Point(lip, extent.y - lip*2, extent.z - lip*2)
		elif DCP_NORTH in absentwalls and DCP_SOUTH in absentwalls:
			brush_start = origin + Point(extent.x - lip, 0, lip)
			brush_extent = Point(lip, extent.y, extent.z - lip*2)
		elif DCP_NORTH in absentwalls:
			brush_start = origin + Point(extent.x - lip, lip, lip)
			brush_extent = Point(lip, extent.y - lip, extent.z - lip*2)
		elif DCP_SOUTH in absentwalls:
			brush_start = origin + Point(extent.x - lip, 0, lip)
			brush_extent = Point(lip, extent.y - lip, extent.z - lip*2)
		else:
			error('absentwalls')
		parts = split.splitWall(
			Region2D(
				Point2D(brush_start.y, brush_start.z),
				Point2D(brush_extent.y, brush_extent.z)
			),
			getHoles(holes, DCP_EAST))
		for part in parts:
			part3d = addDim(part, DIM_X, brush_start.x)
			#uprint('Part:   ' + str(part) + '\nPart3D: ' + str(part3d))
			makeBrush(doc, worldspawn, sf, style, part3d, DCP_EAST)
	# Return inner extents...
	return inner_origin, inner_abslut_extent