Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Paradox.Importer.Common.cpp
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 #include "stdafx.h"
4 
5 using namespace System;
6 using namespace System::Collections::Generic;
7 using namespace System::IO;
8 using namespace SiliconStudio::Core::Diagnostics;
9 using namespace SiliconStudio::Core::Mathematics;
10 using namespace SiliconStudio::Core::Serialization;
11 using namespace SiliconStudio::Paradox::Assets::Materials;
12 using namespace SiliconStudio::Paradox::Assets::Materials::Nodes;
13 using namespace SiliconStudio::Paradox::Effects;
14 using namespace SiliconStudio::Paradox::Effects::Data;
15 using namespace SiliconStudio::Paradox::Effects::Modules;
16 using namespace SiliconStudio::Paradox::Engine::Data;
17 using namespace SiliconStudio::Paradox::Graphics;
18 using namespace SiliconStudio::Paradox::Shaders;
19 
20 namespace SiliconStudio { namespace Paradox { namespace Importer { namespace Common {
21 
22 public ref class MeshParameters
23 {
24 public:
26  {
27  Parameters = gcnew ParameterCollectionData();
28  }
29 
31  String^ MaterialName;
32  String^ MeshName;
33  String^ NodeName;
34 };
35 
36 public ref class NodeInfo
37 {
38 public:
39  String^ Name;
40  int Depth;
41  bool Preserve;
42 };
43 
44 public ref class CameraInfo
45 {
46 public:
47  String^ NodeName;
48  String^ TargetNodeName;
50 };
51 
52 public ref class LightInfo
53 {
54 public:
55  String^ NodeName;
57 };
58 
59 public ref class EntityInfo
60 {
61 public:
62  List<String^>^ TextureDependencies;
63  Dictionary<String^, MaterialDescription^>^ Materials;
64  List<String^>^ AnimationNodes;
65  List<MeshParameters^>^ Models;
66  List<NodeInfo^>^ Nodes;
67  List<CameraInfo^>^ Cameras;
68  List<LightInfo^>^ Lights;
70 };
71 
72 public ref class MeshMaterials
73 {
74 public:
75  Dictionary<String^, MaterialDescription^>^ Materials;
76  List<MeshParameters^>^ Models;
77  List<CameraInfo^>^ Cameras;
78  List<LightInfo^>^ Lights;
79 };
80 
81 public ref class MaterialInstanciation
82 {
83 public:
84  List<String^>^ Parameters;
86  String^ MaterialName;
87 };
88 
89 public ref class TextureLayerGenerator
90 {
91 public:
92 
93  static ShaderClassSource^ GenerateTextureLayer(String^ vfsOutputPath, String^ sourceTextureFile, int textureUVSetIndex, Vector2 textureUVscaling ,
94  int& textureCount, ParameterKey<Texture^>^ surfaceMaterialKey,
95  MeshData^ meshData, Logger^ logger)
96  {
97  ParameterKey<Texture^>^ parameterKey;
98 
99  auto texture = gcnew ContentReference<Texture^>();
100 
101  auto url = vfsOutputPath + "_" + Path::GetFileNameWithoutExtension(sourceTextureFile);
102 
103  texture->Location = url;
104  //assetManager->Url->Set(texture, url);
105 
106  if (File::Exists(sourceTextureFile))
107  {
108  if (logger != nullptr)
109  {
110  logger->Warning("The texture '{0}' referenced in the mesh material can not be found on the system. Loading will probably fail at run time.", sourceTextureFile,
111  nullptr, CallerInfo::Get(__FILEW__, __FUNCTIONW__, __LINE__));
112  }
113  }
114 
115  //meshData->Parameters->Set(
116  // parameterKey = ParameterKeys::IndexedKey(surfaceMaterialKey, textureCount++),
117  // texture);
118 
119  parameterKey = ParameterKeys::IndexedKey(surfaceMaterialKey, textureCount++);
120  String^ uvSetName = "TEXCOORD";
121  if (textureUVSetIndex != 0)
122  uvSetName += textureUVSetIndex;
123  //albedoMaterial->Add(gcnew ShaderClassSource("TextureStream", uvSetName, "TEXTEST" + uvSetIndex));
124  auto uvScaling = textureUVscaling;
125  auto textureName = parameterKey->Name;
126  auto needScaling = uvScaling != Vector2::One;
127  auto currentComposition = needScaling
128  ? gcnew ShaderClassSource("ComputeColorTextureRepeat", textureName, uvSetName, "float2(" + uvScaling[0] + ", " + uvScaling[1] + ")")
129  : gcnew ShaderClassSource((surfaceMaterialKey == MaterialTexturingKeys::DisplacementTexture0) ? "ComputeColorTextureDisplacement" : "ComputeColorTexture", textureName, uvSetName);
130 
131  return currentComposition;
132  }
133 
134  static MaterialTextureNode^ GenerateMaterialTextureNode(String^ vfsOutputPath, String^ sourceTextureFile, int textureUVSetIndex, Vector2 textureUVscaling, bool wrapTextureU, bool wrapTextureV, Logger^ logger)
135  {
136  auto texture = gcnew ContentReference<Texture^>();
137 
138  auto textureFileName = Path::GetFileNameWithoutExtension(sourceTextureFile);
139  auto url = vfsOutputPath + "_" + textureFileName;
140 
141  texture->Location = url;
142 
143  if (File::Exists(sourceTextureFile))
144  {
145  if (logger != nullptr)
146  {
147  logger->Warning("The texture '{0}' referenced in the mesh material can not be found on the system. Loading will probably fail at run time.", sourceTextureFile,
148  nullptr, CallerInfo::Get(__FILEW__, __FUNCTIONW__, __LINE__));
149  }
150  }
151 
152  auto uvScaling = textureUVscaling;
153  auto textureName = textureFileName;
154 
155  auto currentTexture = gcnew MaterialTextureNode(textureName, textureUVSetIndex, uvScaling, Vector2::Zero);
156  currentTexture->Sampler->AddressModeU = wrapTextureU ? TextureAddressMode::Wrap : TextureAddressMode::Clamp;
157  currentTexture->Sampler->AddressModeV = wrapTextureV ? TextureAddressMode::Wrap : TextureAddressMode::Clamp;
158 
159  return currentTexture;
160  }
161 };
162 }}}}
Key of an effect parameter.
Definition: ParameterKey.cs:15
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
string Name
Gets the name of this key.
Definition: PropertyKey.cs:60
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
Data type for SiliconStudio.Paradox.Effects.ParameterCollection.
Definition: ParadoxData.cs:31
Dictionary< String^, MaterialDescription^> Materials
Base implementation for ILogger.
Definition: Logger.cs:10
static MaterialTextureNode GenerateMaterialTextureNode(String^vfsOutputPath, String^sourceTextureFile, int textureUVSetIndex, Vector2 textureUVscaling, bool wrapTextureU, bool wrapTextureV, Logger^logger)
abstract string Location
Gets or sets the URL of the referenced data.
Data type for SiliconStudio.Paradox.Effects.Mesh.
Definition: EngineData.cs:197
Dictionary< String^, MaterialDescription^> Materials
void Warning(string message, Exception exception, CallerInfo callerInfo=null)
Logs the specified warning message with an exception.
Data type for SiliconStudio.Paradox.Engine.LightComponent.
Definition: EngineData.cs:524
Data type for SiliconStudio.Paradox.Engine.CameraComponent.
static ShaderClassSource GenerateTextureLayer(String^vfsOutputPath, String^sourceTextureFile, int textureUVSetIndex, Vector2 textureUVscaling, int &textureCount, ParameterKey< Texture^>^surfaceMaterialKey, MeshData^meshData, Logger^logger)