Exemple #1
0
def drawTree(**p):
	if p['depth'] < p['maxdepth']:

		if p['height'] <1:return

		dep = p['depth']
		p['width'] *= p['dwidth'](dep)


		x0 = p['x']+math.cos(p['angle'])*p['trunk']
		y0 = p['y']-math.sin(p['angle'])*p['trunk']
		u.line(p['surf'],p['color'],[p['x'],p['y']],[x0,y0],p['width'])


		p['width'] *= p['dwidth'](dep)
		a1 = p['angle']-p['opening']*p['dopening'](dep)
		a2 = p['angle']+p['opening']*p['dopening'](dep)

		h1 = p['height'] * p['dheight'](dep)
		x1 = x0+math.cos(a1)*h1
		y1 = y0-math.sin(a1)*h1

		h2 = p['height'] * p['dheight'](dep)
		x2 = x0+math.cos(a2)*h2
		y2 = y0-math.sin(a2)*h2

		#u.text(p['surf'],x1,y1,str(dep),(0,150,0))
		#u.text(p['surf'],x2,y2,str(dep),(0,150,0))

		u.line(p['surf'],p['color'],[x0,y0],[x1,y1],p['width'])
		u.line(p['surf'],p['color'],[x0,y0],[x2,y2],p['width'])


		p['trunk'] *= p['dtrunk'](dep)

		p['depth'] += .5
		p['x'],p['y'],p['height'],p['angle'] = x1,y1,h1,a1-p['dangle'](dep)

		drawTree(**p)


		p['depth'] += .5
		p['x'],p['y'],p['height'],p['angle'] = x2,y2,h2,a2+p['dangle'](dep)
		drawTree(**p)
	else:
		return
Exemple #2
0
 def draw(self, surf):
     u.line(surf, [245, 245, 245], [self.x, self.y], self.calcFeather(), 3)
     u.line(surf, self.color, [self.x, self.y], self.calcHead(),
            random.randrange(0, 2) * self.flicker + 1)
Exemple #3
0
	def line(self,surf,start_pos,end_pos,width=1):
		u.line  (surf,self.color,[self.x+start_pos[0]*self.s*self.dir,self.y+self.yo+start_pos[1]*self.s],
								 [self.x+  end_pos[0]*self.s*self.dir,self.y+self.yo+  end_pos[1]*self.s],width*self.s)
Exemple #4
0
	def draw(self,surf):
		u.line(surf,[245,245,245],[self.x,self.y],self.calcFeather(),3)
		u.line(surf,self.color,[self.x,self.y],self.calcHead(),random.randrange(0,2)*self.flicker+1)
