/// <summary> /// Loads the GL objects into OpenGL buffer. /// </summary> /// <returns>The GL objects.</returns> /// <param name="objects">Objects.</param> /// <param name="nObject">N object.</param> public static int[][] LoadGLObjects( LoadResult[][] objects, PhysicsEngineMathUtility.Vector3[][] translate, int nObject, bool GLM_TEXTURE = false, bool GLM_FLAT = false, bool GLM_SMOOTH = false ) { int[][] displayList = new int[nObject][]; for (int i = 0; i < nObject; i++) { displayList[i] = new int[objects[i].Length]; for (int j = 0; j < objects[i].Length; j++) { displayList[i][j] = GL.GenLists(1); GL.NewList(displayList[i][j], ListMode.CompileAndExecute); GLDrawSolid(objects[i][j], translate[i][j], GLM_TEXTURE, GLM_FLAT, GLM_SMOOTH); GL.EndList(); } } return displayList; }
public IList<Mesh> Convert(LoadResult loadResult) { _loadResult = loadResult; _meshes = new List<Mesh>(); ConvertGroups(); return _meshes; }
private LoadResult CreateResult() { var result = new LoadResult { Vertices = _dataStore.Vertices, Textures = _dataStore.Textures, Normals = _dataStore.Normals, Groups = _dataStore.Groups, Materials = _dataStore.Materials }; return result; }
private LoadResult CreateResult() { var result = new LoadResult { Vertices = _dataStore.Vertices, Textures = _dataStore.Textures, Normals = _dataStore.Normals, Groups = _dataStore.Groups, Materials = _dataStore.Materials }; return(result); }
private static void PrintResult(LoadResult result) { var sb = new StringBuilder(); sb.AppendLine("Load result:"); sb.Append("Vertices: "); sb.AppendLine(result.Vertices.Count.ToString(CultureInfo.InvariantCulture)); sb.Append("Textures: "); sb.AppendLine(result.Textures.Count.ToString(CultureInfo.InvariantCulture)); sb.Append("Normals: "); sb.AppendLine(result.Normals.Count.ToString(CultureInfo.InvariantCulture)); sb.AppendLine(); sb.AppendLine("Groups: "); foreach (var loaderGroup in result.Groups) { sb.AppendLine(loaderGroup.Name); sb.Append("Faces: "); sb.AppendLine(loaderGroup.Faces.Count.ToString(CultureInfo.InvariantCulture)); } Console.WriteLine(sb); }
public static float UnitizeObject(ref LoadResult obj) { float xMax, xMin, yMax, yMin, zMax, zMin; float cx, cy, cz, w, h, d; float scale; xMax = obj.Vertices [0].X; xMin = obj.Vertices [0].X; yMax = obj.Vertices [0].Y; yMin = obj.Vertices [0].Y; zMax = obj.Vertices [0].Z; zMin = obj.Vertices [0].Z; for (int i = 1; i < obj.Vertices.Count; i++) { if (xMax < obj.Vertices [i].X) xMax = obj.Vertices [i].X; if (xMin > obj.Vertices [i].X) xMin = obj.Vertices [i].X; if (yMax < obj.Vertices [i].Y) yMax = obj.Vertices [i].Y; if (yMin > obj.Vertices [i].Y) yMin = obj.Vertices [i].Y; if (zMax < obj.Vertices [i].Z) zMax = obj.Vertices [i].Z; if (zMin > obj.Vertices [i].Z) zMin = obj.Vertices [i].Z; } /* calculate model width, height, and depth */ w = Math.Abs (xMax) + Math.Abs (xMin); h = Math.Abs (yMax) + Math.Abs (yMin); d = Math.Abs (zMax) + Math.Abs (zMin); /* calculate center of the model */ cx = (xMax + xMin) / 2.0f; cy = (yMax + yMin) / 2.0f; cz = (zMax + zMin) / 2.0f; scale = 2.0f / Math.Max (Math.Max (w, h), d); /* translate around center then scale */ for (int i = 0; i < obj.Vertices.Count; i++) { var vertex = new ObjLoader.Loader.Data.VertexData.Vertex ( (obj.Vertices [i].X - cx) * scale, (obj.Vertices [i].Y - cy) * scale, (obj.Vertices [i].Z - cz) * scale); obj.Vertices [i] = vertex; } return scale; }
/// <summary> /// GL draw solid. /// </summary> /// <param name="solid">Solid.</param> /// <param name="GLM_TEXTURE">If set to <c>true</c> GL add texture coordinates.</param> /// <param name="GLM_FLAT">If set to <c>true</c> GL add plane normal.</param> private static void GLDrawSolid( LoadResult solid, PhysicsEngineMathUtility.Vector3 translate, bool GLM_TEXTURE, bool GLM_FLAT, bool GLM_SMOOTH) { int[] indicedata = new int[solid.Groups [0].Faces.Count * 3]; int[] textureData = new int[solid.Groups [0].Faces.Count * 3]; int[] normalData = new int[solid.Groups [0].Faces.Count * 3]; GL.Begin (PrimitiveType.Triangles); for (int i = 0; i < solid.Groups [0].Faces.Count; i++) { int index = i * 3; indicedata [index] = solid.Groups [0].Faces [i] [0].VertexIndex - 1; indicedata [index + 1] = solid.Groups [0].Faces [i] [1].VertexIndex - 1; indicedata [index + 2] = solid.Groups [0].Faces [i] [2].VertexIndex - 1; textureData [index] = solid.Groups [0].Faces [i] [0].TextureIndex - 1; textureData [index + 1] = solid.Groups [0].Faces [i] [1].TextureIndex - 1; textureData [index + 2] = solid.Groups [0].Faces [i] [2].TextureIndex - 1; normalData [index] = solid.Groups [0].Faces [i] [0].NormalIndex - 1; normalData [index + 1] = solid.Groups [0].Faces [i] [1].NormalIndex - 1; normalData [index + 2] = solid.Groups [0].Faces [i] [2].NormalIndex - 1; if (GLM_FLAT) { var a = new PhysicsEngineMathUtility.Vector3 ( solid.Vertices [indicedata [index]].X, solid.Vertices [indicedata [index]].Y, solid.Vertices [indicedata [index]].Z); var b = new PhysicsEngineMathUtility.Vector3 ( solid.Vertices [indicedata [index + 1]].X, solid.Vertices [indicedata [index + 1]].Y, solid.Vertices [indicedata [index + 1]].Z); var c = new PhysicsEngineMathUtility.Vector3 ( solid.Vertices [indicedata [index + 2]].X, solid.Vertices [indicedata [index + 2]].Y, solid.Vertices [indicedata [index + 2]].Z); PhysicsEngineMathUtility.Vector3 normal = PhysicsEngineMathUtility.GeometryUtilities.CalculateNormal (a, b, c); GL.Normal3 (normal.x, normal.y, normal.z); } if (GLM_SMOOTH) GL.Normal3 (solid.Normals[normalData[index]].X, solid.Normals[normalData[index]].Y, solid.Normals[normalData[index]].Z); if (GLM_TEXTURE && solid.Textures.Count > 0) GL.TexCoord2 (solid.Textures [textureData [index]].X, solid.Textures [textureData [index]].Y); GL.Vertex3 (solid.Vertices [indicedata [index]].X - translate.x, solid.Vertices [indicedata [index]].Y - translate.y, solid.Vertices [indicedata [index]].Z - translate.z); if (GLM_SMOOTH) GL.Normal3 (solid.Normals[normalData[index + 1]].X, solid.Normals[normalData[index + 1]].Y, solid.Normals[normalData[index + 1]].Z); if (GLM_TEXTURE && solid.Textures.Count > 0) GL.TexCoord2 (solid.Textures [textureData [index + 1]].X, solid.Textures [textureData [index + 1]].Y); GL.Vertex3 (solid.Vertices [indicedata [index + 1]].X - translate.x, solid.Vertices [indicedata [index + 1]].Y - translate.y, solid.Vertices [indicedata [index + 1]].Z - translate.z); if (GLM_SMOOTH) GL.Normal3 (solid.Normals[normalData[index + 2]].X, solid.Normals[normalData[index + 2]].Y, solid.Normals[normalData[index + 2]].Z); if (GLM_TEXTURE && solid.Textures.Count > 0) GL.TexCoord2 (solid.Textures [textureData [index + 2]].X, solid.Textures [textureData [index + 2]].Y); GL.Vertex3 (solid.Vertices [indicedata [index + 2]].X - translate.x, solid.Vertices [indicedata [index + 2]].Y - translate.y, solid.Vertices [indicedata [index + 2]].Z - translate.z); } GL.End (); }
public static void ScaleObject( ref LoadResult obj, float scale) { for (int i = 0; i < obj.Vertices.Count; i++) { var vertex = new ObjLoader.Loader.Data.VertexData.Vertex ( (obj.Vertices [i].X) * scale, (obj.Vertices [i].Y) * scale, (obj.Vertices [i].Z) * scale); obj.Vertices [i] = vertex; } }
private void Load() { var objectStream = CreateMemoryStreamFromString(ObjectFileString); _loadResult = _loader.Load(objectStream); }
static Catapult() { CatapultBase = ModelsLoader.Load("catapult.obj"); CatapultHand = ModelsLoader.Load("hand.obj"); }
static Flower() { FlowerModel = ModelsLoader.Load("flower.obj"); }
public int[][] GetOpenGLObjectList() { var xmlDoc = new XmlDocument(); xmlDoc.Load(FileNameObjectProperties); XmlNodeList xmlList = xmlDoc.SelectNodes(nodePathObjects); LoadResult[][] loadObjects = new LoadResult[xmlList.Count][]; Vector3[][] translate = new Vector3[xmlList.Count][]; for (int i = 0; i < xmlList.Count; i++) { XmlNodeList xmlGeometryList = xmlList[i].SelectNodes(nodePathGeometry); translate[i] = new Vector3[xmlGeometryList.Count]; loadObjects[i] = new LoadResult[xmlGeometryList.Count]; for (int j = 0; j < xmlGeometryList.Count; j++) { //Object geometry file name string geometryFileName = xmlGeometryList[j][objectGeometryAttribute].InnerText; //Scale float scale = Convert.ToSingle(xmlGeometryList[j][scaleAttribute].InnerText); loadObjects[i][j] = LoadObjSolid(geometryFileName, scale); } } return OpenGLUtilities.LoadGLObjects ( loadObjects, translate, xmlList.Count, true, false, true); }