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() ? _lodGroups[lodGroup] : 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) { }

}

}

相关推荐
Fireworkitte2 小时前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
weixin-a153003083162 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
DCTANT3 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
Touper.3 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
黄雪超3 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice3 小时前
对象的finalization机制Test
java·开发语言·jvm
望获linux5 小时前
【实时Linux实战系列】CPU 隔离与屏蔽技术
java·linux·运维·服务器·操作系统·开源软件·嵌入式软件
JosieBook5 小时前
【Java编程动手学】使用IDEA创建第一个HelloJava程序
java·开发语言·intellij-idea
Thomas_YXQ5 小时前
Unity3D DOTS场景流式加载技术
java·开发语言·unity
summer夏1235 小时前
2025.07 做什么
java·android studio