Exemple #1
0
        private static GeoModel ProcessScene(Scene scene, string filename, AssemblyMode am)
        {
            GeoModel returnModel = new GeoModel();

            returnModel.Filename = filename;
            returnModel.Name     = StripPathFromFile(filename);
            if (am == AssemblyMode.Internal)
            {
                returnModel.PathAbsolute = "";
            }
            else
            {
                if (am == AssemblyMode.User)
                {
                    returnModel.PathAbsolute = Assembly.GetEntryAssembly().GetName().Name + "." + filename;
                }
                else
                {
                    string p  = Assembly.GetExecutingAssembly().Location;
                    string pA = new DirectoryInfo(StripFileNameFromPath(p)).FullName;
                    if (!Path.IsPathRooted(filename))
                    {
                        returnModel.PathAbsolute = Path.Combine(pA, filename);
                    }
                    else
                    {
                        returnModel.PathAbsolute = filename;
                    }

                    bool success = File.Exists(returnModel.PathAbsolute);
                }
            }


            returnModel.AssemblyMode = am;
            returnModel.CalculatePath();
            returnModel.Meshes = new Dictionary <string, GeoMesh>();
            returnModel.TransformGlobalInverse = Matrix4.Invert(HelperMatrix.ConvertAssimpToOpenTKMatrix(scene.RootNode.Transform));
            returnModel.Textures = new Dictionary <string, GeoTexture>();
            returnModel.IsValid  = false;

            GenerateNodeHierarchy(scene.RootNode, ref returnModel);
            ProcessBones(scene, ref returnModel);
            ProcessMeshes(scene, ref returnModel);
            ProcessAnimations(scene, ref returnModel);

            returnModel.IsValid = true;
            GLWindow.StartGarbageCollection();
            return(returnModel);
        }
Exemple #2
0
        private void HACK_FORCLOUSOT()
        {
            // set the fields to avoid the warning from clousot

            automaticallyLookForOOBs = true;
            allowRewritten           = false;
            breakIntoDebugger        = false;
            contracts         = null;
            debug             = true;
            failOnWarnings    = false;
            hideFromDebugger  = true;
            resolvedPaths     = null;
            libpaths          = null;
            level             = 4;
            recursionGuard    = 4;
            throwOnFailure    = false;
            publicSurfaceOnly = false;
            callSiteRequires  = false;
            output            = "same";
            writePDBFile      = true;
            keepOriginalFiles = false;
            passthrough       = false;
            rewrite           = true;
            rewriterMethods   = null;
            shortBranches     = false;
            extractSourceText = true;
            targetplatform    = "";
            framework         = "";
            verbose           = 0;
            nobox             = false;
            nologo            = false;
            verify            = true;
            warn              = 1;
            contractLibrary   = null;
            fSharp            = false;
            assemblyMode      = AssemblyMode.legacy;
            repro             = false;
            inheritInvariants = true;
            skipQuantifiers   = false;
            assembly          = null;
            addInterfaceWrappersWhenNeeded = true;
            useGAC = true;
            nowarn = new List <int>();
            ignoreMetadataErrors = false;
        }
        private void HACK_FORCLOUSOT()
        {
            // set the fields to avoid the warning from clousot

            automaticallyLookForOOBs = true;
            allowRewritten = false;
            breakIntoDebugger = false;
            contracts = null;
            debug = true;
            failOnWarnings = false;
            hideFromDebugger = true;
            resolvedPaths = null;
            libpaths = null;
            level = 4;
            recursionGuard = 4;
            throwOnFailure = false;
            publicSurfaceOnly = false;
            callSiteRequires = false;
            output = "same";
            writePDBFile = true;
            keepOriginalFiles = false;
            passthrough = false;
            rewrite = true;
            rewriterMethods = null;
            shortBranches = false;
            extractSourceText = true;
            targetplatform = "";
            framework = "";
            verbose = 0;
            nobox = false;
            nologo = false;
            verify = true;
            warn = 1;
            contractLibrary = null;
            fSharp = false;
            assemblyMode = AssemblyMode.legacy;
            repro = false;
            inheritInvariants = true;
            skipQuantifiers = false;
            assembly = null;
            addInterfaceWrappersWhenNeeded = true;
            useGAC = true;
            nowarn = new List<int>();
            ignoreMetadataErrors = false;
        }
    protected static void BuildModBundle(AssemblyMode mode)
    {
        Debug.LogFormat("Creating \"{0}\" AssetBundle...", BUNDLE_FILENAME);

        if (ModConfig.Instance == null ||
            ModConfig.ID == "" ||
            ModConfig.OutputFolder == "")
        {
            Debug.LogError("You must configure your mod from the \"Keep Talking ModKit / Configure Mod\" menu first.");
            return;
        }

        AssetBundler bundler = new AssetBundler();

        bundler.assemblyName = ModConfig.ID;
        bundler.outputFolder = ModConfig.OutputFolder + "/" + bundler.assemblyName;
        if (Application.platform == RuntimePlatform.OSXEditor)
        {
            bundler.target = BuildTarget.StandaloneOSX;
        }

        bool success = false;

        try
        {
            bundler.WarnIfExampleAssetsAreIncluded();
            bundler.WarnIfAssetsAreNotTagged();
            bundler.CheckForAssets();

            //Delete the cotnents of OUTPUT_FOLDER
            bundler.CleanBuildFolder();

            //Change all non-Editor scripts to reference ASSEMBLY_NAME instead of Assembly-CSharp
            bundler.AdjustMonoScripts();

            //Update material info components for future compatibility checks
            bundler.UpdateMaterialInfo();

            bool UseHarmony = false;

            //Build the assembly using either MSBuild or Unity EditorUtility methods
            if (mode == AssemblyMode.MSBuild)
            {
                bundler.CompileAssemblyWithMSBuild();
            }
            else if (mode == AssemblyMode.WithEditorUtility)
            {
                bundler.CompileAssemblyWithEditor();
            }

            //Copy any other non-Editor managed assemblies to the output folder
            bundler.CopyManagedAssemblies(ref UseHarmony);

            //Create the modInfo.json file and copy the preview image if available
            bundler.CreateModInfo(UseHarmony);

            //Copy the modSettings.json file from Assets into the build
            bundler.CopyModSettings();

            //Copy PDF manual pages to Manual folder in build
            bundler.CopyManual();

            //Lastly, create the asset bundle itself and copy it to the output folder
            bundler.CreateAssetBundle();

            success = true;
        }
        catch (Exception e)
        {
            Debug.LogErrorFormat("Failed to build AssetBundle: {0}\n{1}", e.Message, e.StackTrace);
        }
        finally
        {
            //Restore script references to Assembly-CSharp, as expected by the Unity Editor
            bundler.RestoreMonoScripts();
        }

        if (success)
        {
            Debug.LogFormat("{0} Build complete! Output: {1}", System.DateTime.Now.ToLocalTime(), bundler.outputFolder);
        }
    }
