コード例 #1
0
        /// <summary>
        /// internal.
        /// </summary>
        internal static void Renew()
        {
            if (MeshIndices.Count > 0)
            {
                xyzf[] _Colors = null;
                if ((MeshColors != null) && (MeshColors.Count == MeshVertices.Count))
                {
                    _Colors = MeshColors.ToArray();
                }
                xyf[] TextureCoords = null;
                if (MeshTextureCoords.Count > 0)
                {
                    TextureCoords = MeshTextureCoords.ToArray();
                }


                CompiledMesh M = new CompiledMesh(MeshIndices.ToArray(), MeshVertices.ToArray(), MeshNormals.ToArray(), TextureCoords, _Colors);
                // sollte nur im snap modus passieren
                M.SnapObject = Selector.StoredSnapItems.Count - 1;
                M.PenWidth   = PenWidth;
                M.Mode       = MeshMode;
                M.Material   = Material;
                M.PenColor   = Emission;
                M.PenStyle   = PenStyle;
                M.Texture    = Texture;
                MeshListCurrent.Progs.Add(M);
                MeshMode = PolygonMode.Fill;
                if (Selector.RegisterSnap)
                {
                    Selector.SnapMesh.Progs.Add(M);
                }
            }



            PenWidth          = 1;
            MeshVertices      = new List <xyzf>();
            MeshNormals       = new List <xyzf>();
            MeshTextureCoords = new List <xyf>();
            MeshIndices       = new List <IndexType>();
            HasMaterial       = false;
            _Material         = Materials.Chrome;
            HasTexture        = false;
            _Texture          = null;
            HasPenWidth       = false;
            _PenWidth         = 1;
            HasEmission       = false;
            _Emission         = System.Drawing.Color.Black;
            HasPenStyle       = false;
            _PenStyle         = PenStyles.Full;
            SnapItem          = null;
            MeshMode          = PolygonMode.Fill;
        }
コード例 #2
0
ファイル: Mesh.cs プロジェクト: unitycoder/Drawing3D
        /// <summary>
        /// overrides the draw method .
        /// </summary>
        /// <param name="Device"></param>
        protected override void OnDraw(OpenGlDevice Device)
        {
            int StoredObject = -1;

            if (Selector.WriteToSnap)
            {
                CompiledMesh C = this as CompiledMesh;
                if (C != null)
                {
                    StoredObject = C.SnapObject;
                }
                Device.Selector.SetObjectNumber(StoredObject);
            }
            Entity.CurrentEntity = this;


            if (Compiling)
            {
                MeshCreator.AddProg(this);
                return;
            }
            float     PW   = Device.PenWidth;
            PenStyles PS   = Device.PenStyle;
            Material  Save = Device.Material;

            if (Mode == PolygonMode.Line)
            {
                Device.PenWidth = PenWidth;
                Device.PenStyle = PenStyle;
                Device.Emission = PenColor;
            }
            else
            {
                Device.Material = Material;
            }
            PolygonMode SavePolygonMode = Device.PolygonMode;

            Device.PolygonMode = Mode;
            if ((VAO >= 0) && (Device.RenderKind == RenderKind.Render))
            {
                OpenGlDevice.CheckError();
                Field C = null;
                if (Colors != null)
                {
                    C = Device.Shader.getvar("ColorEnabled");
                    if (C != null)
                    {
                        C.SetValue(1);
                    }
                }
                GL.BindVertexArray(VAO);
                if (!TesselateOn)
                {
                    GL.DrawElements(Primitives, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0);
                    OpenGlDevice.CheckError();
                }
                else
                {
                    GLShader SaveShader = Device.Shader;
                    Device.Shader = Device.TesselationtShader;
                    if (FieldResolutionFactor == null)
                    {
                        FieldResolutionFactor = Device.Shader.getvar("ResolutionFactor");
                    }
                    if (FieldDispFactor == null)
                    {
                        FieldDispFactor = Device.Shader.getvar("gDispFactor");
                    }
                    if (FieldEyePos == null)
                    {
                        FieldEyePos = Device.Shader.getvar("gEyeWorldPos");
                    }
                    if (FieldDispFactor != null)
                    {
                        FieldDispFactor.SetValue((float)TessDispFactor);
                    }
                    if (FieldEyePos != null)
                    {
                        FieldEyePos.SetValue(Device.Camera.Position);
                    }
                    Device.texture = TessDisplacementMap;
                    //GL.ActiveTexture(TextureUnit.Texture0 + 1);
                    //GL.BindTexture(TextureTarget.Texture2D, TessDisplacementMap.Handle);
                    if (Texture != null)
                    {
                        Device.texture = Texture;
                    }

                    if (FieldResolutionFactor != null)
                    {
                        FieldResolutionFactor.SetValue((float)TessResolutionFactor);
                    }

                    GL.DrawElements(BeginMode.Patches, VBOIndices.IndexArray.Length, DrawElementsType.UnsignedInt, 0);
                    TessDisplacementMap.Hide();
                    Device.Shader  = SaveShader;
                    Device.texture = null;
                }

                GL.BindVertexArray(0);
                if (Colors != null)
                {
                    if (C != null)
                    {
                        C.SetValue(0);
                    }
                }
            }
            else
            {
                if (Primitives == BeginMode.Quads)
                {
                    DrawQuads(Device);
                }
                else
                {
                    Texture SaveTexture = Device.texture;
                    Device.texture = Texture;
                    Device.drawMesh(Indices, VBOPosition.xyzPoints, VBONormals.xyzPoints, VBOTexture.xyPoints, VBOColors.xyzPoints);
                    Device.texture = SaveTexture;
                }
            }
            Device.PolygonMode = SavePolygonMode;
            if (Mode == PolygonMode.Line)
            {
                Device.PenWidth = PW;
                Device.PenStyle = PS;
                Device.Emission = Color.Black;
            }
            Device.Material = Save;
        }