LEAP 71

Automated AI Code generation conversation with ChatGPT

Current time (UTC): 2024-03-29 11:19:57 (UTC) Current local time: 2024-03-29 20:19:57 (+09:00)

Prompt 1

Please create three objects, whose center point is in a equidistant triangle 23mm from each other. A 88mm cube and a 45mm and a 29mm sphere. Create a boolean intersection between the three objects and show (only) the result.

Please include all the code, including the class definition and the static Task function. The function needs to be called ‘Task’, so don’t call it anything else. Please call the class ‘AIExample’.

Do not add placeholder code. It needs to be functional.

Here’s an example code to base your code on:

//
// SPDX-License-Identifier: CC0-1.0
//
// This example code file is released to the public under Creative Commons CC0.
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
//
// To the extent possible under law, LEAP 71 has waived all copyright and
// related or neighboring rights to this PicoGK example code file.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using PicoGK;
using System.Numerics;

namespace PicoGKExamples
{
    ///////////////////////////////////////////////////////////////////////////
    // Below is a static class that implements a single static function
    // that can be called from Library::Go()

    class BooleanShowCase
    {
        public class Sphere : IImplicit
        {
            public Sphere(  float fRadius,
                            Vector3 vecCenter)
            {
                m_fRadius   = fRadius;
                m_vecC      = vecCenter;
                oBB = new BBox3(    vecCenter - new Vector3(fRadius),
                                    vecCenter + new Vector3(fRadius));
            }

            public float fSignedDistance(in Vector3 vecSample)
            {
                Vector3 vecPt = vecSample - m_vecC;
                // Move sample point to origin by subtracting center

                return float.Sqrt(  vecPt.X * vecPt.X +
                                    vecPt.Y * vecPt.Y +
                                    vecPt.Z * vecPt.Z) - m_fRadius;
            }

            public readonly BBox3   oBB;
            float   m_fRadius;
            Vector3 m_vecC;
        }

        public static void Task()
        {
            try
            {
                Library.oViewer().SetGroupMaterial(0, "EE", 0f, 1f);

                Library.oViewer().SetGroupMaterial(1, "FF000033", 0f, 1f);
                // Transparent Red

                Library.oViewer().SetGroupMaterial(2, "00FF0033", 0f, 1f);
                // Transparent Green

                Sphere oSphere1A = new Sphere(20f, new Vector3(-5f, 0, 0));
                Sphere oSphere1B = new Sphere(20f, new Vector3(5f, 0, 0));

                // Boolean Add showcase

                Voxels vox1 = new Voxels(oSphere1A, oSphere1A.oBB);
                vox1.BoolAdd(new Voxels(oSphere1B, oSphere1B.oBB));
                Library.oViewer().Add(vox1);

                Sphere oSphere2A = new Sphere(20f, new Vector3(-5f + 90, 0, 0));
                Sphere oSphere2B = new Sphere(20f, new Vector3(5f + 90, 0, 0));

                // Boolean Subtract showcase

                Voxels vox2A    = new Voxels(oSphere2A, oSphere2A.oBB);
                Voxels vox2B    = new Voxels(oSphere2B, oSphere2B.oBB);

                vox2A.BoolSubtract(vox2B);

                Library.oViewer().Add(vox2A);
                Library.oViewer().Add(vox2B, 1);

                // Boolean Intersect showcase

                Sphere oSphere3A = new Sphere(20f, new Vector3(-5f + 180, 0, 0));
                Sphere oSphere3B = new Sphere(20f, new Vector3(5f + 180, 0, 0));

                Voxels vox3A    = new Voxels(oSphere3A, oSphere3A.oBB);
                Voxels vox3B    = new Voxels(oSphere3B, oSphere3B.oBB);
                Voxels vox3     = new Voxels(vox3A);

                vox3.BoolIntersect(vox3B);

                Library.oViewer().Add(vox3);
                Library.oViewer().Add(vox3A, 2);
                Library.oViewer().Add(vox3B, 2);

                Voxels vox = new Voxels();

                vox.BoolAdd(vox3);
                vox.BoolAdd(vox2A);
                vox.BoolAdd(vox1);

                Mesh msh = new Mesh(vox);
                msh.SaveToStlFile(  Path.Combine(Library.strLogFolder,
                                    "Booleans.stl"));
            }

            catch (Exception e)
            {
                Library.Log($"Failed run example: \n{e.Message}"); ;
            }
        }
    }
}


Response 1

| Response Stats | Tokens | | — | — | | Prompt | 1217 | | Response | 812 | | Total | 2029 |

//
// SPDX-License-Identifier: CC0-1.0
//
// This example code file is released to the public under Creative Commons CC0.
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
//
// To the extent possible under law, LEAP 71 has waived all copyright and
// related or neighboring rights to this PicoGK example code file.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using PicoGK;
using System;
using System.IO;
using System.Numerics;

namespace PicoGKExamples
{
    class AIExample
    {
        public class Cube : IImplicit
        {
            public Cube(float length, Vector3 center)
            {
                Length = length;
                Center = center;
                OBB = new BBox3(center - new Vector3(length / 2f), center + new Vector3(length / 2f));
            }

            public float FSignedDistance(in Vector3 sample)
            {
                Vector3 diff = Vector3.Abs(sample - Center) - new Vector3(Length / 2f);
                return Math.Max(Math.Max(diff.X, diff.Y), diff.Z);
            }

