コード例 #1
0
ファイル: xmlmap.py プロジェクト: squiddy/fifengine
    def parse_imports(self, mapelt, map):
        """ load all objects defined as import into memory
		
		@type	mapelt:	object
		@param	mapelt:	ElementTree root
		@return	FIFE map object			
		@rtype	object
		"""
        parsedImports = {}

        if self.callback:
            tmplist = mapelt.findall("import")
            i = float(0)

        for item in mapelt.findall("import"):
            _file = item.get("file")
            if _file:
                _file = reverse_root_subfile(self.source, _file)
            _dir = item.get("dir")
            if _dir:
                _dir = reverse_root_subfile(self.source, _dir)

                # Don't parse duplicate imports
            if (_dir, _file) in parsedImports:
                if self.debug:
                    print "Duplicate import:", (_dir, _file)
                continue
            parsedImports[(_dir, _file)] = 1

            if _file and _dir:
                loadImportFile(self.obj_loader, "/".join(_dir, _file), self.engine, self.debug)
            elif _file:
                loadImportFile(self.obj_loader, _file, self.engine, self.debug)
            elif _dir:
                loadImportDirRec(self.obj_loader, _dir, self.engine, self.debug)
                map.importDirs.append(_dir)
            else:
                if self.debug:
                    print "Empty import statement?"

            if self.callback:
                i += 1
                self.callback(self.msg["imports"], float(i / float(len(tmplist)) * 0.25 + 0.25))