Exemple #5
0
        internal static GeoModel LoadModel(string filename, bool flipTextureCoordinates = false, AssemblyMode am = AssemblyMode.Internal)
        {
            AssimpContext importer = new AssimpContext();

            importer.SetConfig(new VertexBoneWeightLimitConfig(KWEngine.MAX_BONE_WEIGHTS));
            importer.SetConfig(new MaxBoneCountConfig(KWEngine.MAX_BONES));
            FileType type  = CheckFileEnding(filename);
            Scene    scene = null;

            if (am != AssemblyMode.File)
            {
                if (type == FileType.Invalid)
                {
                    throw new Exception("Model file has invalid type.");
                }
                string   resourceName;
                Assembly assembly;

                if (am == AssemblyMode.Internal)
                {
                    assembly     = Assembly.GetExecutingAssembly();
                    resourceName = "KWEngine2.Assets.Models." + filename;
                }
                else
                {
                    assembly     = Assembly.GetEntryAssembly();
                    resourceName = assembly.GetName().Name + "." + filename;
                }

                using (Stream s = assembly.GetManifestResourceStream(resourceName))
                {
                    PostProcessSteps steps =
                        PostProcessSteps.LimitBoneWeights
                        | PostProcessSteps.Triangulate
                        | PostProcessSteps.ValidateDataStructure
                        | PostProcessSteps.GenerateUVCoords
                        | PostProcessSteps.CalculateTangentSpace;
                    if (filename != "kwcube.obj" && filename != "kwcube6.obj")
                    {
                        steps |= PostProcessSteps.JoinIdenticalVertices;
                    }
                    if (type == FileType.DirectX)
                    {
                        steps |= PostProcessSteps.FlipWindingOrder;
                    }
                    if (flipTextureCoordinates)
                    {
                        steps |= PostProcessSteps.FlipUVs;
                    }
                    scene = importer.ImportFileFromStream(s, steps);
                }
            }
            else
            {
                if (type != FileType.Invalid)
                {
                    PostProcessSteps steps =
                        PostProcessSteps.LimitBoneWeights
                        | PostProcessSteps.Triangulate
                        //| PostProcessSteps.FixInFacingNormals
                        | PostProcessSteps.ValidateDataStructure
                        | PostProcessSteps.GenerateUVCoords
                        | PostProcessSteps.CalculateTangentSpace
                        | PostProcessSteps.JoinIdenticalVertices
                    ;
                    if (type == FileType.DirectX)
                    {
                        steps |= PostProcessSteps.FlipWindingOrder;
                    }
                    if (flipTextureCoordinates)
                    {
                        steps |= PostProcessSteps.FlipUVs;
                    }

                    scene = importer.ImportFile(filename, steps);
                }
                else
                {
                    throw new Exception("Could not load model: only OBJ, DAE, FBX and X are supported (GLTF support coming soon).");
                }
            }
            if (scene == null)
            {
                throw new Exception("Could not load or find model: " + filename);
            }

            GeoModel model = ProcessScene(scene, am == AssemblyMode.File ? filename.ToLower().Trim() : filename, am);

            return(model);
        }