VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
skinBatchInstance.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// SkinBatchInstance — matrix palette manager for dynamic batching.
5//
6//
7//
8// Holds references to the GraphNode of each original mesh instance in a
9// dynamic batch. Each frame, updateMatrices() packs their world transforms
10// into a flat float4x4 array (the "palette"). The renderer binds this
11// palette at Metal buffer slot 6; the vertex shader indexes into it via
12// per-vertex boneIndex to transform vertices on the GPU.
13//
14// DEVIATION: Standalone class, not extending SkinInstance (which is an
15// empty stub). Uses a Metal buffer instead of upstream's RGBA32F bone
16// texture for simpler shader code and idiomatic Metal usage.
17//
18#pragma once
19
20#include <cstring>
21#include <vector>
22
23#include "scene/graphNode.h"
24
25namespace visutwin::canvas
26{
28 {
29 public:
32 explicit SkinBatchInstance(std::vector<GraphNode*> nodes);
33
37 void updateMatrices();
38
40 [[nodiscard]] const float* paletteData() const { return _palette.data(); }
41
43 [[nodiscard]] size_t paletteSizeBytes() const { return _palette.size() * sizeof(float); }
44
46 [[nodiscard]] int boneCount() const { return static_cast<int>(_nodes.size()); }
47
48 private:
49 std::vector<GraphNode*> _nodes;
50 std::vector<float> _palette; // N x 16 floats (float4x4 per bone)
51 };
52
53} // namespace visutwin::canvas
int boneCount() const
Number of bones (= number of original mesh instances).
const float * paletteData() const
CPU-side palette data: N * 16 floats (float4x4 per node).
SkinBatchInstance(std::vector< GraphNode * > nodes)
size_t paletteSizeBytes() const
Total byte size of the palette (for setVertexBytes).