Exemplo n.º 1
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.º 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 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.º 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)