static OcTreeManager()
        {
            LineBuilder b = new LineBuilder();

            b.AddBox(Vector3.Zero, 1, 1, 1);
            CellFrame = b.ToLineGeometry3D();

            EndPoint = LinesCutom.GetEndPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT * 0.8f);
            MidPoint = LinesCutom.GetMidPointMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);
            IntPoint = LinesCutom.GetIntersectionMarker(Vector3.Zero, (float)SNAPPOSMARKER_FACT);

            ChamferedBoxMesh = MeshesCustom.GetChamferedBox(Vector3.Zero, 1f, 1f, 1f, 0.2f, 0.05f);
            MeshesCustom.CompressMesh(ref ChamferedBoxMesh);

            ChamferedBoxMesh_Normals = MeshesCustom.GetVertexNormalsAsLines(ChamferedBoxMesh, 0.15f);

            RedTransparent = new PhongMaterial();
            RedTransparent.DiffuseColor      = new Color4(0.8f, 0f, 0f, 0.25f);
            RedTransparent.AmbientColor      = new Color4(0.6f, 0f, 0f, 1f);
            RedTransparent.SpecularColor     = new Color4(1f, 0.75f, 0f, 1f);
            RedTransparent.SpecularShininess = 1;

            YellowTransparent = new PhongMaterial();
            YellowTransparent.DiffuseColor      = new Color4(1f, 0.93f, 0f, 0.5f);
            YellowTransparent.AmbientColor      = new Color4(0.92f, 0.69f, 0f, 1f);
            YellowTransparent.SpecularColor     = new Color4(1f, 1f, 1f, 1f);
            YellowTransparent.SpecularShininess = 3;
        }
        public SurfaceBasicInfo(LineGeometry3D _display_lines, HelixToolkit.SharpDX.Wpf.MeshGeometry3D _display_mesh, List <Vector3> _vertices_in_order,
                                long _volume_id, bool _is_wall, int _level_or_label, int _label_for_opeings, long _wall_lower_poly, long _wall_upper_poly,
                                double _area, double _height, double _width, long _material_id)
        {
            this.DisplayLines      = _display_lines;
            this.DisplayMesh       = _display_mesh;
            this.vertices_in_order = _vertices_in_order;
            this.SurfaceNormal     = Utils.MeshesCustom.GetPolygonNormalNewell(this.vertices_in_order);

            this.VolumeID         = _volume_id;
            this.IsWall           = _is_wall;
            this.LevelOrLabel     = _level_or_label;
            this.LabelForOpenings = _label_for_opeings;
            this.Wall_LowerPoly   = _wall_lower_poly;
            this.Wall_UpperPoly   = _wall_upper_poly;

            this.Area_AXES   = _area;
            this.Height_AXES = _height;
            this.Width_AXES  = _width;

            this.Material_ID = _material_id;

            this.Openings = new List <SurfaceBasicInfo>();

            this.Processed = false;
        }
Пример #3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // =========================================== GEOMETRY DEFINITIONS ======================================= //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region GEOMETRY DEFINITIONS

        private void UpdateGeometry()
        {
            // show the defining polygons
            LineBuilder b = new LineBuilder();
            int         n = coords_polygons.Count;

            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    // transfer current polygon
                    List <Point3D> cp = coords_polygons[i];
                    int            m  = cp.Count;
                    if (m > 0)
                    {
                        // lines
                        for (int j = 0; j < m; j++)
                        {
                            b.AddLine(cp[j % m].ToVector3(), cp[(j + 1) % m].ToVector3());
                        }
                        // start maker
                        b.AddBox(cp[0].ToVector3(), START_MARKER, 0, START_MARKER);
                    }
                }
            }
            this.polygons.Geometry = b.ToLineGeometry3D();

            // show the resulting volume
            Vector3[] ar1 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[0].ToArray());
            Vector3[] ar2 = CommonExtensions.ConvertPoint3DArToVector3Ar(this.coords_polygons[1].ToArray());
            List <List <Vector3> > coords_poly_asV3 = CommonExtensions.ConvertPoints3DListListToVector3ListList(this.coords_polygons);
            bool capBottom = false;
            bool capTop    = true;

            HelixToolkit.SharpDX.Wpf.MeshGeometry3D volMesh =
                MeshesCustom.MeshFromNPolygons(coords_poly_asV3, this.reverse_polygons, capBottom, capTop);

            this.volume.Geometry        = volMesh;
            this.volumeNormals.Geometry = MeshesCustom.GetVertexNormalsAsLines(volMesh, 0.25f);
            this.volumeEdges.Geometry   = MeshesCustom.GetEdgesAsLines(volMesh);
        }