Exemple #5
0
def convert(fbx_file, options):
    """
    Takes as input an FBX file and converts it to files that can be
    used by either Vision or Animation Studio.
    """

    success = False

    # These are the labels that are spit out by the FBX Importer that
    # we use to parse out the relevant information about the export
    labelAnimationStacks = "Animation stacks:"
    labelTagFile = "Saved tag file:"
    labelSceneLength = "Scene length:"
    labelBones = "Bones:"

    def log(message):
        """ Only print a message if we're in options.verbose mode """
        if options.verbose:
            print(message)

    try:
        inputFile = os.path.abspath(fbx_file)
        if not os.path.isfile(inputFile):
            log("Input file does not exists! [%s]" % fbx_file)
            return False
        else:
            log("Input FBX file: %s" % inputFile)

        currentDirectory = os.path.dirname(os.path.realpath(__file__))

        # If this is a compiled script, then this is going to be 'Tools\FBXImporter.exe\projectanarchy' so
        # it needs some special processing to make it a valid folder
        if '.exe' in currentDirectory:
            extensionIndex = currentDirectory.find('.exe')
            endSlashIndex = currentDirectory.rfind('\\', 0, extensionIndex)
            currentDirectory = currentDirectory[0:endSlashIndex]

        root = os.path.join(currentDirectory, "../../Tools/FBXImporter")
        fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")
        if not os.path.isfile(fbxImporter):
            root = os.path.join(currentDirectory, "../../")
            fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")

        fbxImporter = os.path.abspath(fbxImporter)
        if not os.path.exists(fbxImporter):
            log("Failed to find FBX importer!")
            return False

        # Save
        configPath = os.path.abspath(os.path.join(root, "Scripts/configurations"))

        inputDirectory = os.path.dirname(inputFile)

        log("Converting FBX to Havok Scene Format...")
        fbxImporterOutput = utilities.run([fbxImporter, inputFile], options.verbose)

        parseIndex = fbxImporterOutput.find(labelTagFile)
        if parseIndex == -1:
            log("Conversion to FBX failed!")
            log(utilities.line())
            print(fbxImporterOutput)
            return False

        animationStacks = int(utilities.parse_text(
            fbxImporterOutput,
            labelAnimationStacks))
        
        numBones = int(utilities.parse_text(
            fbxImporterOutput,
            labelBones))

        havokScenes = []
        isRootNode = True
        isAnimationExport = (animationStacks > 0) and (numBones > 0)
        intermediate_files = []

        # Parse the output of the FBXImporter
        while parseIndex >= 0:
            sceneFile = utilities.parse_text(fbxImporterOutput, labelTagFile, parseIndex)
            sceneFile = os.path.join(inputDirectory, sceneFile)
            intermediate_files.append(sceneFile)

            (input_file_path, _) = os.path.splitext(sceneFile)
            target_filename = os.path.basename(input_file_path)

            if isRootNode:
                rootName = target_filename
            else:
                animName = target_filename[len(rootName) + 1:]

            sceneLength = float(utilities.parse_text(
                fbxImporterOutput,
                labelSceneLength,
                parseIndex))

            def _createScene(configFile, outputConfigFile, targetFilename):
                configFile = os.path.abspath(os.path.join(
                    currentDirectory,
                    configFile))
                outputConfigFile = os.path.abspath(outputConfigFile + ".hko")
                
                updateConfigFile = False

                try:
                    with open(outputConfigFile):
                        updateConfigFile = options.overwrite
                except IOError:
                    updateConfigFile = True

                if updateConfigFile:
                    with open(outputConfigFile, 'wt') as out:
                        for line in open(configFile):
                            out.write(line.replace('$(output)', targetFilename))

                havokScene = HavokScene(sceneFile=sceneFile,
                                        filter_set_file=outputConfigFile,
                                        asset_path=inputDirectory,
                                        output_path=inputDirectory,
                                        scene_length=sceneLength,
                                        is_root=isRootNode,
                                        target_file=targetFilename)
                
                
                # Keep config file if command line told us not to delete it or if it didn't exist already, 
                # otherwise it is consindered intermediate and gets removed
                if updateConfigFile and options.keepconfig == False:
                    intermediate_files.append(outputConfigFile)

                return havokScene

            if isRootNode and (not options.anim):
                # always output the Vision model file
                configFile = os.path.join(configPath, "VisionModel.hko")
                target_filename = "%s.model" % (rootName)
                havokScenes.append(_createScene(configFile, input_file_path + '_vision', target_filename))
                intermediate_files.append(input_file_path + '.anim')
                
                # output static mesh
                if not isAnimationExport:
                    configFile = os.path.join(configPath, "VisionStaticMesh.hko")
                    target_filename = "%s.vmesh" % (rootName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))

                # output the rig file for Animation Studio
                if isAnimationExport:
                    configFile = os.path.join(configPath, "AnimationRig.hko")
                    target_filename = "%s__out_rig.hkx" % (rootName)
                    havokScenes.append(_createScene(configFile, input_file_path + '_hat', target_filename))                
            elif (not isRootNode) and isAnimationExport:
                if options.anim:
                    configFile = os.path.join(configPath, "VisionModel.hko")
                    target_filename = "%s__out_anim_%s.model" % (rootName, animName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))
                else:
                    configFile = os.path.join(configPath, "Animation.hko")
                    target_filename = "%s__out_anim_%s.hkx" % (rootName, animName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))

            # We can break out of the loop early if this is just
            # a static mesh export
            if isRootNode and (not isAnimationExport):
                break
           
            isRootNode = False

            # Get the next file that was exported
            parseIndex = fbxImporterOutput.find(labelTagFile,
                                                   parseIndex + 1)

        log(utilities.line())
        log("Generating Vision / Animation Studio files")
        log(utilities.line())

        # Instantiate the Havok Content Tools class so that we can start
        # using it to convert over the scene files we've just exported
        havokContentTools = HCT()

        # Now go through each scene and run the standalone filter manager on each one
        for havokScene in havokScenes:
            outputfilename = os.path.basename(havokScene.target_file)
            log("Tag file: %s" % os.path.basename(havokScene.sceneFile))
            log("Filter set: %s" % os.path.basename(havokScene.filter_set_file))
            log("Output: %s" % outputfilename)
            log(utilities.line(True))

            interactive = False
            if options.anim:
                interactive = (".model" in havokScene.target_file) and (not havokScene.is_root)
            else:
                interactive = options.interactive
                if interactive == False and options.semiinteractive != '.':
                  # semi-interactive mode, enable interactive mode when regex pattern matches output filename
                  regex = re.compile( options.semiinteractive )
                  match = regex.search( outputfilename )
                  if match:
                    interactive = True
                  

            havokContentTools.run(havokScene.sceneFile,
                                    havokScene.filter_set_file,
                                    havokScene.asset_path,
                                    havokScene.output_path,
                                    interactive)
        
        # Remove intermediate files if we didn't set the flag to keep them
        if not options.keep:
            for file in intermediate_files:
                if os.path.exists(file):
                    os.remove(file)

        success = True
    except IOError as error:
        print("I/O error({0}): {1}".format(error[0], error[1]))
        traceback.print_exc(file=sys.stdout)
        utilities.wait()
    except:
        print("Unexpected error: %s" % sys.exc_info()[0])
        traceback.print_exc(file=sys.stdout)
        utilities.wait()

    return success