            public readonly BBox3 OBB;
            float Length;
            Vector3 Center;
        }

        public class Sphere : IImplicit
        {
            public Sphere(float radius, Vector3 center)
            {
                Radius = radius;
                Center = center;
                OBB = new BBox3(center - new Vector3(radius), center + new Vector3(radius));
            }

            public float FSignedDistance(in Vector3 sample)
            {
                Vector3 diff = sample - Center;
                return Vector3.Distance(sample, Center) - Radius;
            }

            public readonly BBox3 OBB;
            float Radius;
            Vector3 Center;
        }

        public static void Task()
        {
            try
            {
                Library.oViewer().SetGroupMaterial(0, "EE", 0f, 1f);

                Library.oViewer().SetGroupMaterial(1, "FF000033", 0f, 1f);
                // Transparent Red

                Library.oViewer().SetGroupMaterial(2, "00FF0033", 0f, 1f);
                // Transparent Green

                Vector3 centerA = new Vector3(-23f, 0, 0);
                Vector3 centerB = new Vector3(23f, 0, 0);
                Vector3 centerC = new Vector3(0, 19.814f, 0);

                Cube cube = new Cube(88f, centerA);
                Sphere sphere1 = new Sphere(45f, centerB);
                Sphere sphere2 = new Sphere(29f, centerC);

                Voxels vox1 = new Voxels(cube, cube.OBB);
                Voxels vox2 = new Voxels(sphere1, sphere1.OBB);
                Voxels vox3 = new Voxels(sphere2, sphere2.OBB);

                vox1.BoolIntersect(vox2);
                vox1.BoolIntersect(vox3);

                Library.oViewer().Add(vox1);

                Mesh meshResult = new Mesh(vox1);
                meshResult.SaveToStlFile(Path.Combine(Library.strLogFolder, "Intersection.stl"));
            }
            catch (Exception e)
            {
                Library.Log($"Failed to run example: \n{e.Message}");
            }
        }
    }
}

Prompt 2

The compiler reported the following errors in your code, could you rewrite? Code compilation failed with the following errors

Response 2

| Response Stats | Tokens | | — | — | | Prompt | 2117 | | Response | 899 | | Total | 3016 |

Here is a revised version of the code that addresses the compilation errors:

//
// SPDX-License-Identifier: CC0-1.0
//
// This example code file is released to the public under Creative Commons CC0.
// See https://creativecommons.org/publicdomain/zero/1.0/legalcode
//
// To the extent possible under law, LEAP 71 has waived all copyright and
// related or neighboring rights to this PicoGK example code file.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using PicoGK;
using System;
using System.IO;
using System.Numerics;

namespace PicoGKExamples
{
    class AIExample
    {
        public class Cube : IImplicit
        {
            public Cube(float length, Vector3 center)
            {
                Length = length;
                Center = center;
                OBB = new BBox3(center - new Vector3(length / 2f), center + new Vector3(length / 2f));
            }

            public float fSignedDistance(in Vector3 sample)
            {
                Vector3 diff = Vector3.Abs(sample - Center) - new Vector3(Length / 2f);
                return Math.Max(Math.Max(diff.X, diff.Y), diff.Z);
            }

            public readonly BBox3 OBB;
            float Length;
            Vector3 Center;
        }

        public class Sphere : IImplicit
        {
            public Sphere(float radius, Vector3 center)
            {
                Radius = radius;
                Center = center;
                OBB = new BBox3(center - new Vector3(radius), center + new Vector3(radius));
            }

            public float fSignedDistance(in Vector3 sample)
            {
                Vector3 diff = sample - Center;
                return Vector3.Distance(sample, Center) - Radius;
            }

            public readonly BBox3 OBB;
            float Radius;
            Vector3 Center;
        }

        public static void Task()
        {
            try
            {
                Library.oViewer().SetGroupMaterial(0, "EE", 0f, 1f);

                Library.oViewer().SetGroupMaterial(1, "FF000033", 0f, 1f);
                // Transparent Red

                Library.oViewer().SetGroupMaterial(2, "00FF0033", 0f, 1f);
                // Transparent Green

                Vector3 centerA = new Vector3(-23f, 0, 0);
                Vector3 centerB = new Vector3(23f, 0, 0);
                Vector3 centerC = new Vector3(0, 19.814f, 0);

                Cube cube = new Cube(88f, centerA);
                Sphere sphere1 = new Sphere(45f, centerB);
                Sphere sphere2 = new Sphere(29f, centerC);

                Voxels vox1 = new Voxels(cube, cube.OBB);
                Voxels vox2 = new Voxels(sphere1, sphere1.OBB);
                Voxels vox3 = new Voxels(sphere2, sphere2.OBB);

                Voxels result = new Voxels();
                result.BoolIntersect(vox1);
                result.BoolIntersect(vox2);
                result.BoolIntersect(vox3);

                Library.oViewer().Add(result);

                Mesh meshResult = new Mesh(result);
                meshResult.SaveToStlFile(Path.Combine(Library.strLogFolder, "Intersection.stl"));
            }
            catch (Exception e)
            {
                Library.Log($"Failed to run example: \n{e.Message}");
            }
        }
    }
}

This revised code implements the required fSignedDistance method for both the Cube and Sphere classes to resolve the compilation errors. It creates the three objects, performs a boolean intersection operation on them, and saves the result as an STL file. Let me know if you need further assistance!

Success

Created compilable code in 2 Attempts