protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { // -- set geometry if given if (geometry != null && geometry.Positions != null && geometry.Positions.Count > 0) { buffer.UploadDataToBuffer(context, geometry.Positions, geometry.Positions.Count); } else { buffer.UploadDataToBuffer(context, emptyVerts, 0); } }
/// <summary> /// Hits the test current node exclude child. /// </summary> /// <param name="octant">The octant.</param> /// <param name="context">The context.</param> /// <param name="model">The model.</param> /// <param name="geometry"></param> /// <param name="modelMatrix">The model matrix.</param> /// <param name="rayWS">The ray ws.</param> /// <param name="rayModel">The ray model.</param> /// <param name="hits">The hits.</param> /// <param name="isIntersect">if set to <c>true</c> [is intersect].</param> /// <param name="hitThickness">The hit thickness.</param> /// <returns></returns> protected override bool HitTestCurrentNodeExcludeChild(ref Octant octant, RenderContext context, object model, Geometry3D geometry, Matrix modelMatrix, ref Ray rayWS, ref Ray rayModel, ref List <HitTestResult> hits, ref bool isIntersect, float hitThickness) { isIntersect = false; if (!octant.IsBuilt) { return(false); } bool isHit = false; var bound = octant.Bound.Transform(modelMatrix); if (rayWS.Intersects(ref bound)) { isIntersect = true; for (int i = octant.Start; i < octant.End; ++i) { var b = Objects[i].Value.Transform(modelMatrix); if (b.Intersects(ref rayWS)) { var result = new HitTestResult() { Tag = Objects[i].Key }; hits.Add(result); isHit = true; } } } return(isHit); }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <returns></returns> protected virtual IGeometryBufferProxy OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(GeometryBufferProxy <EmptyGeometryBufferModel> .Empty); }
/// <summary> /// Called when [create index buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> protected abstract void OnCreateIndexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources);
protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { if (bufferIndex == 0 && geometry != null && geometry.Positions != null && geometry.Positions.Count > 0) { buffer.UploadDataToBuffer(context, geometry.Positions, geometry.Positions.Count); } }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <param name="modelGuid"></param> /// <param name="geometry"></param> /// <returns></returns> protected override IAttachableBufferModel OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { var buffer = geometry != null && geometry.IsDynamic ? EffectsManager.GeometryBufferManager.Register <DynamicBillboardBufferModel>(modelGuid, geometry) : EffectsManager.GeometryBufferManager.Register <DefaultBillboardBufferModel>(modelGuid, geometry); if (geometry is IBillboardText b && Material is IBillboardRenderParams m) { m.Type = b.Type; } return(buffer); }
public OITModel(Geometry3D model, Material material, bool isTransparent) { Model = model; Material = material; IsTransparent = isTransparent; }
/// <summary> /// Called when [create index buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> protected override void OnCreateIndexBuffer(DeviceContext context, IElementsBufferProxy buffer, Geometry3D geometry, IDeviceResources deviceResources) { }
public BatchedMeshGeometryConfig(Geometry3D geometry, Matrix modelTransform, int materialIndex) { Geometry = geometry; ModelTransform = modelTransform; MaterialIndex = materialIndex; }
public override bool HitTestCurrentNodeExcludeChild(HitTestContext context, object model, Geometry3D geometry, Matrix modelMatrix, ref Ray rayModel, ref List <HitTestResult> hits, ref bool isIntersect, float hitThickness) { isIntersect = false; if (!this.treeBuilt) { return(false); } bool isHit = false; //var bound = Bound.Transform(modelMatrix);// BoundingBox.FromPoints(Bound.GetCorners().Select(x => Vector3.TransformCoordinate(x, modelMatrix)).ToArray()); var bound = Bound; var tempHits = new List <HitTestResult>(); var rayWS = context.RayWS; if (rayWS.Intersects(ref bound)) { isIntersect = true; foreach (var r in this.Objects) { isHit |= r.HitTest(context, ref tempHits); hits.AddRange(tempHits); tempHits.Clear(); } } return(isHit); }
public CollisionResult(Vector3 Position1, Vector3 Position2, Vector3 Position3, int ID, Vector3 Or, Vector3 CollisionP, Geometry3D Geom) { P1 = Position1; P2 = Position2; P3 = Position3; InstanceID = ID; GeometryName = Geom.Name; Origin = Or; CollisionPoint = CollisionP; Geometry = Geom; Distance = Vector3.Distance(CollisionP, Or); }
/// <summary> /// Compute the distance between the specified points a and b in the Euclidian Space. /// </summary> /// <param name='a'> /// Point a with x and y and z /// </param> /// <param name='b'> /// Point b with x and y and z /// </param> public static double Distance(Geometry3D.Point3D a, Geometry3D.Point3D b) { return Math.Sqrt(Math.Pow (a.X - b.X) + Math.Pow(a.Y - b.Y) + Math.Pow(a.Z - b.Z)); }
private void InitializeScene() { camera = new PerspectiveCameraCore() { LookDirection = new Vector3(0, 0, 50), Position = new Vector3(0, 0, -50), FarPlaneDistance = 1000, NearPlaneDistance = 0.1f, FieldOfView = 45, UpDirection = new Vector3(0, 1, 0) }; viewport.CameraCore = camera; viewport.Items.Add(new DirectionalLightNode() { Direction = new Vector3(0, -1, 1), Color = Color.White }); viewport.Items.Add(new PointLightNode() { Position = new Vector3(0, 0, -20), Color = Color.Yellow, Range = 20, Attenuation = Vector3.One }); var builder = new MeshBuilder(true, true, true); builder.AddSphere(Vector3.Zero, 1, 12, 12); sphere = builder.ToMesh(); builder = new MeshBuilder(true, true, true); builder.AddBox(Vector3.Zero, 1, 1, 1); box = builder.ToMesh(); points = new PointGeometry3D() { Positions = sphere.Positions }; var lineBuilder = new LineBuilder(); lineBuilder.AddBox(Vector3.Zero, 2, 2, 2); lines = lineBuilder.ToLineGeometry3D(); groupSphere = new GroupNode(); groupBox = new GroupNode(); groupLines = new GroupNode(); groupPoints = new GroupNode(); InitializeMaterials(); materialList = materials.Values.ToArray(); var materialCount = materialList.Length; for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20))); groupSphere.AddChildNode(new MeshNode() { Geometry = sphere, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } for (int i = 0; i < NumItems; ++i) { var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupBox.AddChildNode(new MeshNode() { Geometry = box, Material = materialList[i % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); } //for(int i=0; i< NumItems; ++i) //{ // var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); // groupPoints.AddChildNode(new PointNode() { Geometry = points, ModelMatrix = transform, Material = new PointMaterialCore() { PointColor = Color.Red } }); //} //for (int i = 0; i < NumItems; ++i) //{ // var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); // groupLines.AddChildNode(new LineNode() { Geometry = lines, ModelMatrix = transform, Material = new LineMaterialCore() { LineColor = Color.LightBlue } }); //} viewport.Items.Add(groupSphere); groupSphere.AddChildNode(groupBox); groupSphere.AddChildNode(groupPoints); groupSphere.AddChildNode(groupLines); var viewbox = new ViewBoxNode(); viewport.Items.Add(viewbox); var imGui = new ImGuiNode(); viewport.Items.Add(imGui); imGui.UpdatingImGuiUI += ImGui_UpdatingImGuiUI; io.KeyMap[GuiKey.Tab] = (int)Keys.Tab; io.KeyMap[GuiKey.LeftArrow] = (int)Keys.Left; io.KeyMap[GuiKey.RightArrow] = (int)Keys.Right; io.KeyMap[GuiKey.UpArrow] = (int)Keys.Up; io.KeyMap[GuiKey.DownArrow] = (int)Keys.Down; io.KeyMap[GuiKey.PageUp] = (int)Keys.PageUp; io.KeyMap[GuiKey.PageDown] = (int)Keys.PageDown; io.KeyMap[GuiKey.Home] = (int)Keys.Home; io.KeyMap[GuiKey.End] = (int)Keys.End; io.KeyMap[GuiKey.Delete] = (int)Keys.Delete; io.KeyMap[GuiKey.Backspace] = (int)Keys.Back; io.KeyMap[GuiKey.Enter] = (int)Keys.Enter; io.KeyMap[GuiKey.Escape] = (int)Keys.Escape; }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <returns></returns> protected virtual IAttachableBufferModel OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(EmptyGeometryBufferModel.Empty); }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <param name="modelGuid"></param> /// <param name="geometry"></param> /// <returns></returns> protected override IAttachableBufferModel OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(geometry != null && geometry.IsDynamic ? EffectsManager.GeometryBufferManager.Register <DynamicMeshGeometryBufferModel>(modelGuid, geometry) : EffectsManager.GeometryBufferManager.Register <DefaultMeshGeometryBufferModel>(modelGuid, geometry)); }
/// <summary> /// 设置添加到TrackingLayer的三维几何对象的风格 /// </summary> /// <param name="geometry"></param> private void SetGeometry3DStyle(Geometry3D geometry) { try { GeoStyle3D style = new GeoStyle3D(); if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureAltitude || SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureDistance || SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureHorizontalDistance) { style.AltitudeMode = AltitudeMode.Absolute; style.BottomAltitude = 100; } else { style.AltitudeMode = AltitudeMode.ClampToGround; } style.MarkerSize = 4; style.MarkerColor = Color.FromArgb(255, 0, 255); style.LineColor = Color.Yellow; style.LineWidth = 2; style.FillMode = FillMode3D.LineAndFill; style.FillForeColor = Color.LightSeaGreen; geometry.Style3D = style; } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <param name="modelGuid"></param> /// <param name="geometry"></param> /// <returns></returns> protected override IGeometryBufferProxy OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(EffectsManager.GeometryBufferManager.Register <DefaultBillboardBufferModel>(modelGuid, geometry)); }
/// <summary> /// Called when [create vertex buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> /// <param name="bufferIndex"></param> protected override void OnCreateVertexBuffer(DeviceContext context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { textureView?.Detach(this.GUID); textureView = null; var billboardGeometry = geometry as IBillboardText; billboardGeometry.DrawTexture(deviceResources); if (billboardGeometry != null && billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0) { Type = billboardGeometry.Type; var data = OnBuildVertexArray(billboardGeometry, deviceResources); buffer.UploadDataToBuffer(context, data, billboardGeometry.BillboardVertices.Count); if (billboardGeometry.Texture != null) { textureView = deviceResources.MaterialTextureManager.Register(this.GUID, billboardGeometry.Texture); } } else { buffer.DisposeAndClear(); } }
/// <summary> /// Called when [check geometry]. /// </summary> /// <param name="geometry">The geometry.</param> /// <returns></returns> protected override bool OnCheckGeometry(Geometry3D geometry) { return(base.OnCheckGeometry(geometry) && geometry is PointGeometry3D); }
protected virtual void OnAssignTo(Geometry3D target) { }
/// <summary> /// Called when [create vertex buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> /// <param name="bufferIndex"></param> protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { // -- set geometry if given if (geometry != null && geometry.Positions != null && geometry.Positions.Count > 0) { // --- get geometry var data = OnBuildVertexArray(geometry); buffer.UploadDataToBuffer(context, data, geometry.Positions.Count, 0, geometry.PreDefinedVertexCount); } else { buffer.UploadDataToBuffer(context, emptyVerts, 0); } }
/// <summary> /// Called when [check geometry]. /// </summary> /// <param name="geometry">The geometry.</param> /// <returns></returns> protected override bool OnCheckGeometry(Geometry3D geometry) { return(geometry is IBillboardText); }
/// <summary> /// Called when [create buffer model]. /// </summary> /// <param name="modelGuid"></param> /// <param name="geometry"></param> /// <returns></returns> protected override IGeometryBufferProxy OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(geometry != null && geometry.IsDynamic ? EffectsManager.GeometryBufferManager.Register <DynamicBillboardBufferModel>(modelGuid, geometry) : EffectsManager.GeometryBufferManager.Register <DefaultBillboardBufferModel>(modelGuid, geometry)); }
/// <summary> /// Called when [create vertex buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> /// <param name="bufferIndex"></param> protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { if (geometry is IBillboardText billboardGeometry) { billboardGeometry.DrawTexture(deviceResources); if (billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0) { Type = billboardGeometry.Type; buffer.UploadDataToBuffer(context, billboardGeometry.BillboardVertices, billboardGeometry.BillboardVertices.Count, 0, geometry.PreDefinedVertexCount); if (textureStream != billboardGeometry.Texture) { RemoveAndDispose(ref textureView); textureStream = billboardGeometry.Texture; if (textureStream != null) { textureView = Collect(deviceResources.MaterialTextureManager.Register(textureStream)); } } } else { RemoveAndDispose(ref textureView); textureStream = null; buffer.UploadDataToBuffer(context, emptyVerts, 0); } } }
public GeometryCollisionMask3D(World world, Geometry3D geometry) : base(world, geometry) { }
/// <summary> /// /// </summary> /// <param name="octant"></param> /// <param name="context"></param> /// <param name="model"></param> /// <param name="geometry"></param> /// <param name="modelMatrix"></param> /// <param name="rayWS"></param> /// <param name="rayModel"></param> /// <param name="returnMultiple"></param> /// <param name="hits"></param> /// <param name="isIntersect"></param> /// <param name="hitThickness"></param> /// <returns></returns> protected override bool HitTestCurrentNodeExcludeChild(ref Octant octant, IRenderMatrices context, object model, Geometry3D geometry, Matrix modelMatrix, ref Ray rayWS, ref Ray rayModel, bool returnMultiple, ref List <HitTestResult> hits, ref bool isIntersect, float hitThickness) { isIntersect = false; if (!octant.IsBuilt) { return(false); } var isHit = false; var bound = octant.Bound; bound.Maximum += new Vector3(hitThickness); bound.Minimum -= new Vector3(hitThickness); var lastDist = double.MaxValue; //Hit test in local space. if (rayModel.Intersects(ref bound)) { isIntersect = true; if (octant.Count == 0) { return(false); } var result = new LineHitTestResult { IsValid = false, Distance = double.MaxValue }; result.Distance = double.MaxValue; for (int i = octant.Start; i < octant.End; ++i) { var idx = Objects[i].Key * 2; var idx1 = Indices[idx]; var idx2 = Indices[idx + 1]; var v0 = Positions[idx1]; var v1 = Positions[idx2]; var t0 = Vector3.TransformCoordinate(v0, modelMatrix); var t1 = Vector3.TransformCoordinate(v1, modelMatrix); var rayToLineDistance = LineBuilder.GetRayToLineDistance(rayWS, t0, t1, out Vector3 sp, out Vector3 tp, out float sc, out float tc); var svpm = context.ScreenViewProjectionMatrix; Vector3.TransformCoordinate(ref sp, ref svpm, out var sp3); Vector3.TransformCoordinate(ref tp, ref svpm, out var tp3); var tv2 = new Vector2(tp3.X - sp3.X, tp3.Y - sp3.Y); var dist = tv2.Length() / context.DpiScale; if (returnMultiple) { lastDist = float.MaxValue; } if (dist < lastDist && dist <= hitThickness) { lastDist = dist; result.PointHit = sp; result.NormalAtHit = sp - tp; // not normalized to get length result.Distance = (rayWS.Position - sp).Length(); result.RayToLineDistance = rayToLineDistance; result.ModelHit = model; result.IsValid = true; result.Tag = idx; // For compatibility result.LineIndex = idx; result.TriangleIndices = null; // Since triangles are shader-generated result.RayHitPointScalar = sc; result.LineHitPointScalar = tc; result.Geometry = geometry; isHit = true; if (returnMultiple) { hits.Add(result); result = new LineHitTestResult(); } } } if (isHit && !returnMultiple) { isHit = false; if (hits.Count > 0) { if (hits[0].Distance > result.Distance) { hits[0] = result; isHit = true; } } else { hits.Add(result); isHit = true; } } } return(isHit); }
/// <summary> /// Исследование характеристик работы с геометрией /// в виде одиночного параллелепипеда /// </summary> private static void GeometryParallelepipedTests() { // Примитив - параллелепипед Coordinate3D coordinate3D = new Coordinate3D(1m, 1m, 1m); GeometryPrimitive3DParallelepiped parallelepiped = new GeometryPrimitive3DParallelepiped(coordinate3D, 5m, 1m, 0.5m); NagruzkaRaspredRavnomern nagr1 = new NagruzkaRaspredRavnomern(); nagr1.Q = new Q(200000, 100000, 50000); var areaRectangle1 = new AreaRectangle(); areaRectangle1.Coordinate3DPointMinDistant = new Coordinate3D(1m, 2m, 0.5m); areaRectangle1.Coordinate3DPointMaxDistant = new Coordinate3D(6m, 2m, 1.5m); nagr1.Area = areaRectangle1; parallelepiped.NagruzkaList.Add(nagr1); GeometryElement geometryElement = new GeometryElement3D(new Coordinate3D(0.5m, 1m, 1.5m)); geometryElement.GeometryPrimitives.Add(parallelepiped); geometryElement.GeometryPrimitives.Add(new GeometryPrimitive3DCube(new Coordinate3D(1.1m, 1.2m, 1.1m), 0.15m, true)); Geometry3D geometry = new Geometry3D(); geometry.GeometryElements.Add(geometryElement); ///////////////////////// Console.WriteLine("Сериализация объекта: {0}", geometry.ExportToXML("", "GeometryParallelepiped.xml")); Geometry3D g2 = (Geometry3D)Geometry.ImportFromXML("", "GeometryParallelepiped.xml"); Console.WriteLine("Проверка на равенство серализованного и десериализованного объектов: {0}", Geometry3D.IsGeometryValuesEquals(geometry, g2)); }
/// <summary> /// Hits the test current node exclude child. /// </summary> /// <param name="octant">The octant.</param> /// <param name="context">The context.</param> /// <param name="model">The model.</param> /// <param name="geometry"></param> /// <param name="modelMatrix">The model matrix.</param> /// <param name="rayWS">The ray ws.</param> /// <param name="rayModel">The ray model.</param> /// <param name="hits">The hits.</param> /// <param name="isIntersect">if set to <c>true</c> [is intersect].</param> /// <param name="hitThickness">The hit thickness.</param> /// <returns></returns> protected override bool HitTestCurrentNodeExcludeChild(ref Octant octant, RenderContext context, object model, Geometry3D geometry, Matrix modelMatrix, ref Ray rayWS, ref Ray rayModel, ref List <HitTestResult> hits, ref bool isIntersect, float hitThickness) { isIntersect = false; if (!octant.IsBuilt) { return(false); } bool isHit = false; var bound = octant.Bound.Transform(modelMatrix); if (rayWS.Intersects(ref bound)) { isIntersect = true; for (int i = octant.Start; i < octant.End; ++i) { var b = Objects[i].Value.Transform(modelMatrix); if (b.Intersects(ref rayWS)) { var geo = Geometries[Objects[i].Key]; if (geo.Geometry is MeshGeometry3D mesh) { isHit |= mesh.HitTest(context, geo.ModelTransform * modelMatrix, ref rayWS, ref hits, model); } } } } return(isHit); }
public void DetachOutPut(string ShaderParameterName, Geometry3D DetachGeometry) { DetachOutPut(DetachGeometry, true); }
/// <summary> /// Called when [check geometry]. /// </summary> /// <param name="geometry">The geometry.</param> /// <returns></returns> protected virtual bool OnCheckGeometry(Geometry3D geometry) { return(!(geometry == null || geometry.Positions == null || geometry.Positions.Count == 0)); }
protected override IAttachableBufferModel OnCreateBufferModel(Guid modelGuid, Geometry3D geometry) { return(!(EffectsManager.GeometryBufferManager.Register <BoneSkinnedMeshBufferModel>(modelGuid, geometry) is IBoneSkinMeshBufferModel buffer) ? EmptyGeometryBufferModel.Empty : new BoneSkinPreComputeBufferModel(buffer, buffer.VertexStructSize.FirstOrDefault()) as IAttachableBufferModel); }
/// <summary> /// Called when [geometry changed]. /// </summary> /// <param name="newGeometry">The new geometry.</param> /// <param name="oldGeometry">The old geometry.</param> protected virtual void OnGeometryChanged(Geometry3D newGeometry, Geometry3D oldGeometry) { }
///<exclude/> public bool Equals(Geometry3D other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._Pose.Equals(_Pose) && other._Size.Equals(_Size); }