20 , _radius(
std::max( Util::UINT_TO_FLOAT( descriptor.enumValue() ), s_minRadius ) )
21 , _resolution( descriptor.ID() == 0u ? 16u : descriptor.ID() )
22 , _descriptor(descriptor)
26bool Sphere3D::load( PlatformContext& context )
28 const U32 vertexCount =
SQUARED( _resolution );
30 VertexBuffer::Descriptor vbDescriptor{};
31 vbDescriptor._name = resourceName();
32 vbDescriptor._allowDynamicUpdates =
false;
33 vbDescriptor._keepCPUData =
true;
34 vbDescriptor._largeIndices = vertexCount + 1 >
U16_MAX;
36 auto vb = context.gfx().newVB( vbDescriptor );
37 vb->setVertexCount( vertexCount );
38 vb->reserveIndexCount( vertexCount );
41 geometryDirty(
true );
43 if ( !_descriptor.flag() )
45 ResourceDescriptor<Material> matDesc(
"Material_" + resourceName() );
46 matDesc.waitForReady(
true );
49 setMaterialTpl( matTemp );
52 return Object3D::load(context);
55void Sphere3D::setRadius(
const F32 radius)
noexcept
61void Sphere3D::setResolution(
const U32 resolution)
noexcept
63 _resolution = resolution;
68void Sphere3D::rebuildInternal()
70 const U32 slices = _resolution;
71 const U32 stacks = _resolution;
73 geometryBuffer()->reset();
75 const F32 dtheta = 2.0f *
M_PI_f / slices;
76 const F32 ds = 1.0f / slices;
77 const F32 dt = 1.0f / stacks;
81 geometryBuffer()->setVertexCount(stacks * ((slices + 1) * 2));
83 for (
U32 i = 0u; i < stacks; i++) {
84 const F32 rho = i * drho;
85 const F32 srho = std::sin(rho);
86 const F32 crho = std::cos(rho);
87 const F32 srhodrho = std::sin(rho + drho);
88 const F32 crhodrho = std::cos(rho + drho);
94 for (
U32 j = 0; j <= slices; j++) {
95 const F32 theta = j == slices ? 0.0f : j * dtheta;
96 const F32 stheta = -std::sin(theta);
97 const F32 ctheta = std::cos(theta);
99 F32 x = stheta * srho;
100 F32 y = ctheta * srho;
103 geometryBuffer()->modifyPositionValue(index, x * _radius, y * _radius, z * _radius);
104 geometryBuffer()->modifyTexCoordValue(index, s, t);
105 geometryBuffer()->modifyNormalValue(index, x, y, z);
106 geometryBuffer()->addIndex(index++);
108 x = stheta * srhodrho;
109 y = ctheta * srhodrho;
113 geometryBuffer()->modifyPositionValue(index, x * _radius, y * _radius, z * _radius);
114 geometryBuffer()->modifyTexCoordValue(index, s, t - dt);
115 geometryBuffer()->modifyNormalValue(index, x, y, z);
116 geometryBuffer()->addIndex(index++);
124 setBounds(BoundingBox(vec3<F32>(-_radius), vec3<F32>(_radius)));
126 Object3D::rebuildInternal();
129void Sphere3D::saveToXML(boost::property_tree::ptree& pt)
const {
130 pt.put(
"radius", _radius);
131 pt.put(
"resolution", _resolution);
133 Object3D::saveToXML(pt);
136void Sphere3D::loadFromXML(
const boost::property_tree::ptree& pt) {
137 setRadius(pt.get(
"radius", 1.0f));
138 setResolution(pt.get(
"resolution", 16u));
140 Object3D::loadFromXML(pt);
constexpr F32 s_minRadius
Handle console commands that start with a forward slash.
constexpr SceneNodeType GetSceneNodeType()
constexpr T SQUARED(T input) noexcept
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
void efficient_clear(eastl::fixed_vector< T, nodeCount, bEnableOverflow, OverflowAllocator > &fixed_vector)
FORCE_INLINE T * Get(const Handle< T > handle)