From f6128488625efb81b005a9e450bf6428a32ea59d Mon Sep 17 00:00:00 2001 From: Abdiel Lopez <48071553+PaperPrototype@users.noreply.github.com> Date: Thu, 16 Oct 2025 01:46:52 -0400 Subject: [PATCH 1/3] Added Primitives class --- Prowl.Runtime/Primitives.cs | 96 +++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Prowl.Runtime/Primitives.cs diff --git a/Prowl.Runtime/Primitives.cs b/Prowl.Runtime/Primitives.cs new file mode 100644 index 00000000..48bbb7ca --- /dev/null +++ b/Prowl.Runtime/Primitives.cs @@ -0,0 +1,96 @@ +using System.Runtime.CompilerServices; +using Prowl.Runtime.Resources; +using Prowl.Vector; + +namespace Prowl.Runtime; + +public static class Primitives +{ + private static Material _standardMaterial; + private static Mesh _cubeMesh; + private static Mesh _cylinderMesh; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject Cube(string name, Double3 size) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + + // game object + var (go, ren) = Cube(name, size, _standardMaterial, _cubeMesh); + + return go; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject Cube(string name, Double3 size, Material material) + { + _cubeMesh ??= Mesh.CreateCube(Double3.One); + + // game object + var (go, ren) = Cube(name, size, material, _cubeMesh); + + return go; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static (GameObject, MeshRenderer) Cube(string name, Double3 size, Material material, Mesh mesh) + { + // game object + var go = new GameObject(name); + go.Transform.localScale = size; + + // visuals + var ren = go.AddComponent(); + ren.Mesh = mesh; + ren.Material = material; + + return (go, ren); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject PhysicsCube(string name, Double3 size, bool isStatic = false) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + + // game object + var (go, ren, rb, col) = PhysicsCube(name, size, _standardMaterial, _cubeMesh, isStatic); + rb.IsStatic = isStatic; + + return go; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject PhysicsCube(string name, Double3 size, Material material, bool isStatic = false) + { + _cubeMesh ??= Mesh.CreateCube(Double3.One); + + // game object + var (go, ren, rb, col) = PhysicsCube(name, size, material, _cubeMesh, isStatic); + rb.IsStatic = isStatic; + + return go; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static (GameObject, MeshRenderer, Rigidbody3D, BoxCollider) PhysicsCube(string name, Double3 size, Material material, Mesh mesh, bool isStatic = false) + { + // game object + var go = new GameObject(name); + go.Transform.localScale = size; + + // visuals + var ren = go.AddComponent(); + ren.Mesh = mesh; + ren.Material = material; + + // physics + var rb = go.AddComponent(); + rb.IsStatic = isStatic; + var col = go.AddComponent(); + // col.Size = size; // <- boxCollider is scaled with gameobject, no need to scale it here + + return (go, ren, rb, col); + } +} \ No newline at end of file From abf8d300d69f45b18cdd10dad6c653fb2f98aace Mon Sep 17 00:00:00 2001 From: Abdiel Lopez <48071553+PaperPrototype@users.noreply.github.com> Date: Thu, 16 Oct 2025 02:04:43 -0400 Subject: [PATCH 2/3] Cleanup API and remove tuples syntax --- Prowl.Runtime/Primitives.cs | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/Prowl.Runtime/Primitives.cs b/Prowl.Runtime/Primitives.cs index 48bbb7ca..1af3c0fe 100644 --- a/Prowl.Runtime/Primitives.cs +++ b/Prowl.Runtime/Primitives.cs @@ -15,26 +15,18 @@ public static GameObject Cube(string name, Double3 size) { _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); _cubeMesh ??= Mesh.CreateCube(Double3.One); - - // game object - var (go, ren) = Cube(name, size, _standardMaterial, _cubeMesh); - - return go; + return Cube(name, size, _standardMaterial, _cubeMesh); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static GameObject Cube(string name, Double3 size, Material material) { _cubeMesh ??= Mesh.CreateCube(Double3.One); - - // game object - var (go, ren) = Cube(name, size, material, _cubeMesh); - - return go; + return Cube(name, size, material, _cubeMesh); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static (GameObject, MeshRenderer) Cube(string name, Double3 size, Material material, Mesh mesh) + public static GameObject Cube(string name, Double3 size, Material material, Mesh mesh) { // game object var go = new GameObject(name); @@ -45,7 +37,7 @@ public static (GameObject, MeshRenderer) Cube(string name, Double3 size, Materia ren.Mesh = mesh; ren.Material = material; - return (go, ren); + return go; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -53,28 +45,18 @@ public static GameObject PhysicsCube(string name, Double3 size, bool isStatic = { _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); _cubeMesh ??= Mesh.CreateCube(Double3.One); - - // game object - var (go, ren, rb, col) = PhysicsCube(name, size, _standardMaterial, _cubeMesh, isStatic); - rb.IsStatic = isStatic; - - return go; + return PhysicsCube(name, size, _standardMaterial, _cubeMesh, isStatic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static GameObject PhysicsCube(string name, Double3 size, Material material, bool isStatic = false) { _cubeMesh ??= Mesh.CreateCube(Double3.One); - - // game object - var (go, ren, rb, col) = PhysicsCube(name, size, material, _cubeMesh, isStatic); - rb.IsStatic = isStatic; - - return go; + return PhysicsCube(name, size, material, _cubeMesh, isStatic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static (GameObject, MeshRenderer, Rigidbody3D, BoxCollider) PhysicsCube(string name, Double3 size, Material material, Mesh mesh, bool isStatic = false) + public static GameObject PhysicsCube(string name, Double3 size, Material material, Mesh mesh, bool isStatic = false) { // game object var go = new GameObject(name); @@ -91,6 +73,6 @@ public static (GameObject, MeshRenderer, Rigidbody3D, BoxCollider) PhysicsCube(s var col = go.AddComponent(); // col.Size = size; // <- boxCollider is scaled with gameobject, no need to scale it here - return (go, ren, rb, col); + return go; } } \ No newline at end of file From 261884779d294e69905ff8e9a4aa6b01f44b378a Mon Sep 17 00:00:00 2001 From: Abdiel Lopez <48071553+PaperPrototype@users.noreply.github.com> Date: Thu, 16 Oct 2025 02:52:27 -0400 Subject: [PATCH 3/3] rename size to scale, added position field, added more overloads --- Prowl.Runtime/Primitives.cs | 75 +++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/Prowl.Runtime/Primitives.cs b/Prowl.Runtime/Primitives.cs index 1af3c0fe..d77b9b17 100644 --- a/Prowl.Runtime/Primitives.cs +++ b/Prowl.Runtime/Primitives.cs @@ -1,3 +1,4 @@ +using System; using System.Runtime.CompilerServices; using Prowl.Runtime.Resources; using Prowl.Vector; @@ -9,28 +10,53 @@ public static class Primitives private static Material _standardMaterial; private static Mesh _cubeMesh; private static Mesh _cylinderMesh; - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject Cube(string name) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return Cube(name, Double3.Zero, Double3.One, _standardMaterial, _cubeMesh); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject Cube(Double3 position) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return Cube(position.ToString(), position, Double3.One, _standardMaterial, _cubeMesh); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject Cube(string name, Double3 position) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return Cube(name, position, Double3.One, _standardMaterial, _cubeMesh); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject Cube(string name, Double3 size) + public static GameObject Cube(string name, Double3 position, Double3 scale) { _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); _cubeMesh ??= Mesh.CreateCube(Double3.One); - return Cube(name, size, _standardMaterial, _cubeMesh); + return Cube(name, position, scale, _standardMaterial, _cubeMesh); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject Cube(string name, Double3 size, Material material) + public static GameObject Cube(string name, Double3 position, Double3 scale, Material material) { _cubeMesh ??= Mesh.CreateCube(Double3.One); - return Cube(name, size, material, _cubeMesh); + return Cube(name, scale, position, material, _cubeMesh); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject Cube(string name, Double3 size, Material material, Mesh mesh) + public static GameObject Cube(string name, Double3 position, Double3 scale, Material material, Mesh mesh) { // game object var go = new GameObject(name); - go.Transform.localScale = size; + go.Transform.position = position; + go.Transform.localScale = scale; // visuals var ren = go.AddComponent(); @@ -41,25 +67,50 @@ public static GameObject Cube(string name, Double3 size, Material material, Mesh } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject PhysicsCube(string name, Double3 size, bool isStatic = false) + public static GameObject PhysicsCube(string name, bool isStatic = false) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return PhysicsCube(name, Double3.Zero, Double3.One, _standardMaterial, _cubeMesh, isStatic); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject PhysicsCube(Double3 position, bool isStatic = false) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return PhysicsCube(position.ToString(), position, Double3.One, _standardMaterial, _cubeMesh, isStatic); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject PhysicsCube(string name, Double3 position, bool isStatic = false) + { + _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); + _cubeMesh ??= Mesh.CreateCube(Double3.One); + return PhysicsCube(name, position, Double3.One, _standardMaterial, _cubeMesh, isStatic); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static GameObject PhysicsCube(string name, Double3 position, Double3 size, bool isStatic = false) { _standardMaterial ??= new Material(Shader.LoadDefault(DefaultShader.Standard)); _cubeMesh ??= Mesh.CreateCube(Double3.One); - return PhysicsCube(name, size, _standardMaterial, _cubeMesh, isStatic); + return PhysicsCube(name, position, size, _standardMaterial, _cubeMesh, isStatic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject PhysicsCube(string name, Double3 size, Material material, bool isStatic = false) + public static GameObject PhysicsCube(string name, Double3 position, Double3 size, Material material, bool isStatic = false) { _cubeMesh ??= Mesh.CreateCube(Double3.One); - return PhysicsCube(name, size, material, _cubeMesh, isStatic); + return PhysicsCube(name, position, size, material, _cubeMesh, isStatic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static GameObject PhysicsCube(string name, Double3 size, Material material, Mesh mesh, bool isStatic = false) + public static GameObject PhysicsCube(string name, Double3 position, Double3 size, Material material, Mesh mesh, bool isStatic = false) { // game object var go = new GameObject(name); + go.Transform.position = position; go.Transform.localScale = size; // visuals