|
@@ -4,6 +4,7 @@ using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Runtime.Serialization.Json;
|
|
|
using System.Windows.Forms;
|
|
|
+using BabylonExport.Core.Exporters.FBX;
|
|
|
using Microsoft.Xna.Framework.Content;
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
using SkinnedModel;
|
|
@@ -25,7 +26,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
|
|
|
private int texturesCount = 0;
|
|
|
|
|
|
- public void GenerateBabylonFile(string file, string outputFile, bool skinned)
|
|
|
+ public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft)
|
|
|
{
|
|
|
if (OnImportProgressChanged != null)
|
|
|
OnImportProgressChanged(0);
|
|
@@ -53,7 +54,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
if (string.IsNullOrEmpty(buildError))
|
|
|
{
|
|
|
var model = contentManager.Load<Model>("Model");
|
|
|
- ParseModel(model, scene);
|
|
|
+ ParseModel(model, scene, rightToLeft);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -78,7 +79,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
OnImportProgressChanged(100);
|
|
|
}
|
|
|
|
|
|
- void ParseModel(Model model, BabylonScene scene)
|
|
|
+ void ParseModel(Model model, BabylonScene scene, bool rightToLeft)
|
|
|
{
|
|
|
var effects = model.Meshes.SelectMany(m => m.Effects).ToList();
|
|
|
var meshes = model.Meshes.ToList();
|
|
@@ -115,7 +116,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
|
|
|
foreach (var mesh in meshes)
|
|
|
{
|
|
|
- ParseMesh(mesh, scene, currentSkeleton);
|
|
|
+ ParseMesh(mesh, scene, currentSkeleton, rightToLeft);
|
|
|
if (OnImportProgressChanged != null)
|
|
|
OnImportProgressChanged(((progress++) * 100) / total);
|
|
|
}
|
|
@@ -175,7 +176,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
skeleton.bones = bones.ToArray();
|
|
|
}
|
|
|
|
|
|
- void ParseMesh(ModelMesh modelMesh, BabylonScene scene, BabylonSkeleton skeleton)
|
|
|
+ void ParseMesh(ModelMesh modelMesh, BabylonScene scene, BabylonSkeleton skeleton, bool rightToLeft)
|
|
|
{
|
|
|
var proxyID = ProxyMesh.CreateBabylonMesh(modelMesh.Name, scene);
|
|
|
int indexName = 0;
|
|
@@ -185,17 +186,18 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
var material = exportedMaterials.First(m => m.Name == part.Effect.GetHashCode().ToString());
|
|
|
|
|
|
var indices = new ushort[part.PrimitiveCount * 3];
|
|
|
-
|
|
|
part.IndexBuffer.GetData(part.StartIndex * 2, indices, 0, indices.Length);
|
|
|
- for (int ib = 0; ib < indices.Length; ib += 3) // reverse winding of triangles Needed for Right-Left Coordinate System
|
|
|
+
|
|
|
+ if (rightToLeft)
|
|
|
{
|
|
|
- ushort ti;
|
|
|
- ti = indices[ib];
|
|
|
- indices[ib] = indices[ib + 2];
|
|
|
- indices[ib + 2] = ti;
|
|
|
+ for (int ib = 0; ib < indices.Length; ib += 3) // reverse winding of triangles
|
|
|
+ {
|
|
|
+ ushort ti = indices[ib];
|
|
|
+ indices[ib] = indices[ib + 2];
|
|
|
+ indices[ib + 2] = ti;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if (part.VertexBuffer.VertexDeclaration.VertexStride >= PositionNormalTexturedWeights.Stride)
|
|
|
{
|
|
|
var mesh = new Mesh<PositionNormalTexturedWeights>(material);
|
|
@@ -204,19 +206,21 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
part.VertexBuffer.GetData(part.VertexOffset * part.VertexBuffer.VertexDeclaration.VertexStride, vertices, 0, vertices.Length, part.VertexBuffer.VertexDeclaration.VertexStride);
|
|
|
|
|
|
for (int index = 0; index < vertices.Length; index++)
|
|
|
- {
|
|
|
+ {
|
|
|
vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y;
|
|
|
- // Negate Position.Z & Normal.Z -- Needed for Right-Left Coordinate System
|
|
|
- vertices[index].Position.Z = -vertices[index].Position.Z;
|
|
|
- vertices[index].Normal.Z = -vertices[index].Normal.Z;
|
|
|
+ if (rightToLeft)
|
|
|
+ {
|
|
|
+ vertices[index].Position.Z = -vertices[index].Position.Z;
|
|
|
+ vertices[index].Normal.Z = -vertices[index].Normal.Z;
|
|
|
+ }
|
|
|
}
|
|
|
- // Prefix MeshName to MeshParts -- MeshName#MeshPartIndex
|
|
|
+
|
|
|
mesh.AddPart(modelMesh.Name+"#"+indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
|
|
|
mesh.CreateBabylonMesh(scene, proxyID, skeleton);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (part.VertexBuffer.VertexDeclaration.VertexStride < 32) return; // Error: Not a PositionNormalTextured mesh!
|
|
|
+ if (part.VertexBuffer.VertexDeclaration.VertexStride < PositionNormalTextured.Stride) return; // Error: Not a PositionNormalTextured mesh!
|
|
|
var mesh = new Mesh<PositionNormalTextured>(material);
|
|
|
var vertices = new PositionNormalTextured[part.NumVertices];
|
|
|
part.VertexBuffer.GetData(part.VertexOffset * part.VertexBuffer.VertexDeclaration.VertexStride, vertices, 0, vertices.Length, part.VertexBuffer.VertexDeclaration.VertexStride);
|
|
@@ -224,12 +228,13 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
for (int index = 0; index < vertices.Length; index++)
|
|
|
{
|
|
|
vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y;
|
|
|
- // Negate Position.Z & Normal.Z -- Needed for Right-Left Coordinate System
|
|
|
- vertices[index].Position.Z = -vertices[index].Position.Z;
|
|
|
- vertices[index].Normal.Z = -vertices[index].Normal.Z;
|
|
|
+ if (rightToLeft)
|
|
|
+ {
|
|
|
+ vertices[index].Position.Z = -vertices[index].Position.Z;
|
|
|
+ vertices[index].Normal.Z = -vertices[index].Normal.Z;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // Prefix MeshName to MeshParts -- MeshName#MeshPartIndex
|
|
|
mesh.AddPart(modelMesh.Name + "#" + indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
|
|
|
mesh.CreateBabylonMesh(scene, proxyID, skeleton);
|
|
|
}
|
|
@@ -241,7 +246,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
void ParseEffect(Effect effect, BabylonScene scene)
|
|
|
{
|
|
|
var material = new StandardMaterial(effect.GetHashCode().ToString());
|
|
|
-
|
|
|
+
|
|
|
exportedMaterials.Add(material);
|
|
|
|
|
|
var basicEffect = effect as BasicEffect;
|