Example #1
0
        void AssertMeshLevelPoint(Vector3 testUnleveled, Vector3 controlLeveled, LevelingFunctions levelingFunctions)
        {
            Vector3 testLeveled = levelingFunctions.GetPositionWithZOffset(testUnleveled);

            Assert.AreEqual(testLeveled.X, testUnleveled.X, .001, "We don't adjust the x or y on mesh leveling");
            Assert.AreEqual(testLeveled.X, controlLeveled.X, .001, "We don't adjust the x or y on mesh leveling");
            Assert.AreEqual(testLeveled.Y, testUnleveled.Y, .001, "We don't adjust the x or y on mesh leveling");
            Assert.AreEqual(testLeveled.Y, controlLeveled.Y, .001, "We don't adjust the x or y on mesh leveling");
            Assert.AreEqual(testLeveled.Z, controlLeveled.Z, .001);
            string outPositionString = levelingFunctions.ApplyLeveling(GetGCodeString(testUnleveled), testUnleveled);

            Assert.AreEqual(GetGCodeString(testLeveled), outPositionString);
        }
Example #2
0
 public static bool AwardExp(TeiravonMobile m, int offset, bool epic)
 {
     if (!epic && m.PlayerLevel >= 20)
     {
         return(false);
     }
     else
     {
         m.PlayerExp += offset;
         LevelingFunctions.CheckLevelUp(m);
         if (epic)
         {
             LevelingFunctions.CheckEpicLevelUp(m);
         }
         return(true);
     }
 }
        private string GetLeveledPosition(string lineBeingSent, PrinterMove currentDestination)
        {
            PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

            if (levelingData != null &&
                printer.Settings?.GetValue <bool>(SettingsKey.print_leveling_enabled) == true &&
                (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 ")))
            {
                if (currentLevelingFunctions == null ||
                    currentProbeZOffset != printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset) ||
                    !levelingData.SamplesAreSame(currentLevelingFunctions.SampledPositions))
                {
                    currentProbeZOffset      = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset);
                    currentLevelingFunctions = new LevelingFunctions(printer, levelingData);
                }

                lineBeingSent = currentLevelingFunctions.ApplyLeveling(lineBeingSent, currentDestination.position);
            }

            return(lineBeingSent);
        }
Example #4
0
        public void RestoreTargetInfo(Mobile target)
        {
            TeiravonMobile m_Restore = target as TeiravonMobile;

            m_Restore.Title     = m_Title;
            m_Restore.PlayerExp = Exp;

            LevelingFunctions.CheckLevelUp(m_Restore);

            m_Restore.RawStr  = Str;
            m_Restore.MaxHits = Hits;
            m_Restore.RawDex  = Dex;
            m_Restore.MaxStam = Stam;
            m_Restore.RawInt  = Int;
            m_Restore.MaxMana = Mana;

            for (int i = 0; i < 51; i++)
            {
                m_Restore.Skills[i].Base = m_Skills[i];
            }
        }
