コード例 #1
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourceExists(result, asset, assetAbsolutePath))
            {
                return;
            }

            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = UPath.Combine(assetDirectory, asset.Source);

            var gameSettingsAsset         = context.GetGameSettingsAsset();
            var allow32BitIndex           = gameSettingsAsset.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES;
            var extension = asset.Source.GetFileExtension();

            if (ImportFbxCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new AssetBuildStep(AssetItem)
                {
                    new ImportFbxCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = asset.Materials,
                        ScaleImport    = asset.ScaleImport,
                    },
                };
            }
            else if (ImportAssimpCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new AssetBuildStep(AssetItem)
                {
                    new ImportAssimpCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = asset.Materials,
                        ScaleImport    = asset.ScaleImport,
                    },
                };
            }
            else
            {
                result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
            }
        }
コード例 #2
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result)
        {
            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = UPath.Combine(assetDirectory, asset.Source);
            var extension      = assetSource.GetFileExtension();
            var buildStep      = new ListBuildStep();

            var additiveAnimationAsset = asset as AdditiveAnimationAsset;

            if (additiveAnimationAsset != null)
            {
                var baseUrlInStorage   = urlInStorage + "_animation_base";
                var sourceUrlInStorage = urlInStorage + "_animation_source";

                var baseAssetSource = UPath.Combine(assetDirectory, additiveAnimationAsset.BaseSource);

                // Import base and main animation
                if (ImportFbxCommand.IsSupportingExtensions(extension))
                {
                    buildStep.Add(new ImportFbxCommand {
                        SourcePath = assetSource, Location = sourceUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                    buildStep.Add(new ImportFbxCommand {
                        SourcePath = baseAssetSource, Location = baseUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                }
                else if (ImportAssimpCommand.IsSupportingExtensions(extension))
                {
                    buildStep.Add(new ImportAssimpCommand {
                        SourcePath = assetSource, Location = sourceUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                    buildStep.Add(new ImportAssimpCommand {
                        SourcePath = baseAssetSource, Location = baseUrlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                }
                // Wait for both import fbx commands to be completed
                buildStep.Add(new WaitBuildStep());

                // Generate the diff of those two animations
                buildStep.Add(new AdditiveAnimationCommand(urlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, additiveAnimationAsset.Mode)));
            }
            else
            {
                // Import the main animation
                if (ImportFbxCommand.IsSupportingExtensions(extension))
                {
                    buildStep.Add(new ImportFbxCommand {
                        SourcePath = assetSource, Location = urlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                }
                else if (ImportAssimpCommand.IsSupportingExtensions(extension))
                {
                    buildStep.Add(new ImportAssimpCommand {
                        SourcePath = assetSource, Location = urlInStorage, ExportType = "animation", AnimationRepeatMode = asset.RepeatMode
                    });
                }
            }

            result.BuildSteps = buildStep;
        }
コード例 #3
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
        {
            if (asset.Source == null)
            {
                result.Error("Source cannot be null for Texture Asset [{0}]", asset);
                return;
            }

            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = UPath.Combine(assetDirectory, asset.Source);

            var allow32BitIndex           = context.GetGraphicsProfile() >= GraphicsProfile.Level_9_2;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES;
            var extension = asset.Source.GetFileExtension();

            // compute material and lighting configuration dictionaries here because some null reference can occur
            var materials = new Dictionary <string, Tuple <Guid, string> >();
            var lightings = new Dictionary <string, Tuple <Guid, string> >();

            foreach (var meshParam in asset.MeshParameters)
            {
                if (meshParam.Value.Material != null)
                {
                    materials.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.Material.Id, meshParam.Value.Material.Location));
                }

                // Transform AssetReference to Tuple<Guid,UFile> as AssetReference or ContentReference is not serializable (to generate the command hash)
                // TODO: temporary while the LightingParameters is a Member of MeshMaterialParameter class
                // TODO: should be passed directly in the Parameters of the mesh - no extra case is required
                if (meshParam.Value.LightingParameters != null)
                {
                    lightings.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.LightingParameters.Id, meshParam.Value.LightingParameters.Location));
                }
            }

            if (ImportFbxCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new ListBuildStep
                {
                    new ImportFbxCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = materials,
                        Lightings      = lightings,    // TODO: remove when lighting parameters will be behind a key
                        Parameters     = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
                        ViewDirectionForTransparentZSort = asset.ViewDirectionForTransparentZSort.HasValue ? asset.ViewDirectionForTransparentZSort.Value : -Vector3.UnitZ,
                    },
                    new WaitBuildStep(),
                };
            }
            else if (ImportAssimpCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new ListBuildStep
                {
                    new ImportAssimpCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = materials,
                        Lightings      = lightings,    // TODO: remove when lighting parameters will be behind a key
                        Parameters     = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
                    },
                    new WaitBuildStep(),
                };
            }
            else
            {
                result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
            }
        }