Videra.Core
0.1.0-alpha.1
See the version list below for details.
dotnet add package Videra.Core --version 0.1.0-alpha.1
NuGet\Install-Package Videra.Core -Version 0.1.0-alpha.1
<PackageReference Include="Videra.Core" Version="0.1.0-alpha.1" />
<PackageVersion Include="Videra.Core" Version="0.1.0-alpha.1" />
<PackageReference Include="Videra.Core" />
paket add Videra.Core --version 0.1.0-alpha.1
#r "nuget: Videra.Core, 0.1.0-alpha.1"
#:package Videra.Core@0.1.0-alpha.1
#addin nuget:?package=Videra.Core&version=0.1.0-alpha.1&prerelease
#tool nuget:?package=Videra.Core&version=0.1.0-alpha.1&prerelease
Videra.Core - 核心渲染模块
平台无关的3D渲染核心,提供抽象接口和通用渲染逻辑。
模块架构
graph TB
subgraph "Graphics"
Engine[VideraEngine<br/>渲染引擎]
Factory[GraphicsBackendFactory<br/>后端工厂]
Object3D[Object3D<br/>3D对象]
Grid[GridRenderer<br/>网格渲染器]
Axis[AxisRenderer<br/>坐标轴渲染器]
end
subgraph "Abstractions"
IBackend[IGraphicsBackend]
IBuffer[IBuffer]
IPipeline[IPipeline]
IFactory[IResourceFactory]
IExecutor[ICommandExecutor]
end
subgraph "Cameras"
OrbitCamera[OrbitCamera<br/>轨道相机]
end
subgraph "Software"
SoftwareBackend[SoftwareBackend<br/>软件渲染]
end
Engine --> IBackend
Engine --> Object3D
Engine --> Grid
Engine --> Axis
Engine --> OrbitCamera
Factory --> IBackend
Factory --> SoftwareBackend
IBackend --> IBuffer
IBackend --> IPipeline
IBackend --> IFactory
IBackend --> IExecutor
核心类说明
VideraEngine
渲染引擎核心,管理场景对象、相机和渲染循环。
public class VideraEngine : IDisposable
{
public OrbitCamera Camera { get; }
public GridRenderer Grid { get; }
public WireframeRenderer Wireframe { get; }
public bool ShowAxis { get; set; }
public bool IsInitialized { get; }
public void Initialize(IGraphicsBackend backend);
public void Resize(uint width, uint height);
public void AddObject(Object3D obj);
public void RemoveObject(Object3D obj);
public void Draw();
}
Object3D
表示场景中的 3D 对象,包含独立的位置 / 旋转 / 缩放变换,以及运行时创建的 GPU 缓冲区资源。
public class Object3D : IDisposable
{
public string Name { get; set; }
public Vector3 Position { get; set; }
public Vector3 Rotation { get; set; }
public Vector3 Scale { get; set; }
public Matrix4x4 WorldMatrix { get; }
public void Initialize(IResourceFactory factory, MeshData mesh, ILogger? logger = null);
public void UpdateUniforms(ICommandExecutor executor);
public void Dispose();
}
渲染流程
sequenceDiagram
participant Engine as VideraEngine
participant Backend as IGraphicsBackend
participant Grid as GridRenderer
participant Axis as AxisRenderer
participant Objects as Object3D[]
Engine->>Backend: BeginFrame()
Backend->>Backend: 清除颜色/深度缓冲
Engine->>Grid: Draw()
Grid->>Backend: 绘制网格线
Engine->>Axis: Draw()
Axis->>Backend: 绘制XYZ轴
loop 每个对象
Engine->>Objects: GetTransform()
Engine->>Backend: 更新Uniform
Engine->>Backend: DrawIndexed()
end
Engine->>Backend: EndFrame()
Backend->>Backend: 呈现到屏幕
抽象接口
IGraphicsBackend
图形后端抽象接口,各平台需实现此接口。
public interface IGraphicsBackend : IDisposable
{
bool IsInitialized { get; }
void Initialize(IntPtr windowHandle, int width, int height);
void Resize(int width, int height);
void BeginFrame();
void EndFrame();
void SetClearColor(Vector4 color);
IResourceFactory GetResourceFactory();
ICommandExecutor GetCommandExecutor();
}
IResourceFactory
资源创建工厂接口。
public interface IResourceFactory
{
IBuffer CreateVertexBuffer(VertexPositionNormalColor[] vertices);
IBuffer CreateVertexBuffer(uint sizeInBytes);
IBuffer CreateIndexBuffer(uint[] indices);
IBuffer CreateIndexBuffer(uint sizeInBytes);
IBuffer CreateUniformBuffer(uint sizeInBytes);
IPipeline CreatePipeline(PipelineDescription description);
IPipeline CreatePipeline(uint vertexSize, bool hasNormals, bool hasColors);
IShader CreateShader(ShaderStage stage, byte[] bytecode, string entryPoint);
IResourceSet CreateResourceSet(ResourceSetDescription description);
}
软件渲染
当硬件加速不可用时,自动回退到CPU软件渲染。
flowchart LR
Input[顶点数据] --> Transform[顶点变换]
Transform --> Rasterize[光栅化]
Rasterize --> Fragment[片段着色]
Fragment --> DepthTest[深度测试]
DepthTest --> Output[帧缓冲]
文件结构
Videra.Core/
├── Cameras/
│ └── OrbitCamera.cs # 轨道相机
├── Geometry/
│ └── VertexPositionNormalColor.cs # 顶点结构
├── Graphics/
│ ├── Abstractions/ # 抽象接口
│ │ ├── IBuffer.cs
│ │ ├── ICommandExecutor.cs
│ │ ├── IGraphicsBackend.cs
│ │ ├── IPipeline.cs
│ │ ├── IResourceFactory.cs
│ │ └── ISoftwareBackend.cs
│ ├── Software/ # 软件渲染实现
│ │ ├── SoftwareBackend.cs
│ │ ├── SoftwareBuffer.cs
│ │ └── ...
│ ├── AxisRenderer.cs
│ ├── CameraUniform.cs
│ ├── GraphicsBackendFactory.cs
│ ├── GridRenderer.cs
│ ├── Object3D.cs
│ └── VideraEngine.cs
└── IO/
└── ModelImporter.cs # 模型导入
验证流程
在仓库根目录使用统一验证入口:
# Unix shell
./verify.sh --configuration Release
# PowerShell
pwsh -File ./verify.ps1 -Configuration Release
如需仅执行 Core 相关测试,可直接运行:
dotnet test tests/Videra.Core.Tests/Videra.Core.Tests.csproj -c Release
dotnet test tests/Videra.Core.IntegrationTests/Videra.Core.IntegrationTests.csproj -c Release
依赖
- .NET 8.0
- System.Numerics.Vectors
- SharpGLTF.Core (模型导入)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Logging (>= 9.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.11)
- Serilog (>= 4.2.0)
- Serilog.Extensions.Logging (>= 8.0.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
- SharpGLTF.Toolkit (>= 1.0.6)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Videra.Core:
| Package | Downloads |
|---|---|
|
Videra.Platform.macOS
macOS Metal backend for Videra, providing native GPU rendering through NSView and CAMetalLayer integration. |
|
|
Videra.Avalonia
Avalonia integration layer for Videra, exposing the VideraView control and coordinating native backend selection across platforms. |
|
|
Videra.Platform.Windows
Windows Direct3D 11 backend for Videra, providing native GPU rendering and resource management for Avalonia-hosted 3D views. |
|
|
Videra.Platform.Linux
Linux Vulkan backend for Videra, providing native GPU rendering for X11-hosted Avalonia 3D views. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-alpha.7 | 60 | 4/18/2026 |
| 0.1.0-alpha.3 | 57 | 4/17/2026 |
| 0.1.0-alpha.1 | 55 | 4/16/2026 |