private static Vector3 getBounds(Entity e, out Vector3 center) { ModelComponent mc = e.Get <ModelComponent>(); center = new Vector3(); if (mc == null || mc.Model == null || mc.Model.Meshes.Count <= 0f) { return(Vector3.Zero); } Vector3 biggest = new Vector3(0.05f, 0.05f, 0.05f); int count = mc.Model.Meshes.Count; for (int i = 0; i < count; i++) { Xenko.Rendering.Mesh m = mc.Model.Meshes[i]; BoundingBox bb = m.BoundingBox; Vector3 extent = bb.Extent; if (extent.X > biggest.X) { biggest.X = extent.X; } if (extent.Y > biggest.Y) { biggest.Y = extent.Y; } if (extent.Z > biggest.Z) { biggest.Z = extent.Z; } center += bb.Center; } center /= count; return(biggest * e.Transform.WorldScale()); }
private static unsafe bool getMeshOutputs(Xenko.Rendering.Mesh modelMesh, out List <Vector3> positions, out List <int> indicies) { if (modelMesh.Draw is StagedMeshDraw) { StagedMeshDraw smd = modelMesh.Draw as StagedMeshDraw; object verts = smd.Verticies; if (verts is VertexPositionNormalColor[]) { VertexPositionNormalColor[] vpnc = verts as VertexPositionNormalColor[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions.Add(vpnc[k].Position); } } else if (verts is VertexPositionNormalTexture[]) { VertexPositionNormalTexture[] vpnc = verts as VertexPositionNormalTexture[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions.Add(vpnc[k].Position); } } else if (verts is VertexPositionNormalTextureTangent[]) { VertexPositionNormalTextureTangent[] vpnc = verts as VertexPositionNormalTextureTangent[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions.Add(vpnc[k].Position); } } else { throw new ArgumentException("Couldn't get StageMeshDraw mesh, unknown vert type for " + modelMesh.Name); } // take care of indicies indicies = new List <int>(smd.Indicies.Length); for (int i = 0; i < smd.Indicies.Length; i++) { indicies.Add((int)smd.Indicies[i]); } } else { Xenko.Graphics.Buffer buf = modelMesh.Draw?.VertexBuffers[0].Buffer; Xenko.Graphics.Buffer ibuf = modelMesh.Draw?.IndexBuffer.Buffer; if (buf == null || buf.VertIndexData == null || ibuf == null || ibuf.VertIndexData == null) { throw new ArgumentException("Couldn't get mesh for " + modelMesh.Name + ", buffer wasn't stored probably. Try Xenko.Graphics.Buffer.CaptureAllModelBuffers to true."); } if (ModelBatcher.UnpackRawVertData(buf.VertIndexData, modelMesh.Draw.VertexBuffers[0].Declaration, out Vector3[] arraypositions, out Core.Mathematics.Vector3[] normals, out Core.Mathematics.Vector2[] uvs,
private static unsafe bool getMeshOutputs(Xenko.Rendering.Mesh modelMesh, out List <Vector3> positions, out List <int> indicies) { if (modelMesh.Draw is StagedMeshDraw) { StagedMeshDraw smd = modelMesh.Draw as StagedMeshDraw; object verts = smd.Verticies; if (verts is VertexPositionNormalColor[]) { VertexPositionNormalColor[] vpnc = verts as VertexPositionNormalColor[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions[k] = vpnc[k].Position; } } else if (verts is VertexPositionNormalTexture[]) { VertexPositionNormalTexture[] vpnc = verts as VertexPositionNormalTexture[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions[k] = vpnc[k].Position; } } else if (verts is VertexPositionNormalTextureTangent[]) { VertexPositionNormalTextureTangent[] vpnc = verts as VertexPositionNormalTextureTangent[]; positions = new List <Vector3>(vpnc.Length); for (int k = 0; k < vpnc.Length; k++) { positions[k] = vpnc[k].Position; } } else { positions = null; indicies = null; return(false); } // take care of indicies indicies = new List <int>((int[])(object)smd.Indicies); } else { Xenko.Graphics.Buffer buf = modelMesh.Draw?.VertexBuffers[0].Buffer; Xenko.Graphics.Buffer ibuf = modelMesh.Draw?.IndexBuffer.Buffer; if (buf == null || buf.VertIndexData == null || ibuf == null || ibuf.VertIndexData == null) { positions = null; indicies = null; return(false); } if (ModelBatcher.UnpackRawVertData(buf.VertIndexData, modelMesh.Draw.VertexBuffers[0].Declaration, out Vector3[] arraypositions, out Core.Mathematics.Vector3[] normals, out Core.Mathematics.Vector2[] uvs,