Пример #4
0
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.effectName = Techniques.RenderCubeMap;
            base.Attach(host);

            /// --- get variables               
            this.vertexLayout = host.Effects.GetLayout(this.effectName);
            this.technique = effect.GetTechniqueByName(this.effectName);
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// -- attach cube map 
            if (this.Filename != null)
            {
                /// -- attach texture
                using (var texture = Texture2D.FromFile<Texture2D>(this.device, this.Filename))
                {
                    this.texCubeMapView = new ShaderResourceView(this.device, texture);
                }
                this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource();
                this.texCubeMap.SetResource(this.texCubeMapView);
                this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar();
                this.bHasCubeMap.Set(true);

                /// --- set up geometry
                var sphere = new MeshBuilder(false,true,false);
                sphere.AddSphere(new Vector3(0, 0, 0));
                this.geometry = sphere.ToMeshGeometry3D();

                /// --- set up vertex buffer
                this.vertexBuffer = device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray());

                /// --- set up index buffer
                this.indexBuffer = device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices);

                /// --- set up rasterizer states
                var rasterStateDesc = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Solid,
                    CullMode = CullMode.Back,
                    IsMultisampleEnabled = true,
                    IsAntialiasedLineEnabled = true,
                    IsFrontCounterClockwise = false,
                };
                this.rasterState = new RasterizerState(this.device, rasterStateDesc);

                /// --- set up depth stencil state
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    DepthComparison = Comparison.LessEqual,
                    DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All,
                    IsDepthEnabled = true,
                };
                this.depthStencilState = new DepthStencilState(this.device, depthStencilDesc);
            }

            /// --- flush
            this.device.ImmediateContext.Flush();
        }
Пример #5
0
        public override void Detach()
        {
            if (!this.isAttached)
                return;

            this.bHasCubeMap.Set(false);

            this.effectName = null;
            this.technique = null;
            this.vertexLayout = null;
            this.geometry = null;

            Disposer.RemoveAndDispose(ref this.vertexBuffer);
            Disposer.RemoveAndDispose(ref this.indexBuffer);
            Disposer.RemoveAndDispose(ref this.texCubeMap);
            Disposer.RemoveAndDispose(ref this.texCubeMapView);
            Disposer.RemoveAndDispose(ref this.bHasCubeMap);
            Disposer.RemoveAndDispose(ref this.rasterState);
            Disposer.RemoveAndDispose(ref this.depthStencilState);
            Disposer.RemoveAndDispose(ref this.effectTransforms);

            base.Detach();
        }
