2019-04-30 21:07:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Collada141;
|
2019-05-01 19:38:14 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using ColladaHelper;
|
2019-06-13 21:31:35 +00:00
|
|
|
|
using OpenTK;
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using Toolbox.Library.Rendering;
|
2019-11-12 22:11:35 +00:00
|
|
|
|
using Toolbox.Library.Collada;
|
2019-04-30 21:07:25 +00:00
|
|
|
|
|
2019-07-16 21:35:21 +00:00
|
|
|
|
namespace Toolbox.Library
|
2019-04-30 21:07:25 +00:00
|
|
|
|
{
|
2019-05-01 19:38:14 +00:00
|
|
|
|
public class DAE : DAEHelper
|
2019-04-30 21:07:25 +00:00
|
|
|
|
{
|
2019-11-09 22:36:52 +00:00
|
|
|
|
public class ExportSettings
|
|
|
|
|
{
|
|
|
|
|
public Version FileVersion = new Version();
|
2019-11-10 13:41:17 +00:00
|
|
|
|
|
|
|
|
|
public string ImageExtension = ".png";
|
|
|
|
|
public string ImageFolder = "";
|
2019-11-09 22:36:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 22:11:35 +00:00
|
|
|
|
public class TextureMap
|
|
|
|
|
{
|
|
|
|
|
public uint TextureChannel = 0;
|
|
|
|
|
public string Type = "diffuse";
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 22:36:52 +00:00
|
|
|
|
public class Version
|
|
|
|
|
{
|
|
|
|
|
public int Major = 1;
|
|
|
|
|
public int Minor = 4;
|
|
|
|
|
public int Micro = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Export(string fileName, ExportSettings exportSettings)
|
|
|
|
|
{
|
|
|
|
|
using (ColladaWriter writer = new ColladaWriter(fileName, exportSettings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-12 22:11:35 +00:00
|
|
|
|
|
2019-05-01 19:38:14 +00:00
|
|
|
|
public List<STGenericObject> objects = new List<STGenericObject>();
|
|
|
|
|
public List<STGenericMaterial> materials = new List<STGenericMaterial>();
|
|
|
|
|
public STSkeleton skeleton;
|
|
|
|
|
public List<string> BoneNames = new List<string>();
|
|
|
|
|
|
2019-04-30 21:07:25 +00:00
|
|
|
|
public bool UseTransformMatrix = true;
|
|
|
|
|
|
2019-06-13 21:31:35 +00:00
|
|
|
|
Dictionary<string, Vertex> VertexSkinSources = new Dictionary<string, Vertex>();
|
|
|
|
|
Dictionary<string, Matrix4> MatrixSkinSources = new Dictionary<string, Matrix4>();
|
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
private Matrix4 GlobalTransform = Matrix4.Identity;
|
2019-06-13 21:31:35 +00:00
|
|
|
|
public bool LoadFile(string FileName)
|
2019-04-30 21:07:25 +00:00
|
|
|
|
{
|
2019-09-15 23:13:01 +00:00
|
|
|
|
GlobalTransform = Matrix4.Identity;
|
|
|
|
|
|
2019-04-30 21:07:25 +00:00
|
|
|
|
COLLADA collada = COLLADA.Load(FileName);
|
2019-10-27 00:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
//Check axis up
|
|
|
|
|
if (collada.asset != null)
|
|
|
|
|
{
|
|
|
|
|
switch (collada.asset.up_axis)
|
|
|
|
|
{
|
|
|
|
|
case UpAxisType.X_UP:
|
|
|
|
|
GlobalTransform = Matrix4.CreateRotationX(90);
|
|
|
|
|
break;
|
|
|
|
|
case UpAxisType.Y_UP:
|
|
|
|
|
GlobalTransform = Matrix4.CreateRotationY(90);
|
|
|
|
|
break;
|
|
|
|
|
case UpAxisType.Z_UP:
|
|
|
|
|
GlobalTransform = Matrix4.CreateRotationZ(90);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (collada.asset.unit != null)
|
|
|
|
|
{
|
|
|
|
|
var amount = collada.asset.unit.meter;
|
|
|
|
|
var type = collada.asset.unit.name;
|
|
|
|
|
if (type == "meter")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (type == "centimeter")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-30 21:07:25 +00:00
|
|
|
|
|
|
|
|
|
foreach (var item in collada.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item is library_geometries)
|
2019-05-01 19:38:14 +00:00
|
|
|
|
LoadGeometry((library_geometries)item);
|
2019-09-15 23:13:01 +00:00
|
|
|
|
if (item is library_images)
|
|
|
|
|
LoadImages((library_images)item);
|
|
|
|
|
if (item is library_controllers)
|
|
|
|
|
LoadControllers((library_controllers)item);
|
|
|
|
|
if (item is library_nodes)
|
|
|
|
|
LoadNodes((library_nodes)item);
|
|
|
|
|
if (item is library_visual_scenes)
|
|
|
|
|
LoadVisualScenes((library_visual_scenes)item);
|
2019-04-30 21:07:25 +00:00
|
|
|
|
}
|
2019-06-13 21:31:35 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2019-04-30 21:07:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
private void LoadVisualScenes(library_visual_scenes nodes)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadNodes(library_nodes nodes)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadControllers(library_controllers controllers)
|
2019-05-01 19:38:14 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
private void LoadMaterials(library_materials materials)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-06-13 21:31:35 +00:00
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
private void LoadImages(library_images images)
|
2019-04-30 21:07:25 +00:00
|
|
|
|
{
|
2019-09-15 23:13:01 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadGeometry(library_geometries geometries)
|
|
|
|
|
{
|
|
|
|
|
foreach (var geom in geometries.geometry)
|
2019-05-01 19:38:14 +00:00
|
|
|
|
{
|
|
|
|
|
var mesh = geom.Item as mesh;
|
|
|
|
|
if (mesh == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var source in mesh.source)
|
|
|
|
|
{
|
|
|
|
|
var float_array = source.Item as float_array;
|
|
|
|
|
if (float_array == null)
|
|
|
|
|
continue;
|
2019-04-30 21:07:25 +00:00
|
|
|
|
|
2019-05-01 19:38:14 +00:00
|
|
|
|
Console.Write("Geometry {0} source {1} : ", geom.id, source.id);
|
|
|
|
|
foreach (var mesh_source_value in float_array.Values)
|
|
|
|
|
Console.Write("{0} ", mesh_source_value);
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-30 21:07:25 +00:00
|
|
|
|
}
|
2019-06-13 21:31:35 +00:00
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
public bool ExportFile(string FileName, List<STGenericObject> meshes, STSkeleton skeleton = null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 21:31:35 +00:00
|
|
|
|
private List<STGenericObject> CreateGenericObjects(string Name, library_geometries Geometries)
|
|
|
|
|
{
|
|
|
|
|
List<STGenericObject> objects = new List<STGenericObject>();
|
|
|
|
|
foreach (var geom in Geometries.geometry)
|
|
|
|
|
{
|
|
|
|
|
var daeMesh = geom.Item as mesh;
|
|
|
|
|
if (daeMesh == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
STGenericObject mesh = new STGenericObject();
|
|
|
|
|
mesh.ObjectName = Name;
|
|
|
|
|
|
|
|
|
|
foreach (var source in daeMesh.source)
|
|
|
|
|
{
|
|
|
|
|
var float_array = source.Item as float_array;
|
|
|
|
|
if (float_array == null)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
objects.Add(mesh);
|
|
|
|
|
}
|
|
|
|
|
return objects;
|
|
|
|
|
}
|
2019-04-30 21:07:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|