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) { }

}

}

相关推荐
名字还没想好☜40 分钟前
Java 线上内存泄漏排查实战:jmap 导堆、MAT 找 GC Roots 与四类常见泄漏
java·开发语言·jvm·内存泄漏
IT爱学堂2 小时前
尚硅谷 - 2025年3月Java+AI大模型应用开发
java·开发语言·人工智能
小贤plus3 小时前
SpringBoot 三大核心注解精讲:@ControllerAdvice、@RestControllerAdvice、@Validated 分组校验(实战)
java
吠品3 小时前
Java byte数组与String互转:编码细节与踩坑记录
java·linux·服务器
晚风醉蝶4 小时前
1-6-插入排序-InsertionSort
java·数据结构·排序算法
yaoxin5211234 小时前
497. Java 反射 - 使用反射读取注解
java·开发语言·python
Lam Tang4 小时前
APS 系列文章 01
java·代理模式
eralong5 小时前
Java 面向对象:继承、多态、接口
java·后端
哦虎!5 小时前
【数据库】事务
java·数据库·mysql
CDN3605 小时前
流媒体加速实践:出海东南亚短视频点播频繁缓冲,HLS 分片与 Nginx 配置调优
java·网络·nginx·流媒体加速