<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OpenTK;
using OpenTK.Graphics.OpenGL; using GL = SamSeifert.GLE.GLR;

namespace SamSeifert.GLE.CAD
{
    public class CadObject : DeleteableObject
    {
        internal bool BoolUseTranslationAndRotation = false;
        public bool BoolDisplay = true;
        internal String _Name = "Untitled";
        internal Matrix4 _Matrix = Matrix4.Identity;
        internal ColorGL _Color = null;

        public CadObject[] Children = new CadObject[0];
        internal Vector3[] Vertices;
        internal Vector3[] Normals;
        internal uint[] Indices;

        private bool _BoolSetupGL3 = false;
        private bool _BoolSetupGL4 = false;
        private int _IntList; // Used to support GL3
        private int _IntInterleaveBufferID; // Used to support GL4
        private int _IntIndicesBufferID; // Used to support GL4

        internal enum GLType { GL3, GL4, UNK };
        internal GLType _GLType = GLType.UNK;

        private bool BoundingSphereNeeded = true;
        private Vector3 BoundingSphereCenter = Vector3.Zero;
        private float BoundingSphereRadius = 0;

        private static int UseColorTracker = 0;
        public static void NoColorOn() { UseColorTracker++; }
        public static void NoColorOff() { UseColorTracker--; }

        internal Action AnonymousDraw = null;

        public CadObject(CadObject[] cos, String name = "Group")
        {
            if (cos != null) this.Children = cos;
            this._Name = name;
        }

        internal CadObject()
        {
        }

        public void setMatrix(ref Matrix4 m)
        {
            this._Matrix = m;
            this.BoolUseTranslationAndRotation = true;
        }

        internal CadObject(Vector3[] verts, Vector3[] norms, String name)
        {
            this._Name = name;
            this.initializeWithVectorsAndNormals(verts, norms);
        }

        public override string ToString()
        {
            return this._Name + " " + this._GLType;
        }

        public void GLDelete()
        {
            if (this.Children.Length > 0)
            {
                foreach (CadObject co in this.Children) co.GLDelete();
            }
            else
            {
                if (this._BoolSetupGL3)
                {
                    this._BoolSetupGL3 = false;
                    GL.DeleteLists(this._IntList, 1);
                }

                if (this._BoolSetupGL4)
                {
                    this._BoolSetupGL4 = false;
                    GL.DeleteBuffers(1, ref this._IntIndicesBufferID);
                    GL.DeleteBuffers(1, ref this._IntInterleaveBufferID);
                    this._IntIndicesBufferID = 0;
                    this._IntInterleaveBufferID = 0;
                }
            }
        }

        internal void initializeWithVectorsAndNormals(Vector3[] v, Vector3[] n)
        {
            uint count;
            if (Helpers.ConsolidateData(v, n, out count, out this.Vertices, out this.Normals, out this.Indices)) this.initialize();
            else this._GLType = GLType.UNK;
        }

        internal void initializeWithVectorsAndNormalsSorted(Vector3[] v, Vector3[] n, uint[] ii)
        {
            this.Vertices = v;
            this.Normals = n;
            this.Indices = ii;

            this.initialize();
        }

        internal void initialize()
        {
            this.GLDelete();

            if (this.Vertices.Length != this.Normals.Length)
            {
                Console.WriteLine("CadObject." + System.Reflection.MethodBase.GetCurrentMethod().Name + " vertices and normals mismatch");
                this._GLType = GLType.UNK;
                return;
            }

            this._BoolSetupGL4 = this.setupGL4();
            if (this._BoolSetupGL4) this._GLType = GLType.GL4;
            else
            {
                this._BoolSetupGL3 = this.setupGL3();
                if (this._BoolSetupGL3) this._GLType = GLType.GL3;
                else this._GLType = GLType.UNK;
            }
        }

        public void setUseTranslationAndRotation(bool arg, bool recursive = true)
        {
            this.BoolUseTranslationAndRotation = arg;
            if (recursive) foreach (var e in this.Children) e.setUseTranslationAndRotation(arg);
        }

        public void setAlpha(float a)
        {
            if (this._Color != null) this._Color.setAlpha(a);
            foreach (var e in this.Children) e.setAlpha(a);
        }

        public void setColor(ColorGL c, bool recursive = true)
        {
            this._Color = c;
            if (recursive) foreach (var e in this.Children) e.setColor(c, recursive);
        }

        public void draw(bool useColor = true)
        {

            if (this.BoolDisplay)
            {
                if (this.BoolUseTranslationAndRotation)
                {
                    GL.PushMatrix();
                    GL.MultMatrix(ref this._Matrix);
                    this.draw2(useColor);
                    GL.PopMatrix();
                }
                else this.draw2(useColor);
            }
        }

