Exemplo n.º 1
0
def paddedPrint(msg):
    if debug_printing:
        for i in range(splitWallCoreLevel):
            ldl.uprint(splitWallCorePadding, True)
        ldl.uprint(msg)
Exemplo n.º 2
0
def listBrushes(map):
    brush_planes = []  # stores the (6) planes that make up one brush
    plane_points = []  # stores the (3) points in the current plane
    psa = []  # store one set of non-parallel planes
    psb = []  # store another set of non-parallel planes
    textureSpec = ''
    
    # Process all brushes...
    for brush in map.getElementsByTagName('brush'):
        ldl.uprint('Brush...')
        # Get all planes...
        for plane in brush.getElementsByTagName('plane'):
            ldl.uprint('    Plane...')
            # Get texture spec...
            textureSpec = getText(plane.getElementsByTagName('texture')[0].childNodes)
            ldl.uprint('        Texture: ' + textureSpec)
            # Get all points...
            for point in plane.getElementsByTagName('point'):
                point_match = r_planepoints.match(getText(point.childNodes))
                plane_points.append(Point(
                    float(point_match.group(1)),
                    float(point_match.group(2)),
                    float(point_match.group(3))))
                # NB: We use floats above so that later calculations are still accurate.
                ldl.uprint('        ' + str(plane_points[len(plane_points)-1]))
            # Put points into a plane object...
            brush_planes.append(
                Plane3D(
                    plane_points[0],
                    plane_points[1],
                    plane_points[2]))
            plane_points = []
            # Grab texture and remove this plane...
            brush.removeChild(plane)
        
        # Got all planes; work out brush origin and size...
        for plane in brush_planes:
            ldl.uprint('   ' + str(plane))
        
        # Get and solve parallel planes...
        while len(brush_planes) > 0:
            t = brush_planes.pop(0)
            s = t.N.x + t.N.y + t.N.z
            if s > 0:
                psa.append(t)
            else:
                psb.append(t)
        i1 = intersect(psa[0], psa[1], psa[2])
        i2 = intersect(psb[0], psb[1], psb[2])

        # Work out size (from smallest/lowest coord) and extent...
        i1s = i1.x + i1.y + i1.z
        i2s = i2.x + i2.y + i2.z
        if i1s < i2s:
            origin = i1
            extent = i2 - i1
        else:
            origin = i2
            extent = i2 - i1

        # Update brush info...
        brush.setAttribute('origin', str(origin))
        brush.setAttribute('extent', str(extent))
        brush.setAttribute('texture', textureSpec)
        # Tidy up...
        #brush_planes = []
        psa = []
        psb = []
Exemplo n.º 3
0
		for i in range(6):
			plane = map.createElement('plane')
			for j in range(3):
				point = map.createElement('point')
				point.appendChild(map.createTextNode(
						str(brush_planes[i][j][0]) + ' ' +
						str(brush_planes[i][j][1]) + ' ' +
						str(brush_planes[i][j][2])
					)
				)
				plane.appendChild(point)
			texture = map.createElement('texture')
			texture.appendChild(map.createTextNode(brush_texture))
			plane.appendChild(texture)
			brush.appendChild(plane)

if __name__ == '__main__':
	ldl.stage = '01'
	ldl.uprint('\n === ' + ldl.stackdescs[ldl.stage] + ' ===')
	try:
		m = xml.dom.minidom.parse(sys.stdin)
	except:
		ldl.failParse()
	processBrushes(m)
	ldl.remove_whitespace_nodes(m)
	m.getElementsByTagName('map')[0].setAttribute('stackdesc', ldl.stackdescs['01'])
	m.getElementsByTagName('map')[0].setAttribute('generator', __file__)
	#xml.dom.ext.PrettyPrint(m) 
	print m.toxml()
	m.unlink()
Exemplo n.º 4
0
    # We can't remove the child or we screw over tree traversal (urgh)...
    ldl.insertPlaceholder(doc, parent, solid)


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))


if __name__ == '__main__':
    ldl.stage = '02'
    ldl.uprint('\n === ' + ldl.stackdescs[ldl.stage] + ' ===')
    s = ldl.StyleFetcher()
    try:
        m = xml.dom.minidom.parse(sys.stdin)
    except:
        ldl.failParse()
    ldl.remove_whitespace_nodes(m)
    processMap(m)
    m.getElementsByTagName('map')[0].setAttribute('stackdesc',
                                                  ldl.stackdescs['02'])
    m.getElementsByTagName('map')[0].setAttribute('generator', __file__)
    #xml.dom.ext.PrettyPrint(m)
    print m.toxml()
    m.unlink()
Exemplo n.º 5
0
 def padded_print(self, msg):
     for i in range(self.padding_level):
         ldl.uprint('  ', sameLine=True)
     ldl.uprint(msg)
Exemplo n.º 6
0
def paddedPrint(msg):
    if debug_printing:
        for i in range(splitWallCoreLevel):
            ldl.uprint(splitWallCorePadding, True)
        ldl.uprint(msg)
Exemplo n.º 7
0
	def padded_print(self, msg):
		for i in range(self.padding_level):
			ldl.uprint('  ', sameLine=True)
		ldl.uprint(msg)
Exemplo n.º 8
0
	def characters(self, text):
		self._accumulator.append(text)

	def ignorableWhitespace(self, ws):
		self._accumulator.append(text)

	# Utility Functions...

	def padded_print(self, msg):
		for i in range(self.padding_level):
			ldl.uprint('  ', sameLine=True)
		ldl.uprint(msg)

if __name__ == "__main__":
	ldl.stage = '04'
	ldl.uprint('\n === ' + ldl.stackdescs['04'] + ' ===')
	parser = sax.make_parser()
	#XMLGenerator is a special SAX handler that merely writes
	#SAX events back into an XML document
	downstream_handler = XMLGenerator()
	#upstream, the parser, downstream, the next handler in the chain
	filter_handler = BuilderFilter(parser, downstream_handler)
	#The SAX filter base is designed so that the filter takes
	#on much of the interface of the parser itself, including the
	#"parse" method
	try:
		filter_handler.parse(sys.stdin)
	except sax.SAXParseException, detail:
		ldl.error('The XML you supplied is not valid: ' + str(detail))
	except:
		raise
Exemplo n.º 9
0
    def endElement(self, name):
        if name == "entity" or name == "brush":
            self.paddinglevel = self.paddinglevel - 1
            self.chPadding()
            sys.stdout.write(self.padding + "}\n")
        elif name == "point":
            self.inPoint = 0
            sys.stdout.write(" ) ")
        elif name == "texture":
            self.inTexture = 0
            sys.stdout.write("\n")
        elif name == "name":
            self.inName = 0
            sys.stdout.write('" ')
        elif name == "value":
            self.inValue = 0
            sys.stdout.write('"\n')


if __name__ == "__main__":
    ldl.stage = "00"
    ldl.uprint("\n === " + ldl.stackdescs[ldl.stage] + " ===")
    parser = make_parser()
    conv = MapXML2Map()
    parser.setContentHandler(conv)
    try:
        parser.parse(sys.stdin)
    except:
        ldl.failParse()