vsg 1.1.13
VulkanSceneGraph library
Loading...
Searching...
No Matches
InstanceNode.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2025 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/core/Array.h>
16#include <vsg/maths/sphere.h>
17#include <vsg/nodes/Compilable.h>
18#include <vsg/state/BufferInfo.h>
19
20namespace vsg
21{
22
33 class VSG_DECLSPEC InstanceNode : public Inherit<Compilable, InstanceNode>
34 {
35 public:
36 InstanceNode();
37 InstanceNode(const InstanceNode& rhs, const CopyOp& copyop = {});
38
39 uint32_t firstInstance = 0;
40 uint32_t instanceCount = 0;
41
42 vsg::ref_ptr<BufferInfo> translations;
46
47 void setTranslations(vsg::ref_ptr<vec3Array> data) { translations = BufferInfo::create(data); }
48 vsg::ref_ptr<vec3Array> getTranslations() { return (translations && translations->data) ? translations->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
49 const vsg::ref_ptr<vec3Array> getTranslations() const { return (translations && translations->data) ? translations->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
50
51 void setRotations(vsg::ref_ptr<quatArray> data) { rotations = BufferInfo::create(data); }
52 vsg::ref_ptr<quatArray> getRotations() { return (rotations && rotations->data) ? rotations->data.cast<quatArray>() : vsg::ref_ptr<quatArray>{}; }
53 const vsg::ref_ptr<quatArray> getRotations() const { return (rotations && rotations->data) ? rotations->data.cast<quatArray>() : vsg::ref_ptr<quatArray>{}; }
54
55 void setScales(vsg::ref_ptr<vec3Array> data) { scales = BufferInfo::create(data); }
56 vsg::ref_ptr<vec3Array> getScales() { return (scales && scales->data) ? scales->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
57 const vsg::ref_ptr<vec3Array> getScales() const { return (scales && scales->data) ? scales->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
58
59 void setColors(vsg::ref_ptr<vec3Array> data) { colors = BufferInfo::create(data); }
60 vsg::ref_ptr<vec3Array> getColors() { return (colors && colors->data) ? colors->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
61 const vsg::ref_ptr<vec3Array> getColors() const { return (colors && colors->data) ? colors->data.cast<vec3Array>() : vsg::ref_ptr<vec3Array>{}; }
62
64
65 public:
66 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return InstanceNode::create(*this, copyop); }
67 int compare(const Object& rhs) const override;
68
69 void traverse(Visitor& visitor) override { child->accept(visitor); }
70 void traverse(ConstVisitor& visitor) const override { child->accept(visitor); }
71 void traverse(RecordTraversal& visitor) const override { child->accept(visitor); }
72
73 void read(Input& input) override;
74 void write(Output& output) const override;
75
76 void compile(Context& context) override;
77
78 protected:
79 virtual ~InstanceNode();
80 };
81 VSG_type_name(vsg::InstanceNode);
82
83} // namespace vsg
Definition ConstVisitor.h:179
Definition Object.h:42
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition InstanceNode.h:66
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition Object.h:60
Definition Visitor.h:179
Definition ref_ptr.h:22