20 12, 13, 15, 12, 15, 14,
21 16, 17, 19, 16, 19, 18,
22 20, 21, 23, 20, 23, 22,
33 { 1.0f, -1.0f, -1.0f},
37 { 1.0f, -1.0f, -1.0f},
38 {-1.0f, -1.0f, -1.0f},
42 {-1.0f, -1.0f, -1.0f},
47 {-1.0f, -1.0f, -1.0f},
48 { 1.0f, -1.0f, -1.0f},
59Box3D::Box3D(
const ResourceDescriptor<Box3D>& descriptor )
61 , _descriptor(descriptor)
65bool Box3D::load( PlatformContext& context )
67 constexpr F32 s_minSideLength = 0.0001f;
69 const vec3<F32> targetSize
76 static const vec2<F32> texCoords[4] =
84 static const vec3<F32> normals[] =
95 _halfExtent.set( targetSize / 2);
97 const size_t vertexCount = std::size( vertices );
98 VertexBuffer::Descriptor vbDescriptor{};
99 vbDescriptor._name = resourceName();
100 vbDescriptor._allowDynamicUpdates =
true;
101 vbDescriptor._keepCPUData =
true;
102 vbDescriptor._largeIndices = vertexCount + 1 >
U16_MAX;
104 auto vb = context.gfx().newVB( vbDescriptor );
105 vb->setVertexCount( vertexCount );
106 vb->reserveIndexCount( vertexCount );
108 for (
const U16 idx : indices)
113 for (
U32 i = 0u; i < std::size(vertices); ++i)
115 vb->modifyPositionValue(i, vertices[i] * _halfExtent);
116 vb->modifyTexCoordValue(i, texCoords[i % 4]);
117 vb->modifyNormalValue(i, normals[i / 4]);
121 setBounds(BoundingBox(-_halfExtent, _halfExtent));
123 if ( !_descriptor.flag() )
125 ResourceDescriptor<Material> matDesc(
"Material_" + resourceName() );
126 matDesc.waitForReady(
true );
129 setMaterialTpl( matTemp );
132 return Object3D::load( context );
135void Box3D::setHalfExtent(
const vec3<F32>& halfExtent)
137 _halfExtent = halfExtent;
139 for (
U32 i = 0u; i < std::size(vertices); ++i)
141 geometryBuffer()->modifyPositionValue(i, vertices[i] * _halfExtent);
143 setBounds(BoundingBox(-_halfExtent, _halfExtent));
146void Box3D::fromPoints(
const std::initializer_list<vec3<F32>>& points,
147 const vec3<F32>& halfExtent) {
149 geometryBuffer()->modifyPositionValues(0, points);
150 _halfExtent = halfExtent;
151 setBounds(BoundingBox(-_halfExtent * 0.5f, _halfExtent * 0.5f));
154const vec3<F32>& Box3D::getHalfExtent() const noexcept {
158void Box3D::saveToXML(boost::property_tree::ptree& pt)
const {
159 pt.put(
"halfExtent.<xmlattr>.x", _halfExtent.x);
160 pt.put(
"halfExtent.<xmlattr>.y", _halfExtent.y);
161 pt.put(
"halfExtent.<xmlattr>.z", _halfExtent.z);
163 Object3D::saveToXML(pt);
166void Box3D::loadFromXML(
const boost::property_tree::ptree& pt) {
167 setHalfExtent(vec3<F32>(pt.get(
"halfExtent.<xmlattr>.x", 1.0f),
168 pt.get(
"halfExtent.<xmlattr>.y", 1.0f),
169 pt.get(
"halfExtent.<xmlattr>.z", 1.0f)));
171 Object3D::loadFromXML(pt);
F32 UINT_TO_FLOAT(U32 src)
static const U16 indices[]
static const vec3< F32 > vertices[4 *6]
Handle console commands that start with a forward slash.
constexpr SceneNodeType GetSceneNodeType()
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
FORCE_INLINE T * Get(const Handle< T > handle)