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:
commit
717f82f231
|
@ -323,7 +323,7 @@ namespace SHADE
|
|||
static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere();
|
||||
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());
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Removes all Scripts of the specified type from this GameObject.
|
||||
/// </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
|
||||
void RemoveScript();
|
||||
|
||||
|
|
|
@ -414,19 +414,10 @@ namespace SHADE
|
|||
generic<typename Attribute>
|
||||
Attribute Editor::hasAttribute(System::Reflection::FieldInfo^ field)
|
||||
{
|
||||
array<System::Object^>^ attributes = field->GetCustomAttributes(true);
|
||||
for each (System::Object^ attrib in attributes)
|
||||
array<System::Object^>^ attributes = field->GetCustomAttributes(Attribute::typeid, false);
|
||||
if (attributes->Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Attribute attribute = safe_cast<Attribute>(attrib);
|
||||
if (attribute != nullptr)
|
||||
return attribute;
|
||||
}
|
||||
catch (System::InvalidCastException^)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return safe_cast<Attribute>(attributes[0]);
|
||||
}
|
||||
// Failed to find
|
||||
return Attribute{};
|
||||
|
|
|
@ -39,10 +39,10 @@ namespace SHADE
|
|||
/// <param name="entity">The Entity to render the Scripts of.</param>
|
||||
static void RenderScriptsInInspector(Entity entity);
|
||||
/// <summary>
|
||||
/// Renders a dropdown button that allows for the addition of PlushieScripts
|
||||
/// onto the specified Entity.
|
||||
/// Renders a dropdown button that allows for the addition of Scripts onto the
|
||||
/// specified Entity.
|
||||
/// </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);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace SHADE
|
|||
{
|
||||
/// <summary>
|
||||
/// 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>
|
||||
private ref class EngineInterface abstract sealed
|
||||
{
|
||||
|
|
|
@ -210,7 +210,7 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Removes all Scripts of the specified type from this GameObject.
|
||||
/// </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
|
||||
void RemoveScript();
|
||||
|
||||
|
|
|
@ -276,4 +276,4 @@ namespace SHADE
|
|||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
} // namespace PlushieAPI::Mathematics
|
||||
}
|
||||
|
|
|
@ -294,4 +294,4 @@ namespace SHADE
|
|||
{
|
||||
return Vector3(vec);
|
||||
}
|
||||
} // namespace PlushieAPI::Mathematics
|
||||
}
|
||||
|
|
|
@ -439,4 +439,5 @@ namespace SHADE
|
|||
/// <param name="vec">Vector2 to convert from.</param>
|
||||
static explicit operator Vector3(Vector2 vec);
|
||||
};
|
||||
} // namespace PlushieAPI::Mathematics
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 28, 2021
|
||||
\brief Contains the definition of the functions for the PlushieScript managed
|
||||
class.
|
||||
\brief Contains the definition of the functions for the Script managed class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace SHADE
|
|||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of script to add.
|
||||
/// This needs to be a default constructable PlushieScript.
|
||||
/// This needs to be a default constructable Script.
|
||||
/// </typeparam>
|
||||
/// <param name="entity">The entity to add a script to.</param>
|
||||
/// <returns>Reference to the script added.</returns>
|
||||
|
|
|
@ -33,4 +33,4 @@ namespace SHADE
|
|||
{
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace PlushieAPI
|
||||
}
|
||||
|
|
|
@ -36,4 +36,4 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override;
|
||||
};
|
||||
} // namespace PlushieAPI
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
}
|
|
@ -36,4 +36,10 @@ public class RaccoonShowcase : Script
|
|||
//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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue