default mesh collider are generated by default mesh, add camera info serialization, using error info instead of assert to process missing filepath when deserializing scene, move cullface into internal renderer api, fixed dynamic vertex buffer bug

This commit is contained in:
2026-01-19 13:05:24 +08:00
parent 81b52abf0f
commit 323d646611
32 changed files with 646 additions and 307 deletions

View File

@ -5,18 +5,54 @@ namespace Prism
{
public class Entity
{
private Action<float>? m_CollisionBeginCallbacks;
private Action<float>? m_CollisionEndCallbacks;
private Action<float>? m_Collision2DBeginCallbacks;
private Action<float>? m_Collision2DEndCallbacks;
private Action<float>? m_TriggerBeginCallbacks;
private Action<float>? m_TriggerEndCallbacks;
public ulong ID { get; private set; }
~Entity()
{
}
private Action<float>? m_CollisionBeginCallbacks;
private Action<float>? m_CollisionEndCallbacks;
private Action<float>? m_Collision2DBeginCallbacks;
private Action<float>? m_Collision2DEndCallbacks;
private Action<float>? m_TriggerBeginCallbacks;
private Action<float>? m_TriggerEndCallbacks;
public Vec3 Translation
{
get
{
return GetComponent<TransformComponent>().Translation;
}
set
{
GetComponent<TransformComponent>().Translation = value;
}
}
public Vec3 Rotation
{
get
{
return GetComponent<TransformComponent>().Rotation;
}
set
{
GetComponent<TransformComponent>().Rotation = value;
}
}
public Vec3 Scale
{
get
{
return GetComponent<TransformComponent>().Scale;
}
set
{
GetComponent<TransformComponent>().Scale = value;
}
}
protected Entity() { ID = 0; }

View File

@ -9,8 +9,8 @@ namespace Prism
public Vec3 Rotation;
public Vec3 Scale;
public Vec3 Up;
public Vec3 Right;
public Vec3 Forward;
public Vec3 Up { get; }
public Vec3 Right { get; }
public Vec3 Forward { get; }
}
}

View File

@ -8,6 +8,8 @@ namespace Prism
public float X;
public float Y;
public static Vec2 Zero = new Vec2(0.0f, 0.0f);
public Vec2(float scalar)
{
X = Y = scalar;
@ -39,12 +41,34 @@ namespace Prism
return (float)Math.Sqrt(X * X + Y * Y);
}
public Vec2 SafeNormalized()
{
float length = Length();
if (length > float.Epsilon)
{
return new Vec2(X / length, Y / length);
}
else
{
return Zero;
}
}
public Vec2 Normalized()
{
float length = Length();
return new Vec2(X / length, Y / length);
}
public void SafeNormalize()
{
float length = Length();
if (length > float.Epsilon)
{
X = X / length;
Y = Y / length;
}
}
public void Normalize()
{
float length = Length();

View File

@ -73,15 +73,25 @@ namespace Prism
public Vec3 Normalized()
{
float length = Length();
return new Vec3(X / length, Y / length, Z / length);
if (length > float.Epsilon)
{
return new Vec3(X / length, Y / length, Z / length);
}
else
{
return Zero;
}
}
public void Normalize()
{
float length = Length();
X = X / length;
Y = Y / length;
Z = Z / length;
if (length > float.Epsilon)
{
X = X / length;
Y = Y / length;
Z = Z / length;
}
}

View File

@ -33,21 +33,29 @@ namespace Prism
public class TransformComponent : Component
{
private Transform m_Transform;
public Transform Transform { get { return m_Transform; } }
public Vec3 Position
public Transform Transform
{
get
{
GetTransform_Native(Entity.ID, out m_Transform);
return m_Transform.Position;
GetTransform_Native(Entity.ID, out Transform result);
return result;
}
set
{
m_Transform.Position = value;
SetTransform_Native(Entity.ID, ref m_Transform);
SetTransform_Native(Entity.ID, ref value);
}
}
public Vec3 Translation
{
get
{
GetTranslation_Native(Entity.ID, out Vec3 result);
return result;
}
set
{
SetTranslation_Native(Entity.ID, ref value);
}
}
@ -55,13 +63,12 @@ namespace Prism
{
get
{
GetTransform_Native(Entity.ID, out m_Transform);
return m_Transform.Rotation;
GetRotation_Native(Entity.ID, out Vec3 result);
return result;
}
set
{
m_Transform.Rotation = value;
SetTransform_Native(Entity.ID, ref m_Transform);
SetRotation_Native(Entity.ID, ref value);
}
}
@ -69,22 +76,38 @@ namespace Prism
{
get
{
GetTransform_Native(Entity.ID, out m_Transform);
return m_Transform.Scale;
GetScale_Native(Entity.ID, out Vec3 result);
return result;
}
set
{
m_Transform.Scale = value;
SetTransform_Native(Entity.ID, ref m_Transform);
SetScale_Native(Entity.ID, ref value);
}
}
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetTransform_Native(ulong entityID, out Transform result);
internal static extern void GetTransform_Native(ulong entityID, out Transform inTransform);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void SetTransform_Native(ulong entityID, ref Transform result);
internal static extern void SetTransform_Native(ulong entityID, ref Transform outTransform);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetTranslation_Native(ulong entityID, out Vec3 outTranslation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void SetTranslation_Native(ulong entityID, ref Vec3 inTranslation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetRotation_Native(ulong entityID, out Vec3 outRotation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void SetRotation_Native(ulong entityID, ref Vec3 inRotation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetScale_Native(ulong entityID, out Vec3 outScale);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void SetScale_Native(ulong entityID, ref Vec3 inScale);
}
public class MeshComponent : Component