Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModelAssetCompiler.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 
7 using SiliconStudio.Assets.Compiler;
8 using SiliconStudio.BuildEngine;
9 using SiliconStudio.Core.IO;
10 using SiliconStudio.Core.Mathematics;
11 using SiliconStudio.Core.Serialization;
12 using SiliconStudio.Paradox.Effects;
13 using SiliconStudio.Paradox.Effects.Data;
14 using SiliconStudio.Paradox.Graphics;
15 
16 namespace SiliconStudio.Paradox.Assets.Model
17 {
18  public class ModelAssetCompiler : AssetCompilerBase<ModelAsset>
19  {
20  protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
21  {
22  if (asset.Source == null)
23  {
24  result.Error("Source cannot be null for Texture Asset [{0}]", asset);
25  return;
26  }
27 
28  // Get absolute path of asset source on disk
29  var assetDirectory = assetAbsolutePath.GetParent();
30  var assetSource = UPath.Combine(assetDirectory, asset.Source);
31 
32  var allow32BitIndex = context.GetGraphicsProfile() >= GraphicsProfile.Level_9_2;
33  var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES;
34  var extension = asset.Source.GetFileExtension();
35 
36  // compute material and lighting configuration dictionaries here because some null reference can occur
37  var materials = new Dictionary<string, Tuple<Guid, string>>();
38  var lightings = new Dictionary<string, Tuple<Guid, string>>();
39  foreach (var meshParam in asset.MeshParameters)
40  {
41  if (meshParam.Value.Material != null)
42  materials.Add(meshParam.Key, new Tuple<Guid, string>(meshParam.Value.Material.Id, meshParam.Value.Material.Location));
43 
44  // Transform AssetReference to Tuple<Guid,UFile> as AssetReference or ContentReference is not serializable (to generate the command hash)
45  // TODO: temporary while the LightingParameters is a Member of MeshMaterialParameter class
46  // TODO: should be passed directly in the Parameters of the mesh - no extra case is required
47  if (meshParam.Value.LightingParameters != null)
48  lightings.Add(meshParam.Key, new Tuple<Guid, string>(meshParam.Value.LightingParameters.Id, meshParam.Value.LightingParameters.Location));
49  }
50 
52  {
53  result.BuildSteps = new ListBuildStep
54  {
56  {
57  SourcePath = assetSource,
58  Location = urlInStorage,
59  Allow32BitIndex = allow32BitIndex,
60  AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
61  Compact = asset.Compact,
62  PreservedNodes = asset.PreservedNodes,
63  Materials = materials,
64  Lightings = lightings, // TODO: remove when lighting parameters will be behind a key
65  Parameters = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
66  ViewDirectionForTransparentZSort = asset.ViewDirectionForTransparentZSort.HasValue ? asset.ViewDirectionForTransparentZSort.Value : -Vector3.UnitZ,
67  },
68  new WaitBuildStep(),
69  };
70  }
71  else if (ImportAssimpCommand.IsSupportingExtensions(extension))
72  {
73  result.BuildSteps = new ListBuildStep
74  {
76  {
77  SourcePath = assetSource,
78  Location = urlInStorage,
79  Allow32BitIndex = allow32BitIndex,
80  AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
81  Compact = asset.Compact,
82  PreservedNodes = asset.PreservedNodes,
83  Materials = materials,
84  Lightings = lightings, // TODO: remove when lighting parameters will be behind a key
85  Parameters = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
86  },
87  new WaitBuildStep(),
88  };
89  }
90  else
91  {
92  result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
93  }
94  }
95  }
96 
97 
98 }
Result of a compilation of assets when using IAssetCompiler.Compile
UFile Source
Gets or sets the source file of this
Definition: AssetImport.cs:25
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
static readonly Vector3 UnitZ
The Z unit SiliconStudio.Core.Mathematics.Vector3 (0, 0, 1).
Definition: Vector3.cs:67
The context used when compiling an asset in a Package.
When embedded in a EnumerableBuildStep, this build step will force all previous computations to be fi...
override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
static bool IsSupportingExtensions(string ext)
GraphicsProfile
Identifies the set of supported devices for the demo based on device capabilities.
Collection of Mesh, each one usually being a different LOD of the same Model. The effect system will ...
Definition: Model.cs:23
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13