コード例 #2
0
ファイル: xmlmap.py プロジェクト: fifengine/fifengine
	def parse_lights(self, layerelt, layer):
		""" create light nodes

		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
		_LIGHT_DEFAULT_BLENDING_SRC = -1
		_LIGHT_DEFAULT_BLENDING_DST = -1
		_LIGHT_DEFAULT_SUBDIVISIONS = 32
		_LIGHT_DEFAULT_CAM_ID = 'default'
		_LIGHT_DEFAULT_INTENSITY = 128
		_LIGHT_DEFAULT_RADIUS = 10.0

		print("Processing lights ... ")
		lightelt = layerelt.find('lights')
		if not lightelt:
			print("\tno lights found on layer %s" % layer.getId())
			return

		lights = []
		for attr in ('l', 'light', 'lgt'):
			lights.extend(lightelt.findall(attr))

		for light in lights:
			group = light.get('group')
			if not group:
				print("Light has no group. Omitting...")
				continue

			blending_src = light.get('src')
			if not blending_src:
				blending_src = _LIGHT_DEFAULT_BLENDING_SRC
			blending_dst = light.get('dst')
			if not blending_dst:
				blending_dst = _LIGHT_DEFAULT_BLENDING_DST

			_x = light.get('x')
			if not _x: _x = 0
			_y = light.get('y')
			if not _y: _y = 0
			_z = light.get('y')
			if not _z: _z = 0

			node = {}
			node['blending_src'] = int(blending_src)
			node['blending_dst'] = int(blending_dst)
			node['layer'] = layer.getId()
			node['position'] = int(_x), int(_y), int(_z)

			# where is the light? *sing*
			instance_id = light.get('instance')
			node['instance'] = None
			if instance_id and layer.getInstance(instance_id):
				node['instance'] = instance_id

			type = light.get('type')
			if type:
				s_ref = light.get('s_ref')
				if not s_ref: s_ref = -1
				node['s_ref'] = int(s_ref)
				a_ref = light.get('a_ref')
				if not a_ref: a_ref = 0.0
				node['a_ref'] = float(a_ref)

				if type == 'image':
					image = light.get('image')
					if not image:
						print("Light has no image. Omitting...")
						continue
					node['type'] = 'image'
					image = reverse_root_subfile(self.source, image)
					img = self.image_manager.create(image)
					node['image'] = img
				elif type == 'animation':
					animation = light.get('animation')
					if not animation:
						print("Light has no animation. Omitting...")
						continue
					node['type'] = 'animation'
					animation = reverse_root_subfile(self.source, animation)
					anim = loadXMLAnimation(self.engine, animation)
					node['animation'] = anim
				elif type == 'simple':
					node['type'] = type
					radius = light.get('radius')
					if not radius: radius = _LIGHT_DEFAULT_RADIUS
					node['radius'] = float(radius)

					subdivisions = light.get('subdivisions')
					if not subdivisions:
						subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
					node['subdivisions'] = int(subdivisions)

					intensity = light.get('intensity')
					if not intensity:
						intensity = _LIGHT_DEFAULT_INTENSITY
					node['intensity'] = int(intensity)

					xstretch = light.get('xstretch')
					if not xstretch: xstretch = 1.0
					ystretch = light.get('ystretch')
					if not ystretch: ystretch = 1.0
					node['stretch'] = float(xstretch), float(ystretch)

					color = light.get('color')
					if not color: color = '%d,%d,%d' % (255, 255, 255)
					node['color'] = ([int(c) for c in color.split(',')])

			else:
				continue

			cam_id = light.get('camera_id')
			if not cam_id: cam_id = _LIGHT_DEFAULT_CAM_ID

			if not cam_id in self.light_data:
				self.light_data[cam_id] = {}
			if group not in self.light_data[cam_id]:
				self.light_data[cam_id][group] = []

			self.light_data[cam_id][group].append(node)

		for camera, groups in self.light_data.items():
			print("Lights for camera %s" % camera)
			for group, lights in groups.items():
				print(group, lights)
コード例 #3
0
ファイル: xmlmap.py プロジェクト: squiddy/fifengine
    def parse_lights(self, layerelt, layer):
        """ create light nodes
		
		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
        _LIGHT_DEFAULT_BLENDING_SRC = -1
        _LIGHT_DEFAULT_BLENDING_DST = -1
        _LIGHT_DEFAULT_SUBDIVISIONS = 32
        _LIGHT_DEFAULT_CAM_ID = "default"
        _LIGHT_DEFAULT_INTENSITY = 128
        _LIGHT_DEFAULT_RADIUS = 10.0

        print "Processing lights ... "
        lightelt = layerelt.find("lights")
        if not lightelt:
            print "\tno lights found on layer %s" % layer.getId()
            return

        lights = []
        for attr in ("l", "light", "lgt"):
            lights.extend(lightelt.findall(attr))

        for light in lights:
            group = light.get("group")
            if not group:
                print "Light has no group. Omitting..."
                continue

            blending_src = light.get("src")
            if not blending_src:
                blending_src = _LIGHT_DEFAULT_BLENDING_SRC
            blending_dst = light.get("dst")
            if not blending_dst:
                blending_dst = _LIGHT_DEFAULT_BLENDING_DST

            _x = light.get("x")
            if not _x:
                _x = 0
            _y = light.get("y")
            if not _y:
                _y = 0
            _z = light.get("y")
            if not _z:
                _z = 0

            node = {}
            node["blending_src"] = int(blending_src)
            node["blending_dst"] = int(blending_dst)
            node["layer"] = layer.getId()
            node["position"] = int(_x), int(_y), int(_z)

            # where is the light? *sing*
            instance_id = light.get("instance")
            node["instance"] = None
            if instance_id and layer.getInstance(instance_id):
                node["instance"] = instance_id

            type = light.get("type")
            if type:
                s_ref = light.get("s_ref")
                if not s_ref:
                    s_ref = -1
                node["s_ref"] = int(s_ref)
                a_ref = light.get("a_ref")
                if not a_ref:
                    a_ref = 0.0
                node["a_ref"] = float(a_ref)

                if type == "image":
                    image = light.get("image")
                    if not image:
                        print "Light has no image. Omitting..."
                        continue
                    node["type"] = "image"
                    image = reverse_root_subfile(self.source, image)
                    img = self.image_manager.create(image)
                    node["image"] = img
                elif type == "animation":
                    animation = light.get("animation")
                    if not animation:
                        print "Light has no animation. Omitting..."
                        continue
                    node["type"] = "animation"
                    animation = reverse_root_subfile(self.source, animation)
                    anim = loadXMLAnimation(self.engine, animation)
                    node["animation"] = anim
                elif type == "simple":
                    node["type"] = type
                    radius = light.get("radius")
                    if not radius:
                        radius = _LIGHT_DEFAULT_RADIUS
                    node["radius"] = float(radius)

                    subdivisions = light.get("subdivisions")
                    if not subdivisions:
                        subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
                    node["subdivisions"] = int(subdivisions)

                    intensity = light.get("intensity")
                    if not intensity:
                        intensity = _LIGHT_DEFAULT_INTENSITY
                    node["intensity"] = int(intensity)

                    xstretch = light.get("xstretch")
                    if not xstretch:
                        xstretch = 1.0
                    ystretch = light.get("ystretch")
                    if not ystretch:
                        ystretch = 1.0
                    node["stretch"] = float(xstretch), float(ystretch)

                    color = light.get("color")
                    if not color:
                        color = "%d,%d,%d" % (255, 255, 255)
                    node["color"] = [int(c) for c in color.split(",")]

            else:
                continue

            cam_id = light.get("camera_id")
            if not cam_id:
                cam_id = _LIGHT_DEFAULT_CAM_ID

            if not cam_id in self.light_data:
                self.light_data[cam_id] = {}
            if group not in self.light_data[cam_id]:
                self.light_data[cam_id][group] = []

            self.light_data[cam_id][group].append(node)

        for camera, groups in self.light_data.iteritems():
            print "Lights for camera %s" % camera
            for group, lights in groups.iteritems():
                print group, lights
