Exemplo n.º 1
0
	def macro_plat(self, bi, si):
		'''Make a plat
		Note that we don't specify the size of plat here as later we need to make it either at the top or the bottom of the larger brush.'''
		origin = ldl.getPoint(bi['origin'])
		size = ldl.getPoint(bi['extent'])
		if bi.has_key('texture'):
			texture = 'texture=\'' + bi['texture'] + '\' '
		else:
			texture = ''
		if si.has_key('position'):
			pos = si['position']  # DCP_UP or DCP_DOWN (top or bottomw
		else:
			ldl.error('plat given without a position (up or down)')
		print "<solid origin='" + str(origin) + "' extent='" + str(size) + "' " + texture + "type='plat' position='" + pos + "' />"
Exemplo n.º 2
0
def processHollow(doc, parent, worldspawn, s, offset, hollow):
    '''Note: sets global style var.'''
    global style
    o = ldl.getPoint(hollow.getAttribute('origin')) + offset
    e = ldl.getPoint(hollow.getAttribute('extent'))
    style = hollow.getAttribute('style')
    holes = {}
    absentwalls = []
    # FIXME the following is where we see if this hollow contains an absentwalls element and a holes element before proceeding.  It's implemented in a bit of a hacky way; we ought to be using SAX but then it would be a *lot* more work to create the output XML.  This way we can just change what's there a bit.
    for hollowChild in hollow.childNodes:
        if hollowChild.localName == 'absentwalls':
            # Get absent walls info...
            for absentwall in hollowChild.childNodes:
                wall = absentwall.getAttribute('value')
                absentwalls.append(wall)
            ldl.insertPlaceholder(doc, hollow, hollowChild)
        elif hollowChild.localName == 'holes':
            # Get holes info...
            for hole in hollowChild.childNodes:
                wall = hole.getAttribute('wall')
                # If we've not added a hole to this wall yet then set up an empty array...
                if not holes.has_key(wall):
                    holes[wall] = []
                o_x, o_y = hole.getAttribute('origin').split()
                e_x, e_y = hole.getAttribute('extent').split()
                type = hole.getAttribute('type')
                if type == ldl.RT_DOOR:
                    key = hole.getAttribute('key')
                    button = hole.getAttribute('button')
                else:
                    key = button = None
                # FIXME deal with other types
                holes[wall].append(
                    ldl.Hole2D(ldl.Point2D(float(o_x), float(o_y)),
                               ldl.Point2D(float(e_x), float(e_y)), type,
                               {ldl.PROPS_K_KEY: key}))
            # FIXME we shouldn't need to detect overlapping holes here because they'll be detected higher up (by overlapping connected hollows)
            ldl.insertPlaceholder(doc, hollow, hollowChild)

    # Now we have the required structural info (absent walls and holes), we can turn this hollow into a series of textured brushes...
    io, ie = ldl.makeHollow(doc, worldspawn, s, o, e, absentwalls, holes,
                            style)
    # Contained solids, hollows and entities...
    for node in hollow.childNodes:
        processNode(doc, hollow, worldspawn, s, io, node)
    # We can't remove the child or we screw over tree traversal (urgh)...
    ldl.insertPlaceholder(doc, parent, hollow)
Exemplo n.º 3
0
def processEntity(doc, parent, offset, entity):
    # Adjust coords...
    for property in entity.childNodes:  # we assume all children are property nodes.
        if property.getAttribute('name') == 'origin':
            o = ldl.getPoint(property.getAttribute('value')) + offset
            property.setAttribute('value', str(o))
    # Clone node (inc properties) and add to map...
    doc.documentElement.appendChild(entity.cloneNode(True))
Exemplo n.º 4
0
def processHollow(doc, parent, worldspawn, s, offset, hollow):
	'''Note: sets global style var.'''
	global style
	o = ldl.getPoint(hollow.getAttribute('origin')) + offset
	e = ldl.getPoint(hollow.getAttribute('extent'))
	style = hollow.getAttribute('style')
	holes = {}
	absentwalls = []
	# FIXME the following is where we see if this hollow contains an absentwalls element and a holes element before proceeding.  It's implemented in a bit of a hacky way; we ought to be using SAX but then it would be a *lot* more work to create the output XML.  This way we can just change what's there a bit.
	for hollowChild in hollow.childNodes:
		if hollowChild.localName == 'absentwalls':
			# Get absent walls info...
			for absentwall in hollowChild.childNodes:
				wall = absentwall.getAttribute('value')
				absentwalls.append(wall)
			ldl.insertPlaceholder(doc, hollow, hollowChild)
		elif hollowChild.localName == 'holes':
			# Get holes info...
			for hole in hollowChild.childNodes:
				wall = hole.getAttribute('wall')
				# If we've not added a hole to this wall yet then set up an empty array...
				if not holes.has_key(wall):
					holes[wall] = []
				o_x, o_y = hole.getAttribute('origin').split()
				e_x, e_y = hole.getAttribute('extent').split()
				type = hole.getAttribute('type')
				if type == ldl.RT_DOOR:
					key = hole.getAttribute('key')
					button = hole.getAttribute('button')
				else:
					key = button = None
				# FIXME deal with other types
				holes[wall].append(ldl.Hole2D(
					ldl.Point2D(float(o_x), float(o_y)),
					ldl.Point2D(float(e_x), float(e_y)),
					type, {ldl.PROPS_K_KEY: key}))
			# FIXME we shouldn't need to detect overlapping holes here because they'll be detected higher up (by overlapping connected hollows)
			ldl.insertPlaceholder(doc, hollow, hollowChild)

	# Now we have the required structural info (absent walls and holes), we can turn this hollow into a series of textured brushes...
	io, ie = ldl.makeHollow(doc, worldspawn, s, o, e, absentwalls, holes, style)
	# Contained solids, hollows and entities...
	for node in hollow.childNodes:
		processNode(doc, hollow, worldspawn, s, io, node)
	# We can't remove the child or we screw over tree traversal (urgh)...
	ldl.insertPlaceholder(doc, parent, hollow)
