public static double Test6_Bunny_ExpectedError(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { string path = AppDomain.CurrentDomain.BaseDirectory + "TestData"; Model3D model3DTarget = new Model3D(path + "\\bunny.obj"); myVerticesTarget = model3DTarget.VertexList; Vertices.GetVertexMax(myVerticesTarget); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); Matrix3d R = new Matrix3d(); //ICP converges with a rotation of //R = R.RotationXYZ(60, 60, 60); R = R.RotationXYZ(65, 65, 65); VertexUtils.RotateVertices(myVerticesSource, R); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public static MeshPrimitive WithVertexAccessors <TVertex>(this MeshPrimitive primitive, IReadOnlyList <TVertex> vertices) where TVertex : IVertexBuilder { var memAccessors = VertexUtils.CreateVertexMemoryAccessors(vertices, new PackedEncoding()); return(primitive.WithVertexAccessors(memAccessors)); }
public override void OnSingleClick(ProceduralObject obj) { foreach (var po in selection) { if (po.isRootOfGroup && logic.selectedGroup == null) { Quaternion diff = obj.m_rotation * Quaternion.Inverse(po.m_rotation); foreach (var o in po.group.objects) { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); o.SetRotation(diff * o.m_rotation); if (o != po) { o.SetPosition(VertexUtils.RotatePointAroundPivot(o.m_position, po.m_position, diff)); } o.historyEditionBuffer.ConfirmNewStep(null); } } else { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.rotation, null); po.SetRotation(obj.m_rotation); po.historyEditionBuffer.ConfirmNewStep(null); } } ExitAction(); }
private void resize(int amountVertices) { if (IsDisposed) { throw new ObjectDisposedException(ToString(), "Can not resize disposed vertex buffers."); } T[] oldVertices = Vertices; Vertices = new T[amountVertices]; if (oldVertices != null) { for (int i = 0; i < oldVertices.Length && i < Vertices.Length; ++i) { Vertices[i] = oldVertices[i]; } } if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId)) { VertexUtils <T> .Bind(); } GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * STRIDE), IntPtr.Zero, usage); }
//private static List<Vertex> verticesTarget; //private static List<Vertex> verticesSource; // private static List<Vertex> vectorsResult; public static double Test1_Translation(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateSomePoints(); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.TranslateVertices(myVerticesSource, 10, 3, 8); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public static double Test5_CubeScale_Inhomogenous(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.ScaleByVector(myVerticesSource, new Vertex(1, 2, 3)); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public override void LoadData(Dictionary <string, string> data, bool fromSaveGame) { if (data.ContainsKey("point0")) { point0 = VertexUtils.ParseVector3(data["point0"]); } if (data.ContainsKey("repeat")) { repeat = bool.Parse(data["repeat"]); } if (data.ContainsKey("state")) { state = bool.Parse(data["state"]); } if (data.ContainsKey("timeSpeed")) { timeSpeed = float.Parse(data["timeSpeed"]); } if (data.ContainsKey("gravity")) { gravity = float.Parse(data["gravity"]); } if (data.ContainsKey("initialSpeed")) { initialSpeed = VertexUtils.ParseVector3(data["initialSpeed"]); } if (data.ContainsKey("bounceTimes")) { bounceTimes = int.Parse(data["bounceTimes"]); } if (data.ContainsKey("bounceFactor")) { bounceFactor = float.Parse(data["bounceFactor"]); } if (data.ContainsKey("groupFollows")) { groupFollows = bool.Parse(data["groupFollows"]); } if (data.ContainsKey("t")) { t = int.Parse(data["t"]); } if (data.ContainsKey("vy")) { vy = float.Parse(data["vy"]); } if (data.ContainsKey("points")) { points = data["points"].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll <Vector3>(x => VertexUtils.ParseVector3(x)); } if (data.ContainsKey("vys")) { vys = data["vys"].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll <float>(x => float.Parse(x)); } }
public static double Test5_CubeTranslation(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.TranslateVertices(myVerticesSource, 0, -300, 0); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
/// <summary> /// Initialises this <see cref="VertexBuffer{T}"/>. Guaranteed to be run on the draw thread. /// </summary> protected virtual void Initialise() { ThreadSafety.EnsureDrawThread(); GL.GenBuffers(1, out vboId); if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId)) VertexUtils<DepthWrappingVertex<T>>.Bind(); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * STRIDE), IntPtr.Zero, usage); }
public static Type GetMeshBuilderType(Type materialType, string[] vertexAttributes) { var tvg = VertexUtils.GetVertexGeometryType(vertexAttributes); var tvm = VertexUtils.GetVertexMaterialType(vertexAttributes); var tvs = VertexUtils.GetVertexSkinningType(vertexAttributes); var meshType = typeof(MeshBuilder <, , ,>); meshType = meshType.MakeGenericType(materialType, tvg, tvm, tvs); return(meshType); }
public static double Test9_Inhomogenous(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateCube_Corners(50); //myVerticesTarget = Vertices.CreateSomePoints(); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.InhomogenousTransform(myVerticesSource, 2); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public static double Test3_Scale(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { //myVerticesTarget = CreateSomePoints(); myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.ScaleByFactor(myVerticesSource, 0.2); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public virtual void Bind(bool forRendering) { if (IsDisposed) { throw new ObjectDisposedException(ToString(), "Can not bind disposed vertex buffers."); } if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId)) { VertexUtils <T> .Bind(); } }
public static MeshPrimitive WithVertexAccessors <TVertex>(this MeshPrimitive primitive, IReadOnlyList <TVertex> vertices) where TVertex : IVertexBuilder { var indices = vertices.Select(item => item.GetSkinning().GetWeights().MaxIndex); var maxIndex = indices.Any() ? indices.Max() : 0; var encoding = maxIndex < 256 ? Schema2.EncodingType.UNSIGNED_BYTE : EncodingType.UNSIGNED_SHORT; var memAccessors = VertexUtils.CreateVertexMemoryAccessors(vertices, encoding); return(primitive.WithVertexAccessors(memAccessors)); }
public void DoSlope(bool oriented) { var maxObjects = VertexUtils.OutmostPoints(selection.ToArray()); float heightDiff = maxObjects.Value.m_position.y - maxObjects.Key.m_position.y; float distDiff = Vector2.Distance(maxObjects.Value.m_position.AsXZVector2(), maxObjects.Key.m_position.AsXZVector2()); Vector3 flatDirection = new Vector3(maxObjects.Value.m_position.x, 0, maxObjects.Value.m_position.z) - new Vector3(maxObjects.Key.m_position.x, 0, maxObjects.Key.m_position.z); Quaternion rotDiff = Quaternion.FromToRotation(flatDirection, maxObjects.Value.m_position - maxObjects.Key.m_position); foreach (var po in selection) { var localdistdiff = Vector3.Project((po.m_position - maxObjects.Key.m_position).NullY(), (maxObjects.Value.m_position - maxObjects.Key.m_position).NullY()).magnitude; var localheightdiff = (po == maxObjects.Key) ? 0f : ((po == maxObjects.Value) ? heightDiff : heightDiff * localdistdiff / distDiff); if (po.isRootOfGroup && logic.selectedGroup == null) { foreach (var o in po.group.objects) { if (oriented) { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); o.SetPosition(new Vector3(o.m_position.x, localheightdiff + maxObjects.Key.m_position.y, o.m_position.z)); o.SetRotation(rotDiff * o.m_rotation); if (o != po) { o.m_position = VertexUtils.RotatePointAroundPivot(o.m_position, po.m_position, rotDiff); } } else { o.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.position, null); o.SetPosition(new Vector3(o.m_position.x, localheightdiff + maxObjects.Key.m_position.y, o.m_position.z)); } o.historyEditionBuffer.ConfirmNewStep(null); } } else { if (oriented) { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.moveTo, null); po.SetRotation(rotDiff * po.m_rotation); } else { po.historyEditionBuffer.InitializeNewStep(EditingStep.StepType.position, null); } po.SetPosition(new Vector3(po.m_position.x, localheightdiff + maxObjects.Key.m_position.y, po.m_position.z)); po.historyEditionBuffer.ConfirmNewStep(null); } } }
public virtual void Bind(bool forRendering) { if (IsDisposed) throw new ObjectDisposedException(ToString(), "Can not bind disposed vertex buffers."); if (!isInitialised) { Initialise(); isInitialised = true; } if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId)) VertexUtils<DepthWrappingVertex<T>>.Bind(); }
public static double Test2_RotationX30Degrees(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { //myVerticesTarget = Vertices.CreateSomePoints(); myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); Matrix3d R = Matrix3d.CreateRotationX(30); VertexUtils.RotateVertices(myVerticesSource, R); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public static double Test5_CubeRotate(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); Matrix3d R = new Matrix3d(); R = R.RotateSome(); VertexUtils.RotateVertices(myVerticesSource, R); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public Type GetCompatibleVertexType() { var hasNormals = Normals != null; var hasTangents = hasNormals && Tangents != null; int numCols = 0; if (Colors0 != null) { numCols = 1; } if (numCols == 1 && Colors1 != null) { numCols = 2; } int numTexs = 0; if (TexCoords0 != null) { numTexs = 1; } if (numTexs == 1 && TexCoords1 != null) { numTexs = 2; } if (numTexs == 2 && TexCoords2 != null) { numTexs = 3; } if (numTexs == 3 && TexCoords3 != null) { numTexs = 4; } int numJoints = 0; if (Joints0 != null) { numJoints = 4; } if (Joints0 != null && Joints1 != null) { numJoints = 8; } return(VertexUtils.GetVertexBuilderType(hasNormals, hasTangents, numCols, numTexs, numJoints)); }
private void resize(int amountVertices) { if (IsDisposed) { throw new ObjectDisposedException(ToString(), "Can not resize disposed vertex buffers."); } Array.Resize(ref Vertices, amountVertices); if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId)) { VertexUtils <T> .Bind(); } GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * STRIDE), IntPtr.Zero, usage); }
public override void LoadData(Dictionary <string, string> data, bool fromSaveGame) { if (data.ContainsKey("rotateAround_speedRPM")) { this.speedRPM = float.Parse(data["rotateAround_speedRPM"]); } if (data.ContainsKey("rotateAround_reverseDirection")) { this.reverseDirection = bool.Parse(data["rotateAround_reverseDirection"]); } if (data.ContainsKey("rotateAround_center")) { this.center = VertexUtils.ParseVector3(data["rotateAround_center"]); } }
public static double Test5_CubeRotateTranslate_ScaleInhomogenous(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { myVerticesTarget = Vertices.CreateCube_Corners(50); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.TranslateVertices(myVerticesSource, 0, 0, 149); VertexUtils.ScaleByVector(myVerticesSource, new Vertex(1, 2, 3)); Matrix3d R = new Matrix3d(); R = R.RotateSome(); VertexUtils.RotateVertices(myVerticesSource, R); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public override void OnOpen(List <ProceduralObject> selection) { confirmed = false; this.selection = POGroup.AllObjectsInSelection(selection, logic.selectedGroup); if (this.selection.Count < 2) { ExitAction(); return; } oldColors = new Dictionary <ProceduralObject, Color>(); foreach (var obj in this.selection) { oldColors.Add(obj, obj.m_color); } gradientTex = TextureUtils.PlainTexture(100, 22, Color.white); maxObjects = VertexUtils.OutmostPoints(this.selection.ToArray()); gradient = new Gradient(); }
// move vertices public void ApplyToNewPosition(Vector3 newHitPoint, ProceduralObject obj) { if (relativePositions == null) { return; } if (relativePositions.Count == 0) { return; } var referencial = VertexUtils.RotatePointAroundPivot(newHitPoint, originHitPoint, Quaternion.Inverse(obj.m_rotation)); foreach (KeyValuePair <Vertex, Vector3> kvp in relativePositions) { var newpos = kvp.Value + referencial; kvp.Key.Position = new Vector3(newpos.x, kvp.Key.Position.y, newpos.z); } }
// rotate vertices public void ApplyToNewPosition(float mousePosX) { float diff = originMousePosition.x - mousePosX; Quaternion rot = Quaternion.identity; if (diff > 0) { rot = Quaternion.Euler(0, (diff * 370f) / Screen.width, 0); } else { rot = Quaternion.Euler(0, -(((-diff) * 370f) / Screen.width), 0); } foreach (KeyValuePair <Vertex, Vertex> kvp in rotVertices) { kvp.Value.Position = VertexUtils.RotatePointAroundPivot(kvp.Key.Position, verticesBounds.center, rot); } }
public static double Test8_CubeOutliers_Rotate(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { //myVerticesTarget = Vertices.CreateCube_Corners(50); Model3D myModel = Example3DModels.Cuboid("Cuboid", 20f, 40f, 100, new Vector3d(1, 1, 1), null); myVerticesTarget = myModel.VertexList; myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); Matrix3d R = new Matrix3d(); R = R.Rotation30Degrees(); VertexUtils.RotateVertices(myVerticesSource, R); VertexUtils.CreateOutliers(myVerticesSource, 5); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
public void TransformPointCloud_SaveObjFile() { //open a file DepthMetaData DepthMetaData = new DepthMetaData(); byte[] colorInfo = null; DepthMetaData.ReadDepthWithColor_OBJ(path, "KinectFace1.obj", ref DepthMetaData.FrameData, ref colorInfo); List <Vector3d> myVectors = Vertices.ConvertToVector3DList_FromArray(DepthMetaData.FrameData, DepthMetaData.XResDefault, DepthMetaData.YResDefault); List <float[]> myColorsFloats = PointCloudUtils.CreateColorInfo(colorInfo, DepthMetaData.FrameData, DepthMetaData.XResDefault, DepthMetaData.YResDefault); List <Vertex> myVertexList = Model3D.CreateVertexList(myVectors, myColorsFloats); VertexUtils.ScaleByFactor(myVertexList, 0.9); VertexUtils.RotateVertices30Degrees(myVertexList); VertexUtils.TranslateVertices(myVertexList, 10, 3, 5); Model3D.Save_ListVertices_Obj(myVertexList, path, "transformed.obj"); }
public static double Test7_Face_KnownTransformation(ref List <Vertex> myVerticesTarget, ref List <Vertex> myVerticesSource, ref List <Vertex> myVerticesResult) { string path = AppDomain.CurrentDomain.BaseDirectory + "TestData"; Model3D model3DTarget = new Model3D(path + "\\KinectFace1.obj"); myVerticesTarget = model3DTarget.VertexList; Vertices.GetVertexMax(myVerticesTarget); myVerticesSource = VertexUtils.CloneListVertex(myVerticesTarget); VertexUtils.ScaleByFactor(myVerticesSource, 0.9); Matrix3d R = new Matrix3d(); R = R.Rotation60Degrees(); VertexUtils.RotateVertices(myVerticesSource, R); VertexUtils.TranslateVertices(myVerticesSource, 0.3, 0.5, -0.4); myVerticesResult = IterativeClosestPointTransform.Instance.PerformICP(myVerticesTarget, myVerticesSource); return(IterativeClosestPointTransform.Instance.MeanDistance); }
private void ApplyRotations() { foreach (var po in selection) { Quaternion appliedRot = Quaternion.Euler(RandomX ? randomizedRotations[po].x : 0f, RandomY ? randomizedRotations[po].y : 0f, RandomZ ? randomizedRotations[po].z : 0f); if (po.isRootOfGroup && logic.selectedGroup == null) { foreach (var o in po.group.objects) { o.SetRotation(appliedRot * oldRotations[o]); if (o != po) { o.SetPosition(VertexUtils.RotatePointAroundPivot(oldPositions[o], po.m_position, appliedRot)); } } } else { po.SetRotation(appliedRot * oldRotations[po]); } } }
private string _GetDebuggerDisplay() => VertexUtils._GetDebuggerDisplay(this);