Exemple #6
0
def convert(fbx_file, options):
    """
    Takes as input an FBX file and converts it to files that can be
    used by either Vision or Animation Studio.
    """

    success = False

    # These are the labels that are spit out by the FBX Importer that
    # we use to parse out the relevant information about the export
    labelAnimationStacks = "Animation stacks:"
    labelTagFile = "Saved tag file:"
    labelSceneLength = "Scene length:"
    labelBones = "Bones:"

    def log(message):
        """ Only print a message if we're in options.verbose mode """
        if options.verbose:
            print(message)

    try:
        inputFile = os.path.abspath(fbx_file)
        if not os.path.isfile(inputFile):
            log("Input file does not exists! [%s]" % fbx_file)
            return False
        else:
            log("Input FBX file: %s" % inputFile)

        currentDirectory = os.path.dirname(os.path.realpath(__file__))

        # If this is a compiled script, then this is going to be 'Tools\FBXImporter.exe\projectanarchy' so
        # it needs some special processing to make it a valid folder
        if '.exe' in currentDirectory:
            extensionIndex = currentDirectory.find('.exe')
            endSlashIndex = currentDirectory.rfind('\\', 0, extensionIndex)
            currentDirectory = currentDirectory[0:endSlashIndex]

        root = os.path.join(currentDirectory, "../../Tools/FBXImporter")
        fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")
        if not os.path.isfile(fbxImporter):
            root = os.path.join(currentDirectory, "../../")
            fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")

        fbxImporter = os.path.abspath(fbxImporter)
        if not os.path.exists(fbxImporter):
            log("Failed to find FBX importer!")
            return False

        # Save
        configPath = os.path.abspath(os.path.join(root, "Scripts/configurations"))

        inputDirectory = os.path.dirname(inputFile)

        log("Converting FBX to Havok Scene Format...")
        fbxImporterOutput = utilities.run([fbxImporter, inputFile], options.verbose)

        parseIndex = fbxImporterOutput.find(labelTagFile)
        if parseIndex == -1:
            log("Conversion to FBX failed!")
            log(utilities.line())
            print(fbxImporterOutput)
            return False

        animationStacks = int(utilities.parse_text(
            fbxImporterOutput,
            labelAnimationStacks))
        
        numBones = int(utilities.parse_text(
            fbxImporterOutput,
            labelBones))

        havokScenes = []
        isRootNode = True
        isAnimationExport = (animationStacks > 0) and (numBones > 0)
        intermediate_files = []

        # Parse the output of the FBXImporter
        while parseIndex >= 0:
            sceneFile = utilities.parse_text(fbxImporterOutput, labelTagFile, parseIndex)
            sceneFile = os.path.join(inputDirectory, sceneFile)
            intermediate_files.append(sceneFile)

            (input_file_path, _) = os.path.splitext(sceneFile)
            target_filename = os.path.basename(input_file_path)

            if isRootNode:
                rootName = target_filename
            else:
                animName = target_filename[len(rootName) + 1:]

            sceneLength = float(utilities.parse_text(
                fbxImporterOutput,
                labelSceneLength,
                parseIndex))

            def _createScene(configFile, outputConfigFile, targetFilename):
                configFile = os.path.abspath(os.path.join(
                    currentDirectory,
                    configFile))
                outputConfigFile = os.path.abspath(outputConfigFile + ".hko")
                
                updateConfigFile = False

                try:
                    with open(outputConfigFile):
                        updateConfigFile = options.overwrite
                except IOError:
                    updateConfigFile = True

                if updateConfigFile:
                    with open(outputConfigFile, 'wt') as out:
                        for line in open(configFile):
                            out.write(line.replace('$(output)', targetFilename))

                havokScene = HavokScene(sceneFile=sceneFile,
                                        filter_set_file=outputConfigFile,
                                        asset_path=inputDirectory,
                                        output_path=inputDirectory,
                                        scene_length=sceneLength,
                                        is_root=isRootNode,
                                        target_file=targetFilename)

                intermediate_files.append(outputConfigFile)

                return havokScene

            if isRootNode and (not options.anim):
                # always output the Vision model file
                configFile = os.path.join(configPath, "VisionModel.hko")
                target_filename = "%s.model" % (rootName)
                havokScenes.append(_createScene(configFile, input_file_path + '_vision', target_filename))
                intermediate_files.append(input_file_path + '.anim')
                
                # output static mesh
                if not isAnimationExport:
                    configFile = os.path.join(configPath, "VisionStaticMesh.hko")
                    target_filename = "%s.vmesh" % (rootName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))

                # output the rig file for Animation Studio
                if isAnimationExport:
                    configFile = os.path.join(configPath, "AnimationRig.hko")
                    target_filename = "%s__out_rig.hkx" % (rootName)
                    havokScenes.append(_createScene(configFile, input_file_path + '_hat', target_filename))                
            elif (not isRootNode) and isAnimationExport:
                if options.anim:
                    configFile = os.path.join(configPath, "VisionModel.hko")
                    target_filename = "%s__out_anim_%s.model" % (rootName, animName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))
                else:
                    configFile = os.path.join(configPath, "Animation.hko")
                    target_filename = "%s__out_anim_%s.hkx" % (rootName, animName)
                    havokScenes.append(_createScene(configFile, input_file_path, target_filename))

            # We can break out of the loop early if this is just
            # a static mesh export
            if isRootNode and (not isAnimationExport):
                break
           
            isRootNode = False

            # Get the next file that was exported
            parseIndex = fbxImporterOutput.find(labelTagFile,
                                                   parseIndex + 1)

        log(utilities.line())
        log("Generating Vision / Animation Studio files")
        log(utilities.line())

        # Instantiate the Havok Content Tools class so that we can start
        # using it to convert over the scene files we've just exported
        havokContentTools = HCT()

        # Now go through each scene and run the standalone filter manager on each one
        for havokScene in havokScenes:
            log("Tag file: %s" % os.path.basename(havokScene.sceneFile))
            log("Filter set: %s" % os.path.basename(havokScene.filter_set_file))
            log("Output: %s" % os.path.basename(havokScene.target_file))
            log(utilities.line(True))

            interactive = False
            if options.anim:
                interactive = (".model" in havokScene.target_file) and (not havokScene.is_root)
            else:
                interactive = options.interactive

            havokContentTools.run(havokScene.sceneFile,
                                    havokScene.filter_set_file,
                                    havokScene.asset_path,
                                    havokScene.output_path,
                                    interactive)
        
        # Remove intermediate files if we didn't set the flag to keep them
        if not options.keep:
            for file in intermediate_files:
                if os.path.exists(file):
                    os.remove(file)

        success = True
    except IOError as error:
        print("I/O error({0}): {1}".format(error[0], error[1]))
        traceback.print_exc(file=sys.stdout)
        utilities.wait()
    except:
        print("Unexpected error: %s" % sys.exc_info()[0])
        traceback.print_exc(file=sys.stdout)
        utilities.wait()

    return success