Exemplo n.º 5
0
def processEntity(doc, parent, offset, entity):
	# Adjust coords...
	for property in entity.childNodes:  # we assume all children are property nodes.
		if property.getAttribute('name') == 'origin':
			o = ldl.getPoint(property.getAttribute('value')) + offset
			property.setAttribute('value', str(o))
	# Clone node (inc properties) and add to map...
	doc.documentElement.appendChild(entity.cloneNode(True))
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def _get_bounds(self, hollow_attrs):
     '''Work out the internal cube of the hollow.'''
     origin = ldl.getPoint(hollow_attrs['origin'])
     extent = ldl.getPoint(hollow_attrs['extent'])
     return extent - Point(ldl.lip * 2, ldl.lip * 2, ldl.lip * 2)
Exemplo n.º 9
0
	def macro_stairs(self, bi, si):
		'''Make some stairs
		we see this as a 2D problem then add the missing dimension later (width/depth)
		dir tells us in which dir the steps go up
		length is the distance from start of lowest to end of heighest step
		height is the height of the highest step'''
		# FIXME cope with being able to make a hole through (under) the stairs
		origin = ldl.getPoint(bi['origin'])
		size = ldl.getPoint(bi['extent'])
		dir = si['dir']
		texture = ''
		if bi.has_key('texture'): texture = bi['texture']
		#slength = float(si['steplength'])
		slength = 0
		sheight = float(si['stepheight'])
		parts = []
		parts3d = []

		# FIXME repeated code: n/e == s/w -- collapse into 2?

		# Work out which dimension is which
		if dir == ldl.DCP_NORTH:
			# use X and Y; Z rising with increasing Y
			length = size.y
			height = size.z
			width = size.x
			flip = False
			parts = self._macro_stairs_core(length, height, width, flip, slength, sheight, texture)
			for part in parts:
				part3d = ldl.Region3D(
					Point(0,part.origin.x,part.origin.y) + origin,
					Point(width, part.extent.x, part.extent.y)
				)
				parts3d.append(part3d)
		elif dir == ldl.DCP_SOUTH:
			# use X and Y; Z falling with increasing Y
			length = size.y
			height = size.z
			width = size.x
			flip = True
			parts = self._macro_stairs_core(length, height, width, flip, slength, sheight, texture)
			for part in parts:
				part3d = ldl.Region3D(
					Point(0,part.origin.x,part.origin.y) + origin,
					Point(width, part.extent.x, part.extent.y)
				)
				parts3d.append(part3d)
		elif dir == ldl.DCP_EAST:
			# use X and Y; Z rising with increasing X
			length = size.x
			height = size.z
			width = size.y
			flip = False
			parts = self._macro_stairs_core(length, height, width, flip, slength, sheight, texture)
			for part in parts:
				part3d = ldl.Region3D(
					Point(part.origin.x, 0, part.origin.y) + origin,
					Point(part.extent.x, width, part.extent.y)
				)
				parts3d.append(part3d)
		elif dir == ldl.DCP_WEST:
			# use X and y; Z falling with increasing X
			length = size.x
			height = size.z
			width = size.y
			flip = True
			parts = self._macro_stairs_core(length, height, width, flip, slength, sheight, texture)
			for part in parts:
				part3d = ldl.Region3D(
					Point(part.origin.x, 0, part.origin.y) + origin,
					Point(part.extent.x, width, part.extent.y)
				)
				parts3d.append(part3d)
		else:
			ldl.error('invalid direction specified for stairs (up and down are currently unsupported)')

		for part3d in parts3d:
			#ldl.uprint(str(part3d))
			print "<solid origin='" + str(part3d.origin) + "' extent='" + str(part3d.extent) + "' texture='" + texture + "' type='step' />"
Exemplo n.º 10
0
	def _get_bounds(self, hollow_attrs):
		'''Work out the internal cube of the hollow.'''
		origin = ldl.getPoint(hollow_attrs['origin'])
		extent = ldl.getPoint(hollow_attrs['extent'])
		return extent - Point(ldl.lip*2, ldl.lip*2, ldl.lip*2)