Example #5
0
        public void LevelingMesh3x3CorectInterpolation()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            var printerSettings = new PrinterSettings();

            printerSettings.SetValue(SettingsKey.z_probe_z_offset, "0");

            var printer = new PrinterConfig(printerSettings);

            // a 2 x 2 mesh that goes form 0 on the left to 10 on the right
            {
                var levelingData = new PrintLevelingData();

                // put them in left to right - bottom to top
                levelingData.SampledPositions = new List <Vector3>();
                levelingData.SampledPositions.Add(new Vector3(0, 0, 0));
                levelingData.SampledPositions.Add(new Vector3(10, 0, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 10, 0));
                levelingData.SampledPositions.Add(new Vector3(10, 10, 10));

                LevelingFunctions levelingFunctionsMesh2x2 = new LevelingFunctions(printer, levelingData);

                // check on points
                AssertMeshLevelPoint(new Vector3(0, 0, 0), new Vector3(0, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 0), new Vector3(10, 0, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 0), new Vector3(10, 10, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 0), new Vector3(0, 10, 0), levelingFunctionsMesh2x2);

                // check raised on points
                AssertMeshLevelPoint(new Vector3(0, 0, 5), new Vector3(0, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 5), new Vector3(10, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 5), new Vector3(10, 10, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 5), new Vector3(0, 10, 5), levelingFunctionsMesh2x2);

                // check between points
                AssertMeshLevelPoint(new Vector3(5, 0, 0), new Vector3(5, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(5, 0, 5), new Vector3(5, 0, 10), levelingFunctionsMesh2x2);

                // check outside points
                AssertMeshLevelPoint(new Vector3(-5, 0, 0), new Vector3(-5, 0, -5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(-5, 0, 5), new Vector3(-5, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 0), new Vector3(15, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 5), new Vector3(15, 0, 20), levelingFunctionsMesh2x2);
            }

            // a 3 x 3 mesh that goes form 0 on the left to 10 on the right
            {
                var levelingData = new PrintLevelingData();

                // put them in left to right - bottom to top
                levelingData.SampledPositions = new List <Vector3>();
                levelingData.SampledPositions.Add(new Vector3(0, 0, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 0, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 0, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 5, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 5, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 5, 10));
                levelingData.SampledPositions.Add(new Vector3(0, 10, 0));
                levelingData.SampledPositions.Add(new Vector3(5, 10, 5));
                levelingData.SampledPositions.Add(new Vector3(10, 10, 10));

                LevelingFunctions levelingFunctionsMesh2x2 = new LevelingFunctions(printer, levelingData);

                // check on points
                AssertMeshLevelPoint(new Vector3(0, 0, 0), new Vector3(0, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 0), new Vector3(10, 0, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 0), new Vector3(10, 10, 10), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 0), new Vector3(0, 10, 0), levelingFunctionsMesh2x2);

                // check raised on points
                AssertMeshLevelPoint(new Vector3(0, 0, 5), new Vector3(0, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 0, 5), new Vector3(10, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(10, 10, 5), new Vector3(10, 10, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(0, 10, 5), new Vector3(0, 10, 5), levelingFunctionsMesh2x2);

                // check between points
                AssertMeshLevelPoint(new Vector3(5, 0, 0), new Vector3(5, 0, 5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(5, 0, 5), new Vector3(5, 0, 10), levelingFunctionsMesh2x2);

                // check outside points
                AssertMeshLevelPoint(new Vector3(-5, 0, 0), new Vector3(-5, 0, -5), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(-5, 0, 5), new Vector3(-5, 0, 0), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 0), new Vector3(15, 0, 15), levelingFunctionsMesh2x2);
                AssertMeshLevelPoint(new Vector3(15, 0, 5), new Vector3(15, 0, 20), levelingFunctionsMesh2x2);
            }
        }
        public static Mesh BuildMeshFromLevelingData(PrinterConfig printer)
        {
            var printerShim = ApplicationController.Instance.Shim(printer);
            PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;
            var currentLevelingFunctions   = new LevelingFunctions(printerShim, levelingData);

            var vertices = new List <Vector3Float>();

            var pointCounts = new Dictionary <Vector3Float, int>();

            var points = new int[3];

            var faces = new FaceList();

            // Add top faces
            foreach (var region in currentLevelingFunctions.Regions)
            {
                int i = 0;

                foreach (var point in new[] { new Vector3Float(region.V0), new Vector3Float(region.V1), new Vector3Float(region.V2) })
                {
                    int index = vertices.IndexOf(point);
                    if (index == -1)
                    {
                        index = vertices.Count;
                        vertices.Add(point);
                    }

                    if (!pointCounts.TryGetValue(point, out int pointCount))
                    {
                        pointCount = 0;
                    }

                    pointCounts[point] = pointCount + 1;

                    points[i++] = index;
                }

                faces.Add(new Face(points[0], points[2], points[1], vertices));
            }

            List <Vector3Float> outerPoints = GetOuterPoints(vertices, pointCounts, printer.Bed.BedCenter);

            // Add reflected hull points at the bed - reflected point for item in negative z should be the negative value
            var reflectedVertices = outerPoints.Select(h => new Vector3Float(h.X, h.Y, h.Z > 0 ? 0 : h.Z)).ToList();

            vertices.AddRange(reflectedVertices);

            int lastReflected = vertices.IndexOf(reflectedVertices.Last());

            int currIndex, reflectedIndex, nextIndex = -1;

            var anchorIndex = vertices.IndexOf(reflectedVertices.First());

            // Loop over all outer points, reflecting a point onto the bed and stitching the current, reflect and next points together
            for (var i = 0; i < outerPoints.Count; i++)
            {
                var point     = outerPoints[i];
                var reflected = reflectedVertices[i];

                bool lastIndex = (i == outerPoints.Count - 1);

                Vector3Float nextPoint = lastIndex ? outerPoints.First() : outerPoints[i + 1];

                currIndex      = vertices.IndexOf(point);
                nextIndex      = vertices.IndexOf(nextPoint);
                reflectedIndex = vertices.IndexOf(reflected);

                Face faceA, faceB;

                // Add face back to previous
                faces.Add(faceB = new Face(currIndex, lastReflected, reflectedIndex, vertices));

                // Add face for current
                faces.Add(faceA = new Face(currIndex, reflectedIndex, nextIndex, vertices));

                lastReflected = reflectedIndex;
            }

            // Add bottom faces
            foreach (var region in currentLevelingFunctions.Regions)
            {
                int i = 0;

                foreach (var point in new[] { GetReflected(region.V0), GetReflected(region.V1), GetReflected(region.V2) })
                {
                    int index = vertices.IndexOf(point);
                    if (index == -1)
                    {
                        index = vertices.Count;
                        vertices.Add(point);
                    }

                    points[i++] = index;
                }

                faces.Add(new Face(points[0], points[1], points[2], vertices));
            }

            return(new Mesh(vertices, faces));
        }