Exemple #7
0
def convert(fbx_file,
            static_mesh=False,
            vision_model=False,
            interactive=False,
            verbose=True):
    """
    Takes as input an FBX file and converts it to files that can be
    used by either Vision or Animation Studio.
    """

    success = False

    # These are the labels that are spit out by the FBX Importer that
    # we use to parse out the relevant information about the export
    labelAnimationStacks = "Animation stacks:"
    labelTagFile = "Saved tag file:"
    labelSceneLength = "Scene length:"
    labelBones = "Bones:"

    def log(message):
        """ Only print a message if we're in verbose mode """
        if verbose:
            print(message)

    try:
        inputFile = os.path.abspath(fbx_file)
        if not os.path.isfile(inputFile):
            log("Input file does not exists! [%s]" % fbx_file)
            return False
        else:
            log("Input FBX file: %s" % inputFile)

        currentDirectory = os.path.dirname(os.path.realpath(__file__))

        # If this is a compiled script, then this is going to be 'Tools\FBXImporter.exe\projectanarchy' so
        # it needs some special processing to make it a valid folder
        if '.exe' in currentDirectory:
            extensionIndex = currentDirectory.find('.exe')
            endSlashIndex = currentDirectory.rfind('\\', 0, extensionIndex)
            currentDirectory = currentDirectory[0:endSlashIndex]

        root = os.path.join(currentDirectory, "../../Tools/FBXImporter")
        fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")
        if not os.path.isfile(fbxImporter):
            root = os.path.join(currentDirectory, "../../")
            fbxImporter = os.path.join(root, "Bin/FBXImporter.exe")

        fbxImporter = os.path.abspath(fbxImporter)
        if not os.path.exists(fbxImporter):
            log("Failed to find FBX importer!")
            return False

        # Save
        configPath = os.path.abspath(os.path.join(root, "Scripts/configurations"))

        inputDirectory = os.path.dirname(inputFile)

        log("Converting FBX to Havok Scene Format...")
        fbxImporterOutput = utilities.run([fbxImporter, inputFile], verbose)

        parseIndex = fbxImporterOutput.find(labelTagFile)
        if parseIndex == -1:
            log("Conversion to FBX failed!")
            log(utilities.line())
            print(fbxImporterOutput)
            return False

        animationStacks = int(utilities.parse_text(
            fbxImporterOutput,
            labelAnimationStacks))
        
        numBones = int(utilities.parse_text(
            fbxImporterOutput,
            labelBones))

        havokScenes = []
        isRootNode = True
        isAnimationExport = (animationStacks > 0) and (numBones > 0) and (not static_mesh)

        # Parse the output of the FBXImporter
        while parseIndex >= 0:
            sceneFile = utilities.parse_text(fbxImporterOutput, labelTagFile, parseIndex)
            sceneFile = os.path.join(inputDirectory, sceneFile)

            (input_file_path, _) = os.path.splitext(sceneFile)
            target_filename = os.path.basename(input_file_path)

            if isRootNode:
                rootName = target_filename
            else:
                animName = target_filename[len(rootName) + 1:]

            if vision_model:
                configFile = os.path.join(configPath, "VisionModel.hko")
                target_filename = "%s.model" % (rootName)
            elif isRootNode and isAnimationExport:
                configFile = os.path.join(configPath, "AnimationRig.hko")
                target_filename = "%s__out_rig.hkx" % (rootName)
            elif isAnimationExport:
                configFile = os.path.join(configPath, "Animation.hko")
                target_filename = "%s__out_anim_%s.hkx" % (rootName, animName)
            else:
                configFile = os.path.join(configPath, "VisionStaticMesh.hko")
                target_filename = "%s.vmesh" % (rootName)

            configFile = os.path.abspath(os.path.join(
                currentDirectory,
                configFile))
            outputConfigFile = os.path.abspath(input_file_path + ".hko")

            with open(outputConfigFile, 'wt') as out:
                for line in open(configFile):
                    out.write(line.replace('$(output)', target_filename))

            sceneLength = float(utilities.parse_text(
                fbxImporterOutput,
                labelSceneLength,
                parseIndex))
            
            havokScene = HavokScene(sceneFile=sceneFile,
                                    filter_set_file=outputConfigFile,
                                    asset_path=inputDirectory,
                                    output_path=inputDirectory,
                                    scene_length=sceneLength,
                                    is_root=isRootNode)

            # We accumulate all scenes before actually exporting them
            havokScenes.append(havokScene)

            # We can break out of the loop early if this is just
            # a static mesh export
            if isRootNode and ((not isAnimationExport) or vision_model):
                break
            else:
                isRootNode = False

            # Get the next file that was exported
            parseIndex = fbxImporterOutput.find(labelTagFile,
                                                   parseIndex + 1)

        log(utilities.line())
        log("Generating Vision / Animation Studio files")
        log(utilities.line())

        # Instantiate the Havok Content Tools class so that we can start
        # using it to convert over the scene files we've just exported
        havokContentTools = HCT()

        # Now go through each scene and run the standalone filter manager on each one
        for havokScene in havokScenes:
            log("Tag file: %s" % os.path.basename(havokScene.sceneFile))
            log("Filter set: %s" % os.path.basename(outputConfigFile))
            log("Target name: %s" % target_filename)
            log(utilities.line(True))

            havokContentTools.run(havokScene.sceneFile,
                                    havokScene.filter_set_file,
                                    havokScene.asset_path,
                                    havokScene.output_path,
                                    interactive)

        success = True
    except IOError as error:
        print("I/O error({0}): {1}".format(error[0], error[1]))
        traceback.print_exc(file=sys.stdout)
        utilities.wait()
    except:
        print("Unexpected error: %s" % sys.exc_info()[0])
        traceback.print_exc(file=sys.stdout)
        utilities.wait()

    return success