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

}

}

相关推荐
我命由我1234513 分钟前
Kotlin 数据容器 - List(List 概述、创建 List、List 核心特性、List 元素访问、List 遍历)
java·开发语言·jvm·windows·java-ee·kotlin·list
武子康2 小时前
Java-80 深入浅出 RPC Dubbo 动态服务降级:从雪崩防护到配置中心秒级生效
java·分布式·后端·spring·微服务·rpc·dubbo
YuTaoShao5 小时前
【LeetCode 热题 100】131. 分割回文串——回溯
java·算法·leetcode·深度优先
源码_V_saaskw5 小时前
JAVA图文短视频交友+自营商城系统源码支持小程序+Android+IOS+H5
java·微信小程序·小程序·uni-app·音视频·交友
超浪的晨5 小时前
Java UDP 通信详解:从基础到实战,彻底掌握无连接网络编程
java·开发语言·后端·学习·个人开发
双力臂4046 小时前
Spring Boot 单元测试进阶:JUnit5 + Mock测试与切片测试实战及覆盖率报告生成
java·spring boot·后端·单元测试
Edingbrugh.南空6 小时前
Aerospike与Redis深度对比:从架构到性能的全方位解析
java·开发语言·spring
QQ_4376643147 小时前
C++11 右值引用 Lambda 表达式
java·开发语言·c++
永卿0017 小时前
设计模式-迭代器模式
java·设计模式·迭代器模式
誰能久伴不乏7 小时前
Linux如何执行系统调用及高效执行系统调用:深入浅出的解析
java·服务器·前端