VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
meshInstance.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers 21.12.2025.
5//
6#include "meshInstance.h"
7
8namespace visutwin::canvas
9{
10 static BoundingBox _tmpAabb;
11
13 : _material(material), _mesh(mesh), _node(node)
14 {
15 }
16
18 {
19 // Use specified world space aabb
20 if (!_updateAabb) {
21 return _aabb;
22 }
23
24 // Callback function returning world space aabb
25 if (_updateAabbFunc) {
26 return _updateAabbFunc(_aabb);
27 }
28
29 // Use local space override aabb if specified
30 BoundingBox* localAabb = _customAabb;
31 bool toWorldSpace = (localAabb != nullptr);
32
33 // Otherwise evaluate local aabb
34 if (!localAabb) {
35 localAabb = &_tmpAabb;
36
37 if (_skinInstance) {
38 // Note: skinned AABB calculation not yet implemented.
39 // Requires accessing bone AABBs and transforming them.
40 toWorldSpace = true;
41 } else if (_node && (_aabbVer != _node->aabbVer() || (_mesh && _aabbMeshVer != _mesh->aabbVer()))) {
42 // Local space bounding box from mesh
43 if (_mesh) {
44 localAabb->setCenter(_mesh->aabb().center());
45 localAabb->setHalfExtents(_mesh->aabb().halfExtents());
46 } else {
47 localAabb->setCenter(0, 0, 0);
48 localAabb->setHalfExtents(0, 0, 0);
49 }
50
51 // Note: morph target AABB expansion not yet implemented.
52 // if (_mesh && _mesh->morph) {
53 // const BoundingBox& morphAabb = _mesh->morph->aabb;
54 // localAabb->_expand(morphAabb.getMin(), morphAabb.getMax());
55 // }
56
57 toWorldSpace = true;
58 if (_node) {
59 _aabbVer = _node->aabbVer();
60 }
61 if (_mesh) {
62 _aabbMeshVer = _mesh->aabbVer();
63 }
64 }
65 }
66
67 // Store world space bounding box
68 if (toWorldSpace && _node) {
69 _aabb.setFromTransformedAabb(*localAabb, _node->worldTransform());
70 }
71
72 return _aabb;
73 }
74}
Axis-Aligned Bounding Box defined by center and half-extents.
Definition boundingBox.h:21
void setHalfExtents(const Vector3 &halfExtents)
Definition boundingBox.h:36
void setCenter(const Vector3 &center)
Definition boundingBox.h:28
Hierarchical scene graph node with local/world transforms and parent-child relationships.
Definition graphNode.h:28
Base class for GPU materials — owns uniform data, texture bindings, blend/depth state,...
Definition material.h:143
GPU-resident geometry defined by vertex/index buffers and one or more Primitives.
Definition mesh.h:79
Material * material() const
MeshInstance(Mesh *mesh, Material *material, GraphNode *node=nullptr)