Merge pull request #186 from SHADE-DP/S3-6-Gizmos

Added Script.OnDrawGizmos and Gizmos class for debug draw in C#
Also fixed performance issues with Script inspectors and deplushie-ed comments.
This commit is contained in:
XiaoQiDigipen 2022-11-09 14:51:28 +08:00 committed by GitHub
commit 717f82f231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 190 additions and 27 deletions

View File

@ -323,7 +323,7 @@ namespace SHADE
static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere(); static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere();
for (const auto& idx : SPHERE.Indices) for (const auto& idx : SPHERE.Indices)
{ {
spherePoints.emplace_back(SPHERE.VertexPositions[idx]); spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius);
} }
} }
drawLineSet(storage, color, spherePoints.begin(), spherePoints.end()); drawLineSet(storage, color, spherePoints.begin(), spherePoints.end());

View File

@ -97,7 +97,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Removes all Scripts of the specified type from this GameObject. /// Removes all Scripts of the specified type from this GameObject.
/// </summary> /// </summary>
/// <typeparam name="T">Type of PLushieScripts to remove.</typeparam> /// <typeparam name="T">Type of Scripts to remove.</typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();

View File

@ -414,19 +414,10 @@ namespace SHADE
generic<typename Attribute> generic<typename Attribute>
Attribute Editor::hasAttribute(System::Reflection::FieldInfo^ field) Attribute Editor::hasAttribute(System::Reflection::FieldInfo^ field)
{ {
array<System::Object^>^ attributes = field->GetCustomAttributes(true); array<System::Object^>^ attributes = field->GetCustomAttributes(Attribute::typeid, false);
for each (System::Object^ attrib in attributes) if (attributes->Length > 0)
{ {
try return safe_cast<Attribute>(attributes[0]);
{
Attribute attribute = safe_cast<Attribute>(attrib);
if (attribute != nullptr)
return attribute;
}
catch (System::InvalidCastException^)
{
continue;
}
} }
// Failed to find // Failed to find
return Attribute{}; return Attribute{};

View File

@ -39,10 +39,10 @@ namespace SHADE
/// <param name="entity">The Entity to render the Scripts of.</param> /// <param name="entity">The Entity to render the Scripts of.</param>
static void RenderScriptsInInspector(Entity entity); static void RenderScriptsInInspector(Entity entity);
/// <summary> /// <summary>
/// Renders a dropdown button that allows for the addition of PlushieScripts /// Renders a dropdown button that allows for the addition of Scripts onto the
/// onto the specified Entity. /// specified Entity.
/// </summary> /// </summary>
/// <param name="entity">The Entity to add PlushieScripts to.</param> /// <param name="entity">The Entity to add Scripts to.</param>
static void RenderScriptAddButton(Entity entity); static void RenderScriptAddButton(Entity entity);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -20,7 +20,7 @@ namespace SHADE
{ {
/// <summary> /// <summary>
/// Static class that contains the functions for interfacing with the core /// Static class that contains the functions for interfacing with the core
/// PlushieEngine written in C++ for managing the lifecycle of managed code. /// SHADE Engine written in C++ for managing the lifecycle of managed code.
/// </summary> /// </summary>
private ref class EngineInterface abstract sealed private ref class EngineInterface abstract sealed
{ {

View File

@ -210,7 +210,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Removes all Scripts of the specified type from this GameObject. /// Removes all Scripts of the specified type from this GameObject.
/// </summary> /// </summary>
/// <typeparam name="T">Type of PLushieScripts to remove.</typeparam> /// <typeparam name="T">Type of Scripts to remove.</typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();

View File

@ -276,4 +276,4 @@ namespace SHADE
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
} // namespace PlushieAPI::Mathematics }

View File

@ -294,4 +294,4 @@ namespace SHADE
{ {
return Vector3(vec); return Vector3(vec);
} }
} // namespace PlushieAPI::Mathematics }

View File

@ -439,4 +439,5 @@ namespace SHADE
/// <param name="vec">Vector2 to convert from.</param> /// <param name="vec">Vector2 to convert from.</param>
static explicit operator Vector3(Vector2 vec); static explicit operator Vector3(Vector2 vec);
}; };
} // namespace PlushieAPI::Mathematics }

View File

@ -3,8 +3,7 @@
\author Tng Kah Wei, kahwei.tng, 390009620 \author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu \par email: kahwei.tng\@digipen.edu
\date Oct 28, 2021 \date Oct 28, 2021
\brief Contains the definition of the functions for the PlushieScript managed \brief Contains the definition of the functions for the Script managed class.
class.
Note: This file is written in C++17/CLI. Note: This file is written in C++17/CLI.

View File

@ -36,7 +36,7 @@ namespace SHADE
/// </summary> /// </summary>
/// <typeparam name="T"> /// <typeparam name="T">
/// Type of script to add. /// Type of script to add.
/// This needs to be a default constructable PlushieScript. /// This needs to be a default constructable Script.
/// </typeparam> /// </typeparam>
/// <param name="entity">The entity to add a script to.</param> /// <param name="entity">The entity to add a script to.</param>
/// <returns>Reference to the script added.</returns> /// <returns>Reference to the script added.</returns>

View File

@ -33,4 +33,4 @@ namespace SHADE
{ {
return nullptr; return nullptr;
} }
} // namespace PlushieAPI }

View File

@ -36,4 +36,4 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override; System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override;
}; };
} // namespace PlushieAPI }

