public LogPipe(LogStore logStore) { _logStore = logStore; _stream = new LogStream(LogStreamCallback); _stream.Attach(); }
private static void ImportGenericModel(String path, out Scene scene) { try { using (LogStream logStream = new LogStream(delegate(String msg, String userData) { Console.WriteLine(msg); })) { logStream.Attach(); using (AssimpContext importer = new AssimpContext()) scene = importer.ImportFile(path, PostProcessPreset.TargetRealTimeMaximumQuality); logStream.Detach(); } } catch (Exception exception) { scene = null; System.Windows.MessageBox.Show(exception.Message); } }
// // IMPOTER // private void InitLog() { LogStream logstream = new LogStream(delegate(String msg, String userData) { Console.WriteLine(msg); }); logstream.Attach(); }
private bool ImportGenericModel() { LogStream logStream = new LogStream(delegate (String msg, String userData) { Console.WriteLine(msg); }); try { logStream.Attach(); using (AssimpContext importer = new AssimpContext()) Scene = importer.ImportFile(ModelPath, PostProcessPreset.TargetRealTimeMaximumQuality); logStream.Detach(); logStream.Dispose(); if (Scene == null) return false; return true; } catch (Exception exception) { logStream.Detach(); logStream.Dispose(); System.Windows.MessageBox.Show("An error appear : " + exception.Message); return false; } }
public override bool Execute(List<string> args) { if (args.Count != 1) return false; var builder = new RenderModelBuilder(_info.Version); // Add a root node var node = builder.AddNode(new RenderModel.Node { Name = _stringIds.GetStringId("street_cone"), ParentNode = -1, FirstChildNode = -1, NextSiblingNode = -1, DefaultRotation = new Vector4(0, 0, 0, -1), DefaultScale = 1, InverseForward = new Vector3(1, 0, 0), InverseLeft = new Vector3(0, 1, 0), InverseUp = new Vector3(0, 0, 1), }); // Begin building the default region and permutation builder.BeginRegion(_stringIds.GetStringId("default")); builder.BeginPermutation(_stringIds.GetStringId("default")); using (var importer = new AssimpContext()) { Scene model; using (var logStream = new LogStream((msg, userData) => Console.WriteLine(msg))) { logStream.Attach(); model = importer.ImportFile(args[0], PostProcessSteps.CalculateTangentSpace | PostProcessSteps.GenerateNormals | PostProcessSteps.JoinIdenticalVertices | PostProcessSteps.SortByPrimitiveType | PostProcessSteps.PreTransformVertices | PostProcessSteps.Triangulate); logStream.Detach(); } Console.WriteLine("Assembling vertices..."); // Build a multipart mesh from the model data, // with each model mesh mapping to a part of one large mesh and having its own material builder.BeginMesh(); ushort partStartVertex = 0; ushort partStartIndex = 0; var vertices = new List<RigidVertex>(); var indices = new List<ushort>(); foreach (var mesh in model.Meshes) { for (var i = 0; i < mesh.VertexCount; i++) { var position = mesh.Vertices[i]; var normal = mesh.Normals[i]; var uv = mesh.TextureCoordinateChannels[0][i]; var tangent = mesh.Tangents[i]; var bitangent = mesh.BiTangents[i]; vertices.Add(new RigidVertex { Position = new Vector4(position.X, position.Y, position.Z, 1), Normal = new Vector3(normal.X, normal.Y, normal.Z), Texcoord = new Vector2(uv.X, uv.Y), Tangent = new Vector4(tangent.X, tangent.Y, tangent.Z, 1), Binormal = new Vector3(bitangent.X, bitangent.Y, bitangent.Z), }); } // Build the index buffer var meshIndices = mesh.GetIndices(); indices.AddRange(meshIndices.Select(i => (ushort)(i + partStartVertex))); // Define a material and part for this mesh var material = builder.AddMaterial(new RenderMaterial { RenderMethod = _cache.Tags[0x101F], }); builder.DefinePart(material, partStartIndex, (ushort)meshIndices.Length, (ushort)mesh.VertexCount); // Move to the next part partStartVertex += (ushort)mesh.VertexCount; partStartIndex += (ushort)meshIndices.Length; } // Bind the vertex and index buffers builder.BindRigidVertexBuffer(vertices, node); builder.BindIndexBuffer(indices, PrimitiveType.TriangleList); builder.EndMesh(); } builder.EndPermutation(); builder.EndRegion(); Console.WriteLine("Building Blam mesh data..."); var resourceStream = new MemoryStream(); var renderModel = builder.Build(_info.Serializer, resourceStream); Console.WriteLine("Writing resource data..."); // Add a new resource for the model data var resources = new ResourceDataManager(); resources.LoadCachesFromDirectory(_fileInfo.DirectoryName); resourceStream.Position = 0; resources.Add(renderModel.Geometry.Resource, ResourceLocation.Resources, resourceStream); Console.WriteLine("Writing tag data..."); using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite)) { var tag = _cache.Tags[0x3317]; var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tag); _info.Serializer.Serialize(context, renderModel); } Console.WriteLine("Model imported successfully!"); return true; }
public override bool Execute(List<string> args) { if (args.Count < 1 || args.Count > 3) return false; ResourceLocation location = ResourceLocation.Resources; TagInstance destination = Info.Cache.Tags[0x3317]; if (args.Count == 3) { var value = args[0]; switch (value) { case "resources": location = ResourceLocation.Resources; break; case "textures": location = ResourceLocation.Textures; break; case "textures_b": location = ResourceLocation.TexturesB; break; case "audio": location = ResourceLocation.Audio; break; case "video": location = ResourceLocation.Video; break; case "render_models": location = ResourceLocation.RenderModels; break; case "lightmaps": location = ResourceLocation.Lightmaps; break; default: Console.WriteLine("Invalid resource location: " + value); return false; } args.RemoveAt(0); } if (args.Count == 2) { destination = ArgumentParser.ParseTagIndex(Info, args[0]); if (!destination.IsInGroup("mode")) { Console.WriteLine("Specified tag is not a render_model: " + args[0]); return false; } args.RemoveAt(0); } var builder = new RenderModelBuilder(Info.Version); // Add a root node var node = builder.AddNode(new RenderModel.Node { Name = Info.StringIDs.GetStringID("street_cone"), ParentNode = -1, FirstChildNode = -1, NextSiblingNode = -1, DefaultRotation = new Vector4(0, 0, 0, -1), DefaultScale = 1, InverseForward = new Vector3(1, 0, 0), InverseLeft = new Vector3(0, 1, 0), InverseUp = new Vector3(0, 0, 1), }); // Begin building the default region and permutation builder.BeginRegion(Info.StringIDs.GetStringID("default")); builder.BeginPermutation(Info.StringIDs.GetStringID("default")); using (var importer = new AssimpContext()) { Scene model; using (var logStream = new LogStream((msg, userData) => Console.WriteLine(msg))) { logStream.Attach(); model = importer.ImportFile(args[0], PostProcessSteps.CalculateTangentSpace | PostProcessSteps.GenerateNormals | PostProcessSteps.JoinIdenticalVertices | PostProcessSteps.SortByPrimitiveType | PostProcessSteps.PreTransformVertices | PostProcessSteps.Triangulate); logStream.Detach(); } Console.WriteLine("Assembling vertices..."); // Build a multipart mesh from the model data, // with each model mesh mapping to a part of one large mesh and having its own material builder.BeginMesh(); ushort partStartVertex = 0; ushort partStartIndex = 0; var vertices = new List<RigidVertex>(); var indices = new List<ushort>(); foreach (var mesh in model.Meshes) { for (var i = 0; i < mesh.VertexCount; i++) { var position = mesh.Vertices[i]; var normal = mesh.Normals[i]; var uv = mesh.TextureCoordinateChannels[0][i]; var tangent = mesh.Tangents[i]; var bitangent = mesh.BiTangents[i]; vertices.Add(new RigidVertex { Position = new Vector4(position.X, position.Y, position.Z, 1), Normal = new Vector3(normal.X, normal.Y, normal.Z), Texcoord = new Vector2(uv.X, uv.Y), Tangent = new Vector4(tangent.X, tangent.Y, tangent.Z, 1), Binormal = new Vector3(bitangent.X, bitangent.Y, bitangent.Z), }); } // Build the index buffer var meshIndices = mesh.GetIndices(); indices.AddRange(meshIndices.Select(i => (ushort)(i + partStartVertex))); // Define a material and part for this mesh var material = builder.AddMaterial(new RenderMaterial { RenderMethod = Info.Cache.Tags[0x101F], }); builder.BeginPart(material, partStartIndex, (ushort)meshIndices.Length, (ushort)mesh.VertexCount); builder.DefineSubPart(partStartIndex, (ushort)meshIndices.Length, (ushort)mesh.VertexCount); builder.EndPart(); // Move to the next part partStartVertex += (ushort)mesh.VertexCount; partStartIndex += (ushort)meshIndices.Length; } // Bind the vertex and index buffers builder.BindRigidVertexBuffer(vertices, node); builder.BindIndexBuffer(indices, PrimitiveType.TriangleList); builder.EndMesh(); } builder.EndPermutation(); builder.EndRegion(); Console.WriteLine("Building Blam mesh data..."); var resourceStream = new MemoryStream(); var renderModel = builder.Build(Info.Serializer, resourceStream); Console.WriteLine("Writing resource data..."); // Add a new resource for the model data var resources = new ResourceDataManager(); resources.LoadCachesFromDirectory(Info.CacheFile.DirectoryName); resourceStream.Position = 0; resources.Add(renderModel.Geometry.Resource, location, resourceStream); Console.WriteLine("Writing tag data..."); using (var cacheStream = Info.OpenCacheReadWrite()) { var tag = destination; var context = new TagSerializationContext(cacheStream, Info.Cache, Info.StringIDs, tag); Info.Serializer.Serialize(context, renderModel); } Console.WriteLine("Model imported successfully!"); return true; }
static public AssimpVolume LoadFromFile(string filename) { string path = Path.Combine("Assets", "Models", filename); AssimpContext importer = new AssimpContext(); NormalSmoothingAngleConfig normalSmoothing = new NormalSmoothingAngleConfig(66.0f); importer.SetConfig(normalSmoothing); LogStream logStream = new LogStream ( delegate(string message, string userData) { Console.Write(message); } ); logStream.Attach(); Scene model = importer.ImportFile(path, PostProcessPreset.TargetRealTimeMaximumQuality); Mesh mesh = model.Meshes[0]; AssimpVolume v = new AssimpVolume(); List<Vector3> newVertices = new List<Vector3>(); foreach (Assimp.Vector3D vert in mesh.Vertices) { newVertices.Add(new Vector3(vert.X, vert.Y, vert.Z)); } v.vertices = newVertices.ToArray(); v.indices = mesh.GetIndices(); if (mesh.HasNormals) { v.generateNormals = false; List<Vector3> newNormals = new List<Vector3>(); foreach (Assimp.Vector3D n in mesh.Normals) { newNormals.Add(new Vector3(n.X, n.Y, n.Z)); } v.normals = newNormals.ToArray(); } if (mesh.HasTextureCoords(0)) { List<Vector2> newTextureCoords = new List<Vector2>(); foreach (Assimp.Vector3D tc in mesh.TextureCoordinateChannels[0]) { newTextureCoords.Add(new Vector2(tc.X, tc.Y)); } v.textureCoords = newTextureCoords.ToArray(); } if (mesh.HasVertexColors(0)) { List<Vector3> newColors = new List<Vector3>(); foreach (Assimp.Color4D c in mesh.VertexColorChannels[0]) { newColors.Add(new Vector3(c.R, c.G, c.B)); } v.colors = newColors.ToArray(); } importer.Dispose(); return v; }