Skip to content

Commit

Permalink
fix: remove Gizmo testing code and custom serialization from MeshRend…
Browse files Browse the repository at this point in the history
…erer
  • Loading branch information
sinnwrig committed Oct 3, 2024
1 parent 2027bc5 commit 1ea1469
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions Prowl.Runtime/Components/MeshRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ namespace Prowl.Runtime;

[ExecuteAlways]
[AddComponentMenu($"{FontAwesome6.Tv} Rendering/{FontAwesome6.Shapes} Mesh Renderer")]
public class MeshRenderer : MonoBehaviour, ISerializable, IRenderable
public class MeshRenderer : MonoBehaviour, IRenderable
{
public AssetRef<Mesh> Mesh;
public AssetRef<Material> Material;
public Color MainColor = Color.white;
public PropertyState Properties;

public AssetRef<Texture2D> IconTest;
public PropertyState Properties;

public override void Update()
{
Expand All @@ -23,63 +21,23 @@ public override void Update()

Properties ??= new();

Properties.SetColor("_MainColor", MainColor);
Properties.SetInt("_ObjectID", InstanceID);

RenderPipelines.RenderPipeline.AddRenderable(this);
}

public override void DrawGizmos()
{
Debug.DrawLine(new Vector3(0, 2, 1), new Vector3(0, 2, 3), Color.red);
Debug.DrawTriangle(new Vector3(0, 0, -0.5), new Vector3(0, 1, 0), new Vector3(0, 0, 0.5), Color.green);

Debug.DrawWireCube(new Vector3(0, 5, 0), Vector3.one / 2f, Color.blue);
Debug.DrawCube(new Vector3(0, 5, -5), Vector3.one / 2f, Color.yellow);

Debug.DrawWireSphere(new Vector3(0, 10, -5), 1, Color.cyan);
Debug.DrawSphere(new Vector3(0, 10, 0), 1, Color.magenta);

Debug.DrawWireCone(new Vector3(0, 15, 0), Vector3.up, 1, Color.red);

Debug.DrawArrow(new Vector3(0, 15, 5), new Vector3(0, 0, 1), Color.green);

if (IconTest.IsAvailable)
Debug.DrawIcon(IconTest.Res, new Vector3(0, 20, 0), 1f, Color.white);

}

public SerializedProperty Serialize(Serializer.SerializationContext ctx)
{
SerializedProperty compoundTag = SerializedProperty.NewCompound();
compoundTag.Add("Mesh", Serializer.Serialize(Mesh, ctx));
compoundTag.Add("Material", Serializer.Serialize(Material, ctx));
compoundTag.Add("MainColor", Serializer.Serialize(MainColor, ctx));
return compoundTag;
}

public void Deserialize(SerializedProperty value, Serializer.SerializationContext ctx)
{
Mesh = Serializer.Deserialize<AssetRef<Mesh>>(value["Mesh"], ctx);
Material = Serializer.Deserialize<AssetRef<Material>>(value["Material"], ctx);
MainColor = Serializer.Deserialize<Color>(value["MainColor"], ctx);
}


public Material GetMaterial()
{
return Material.Res;
}


public void GetRenderingData(out PropertyState properties, out IGeometryDrawData drawData, out Matrix4x4 model)
{
drawData = Mesh.Res;
properties = Properties;
model = Transform.localToWorldMatrix;
}


public void GetCullingData(out bool isRenderable, out Bounds bounds)
{
isRenderable = true;
Expand Down

0 comments on commit 1ea1469

Please sign in to comment.