View File

@ -0,0 +1,69 @@
/************************************************************************************//*!
\file Gizmos.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 8, 2022
\brief Contains the definition of the functions for the Convert managed static
class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Gizmos.hxx"
#include "Convert.hxx"
#include "Tools/SHDebugDraw.h"
// External Dependencies
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Public Properties */
/*---------------------------------------------------------------------------------*/
Color Gizmos::Color::get()
{
return defaultColor;
}
void Gizmos::Color::set(SHADE::Color color)
{
defaultColor = color;
}
/*---------------------------------------------------------------------------------*/
/* Debug Draw Functions */
/*---------------------------------------------------------------------------------*/
void Gizmos::DrawLine(Vector3 from, Vector3 to)
{
DrawLine(from, to, defaultColor);
}
void Gizmos::DrawLine(Vector3 from, Vector3 to, SHADE::Color color)
{
SHDebugDraw::Line(Convert::ToNative(color), Convert::ToNative(from), Convert::ToNative(to));
}
void Gizmos::DrawWireCube(Vector3 center, Vector3 extents)
{
DrawWireCube(center, extents, defaultColor);
}
void Gizmos::DrawWireCube(Vector3 center, Vector3 extents, SHADE::Color color)
{
SHDebugDraw::Cube(Convert::ToNative(color), Convert::ToNative(center), Convert::ToNative(extents));
}
void Gizmos::DrawWireSphere(Vector3 center, float radius)
{
DrawWireSphere(center, radius, defaultColor);
}
void Gizmos::DrawWireSphere(Vector3 center, float radius, SHADE::Color color)
{
SHDebugDraw::Sphere(Convert::ToNative(color), Convert::ToNative(center), radius);
}
}

View File

@ -0,0 +1,97 @@
/************************************************************************************//*!
\file Gizmos.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 8, 2022
\brief Contains the definition of the Gizmos static class and the
declaration of its functions.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// Project Includes
#include "Math/Vector3.hxx"
#include "Graphics/Color.hxx"
namespace SHADE
{
/// <summary>
/// Provides functions for implementing debug drawing.
/// </summary>
public value class Gizmos abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Public Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Default colour that will be used for drawing debug primitives if the color
/// parameter is not specified.
/// </summary>
static property Color Color
{
SHADE::Color get();
void set(SHADE::Color color);
}
/*-----------------------------------------------------------------------------*/
/* Debug Draw Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Renders a line between two points in world space.
/// Uses <see cref="Gizmos.Color">Color</see> to render.
/// </summary>
/// <param name="from">First point of the line.</param>
/// <param name="to">Second point of the line.</param>
static void DrawLine(Vector3 from, Vector3 to);
/// <summary>
/// Renders a line between two points in world space.
/// </summary>
/// <param name="from">First point of the line.</param>
/// <param name="to">Second point of the line.</param>
/// <param name="color">Colour of the line.</param>
static void DrawLine(Vector3 from, Vector3 to, SHADE::Color color);
/// <summary>
/// Renders a wireframe cube centered around the position specified in world
/// space.
/// Uses <see cref="Gizmos.Color">Color</see> to render.
/// </summary>
/// <param name="center">Position where the cube wil be centered at.</param>
/// <param name="extents">Size of the rendered cube.</param>
static void DrawWireCube(Vector3 center, Vector3 extents);
/// <summary>
/// Renders a wireframe cube centered around the position specified in world
/// space.
/// </summary>
/// <param name="center">Position where the cube wil be centered at.</param>
/// <param name="extents">Size of the rendered cube.</param>
/// <param name="color">Colour of the cube.</param>
static void DrawWireCube(Vector3 center, Vector3 extents, SHADE::Color color);
/// <summary>
/// Renders a wireframe sphere centered around the position specified in world
/// space.
/// Uses <see cref="Gizmos.Color">Color</see> to render.
/// </summary>
/// <param name="center">Position where the sphere wil be centered at.</param>
/// <param name="radius">Radius of the rendered sphere.</param>
static void DrawWireSphere(Vector3 center, float radius);
/// <summary>
/// Renders a wireframe sphere centered around the position specified in world
/// space.
/// </summary>
/// <param name="center">Position where the sphere wil be centered at.</param>
/// <param name="radius">Radius of the rendered sphere.</param>
/// <param name="color">Colour of the sphere.</param>
static void DrawWireSphere(Vector3 center, float radius, SHADE::Color color);
private:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
static SHADE::Color defaultColor = SHADE::Color::White;
};
}

View File

@ -36,4 +36,10 @@ public class RaccoonShowcase : Script
//Transform.LocalRotation = new Vector3(0.0f, rotation, 0.0f); //Transform.LocalRotation = new Vector3(0.0f, rotation, 0.0f);
//Transform.LocalScale = new Vector3(System.Math.Abs(System.Math.Sin(scale.x)) * originalScale, System.Math.Abs(System.Math.Cos(scale.y)) * originalScale, System.Math.Abs(System.Math.Sin(scale.z)) * originalScale); //Transform.LocalScale = new Vector3(System.Math.Abs(System.Math.Sin(scale.x)) * originalScale, System.Math.Abs(System.Math.Cos(scale.y)) * originalScale, System.Math.Abs(System.Math.Sin(scale.z)) * originalScale);
} }
protected override void onDrawGizmos()
{
Gizmos.DrawLine(new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f));
Gizmos.DrawLine(new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.0f), Color.Red);
}
} }