public override void Initialize(size videosize, long timebase) { base.Initialize(videosize, timebase); using (var lck = this.Display.Renderer.GetDrawLock()) { this.vertices = new vertices <vertex>( new vertex[] { new vertex(new Vector3(0, -1, 0)), new vertex(new Vector3(-1, 1, 0)), new vertex(new Vector3(1, 1, 0)) }); vertices.define("position", "pos"); this.shader = new shader( @"#version 150 core in vec4 position; void main() { gl_Position = position; }", @"#version 150 core precision mediump float; out vec4 outColor; void main() { outColor = vec4(1,0,0,1); } ", this.vertices); } }
public VerticesOfSurface(vertices vert1, vertices vert2, vertices vert3, vertices vert4) { this.vert1 = vert1; this.vert2 = vert2; this.vert3 = vert3; this.vert4 = vert4; }
public static vertices MakeVertices() { vertices verts = new vertices(); verts.id = "vertices"; verts.input = new InputLocal[] { makeInput("positions_source", "POSITION") }; return(verts); }
// 指定した頂点の3つのindexを配列で返す public static int[] GetIndexArrayOf(vertices vert) { var data = indexData[(int)vert]; int[] array = { data.index1, data.index2, data.index3 }; return(array); }
protected override void Dispose(bool disposing) { using (var lck = this.Display.Renderer.GetDrawLock()) { this.shader?.Dispose(); this.shader = null; this.vertices?.Dispose(); this.vertices = null; } base.Dispose(disposing); }
void IDockNotify.OnLoaded(IDockPane pane) { Debug.Assert(this.Renderer == null); this.Renderer = factory.Open(xwtrender, this, this, new FPS(1, 25, true), new size(1920, 1080)); using (var lck = this.Renderer.GetDrawLock()) { /* List<Vector3> simpleVertices = new List<Vector3>(); * simpleVertices.Add(new Vector3(0, 0, 0)); * simpleVertices.Add(new Vector3(100, 0, 0)); * simpleVertices.Add(new Vector3(100, 100, 0));*/ this.vertices = new vertices <vertex>( new vertex[] { new vertex(new Vector3(0, -1, 0)), new vertex(new Vector3(-1, 1, 0)), new vertex(new Vector3(1, 1, 0)) }); this.shader = new shader( @"#version 150 core in vec4 position; void main() { gl_Position = position; }", @"#version 150 core precision mediump float; out vec4 outColor; void main() { outColor = vec4(1,0,0,1); } ", this.vertices); vertices.define("position", "pos"); } this.Renderer.Start(); }
internal void OnLoaded() { this.Renderer = this.RenderFactory.Open(this.XwtRender, this, this, new size(1920, 1080)); using (var lck = this.Renderer.GetDrawLock()) { /* List<Vector3> simpleVertices = new List<Vector3>(); * simpleVertices.Add(new Vector3(0, 0, 0)); * simpleVertices.Add(new Vector3(100, 0, 0)); * simpleVertices.Add(new Vector3(100, 100, 0));*/ this.vertices = new vertices <vertex>( new vertex[] { new vertex(new Vector3(0, -1, 0)), new vertex(new Vector3(-1, 1, 0)), new vertex(new Vector3(1, 1, 0)) }); this.shader = new shader( @"#version 150 core in vec4 position; void main() { gl_Position = position; }", @"#version 150 core precision mediump float; out vec4 outColor; void main() { outColor = vec4(0,1,0,1); } ", this.vertices); vertices.define("position", "pos"); } this.Renderer.Start(); }
static List <CELLMARK> cellmark_List = new List <CELLMARK>(); // для текущей сцены static void Main() { var filesName = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.cellgrup", SearchOption.AllDirectories); System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); List <Model> Models = new List <Model>(); // список мешей на сцене foreach (var file in filesName) { byte[] array1d = File.ReadAllBytes(file); int ci = 0; // счётчик вхождений //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 using (var br = new BinaryReader(File.Open(file, FileMode.Open))) { for (int i = 0; i < array1d.Length; i++) // проходим по всем байтам файла *.cellgrup { if (array1d[i + 0] == 0x69 && array1d[i + 1] == 0x00 && array1d[i + 2] == 0x00 && array1d[i + 3] == 0x00 && // i*** array1d[i + 4] == 0x64 && array1d[i + 5] == 0x65 && array1d[i + 6] == 0x66 && array1d[i + 7] == 0x61 && // defa array1d[i + 8] == 0x75 && array1d[i + 9] == 0x6C && array1d[i + 10] == 0x74 && array1d[i + 11] == 0x00) // ult* { br.BaseStream.Position = i + 12; // отступаем от "вхождения" на i***default* байт int BlockSize = br.ReadInt32(); // размер блока br.ReadInt32(); // пропускаем пустые байты [00 00 00 00] int type = br.ReadInt32(); // "тип" модели if (type == 1819045731) { ci++; // coll[modc] } if (type == 1634493549) { ci++; // mdla[ttr*] } if (type == 6581618) // только для rmd*[****] { br.BaseStream.Position = i + 4; // "возвращаемся", чтобы скопировать модель Model mesh = new Model(); // создаём модель mesh.BaseStreamPosition = br.BaseStream.Position; mesh.type = type; mesh.index = ci++; // присваиваем и увеличиваем индекс mesh.content = br.ReadBytes(BlockSize).ToList(); Models.Add(mesh); // добавляем её в список моделей на "сцене" } i = i + BlockSize; // ускоряем поиск? } // 63 65 6C 6C 69 6E 73 74 (места моделей) if (array1d[i + 0] == 0x63 && array1d[i + 1] == 0x65 && array1d[i + 2] == 0x6C && array1d[i + 3] == 0x6C && // cell array1d[i + 4] == 0x69 && array1d[i + 5] == 0x6E && array1d[i + 6] == 0x73 && array1d[i + 7] == 0x74) // inst { br.BaseStream.Position = i + 16; int count = br.ReadInt32(); // кол-во координат для расстановки моделей for (int j = 0; j < count; j++) { CELLINST cellinst = new CELLINST(br); cellinst_List.Add(cellinst); } } // 63 65 6C 6C 6D 61 72 6B cellmark if (array1d[i + 0] == 0x63 && array1d[i + 1] == 0x65 && array1d[i + 2] == 0x6C && array1d[i + 3] == 0x6C && // cell array1d[i + 4] == 0x6D && array1d[i + 5] == 0x61 && array1d[i + 6] == 0x72 && array1d[i + 7] == 0x6B) // mark { br.BaseStream.Position = i + 16; int count = br.ReadInt32(); // кол-во координат для расстановки моделей for (int j = 0; j < count; j++) { CELLMARK cellmark = new CELLMARK(br); cellmark_List.Add(cellmark); } } } //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 foreach (var mesh in Models) { for (int ji = 0; ji < mesh.content.Count; ji++) { // ИЩЕМ ВЕРШИНЫ // v // если нашли строку "position" = 00 00 00 00 70 6F 73 69 74 69 6F 6E if (mesh.content[ji + 0] == 0x70 && mesh.content[ji + 1] == 0x6F && mesh.content[ji + 2] == 0x73 && mesh.content[ji + 3] == 0x69 && // 70 6F 73 69 mesh.content[ji + 4] == 0x74 && mesh.content[ji + 5] == 0x69 && mesh.content[ji + 6] == 0x6F && mesh.content[ji + 7] == 0x6E) // 74 69 6F 6E { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; // +20, если отступаем OOOO_position int count = br.ReadInt32(); for (int j = 0; j < count; j++) { mesh.positionList.Add(new Vector3(br)); } } ///////////// ИЩЕМ Vn (нормали) if (mesh.content[ji + 0] == 0x6E && mesh.content[ji + 1] == 0x6F && mesh.content[ji + 2] == 0x72 && mesh.content[ji + 3] == 0x6D && // 6E 6F 72 6D mesh.content[ji + 4] == 0x61 && mesh.content[ji + 5] == 0x6C && mesh.content[ji + 6] == 0x73 && mesh.content[ji + 7] == 0x00) // 61 6C 73 00 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int count = br.ReadInt32(); for (int j = 0; j < count; j++) { mesh.normalsList.Add(new Vector3(br)); } } ///////////// ИЩЕМ ГРАНИ FACES // 70 72 69 6D // 73 ( 00 00 00 ) if (mesh.content[ji + 0] == 0x70 && mesh.content[ji + 1] == 0x72 && mesh.content[ji + 2] == 0x69 && mesh.content[ji + 3] == 0x6D) // 70 72 69 6D 73 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int primsCount = br.ReadInt32(); for (int j = 0; j < primsCount; j++) { int faceNumber = br.ReadInt32(); int faceCount = br.ReadInt32(); int faceSize = br.ReadInt32(); List <TRI> face = new List <TRI>(); for (int f = 0; f < faceCount; f++) { face.Add(new TRI(br, faceNumber)); } mesh.subMeshFaces.Add(face); for (int jj = 0; jj < 10; jj++) { br.ReadInt32(); // непонятные данные, мб для наложения текстур } if ((faceCount % 2) != 0) { br.ReadUInt16(); // для "выравнивания" читается FF FF } } } ///////////// ИЩЕМ uvs index , индексы текстурных координат // строку "textures" = // (00 00 FF FF) 74 65 78 74 75 72 65 73 // if ( mesh.content[ji+0] == 0x00 && mesh.content[ji+1] == 0x00 && mesh.content[ji+2] == 0x00 && mesh.content[ji+3] == 0x00 && // это необходимо ? if (mesh.content[ji + 0] == 0x74 && mesh.content[ji + 1] == 0x65 && mesh.content[ji + 2] == 0x78 && mesh.content[ji + 3] == 0x74 && // если да mesh.content[ji + 4] == 0x75 && mesh.content[ji + 5] == 0x72 && mesh.content[ji + 6] == 0x65 && mesh.content[ji + 7] == 0x73) // то изменить индексы { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; // или +20 в big файле int count = br.ReadInt32(); for (int j = 0; j < count; j++) { mesh.texturesList.Add(br.ReadUInt16()); } } ///////////// ТЕКСТУРНЫЕ КООРДИНАТЫ // vt // uvs. // 75 76 73 00 00 00 00 00 // может попастся два набора, поэтому пока что сохраняем смещение, а затем читаем что надо if (mesh.content[ji + 0] == 0x75 && mesh.content[ji + 1] == 0x76 && mesh.content[ji + 2] == 0x73 && mesh.content[ji + 3] == 0x00) // 75 76 73 00 { uvs_offset_int_list.Add(ji); } /////////////// /* * // mdlattr* * * if ( mesh.content[ji+0] == 0x6D && mesh.content[ji+1] == 0x64 && mesh.content[ji+2] == 0x6C && mesh.content[ji+3] == 0x61 && * mesh.content[ji+4] == 0x74 && mesh.content[ji+5] == 0x74 && mesh.content[ji+6] == 0x72 && mesh.content[ji+7] == 0x00) * { * br.BaseStream.Position = mesh.BaseStreamPosition + ji + 8; * int BlockSize = br.ReadInt32(); br.ReadInt32(); // 00 00 00 00 * * br.ReadInt32(); // 00 00 00 00 * br.ReadInt32(); // 00 00 00 00 * * int defaultBlockSize = br.ReadInt32(); * * br.ReadInt32(); * br.ReadInt32(); * } */ ///////////// mtlctrl* // 6D 74 6C 63 74 72 6C 00 if (mesh.content[ji + 0] == 0x6D && mesh.content[ji + 1] == 0x74 && mesh.content[ji + 2] == 0x6C && mesh.content[ji + 3] == 0x63 && // 6D 74 6C 63 mesh.content[ji + 4] == 0x74 && mesh.content[ji + 5] == 0x72 && mesh.content[ji + 6] == 0x6C && mesh.content[ji + 7] == 0x00) // 74 72 6C 00 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int count = br.ReadInt32(); for (int j = 0; j < count; j++) { Mtlctrl mtlctrl = new Mtlctrl(br); mesh.mtlctrlList.Add(mtlctrl); } } ///////////// mlyrcolr ??? привильно ли я добавляю в список? по "сомнению" надо выделить три "строки" в один объект if (mesh.content[ji + 0] == 0x6D && mesh.content[ji + 1] == 0x6C && mesh.content[ji + 2] == 0x79 && mesh.content[ji + 3] == 0x72 && // 6D 6C 79 72 mesh.content[ji + 4] == 0x63 && mesh.content[ji + 5] == 0x6F && mesh.content[ji + 6] == 0x6C && mesh.content[ji + 7] == 0x72) // 63 6F 6C 72 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 20; int count = br.ReadInt32(); for (int j = 0; j < count; j++) { for (int jj = 0; jj < 3; jj++) { Mlyrcolr mlyrcolr = new Mlyrcolr(br); mesh.mlyrcolrList.Add(mlyrcolr); } } } ///////////// mlyrctrl +++ if (mesh.content[ji + 0] == 0x6D && mesh.content[ji + 1] == 0x6C && mesh.content[ji + 2] == 0x79 && mesh.content[ji + 3] == 0x72 && // 6D 6C 79 72 mesh.content[ji + 4] == 0x63 && mesh.content[ji + 5] == 0x74 && mesh.content[ji + 6] == 0x72 && mesh.content[ji + 7] == 0x6C) // 63 74 72 6C { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int flag = br.ReadInt32(); // 0 или 1 int count = br.ReadInt32(); for (int j = 0; j < count; j++) { Mlyrctrl m = new Mlyrctrl(br); mesh.mlyrctrlList.Add(m); } } ///////////// texture* +++ if (mesh.content[ji + 0] == 0x74 && mesh.content[ji + 1] == 0x65 && mesh.content[ji + 2] == 0x78 && mesh.content[ji + 3] == 0x74 && // 74 65 78 74 mesh.content[ji + 4] == 0x75 && mesh.content[ji + 5] == 0x72 && mesh.content[ji + 6] == 0x65 && mesh.content[ji + 7] == 0x00) // 75 72 65 00 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 20; // br.BaseStream.Position = mesh.BaseStreamPosition + ji + 20; int count = br.ReadInt32(); for (int j = 0; j < count; j++) { Texture thz = new Texture(br); mesh.texture_List.Add(thz); } } ///////////// vtxweigh +++ if (mesh.content[ji + 0] == 0x76 && mesh.content[ji + 1] == 0x74 && mesh.content[ji + 2] == 0x78 && mesh.content[ji + 3] == 0x77 && // 76 74 78 77 mesh.content[ji + 4] == 0x65 && mesh.content[ji + 5] == 0x69 && mesh.content[ji + 6] == 0x67 && mesh.content[ji + 7] == 0x68) // 65 69 67 68 { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int count = br.ReadInt32(); for (int ii = 0; ii < count; ii++) { mesh.vtxweighList.Add(br.ReadSingle()); } } ///////////// jointidx +++ if (mesh.content[ji + 0] == 0x6A && mesh.content[ji + 1] == 0x6F && mesh.content[ji + 2] == 0x69 && mesh.content[ji + 3] == 0x6E && // 6A 6F 69 6E // join mesh.content[ji + 4] == 0x74 && mesh.content[ji + 5] == 0x69 && mesh.content[ji + 6] == 0x64 && mesh.content[ji + 7] == 0x78) // 74 69 64 78 // tidx { br.BaseStream.Position = mesh.BaseStreamPosition + ji + 16; int count = br.ReadInt32(); for (int j = 0; j < count; j++) { mesh.jointidxList.Add(br.ReadUInt16()); } int ffff = 0; if (count % 2 != 0) { ffff = br.ReadUInt16(); } } ///////////// collmodc } // для массива внутри модели //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 if (uvs_offset_int_list.Count > 0) { br.BaseStream.Position = mesh.BaseStreamPosition + uvs_offset_int_list[0] + 8; int BlockSizeU0 = br.ReadInt32(); br.ReadInt32(); int number0 = br.ReadInt32(); // 00 00 00 00 int uvsCount = br.ReadInt32(); for (int uvc = 0; uvc < uvsCount; uvc++) { mesh.uvs0.Add(new Vector2(br)); } mesh.uvsList.Add(mesh.uvs0); } if (uvs_offset_int_list.Count > 1) { br.BaseStream.Position = mesh.BaseStreamPosition + uvs_offset_int_list[1] + 8; int BlockSizeU1 = br.ReadInt32(); br.ReadInt32(); int number1 = br.ReadInt32(); // 01 00 00 00 int uvsCount = br.ReadInt32(); for (int uvc = 0; uvc < uvsCount; uvc++) { mesh.uvs1.Add(new Vector2(br)); } mesh.uvsList.Add(mesh.uvs1); } uvs_offset_int_list.Clear(); // обязательно очищаем для другой модели } // для каждой модели } // binary reader //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 string name = file.Replace(".cellgrup", ""); library_geometries lgeom = new library_geometries() // создаём библиотеку мешей { geometry = new geometry[Models.Count] // в библиотеке геометрии Models.Count мешей }; ///////////////////////////////////////////////////////////////////////////////////////////////// int qqq = 0; // шагаем по списку геометрий в файле foreach (var mesh in Models) // для каждой модели { //----------------------------------------------------------------------------------------------- //{ создаём массив координат для вершин модели float_array xyz_N_array = new float_array() // массив для координат { count = (ulong)mesh.positionList.Count * 3, id = "mesh_" + mesh.index + "_positions_array" }; float_coords = new List <double>(); foreach (var fl in mesh.positionList) { float_coords.Add(fl.x); float_coords.Add(fl.y); float_coords.Add(fl.z); } xyz_N_array.Values = float_coords.ToArray(); //---------------------------------- source pos_source = new source() // источник для координат { Item = xyz_N_array, id = "mesh_" + mesh.index + "_positions", technique_common = new sourceTechnique_common() { accessor = new accessor() { count = (ulong)mesh.positionList.Count, offset = 0L, source = "#" + xyz_N_array.id, stride = 3L, param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } } }; //} //----------------------------------------------------------------------------------------------- /* * //{ создаём массив координат для нормалей модели * * float_array xyz_Normals = new float_array() * { * count = (ulong)mesh.normalsList.Count * 3; * id = "mesh_" + mesh.index + "_normals_array"; * } * * float_coords = new List<double>(); * * foreach(var fl in mesh.positionList) * { * float_coords.Add(fl.x); * float_coords.Add(fl.y); * float_coords.Add(fl.z); * } * * xyz_Normals.Values = float_coords.ToArray(); * * //---------------------------------- * * source norm_source = new source() * { * Item = xyz_N_array, * id = "mesh_" + mesh.index + "_positions", * * technique_common = new sourceTechnique_common() * { * accessor = new accessor() * { * count = (ulong)mesh.positionList.Count, * offset = 0L, * source = "#" + xyz_N_array.id, * stride = 3L, * * param = new param[] * { * new param() { name = "X", type = "float" }, * new param() { name = "Y", type = "float" }, * new param() { name = "Z", type = "float" } * } * } * } * }; * //} */ //----------------------------------------------------------------------------------------------- vertices v = new vertices() // вершины = часть объекта mesh { id = "mesh_" + mesh.index + "_vertices", input = new InputLocal[] { new InputLocal() // пока что только коорднаты { semantic = "POSITION", source = "#" + pos_source.id } } }; //----------------------------------------------------------------------------------------------- int faceNumber = 0; foreach (var q in mesh.subMeshFaces) { foreach (var qq in q) { faceNumber++; } } triangles tres = new triangles() // треугольники = часть объекта mesh { count = (ulong)faceNumber, input = new InputLocalOffset[] { new InputLocalOffset() // пока что только для координат { semantic = "VERTEX", offset = 0L, source = "#" + v.id } } }; //---------------------------------- StringBuilder all_TRI = new StringBuilder(); foreach (var q in mesh.subMeshFaces) { foreach (var qq in q) { string str = qq.vi0 + " " + qq.vi1 + " " + qq.vi2 + " "; all_TRI.Append(str); } } tres.p = all_TRI.ToString(); //----------------------------------------------------------------------------------------------- mesh m = new mesh() // создаём объект меша { vertices = v, source = new source[1] // пока что только 1 источник для position { pos_source }, Items = new object[1] // для треугольников { tres } }; //----------------------------------------------------------------------------------------------- geometry geom = new geometry() // создаём оболочку для меши { id = "mesh_" + mesh.index, // задаём ей имя mesh_№ Item = m }; lgeom.geometry[qqq++] = geom; } // для каждой модели в файле cellgrup создаём блоки с геометрией //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 library_visual_scenes lvs = new library_visual_scenes(); // создаём библиотеку сцен visual_scene vs = new visual_scene() // создаём сцену, вроде всегда одна { id = "MyScene", // обзываем её node = new node[Models.Count] // добавляем узлы для моделей на сцене }; //=============================================================================================== qqq = 0; // шагаем по списку мешей, создаём им ноды, задаём расположение foreach (var mesh in Models) { //---------------------------------- node n = new node() { id = "mesh" + mesh.index, instance_geometry = new instance_geometry[] { new instance_geometry() { url = "#" + lgeom.geometry[qqq].id } } }; //---------------------------------- n.ItemsElementName = new ItemsChoiceType2[5] { ItemsChoiceType2.translate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate, ItemsChoiceType2.rotate, ItemsChoiceType2.scale }; //---------------------------------- float xx = 0.0f; float yy = 0.0f; float zz = 0.0f; float rx = 0.0f; float ry = 0.0f; float rz = 0.0f; for (int ccc = 0; ccc < cellinst_List.Count; ccc++) { if (mesh.index == cellinst_List[ccc].number) { xx = cellinst_List[ccc].position.x; yy = cellinst_List[ccc].position.y; zz = cellinst_List[ccc].position.z; rx = cellinst_List[ccc].rotation.x; ry = cellinst_List[ccc].rotation.y; rz = cellinst_List[ccc].rotation.z; } } for (int ccc = 0; ccc < cellmark_List.Count; ccc++) { if (mesh.index == cellmark_List[ccc].number1) { xx = cellmark_List[ccc].position.x; yy = cellmark_List[ccc].position.y; zz = cellmark_List[ccc].position.z; rx = cellmark_List[ccc].rotation.x; ry = cellmark_List[ccc].rotation.y; rz = cellmark_List[ccc].rotation.z; } } //---------------------------------- n.Items = new object[5] { new TargetableFloat3() { sid = "location", // translate Values = new double[3] { xx, yy, zz } }, new rotate() { sid = "rotationX", Values = new double[4] { 0, 0, 1, rz *57.5 } }, // Z new rotate() { sid = "rotationY", Values = new double[4] { 0, 1, 0, ry *57.5 } }, // Y почему такой "угол" ? new rotate() { sid = "rotationZ", Values = new double[4] { 1, 0, 0, rx *57.5 } }, // X new TargetableFloat3() { sid = "scale", Values = new double[3] { 1, 1, 1 } } }; //---------------------------------- vs.node[qqq] = n; qqq++; } // для каждой модели в файле cellgrup //----------------------------------------------------------------------------------------------- lvs.visual_scene = new visual_scene[1] // создаём массив для сцен { vs // добавляем visual_scene в library_visual_scenes }; //----------------------------------------------------------------------------------------------- COLLADA collada = new COLLADA() { asset = new asset() { up_axis = UpAxisType.Z_UP }, Items = new object[] // для библиотеки мешей и сцен { lgeom, // присваиваем колладе библиотеку геометрию lvs // в массив Item добавляем библиотеку сцен }, scene = new COLLADAScene() { instance_visual_scene = new InstanceWithExtra() { url = "#" + vs.id } } }; //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 collada.Save(name + ".dae"); Models.Clear(); cellinst_List.Clear(); cellmark_List.Clear(); //88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 } // для каждого cellgrup файла } // void Main()
=> Create(mesh, triangles, vertices, Vertex.Descriptors(Allocator.Temp));
public void OnLoaded(bool renderlocked) { try { if (!renderlocked) { #if (!TRIANGLE) try { if (BaseLib.Xwt.Platform.OSPlatform == PlatformID.MacOSX) { this.MoviePlayer = new Player(this.owner, @"/Volumes/Projects/movies/Yamaha_final.avi", this.impl.Timebase); } else if (BaseLib.Xwt.Platform.OSPlatform == PlatformID.Unix) { this.MoviePlayer = new Player(this.owner, @"/home/bert/Projects/movies/Yamaha_final.avi", this.impl.Timebase); } else { this.MoviePlayer = new Player(this.owner, @"e:\movies\Yamaha_final.avi", this.impl.Timebase); } } catch { } #endif } else { #if TRIANGLE List <Vector3> simpleVertices = new List <Vector3>(); simpleVertices.Add(new Vector3(0, 0, 0)); simpleVertices.Add(new Vector3(100, 0, 0)); simpleVertices.Add(new Vector3(100, 100, 0)); this.vertices = new vertices <vertex>(new vertex[] { new vertex(0, -1), new vertex(-1, 1), new vertex(1, 1) }); vertices.define("position", "pos"); this.shader = new shader( @"#version 150 core in vec4 position; void main() { gl_Position = position; }", @"#version 150 core precision mediump float; out vec4 outColor; void main() { outColor = vec4(1,0,0,1); } ", this.vertices); #else this.vertices = new vertices <vertex_tex>( new vertex_tex[] { new vertex_tex(-1, -1, 0, 0), new vertex_tex(1, -1, 1, 0), new vertex_tex(-1, 1, 0, 1), new vertex_tex(1, -1, 1, 0), new vertex_tex(-1, 1, 0, 1), new vertex_tex(1, 1, 1, 1) }); this.shader = new shader( @"#version 150 core in vec3 position; in vec2 texcoord0; out vec2 Texcoord0; void main() { gl_Position = vec4(position,1);//*vec4(1,-1,1,1); Texcoord0 = texcoord0; }", @"#version 150 core precision mediump float; in vec2 Texcoord0; uniform sampler2D texure0; out vec4 outColor; void main() { outColor = texture(texure0, Texcoord0); } ", this.vertices); vertices.define("position", "pos"); vertices.define("texcoord0", "tex0"); GL.UseProgram(this.shader); var pos = GL.GetUniformLocation(this.shader, "texture0"); if (pos != -1) { GL.Uniform1(pos, 0); } #endif } } catch (Exception e) { } }
internal void OnLoaded() { try { this.Renderer = this.RenderFactory.Open(this.XwtRender, this, this, new FPS(1, 25, true), new size(1920, 1080)); this.Audio = new AudioOut(48000, AudioFormat.Float32, ChannelsLayout.Stereo, 2); this.Mixer = new Mixer(this.Audio.SampleRate, this.Audio.Format, this.Audio.ChannelLayout); try { if (BaseLib.Xwt.Platform.OSPlatform == PlatformID.MacOSX) { this.MoviePlayer = new Player(this.owner, @"/Volumes/Projects/movies/Yamaha_final.avi", TimeBase); } else if (BaseLib.Xwt.Platform.OSPlatform == PlatformID.Unix) { this.MoviePlayer = new Player(this.owner, @"/home/bert/Projects/movies/Yamaha_final.avi", TimeBase); } else { this.MoviePlayer = new Player(this.owner, @"e:\movies\Yamaha_final.avi", TimeBase); } } catch { } using (var lck = this.Renderer.GetDrawLock()) { /* List<Vector3> simpleVertices = new List<Vector3>(); * simpleVertices.Add(new Vector3(0, 0, 0)); * simpleVertices.Add(new Vector3(100, 0, 0)); * simpleVertices.Add(new Vector3(100, 100, 0));*/ this.vertices = new vertices <vertex>( new vertex[] { new vertex(new Vector3(0, -1, 0)), new vertex(new Vector3(-1, 1, 0)), new vertex(new Vector3(1, 1, 0)) }); vertices.define("position", "pos"); this.shader = new shader( @"#version 150 core in vec4 position; void main() { gl_Position = position; }", @"#version 150 core precision mediump float; out vec4 outColor; void main() { outColor = vec4(1,0,0,1); } ", this.vertices); this.verticestex = new vertices <vertex_tex>( new vertex_tex[] { new vertex_tex(new Vector3(-1, -1, 0), new Vector2(0, 0)), new vertex_tex(new Vector3(1, -1, 0), new Vector2(1, 0)), new vertex_tex(new Vector3(-1, 1, 0), new Vector2(0, 1)), new vertex_tex(new Vector3(1, -1, 0), new Vector2(1, 0)), new vertex_tex(new Vector3(-1, 1, 0), new Vector2(0, 1)), new vertex_tex(new Vector3(1, 1, 0), new Vector2(1, 1)), }); this.shadertex = new shader( @"#version 150 core in vec4 position; in vec2 texcoord0; out vec2 Texcoord0; void main() { gl_Position = position*vec4(1,-1,1,1); Texcoord0 = texcoord0; }", @"#version 150 core precision mediump float; in vec2 Texcoord0; uniform sampler2D texure0; out vec4 outColor; void main() { outColor = texture(texure0, Texcoord0); } ", this.verticestex); verticestex.define("position", "pos"); verticestex.define("texcoord0", "tex0"); GL.UseProgram(this.shadertex); var pos = GL.GetUniformLocation(this.shadertex, "texture0"); GL.Uniform1(pos, 0); } //this.Display.WaitBuffered(); // this.Audio?.Buffered.WaitOne(-1, false); this.audiostop.Reset(); this.audiothread = new Thread(() => { while (!audiostop.WaitOne(0, false)) { try { var data = this.Mixer.Read(0, 48000 / 25); Audio.Write(data, data.Length / 8); } catch { } } }); this.audiothread.Start(); this.Audio.Buffered.WaitOne(-1, false); this.Audio?.Start(); this.Renderer.Start(); //this.movie.p } catch (Exception e) { throw; } }
FastCreateQuad(vertices, o, b, c, d, r, samplers, paletteTextureIndex, tint, alpha, nv);
public static void ExportIOModelAsDAE(string FileName, IOModel m) { COLLADA colladaFile = new COLLADA(); List <geometry> list_geometries = new List <geometry>(m.Meshes.Count); if (m.HasMeshes) { foreach (IOMesh iomesh in m.Meshes) { geometry g = new geometry(); g.name = iomesh.Name; g.id = iomesh.Name + $"_{m.Meshes.IndexOf(iomesh)}"; List <double> list_positions = new List <double>(); List <double> list_normals = new List <double>(); List <double> list_uvs = new List <double>(); List <double> list_colors = new List <double>(); foreach (IOVertex v in iomesh.Vertices) { list_positions.Add(v.Position.X); list_positions.Add(v.Position.Y); list_positions.Add(v.Position.Z); list_normals.Add(v.Normal.X); list_normals.Add(v.Normal.Y); list_normals.Add(v.Normal.Z); list_uvs.Add(v.UV0.X); list_uvs.Add(v.UV0.Y); } // Position source source_position = new source(); { float_array floats = new float_array(); floats.count = (ulong)list_positions.Count; floats.id = g.id + "_pos_arr"; floats.Values = list_positions.ToArray(); source_position = CreateSource(list_positions.Count, 3, floats.id, floats, new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }); } // Normal source source_normal = new source(); { float_array floats = new float_array(); floats.count = (ulong)list_normals.Count; floats.id = g.id + "_nrm_arr"; floats.Values = list_normals.ToArray(); source_normal = CreateSource(list_normals.Count, 3, floats.id, floats, new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } }); } // UV0 source source_uv0 = new source(); { float_array floats = new float_array(); floats.count = (ulong)list_uvs.Count; floats.id = g.id + "_uv0_arr"; floats.Values = list_uvs.ToArray(); source_uv0 = CreateSource(list_uvs.Count, 2, floats.id, floats, new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } }); } // vertices vertices vertices = new vertices(); vertices.id = g.id + "_verts"; vertices.input = new InputLocal[] { new InputLocal() { source = "#" + source_position.id, semantic = "POSITION" }, new InputLocal() { source = "#" + source_normal.id, semantic = "NORMAL" }, new InputLocal() { source = "#" + source_uv0.id, semantic = "TEXCOORD" } }; // triangles triangles triangles = new triangles(); triangles.count = (ulong)iomesh.Indices.Count; triangles.input = new InputLocalOffset[] { new InputLocalOffset() { offset = 0, semantic = "VERTEX", source = "#" + vertices.id } }; triangles.p = string.Join(" ", iomesh.Indices); // creating mesh mesh geomesh = new mesh(); geomesh.source = new source[] { source_position, source_normal, source_uv0 }; geomesh.Items = new object[] { triangles }; geomesh.vertices = vertices; g.Item = geomesh; list_geometries.Add(g); } } library_geometries lib_geometry = new library_geometries(); lib_geometry.geometry = list_geometries.ToArray(); // controllers List <controller> list_controller = new List <controller>(); if (m.HasMeshes && m.HasSkeleton) { // create lists List <source> skinSources = new List <source>(); List <string> boneNames = new List <string>(); List <double> InverseBinds = new List <double>(); foreach (RBone b in m.Skeleton.Bones) { boneNames.Add(b.Name); InverseBinds.AddRange(new double[] { b.InvWorldTransform.M11, b.InvWorldTransform.M21, b.InvWorldTransform.M31, b.InvWorldTransform.M41, b.InvWorldTransform.M12, b.InvWorldTransform.M22, b.InvWorldTransform.M32, b.InvWorldTransform.M42, b.InvWorldTransform.M13, b.InvWorldTransform.M23, b.InvWorldTransform.M33, b.InvWorldTransform.M43, b.InvWorldTransform.M14, b.InvWorldTransform.M24, b.InvWorldTransform.M34, b.InvWorldTransform.M44, }); } // setup controllers foreach (IOMesh iomesh in m.Meshes) { controller controller = new controller() { id = iomesh.Name + "_" + m.Meshes.IndexOf(iomesh) + "_controller" }; list_controller.Add(controller); // create source for weights List <double> weights = new List <double>(); List <int> bones = new List <int>(); List <int> boneCount = new List <int>(); StringBuilder build_v = new StringBuilder(); foreach (IOVertex v in iomesh.Vertices) { int bcount = 0; if (v.BoneWeights.X > 0) { if (!weights.Contains(v.BoneWeights.X)) { weights.Add(v.BoneWeights.X); } build_v.Append($"{(int)v.BoneIndices.X} {weights.IndexOf(v.BoneWeights.X)} "); bcount++; } if (v.BoneWeights.Y > 0) { if (!weights.Contains(v.BoneWeights.Y)) { weights.Add(v.BoneWeights.Y); } build_v.Append($"{(int)v.BoneIndices.Y} {weights.IndexOf(v.BoneWeights.Y)} "); bcount++; } if (v.BoneWeights.Z > 0) { if (!weights.Contains(v.BoneWeights.Z)) { weights.Add(v.BoneWeights.Z); } build_v.Append($"{(int)v.BoneIndices.Z} {weights.IndexOf(v.BoneWeights.Z)} "); bcount++; } if (v.BoneWeights.W > 0) { if (!weights.Contains(v.BoneWeights.W)) { weights.Add(v.BoneWeights.W); } build_v.Append($"{(int)v.BoneIndices.W} {weights.IndexOf(v.BoneWeights.W)} "); bcount++; } boneCount.Add(bcount); } // skin Name_array arr_name = new Name_array(); arr_name.count = (ulong)boneNames.Count; arr_name.id = controller.id + "joints"; arr_name.Values = boneNames.ToArray(); source source_skin = CreateSource(boneNames.Count, 1, arr_name.id, arr_name, new param[] { new param() { name = "JOINT", type = "name" } }); // bind float_array arr_bind = new float_array(); arr_bind.count = (ulong)InverseBinds.Count; arr_bind.id = controller.id + "binds"; arr_bind.Values = InverseBinds.ToArray(); source source_binds = CreateSource(InverseBinds.Count, 16, arr_bind.id, arr_bind, new param[] { new param() { name = "TRANSFORM", type = "float4x4" } }); // weight source source_weight = new source(); { float_array floats = new float_array(); floats.count = (ulong)weights.Count; floats.id = controller.id + "_weights"; floats.Values = weights.ToArray(); source_weight = CreateSource(weights.Count, 1, floats.id, floats, new param[] { new param() { name = "WEIGHT", type = "float" }, }); } skin skin = new skin(); skin.source1 = "#" + iomesh.Name + $"_{m.Meshes.IndexOf(iomesh)}"; skin.source = new source[] { source_skin, source_binds, source_weight }; skin.joints = new skinJoints() { input = new InputLocal[] { new InputLocal() { semantic = "JOINT", source = "#" + source_skin.id }, new InputLocal() { semantic = "INV_BIND_MATRIX", source = "#" + source_binds.id } } }; //skin weights skin.vertex_weights = new skinVertex_weights(); skin.vertex_weights.count = (ulong)iomesh.Vertices.Count; skin.vertex_weights.input = new InputLocalOffset[] { new InputLocalOffset() { semantic = "JOINT", source = "#" + source_skin.id, offset = 0 }, new InputLocalOffset() { semantic = "WEIGHT", source = "#" + source_weight.id, offset = 1 } }; skin.vertex_weights.vcount = string.Join(" ", boneCount); skin.vertex_weights.v = build_v.ToString(); controller.Item = skin; } } library_controllers lib_controllers = new library_controllers(); lib_controllers.controller = list_controller.ToArray(); // scene nodes List <node> scene_nodes = new List <node>(); int visual_index = 0; if (m.HasSkeleton) { Dictionary <RBone, node> boneToNode = new Dictionary <RBone, node>(); foreach (RBone b in m.Skeleton.Bones) { // create bone node node node = new node(); node.name = b.Name; node.id = "bone" + visual_index++; node.sid = b.Name; node.type = NodeType.JOINT; // add transform matrix mat = new matrix() { Values = new double[] { b.Transform.M11, b.Transform.M21, b.Transform.M31, b.Transform.M41, b.Transform.M12, b.Transform.M22, b.Transform.M32, b.Transform.M42, b.Transform.M13, b.Transform.M23, b.Transform.M33, b.Transform.M43, b.Transform.M14, b.Transform.M24, b.Transform.M34, b.Transform.M44, } }; node.ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.matrix }; node.Items = new object[] { mat }; // deal with parenting boneToNode.Add(b, node); if (b.ParentID == -1) { scene_nodes.Add(node); } else { if (boneToNode[m.Skeleton.Bones[b.ParentID]].node1 == null) { boneToNode[m.Skeleton.Bones[b.ParentID]].node1 = new node[0]; } node[] parentnode = boneToNode[m.Skeleton.Bones[b.ParentID]].node1; Array.Resize <node>(ref parentnode, parentnode.Length + 1); parentnode[parentnode.Length - 1] = node; boneToNode[m.Skeleton.Bones[b.ParentID]].node1 = parentnode; } } } if (m.HasMeshes) { foreach (IOMesh iomesh in m.Meshes) { node node = new node() { id = "mesh" + visual_index++, name = iomesh.Name, type = NodeType.NODE }; if (m.HasSkeleton) { instance_controller controller = new instance_controller() { url = iomesh.Name + "_" + m.Meshes.IndexOf(iomesh) + "_controller" }; controller.skeleton = new string[] { "#bone0" }; node.instance_controller = new instance_controller[] { controller }; } scene_nodes.Add(node); } } // visual scene root library_visual_scenes scenes = new library_visual_scenes(); scenes.visual_scene = new visual_scene[] { new visual_scene() { id = "visualscene0", name = "rdmscene" } }; scenes.visual_scene[0].node = scene_nodes.ToArray(); // scene COLLADAScene scene = new COLLADAScene(); scene.instance_visual_scene = new InstanceWithExtra() { url = "#visualscene0" }; // putting it all together colladaFile.Items = new object[] { lib_geometry, lib_controllers, scenes }; colladaFile.scene = scene; colladaFile.Save(FileName); }
LoadPlain(action, static (action, vertices, indices) => action(vertices, indices));
CreateFaces(vertices, indices);
public static IndexOfVertex GetIndexOf(vertices vert) { return(indexData[(int)vert]); }