コード例 #4
0
	def parse_lights(self, layerelt, layer):
		""" create light nodes
		
		@type	layerelt:	object
		@param	layerelt:	ElementTree layer branch
		@type	layer:	object
		@param	layer:	FIFE layer object
		"""
		_LIGHT_DEFAULT_BLENDING_SRC = -1
		_LIGHT_DEFAULT_BLENDING_DST = -1
		_LIGHT_DEFAULT_SUBDIVISIONS = 32
		_LIGHT_DEFAULT_CAM_ID = 'default'
		_LIGHT_DEFAULT_INTENSITY = 128
		_LIGHT_DEFAULT_RADIUS = 10.0
		
		print "Processing lights ... "		
		lightelt = layerelt.find('lights')
		if not lightelt: 
			print "\tno lights found on layer %s" % layer.getId()
			return		
		
		lights = []
		for attr in ('l', 'light', 'lgt'):
			lights.extend(lightelt.findall(attr))
		
		for light in lights:
			group = light.get('group')
			if not group:
				print "Light has no group. Omitting..."
				continue
				
			blending_src = light.get('src')
			if not blending_src:
				blending_src = _LIGHT_DEFAULT_BLENDING_SRC
			blending_dst = light.get('dst')
			if not blending_dst:
				blending_dst = _LIGHT_DEFAULT_BLENDING_DST
				
			_x = light.get('x')
			if not _x: _x = 0
			_y = light.get('y')
			if not _y: _y = 0
			_z = light.get('y')
			if not _z: _z = 0

			node = {}				
			node['blending_src'] = int(blending_src)
			node['blending_dst'] = int(blending_dst)
			node['layer'] = layer.getId()
			node['position'] = int(_x), int(_y), int(_z)

			# where is the light? *sing*
			instance_id = light.get('instance')
			node['instance'] = None
			if instance_id and layer.getInstance(instance_id):
				node['instance'] = instance_id
			
			type = light.get('type')
			if type:
				s_ref = light.get('s_ref')
				if not s_ref: s_ref = -1
				node['s_ref'] = int(s_ref)
				a_ref = light.get('a_ref')
				if not a_ref: a_ref = 0.0
				node['a_ref'] = float(a_ref)
				
				if type == 'image':
					image = light.get('image')					
					if not image:
						print "Light has no image. Omitting..."
						continue
					node['type'] = 'image'
					image = reverse_root_subfile(self.source, image)
					img = self.image_manager.create(image)
					node['image'] = img
				elif type == 'animation':
					animation = light.get('animation')					
					if not animation:
						print "Light has no animation. Omitting..."
						continue
					node['type'] = 'animation'
					animation = reverse_root_subfile(self.source, animation)
					anim = loadXMLAnimation(self.engine, animation)
					node['animation'] = anim					
				elif type == 'simple':
					node['type'] = type
					radius = light.get('radius')
					if not radius: radius = _LIGHT_DEFAULT_RADIUS
					node['radius'] = float(radius)

					subdivisions = light.get('subdivisions')
					if not subdivisions: 
						subdivisions = _LIGHT_DEFAULT_SUBDIVISIONS
					node['subdivisions'] = int(subdivisions)
					
					intensity = light.get('intensity')
					if not intensity:
						intensity = _LIGHT_DEFAULT_INTENSITY
					node['intensity'] = int(intensity)

					xstretch = light.get('xstretch')
					if not xstretch: xstretch = 1.0
					ystretch = light.get('ystretch')
					if not ystretch: ystretch = 1.0
					node['stretch'] = float(xstretch), float(ystretch)

					color = light.get('color')
					if not color: color = '%d,%d,%d' % (255, 255, 255)
					node['color'] = ([int(c) for c in color.split(',')])

			else:
				continue
			
			cam_id = light.get('camera_id')
			if not cam_id: cam_id = _LIGHT_DEFAULT_CAM_ID
	
			if not cam_id in self.light_data:
				self.light_data[cam_id] = {}
			if group not in self.light_data[cam_id]:
				self.light_data[cam_id][group] = []
			
			self.light_data[cam_id][group].append(node)
			
		for camera, groups in self.light_data.iteritems():
			print "Lights for camera %s" % camera
			for group, lights in groups.iteritems():
				print group, lights