wpf游戏引擎下的Geometry实现

1.Geometry.cs

using PrimalEditor.Common;

using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Printing.IndexedProperties;

using System.Text;

using System.Threading.Tasks;

namespace PrimalEditor.Content

{

enum PrimitiveMeshType

{

Plane,

Cube,

UvSphere,

IcoSphere,

Cylinder,

Capsule

}

class Mesh : ViewModelBase

{

private int _vertexSize;

public int VertexSize

{

get => _vertexSize;

set

{

if (_vertexSize != value)

{

_vertexSize = value;

OnPropertyChanged(nameof(VertexSize));

}

}

}

private int _vertexCount;

public int VertexCount

{

get => _vertexCount;

set

{

if (_vertexCount != value)

{

_vertexCount = value;

OnPropertyChanged(nameof(VertexCount));

}

}

}

private int _indexSize;

public int IndexSize

{

get => _indexSize;

set

{

if (_indexSize != value)

{

_indexSize = value;

OnPropertyChanged(nameof(IndexSize));

}

}

}

private int _indexCount;

public int IndexCount

{

get => _indexCount;

set

{

if (_indexCount != value)

{

_indexCount = value;

OnPropertyChanged(nameof(IndexCount));

}

}

}

public byte\[\] Vertices { get; set; }

public byte\[\] Indices { get; set; }

}

class MeshLOD : ViewModelBase

{

private string _name;

public string Name

{

get => _name;

set

{

if (_name != value)

{

_name = value;

OnPropertyChanged(nameof(Name));

}

}

}

private float _lodThreshold;

public float LodThreshold

{

get => _lodThreshold;

set

{

if (_lodThreshold != value)

{

_lodThreshold = value;

OnPropertyChanged(nameof(LodThreshold));

}

}

}

public ObservableCollection<Mesh> Meshes { get; } = new ObservableCollection<Mesh>();

}

class LODGroup : ViewModelBase

{

private string _name;

public string Name

{

get =>_name;

set

{

if (_name != value)

{

_name = value;

OnPropertyChanged(nameof(Name));

}

}

}

public ObservableCollection<MeshLOD> LODs { get; } = new ObservableCollection<MeshLOD> ();

}

class Geometry :Asset

{

private readonly List<LODGroup> _lodGroups = new List<LODGroup> ();

public LODGroup GetLODGroup(int lodGroup = 0)

{

Debug.Assert(lodGroup >= 0 && lodGroup < _lodGroups.Count);

return _lodGroups.Any() ? _lodGroupslodGroup : null;

}

public void FromRawData(byte\[\] data)

{

Debug.Assert(data?.Length > 0);

_lodGroups.Clear ();

using var reader = new BinaryReader(new MemoryStream(data));

//skip scene name string

var s = reader.ReadInt32();

reader.BaseStream.Position += s;

//get number of LODs

var numLODGroups = reader.ReadUInt32();

Debug.Assert (numLODGroups > 0);

for (int i = 0; i < numLODGroups; ++i)

{

s = reader.ReadInt32();

string lodGroupName;

if (s > 0)

{

var nameBytes = reader.ReadBytes(s);

lodGroupName = Encoding.UTF8.GetString(nameBytes);

}

else

{

lodGroupName = $"lod_{ContentHelper.GetRandomString()}";

}

//get number of meshes in this LOD group

var numMeshes = reader.ReadUInt32();

Debug.Assert (numMeshes > 0);

}

}

public override IEnumerable<string> Save(string file)

{

throw new NotImplementedException();

}

public Geometry() : base(AssetType.Mesh) { }

}

}

相关推荐
是苏浙14 小时前
Java实现链表1
java·开发语言
未若君雅裁14 小时前
上传数据安全:对称加密、非对称加密、签名与重放防护
java·安全
可乐ea14 小时前
【Spring Boot + MyBatis|第7篇】JWT 登录认证与拦截器实现
java·spring boot·后端·mybatis·状态模式
步步为营DotNet14 小时前
借助 C# 14 特性强化 .NET 后端数据验证的深度实践
java·c#·.net
西安邮电大学15 小时前
有关栈的经典算法题
java·后端·其他·算法·面试
手握风云-15 小时前
ProtoBuf:从序列化原理到高性能架构底座(一)
java·网络·架构
摇滚侠15 小时前
SpringMVC 入门到实战 配置类替换 XML 配置文件 86-91
xml·java·后端·spring·maven·intellij-idea
栗子~~15 小时前
金融场景下BigDecimal 运算规范 + 常用场景使用 + 数据库字段设计详解
java·数据库·金融
我登哥MVP15 小时前
SpringCloud Alibaba 核心组件解析:服务注册与发现(Nacos)
java·spring boot·后端·spring·spring cloud·java-ee·maven
兰令水15 小时前
leecodecode【单调栈】【2026.6.12打卡-java版本】
java·开发语言·算法