Пример #6
0
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.effectName = Techniques.RenderCubeMap;
            base.Attach(host);

            /// --- get variables
            this.vertexLayout     = host.Effects.GetLayout(this.effectName);
            this.technique        = effect.GetTechniqueByName(this.effectName);
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// -- attach cube map
            if (this.Filename != null)
            {
                /// -- attach texture
                using (var texture = Texture2D.FromFile <Texture2D>(this.device, this.Filename))
                {
                    this.texCubeMapView = new ShaderResourceView(this.device, texture);
                }
                this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource();
                this.texCubeMap.SetResource(this.texCubeMapView);
                this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar();
                this.bHasCubeMap.Set(true);

                /// --- set up geometry
                var sphere = new MeshBuilder(false, true, false);
                sphere.AddSphere(new Vector3(0, 0, 0));
                this.geometry = sphere.ToMeshGeometry3D();

                /// --- set up vertex buffer
                this.vertexBuffer = device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex()
                {
                    Position = new Vector4(x, 1f)
                }).ToArray());

                /// --- set up index buffer
                this.indexBuffer = device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices);

                /// --- set up rasterizer states
                var rasterStateDesc = new RasterizerStateDescription()
                {
                    FillMode                 = FillMode.Solid,
                    CullMode                 = CullMode.Back,
                    IsMultisampleEnabled     = true,
                    IsAntialiasedLineEnabled = true,
                    IsFrontCounterClockwise  = false,
                };
                this.rasterState = new RasterizerState(this.device, rasterStateDesc);

                /// --- set up depth stencil state
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    DepthComparison = Comparison.LessEqual,
                    DepthWriteMask  = global::SharpDX.Direct3D11.DepthWriteMask.All,
                    IsDepthEnabled  = true,
                };
                this.depthStencilState = new DepthStencilState(this.device, depthStencilDesc);
            }

            /// --- flush
            this.device.ImmediateContext.Flush();
        }
        private void UpdateGeometry()
        {
            // show the polygon edges
            LineBuilder b = new LineBuilder();
            int         n = this.polygonDef.Count;

            if (n > 0)
            {
                for (int i = 0; i < n; i++)
                {
                    b.AddLine(this.polygonDef[i].ToVector3(), this.polygonDef[(i + 1) % n].ToVector3());
                }
            }

            // and the hole edges...
            if (this.holesDef != null)
            {
                foreach (List <Point3D> hole in this.holesDef)
                {
                    int h = hole.Count;
                    for (int j = 0; j < h; j++)
                    {
                        b.AddLine(hole[j].ToVector3(), hole[(j + 1) % h].ToVector3());
                    }
                }
            }

            this.polygonEdges.Geometry = b.ToLineGeometry3D();

            // 1. decompose the polygon with holes into simple polygons
            List <List <Point3D> > simplePolys = Utils.MeshesCustom.DecomposeInSimplePolygons(this.polygonDef, this.holesDef);
            List <List <Point3D> > monPolys    = new List <List <Point3D> >();

            if (simplePolys.Count > 0)
            {
                int counter = 0;
                foreach (List <Point3D> spoly in simplePolys)
                {
                    // draw it
                    LineBuilder bmp = new LineBuilder();
                    counter++;
                    int m = spoly.Count;
                    for (int i = 0; i < m; i++)
                    {
                        Vector3 start = new Vector3((float)spoly[i].X, (float)spoly[i].Y - counter, (float)spoly[i].Z);
                        Vector3 end   = new Vector3((float)spoly[(i + 1) % m].X, (float)spoly[(i + 1) % m].Y - counter, (float)spoly[(i + 1) % m].Z);
                        bmp.AddLine(start, end);
                    }
                    // 2. decompose it in monotone polygons
                    List <List <Point3D> > mPolys = Utils.MeshesCustom.DecomposeInMonotonePolygons(spoly);
                    monPolys.AddRange(mPolys);

                    int counterM = 0;
                    foreach (List <Point3D> mpoly in mPolys)
                    {
                        // and draw them
                        counterM++;
                        int k = mpoly.Count;
                        for (int j = 0; j < k; j++)
                        {
                            Vector3 start = new Vector3((float)mpoly[j].X, (float)mpoly[j].Y - counter * 1.2f - counterM * 0.05f, (float)mpoly[j].Z);
                            Vector3 end   = new Vector3((float)mpoly[(j + 1) % k].X, (float)mpoly[(j + 1) % k].Y - counter * 1.2f - counterM * 0.05f, (float)mpoly[(j + 1) % k].Z);
                            bmp.AddLine(start, end);
                        }
                    }

                    if (counter > 0 && this.subpolygonEdges.Count > counter - 1)
                    {
                        this.subpolygonEdges[counter - 1].Geometry = bmp.ToLineGeometry3D();
                    }
                }
            }


            // 3. triangulate each of the monotone polygons
            List <HelixToolkit.SharpDX.Wpf.MeshGeometry3D> mFills = new List <HelixToolkit.SharpDX.Wpf.MeshGeometry3D>();

            foreach (List <Point3D> mpoly in monPolys)
            {
                List <Vector3> mpoly_V3 = Utils.CommonExtensions.ConvertPoints3DListToVector3List(mpoly);
                HelixToolkit.SharpDX.Wpf.MeshGeometry3D fill = Utils.MeshesCustom.PolygonFillMonotone(mpoly_V3);
                mFills.Add(fill);
            }

            HelixToolkit.SharpDX.Wpf.MeshGeometry3D fillAll = Utils.MeshesCustom.CombineMeshes(mFills);
            this.polygonFill.Geometry      = fillAll;
            this.polygonFillEdges.Geometry = Utils.MeshesCustom.GetEdgesAsLines(fillAll);
        }
Пример #8
0
        /// <summary>
        /// Appends the specified mesh.
        /// </summary>
        /// <param name="mesh">
        /// The mesh.
        /// </param>
        public void Append(MeshGeometry3D mesh)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException("mesh");
            }

            this.Append(mesh.Positions, mesh.Indices, mesh.Normals, mesh.TextureCoordinates);
        }
        /// <summary>
        /// 
        /// </summary>
        public override void Detach()
        {                    
            Disposer.RemoveAndDispose(ref this.vertexBuffer);
            Disposer.RemoveAndDispose(ref this.indexBuffer);
            Disposer.RemoveAndDispose(ref this.instanceBuffer);

            Disposer.RemoveAndDispose(ref this.effectMaterial);
            Disposer.RemoveAndDispose(ref this.effectTransforms);
            Disposer.RemoveAndDispose(ref this.texDiffuseMapView);
            Disposer.RemoveAndDispose(ref this.texNormalMapView);
            Disposer.RemoveAndDispose(ref this.texDisplacementMapView);
            Disposer.RemoveAndDispose(ref this.bHasInstances);            

            this.effectName = null;
            this.phongMaterial = null;
            this.geometry = null;
            this.shaderTechnique = null;
            this.vertexLayout = null;

            base.Detach();
        }