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

}

}

相关推荐
坐吃山猪1 天前
SpringBoot01-配置文件
java·开发语言
我叫汪枫1 天前
《Java餐厅的待客之道:BIO, NIO, AIO三种服务模式的进化》
java·开发语言·nio
yaoxtao1 天前
java.nio.file.InvalidPathException异常
java·linux·ubuntu
Swift社区1 天前
从 JDK 1.8 切换到 JDK 21 时遇到 NoProviderFoundException 该如何解决?
java·开发语言
DKPT1 天前
JVM中如何调优新生代和老生代?
java·jvm·笔记·学习·spring
phltxy1 天前
JVM——Java虚拟机学习
java·jvm·学习
一线灵1 天前
跨平台游戏引擎 Axmol-2.8.1 发布
junit·游戏引擎
seabirdssss1 天前
使用Spring Boot DevTools快速重启功能
java·spring boot·后端
喂完待续1 天前
【序列晋升】29 Spring Cloud Task 微服务架构下的轻量级任务调度框架
java·spring·spring cloud·云原生·架构·big data·序列晋升