        /// <summary>
        /// Checks The Viewport to see if we're inside.
        /// </summary>
        /// <param name="useColor"></param>
        private static bool FilterStuff = false;
        private void draw2(bool useColor)
        {
            if (FilterStuff)
            {
                this.updateBoundingSphere();
<commit_msg>Update CadObject Sanity Render Name<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OpenTK;
using OpenTK.Graphics.OpenGL; using GL = SamSeifert.GLE.GLR;

namespace SamSeifert.GLE.CAD
{
    public class CadObject : DeleteableObject
    {
        internal bool BoolUseTranslationAndRotation = false;
        public bool BoolDisplay = true;
        internal String _Name = "Untitled";
        internal Matrix4 _Matrix = Matrix4.Identity;
        internal ColorGL _Color = null;

        public CadObject[] Children = new CadObject[0];
        internal Vector3[] Vertices;
        internal Vector3[] Normals;
        internal uint[] Indices;

        private bool _BoolSetupGL3 = false;
        private bool _BoolSetupGL4 = false;
        private int _IntList; // Used to support GL3
        private int _IntInterleaveBufferID; // Used to support GL4
        private int _IntIndicesBufferID; // Used to support GL4

        internal enum GLType { GL3, GL4, UNK };
        internal GLType _GLType = GLType.UNK;

        private bool BoundingSphereNeeded = true;
        private Vector3 BoundingSphereCenter = Vector3.Zero;
        private float BoundingSphereRadius = 0;

        private static int UseColorTracker = 0;
        public static void NoColorOn() { UseColorTracker++; }
        public static void NoColorOff() { UseColorTracker--; }

        internal Action AnonymousDraw = null;

        public CadObject(CadObject[] cos, String name = "Group")
        {
            if (cos != null) this.Children = cos;
            this._Name = name;
        }

        internal CadObject()
        {
        }

        public void setMatrix(ref Matrix4 m)
        {
            this._Matrix = m;
            this.BoolUseTranslationAndRotation = true;
        }

        internal CadObject(Vector3[] verts, Vector3[] norms, String name)
        {
            this._Name = name;
            this.initializeWithVectorsAndNormals(verts, norms);
        }

        public override string ToString()
        {
            return this._Name + " " + this._GLType;
        }

        public void GLDelete()
        {
            if (this.Children.Length > 0)
            {
                foreach (CadObject co in this.Children) co.GLDelete();
            }
            else
            {
                if (this._BoolSetupGL3)
                {
                    this._BoolSetupGL3 = false;
                    GL.DeleteLists(this._IntList, 1);
                }

                if (this._BoolSetupGL4)
                {
                    this._BoolSetupGL4 = false;
                    GL.DeleteBuffers(1, ref this._IntIndicesBufferID);
                    GL.DeleteBuffers(1, ref this._IntInterleaveBufferID);
                    this._IntIndicesBufferID = 0;
                    this._IntInterleaveBufferID = 0;
                }
            }
        }

        internal void initializeWithVectorsAndNormals(Vector3[] v, Vector3[] n)
        {
            uint count;
            if (Helpers.ConsolidateData(v, n, out count, out this.Vertices, out this.Normals, out this.Indices)) this.initialize();
            else this._GLType = GLType.UNK;
        }

        internal void initializeWithVectorsAndNormalsSorted(Vector3[] v, Vector3[] n, uint[] ii)
        {
            this.Vertices = v;
            this.Normals = n;
            this.Indices = ii;

            this.initialize();
        }

        internal void initialize()
        {
            this.GLDelete();

            if (this.Vertices.Length != this.Normals.Length)
            {
                Console.WriteLine("CadObject." + System.Reflection.MethodBase.GetCurrentMethod().Name + " vertices and normals mismatch");
                this._GLType = GLType.UNK;
                return;
            }

            this._BoolSetupGL4 = this.setupGL4();
            if (this._BoolSetupGL4) this._GLType = GLType.GL4;
            else
            {
                this._BoolSetupGL3 = this.setupGL3();
                if (this._BoolSetupGL3) this._GLType = GLType.GL3;
                else this._GLType = GLType.UNK;
            }
        }

        public void setUseTranslationAndRotation(bool arg, bool recursive = true)
        {
            this.BoolUseTranslationAndRotation = arg;
            if (recursive) foreach (var e in this.Children) e.setUseTranslationAndRotation(arg);
        }

        public void setAlpha(float a)
        {
            if (this._Color != null) this._Color.setAlpha(a);
            foreach (var e in this.Children) e.setAlpha(a);
        }

        public void setColor(ColorGL c, bool recursive = true)
        {
            this._Color = c;
            if (recursive) foreach (var e in this.Children) e.setColor(c, recursive);
        }

        public void draw(bool useColor = true)
        {

            if (this.BoolDisplay)
            {
                if (this.BoolUseTranslationAndRotation)
                {
                    GL.PushMatrix();
                    GL.MultMatrix(ref this._Matrix);
                    this.draw2(useColor);
                    GL.PopMatrix();
                }
                else this.draw2(useColor);
            }
        }

        /// <summary>
        /// Checks The Viewport to see if we're inside.
        /// Requires using SamSeifert.GLE.GLR everywhere
        /// </summary>
        /// <param name="useColor"></param>
        public static bool RenderOnlyOnscreenObjects = false;
        private void draw2(bool useColor)
        {
            if (CadObject.RenderOnlyOnscreenObjects)
            {
                this.updateBoundingSphere();

{'fraction_non_alphanumeric': 0.08680121450258975, 'fraction_numerical': 0.007858546168958742, 'mean_word_length': 1.575666973321067, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4365798', 'n_tokens_mistral': 3058, 'n_tokens_neox': 2920, 'n_words': 726}