12 #ifndef hifi_RenderablePolyVoxEntityItem_h
13 #define hifi_RenderablePolyVoxEntityItem_h
19 #include <gpu/Forward.h>
20 #include <gpu/Context.h>
21 #include <graphics/Forward.h>
22 #include <graphics/Geometry.h>
23 #include <TextureCache.h>
24 #include <PolyVoxEntityItem.h>
26 #include "RenderableEntityItem.h"
28 namespace render {
namespace entities {
29 class PolyVoxEntityRenderer;
34 enum class PolyVoxState
38 UncompressingFinished,
42 BakingMeshNoCompressFinished,
49 QDebug operator<<(QDebug debug, PolyVoxState state);
51 class RenderablePolyVoxEntityItem :
public PolyVoxEntityItem,
public scriptable::ModelProvider {
52 friend class render::entities::PolyVoxEntityRenderer;
55 static EntityItemPointer factory(
const EntityItemID& entityID,
const EntityItemProperties& properties);
56 RenderablePolyVoxEntityItem(
const EntityItemID& entityItemID);
58 virtual ~RenderablePolyVoxEntityItem();
60 void initializePolyVox();
62 using PolyVoxEntityItem::getVoxel;
63 virtual uint8_t getVoxel(
const ivec3& v)
const override;
65 using PolyVoxEntityItem::setVoxel;
66 virtual bool setVoxel(
const ivec3& v, uint8_t toValue)
override;
68 int getOnCount()
const override {
return _onCount; }
70 virtual bool supportsDetailedIntersection()
const override {
return true; }
71 virtual bool findDetailedRayIntersection(
const glm::vec3& origin,
72 const glm::vec3& direction,
73 const glm::vec3& viewFrustumPos,
74 OctreeElementPointer& element,
77 glm::vec3& surfaceNormal,
78 QVariantMap& extraInfo,
79 bool precisionPicking)
const override;
80 virtual bool findDetailedParabolaIntersection(
const glm::vec3& origin,
81 const glm::vec3& velocity,
82 const vec3& accleration,
83 const glm::vec3& viewFrustumPos,
84 OctreeElementPointer& element,
85 float& parabolicDistance,
87 glm::vec3& surfaceNormal,
88 QVariantMap& extraInfo,
89 bool precisionPicking)
const override;
91 virtual void setVoxelData(
const QByteArray& voxelData)
override;
92 virtual void setVoxelVolumeSize(
const glm::vec3& voxelVolumeSize)
override;
93 virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle)
override;
95 virtual ShapeType getShapeType()
const override;
96 virtual bool isReadyToComputeShape()
const override;
97 virtual void computeShapeInfo(ShapeInfo& info)
override;
100 virtual bool setSphereInVolume(
const vec3& center,
float radius, uint8_t toValue)
override;
101 virtual bool setVoxelInVolume(
const vec3& position, uint8_t toValue)
override;
104 virtual bool setSphere(
const vec3& center,
float radius, uint8_t toValue)
override;
105 virtual bool setCapsule(
const vec3& startWorldCoords,
106 const vec3& endWorldCoords,
107 float radiusWorldCoords,
108 uint8_t toValue)
override;
109 virtual bool setAll(uint8_t toValue)
override;
110 virtual bool setCuboid(
const vec3& lowPosition,
const vec3& cuboidSize,
int toValue)
override;
112 virtual void setXNNeighborID(
const EntityItemID& xNNeighborID)
override;
113 virtual void setYNNeighborID(
const EntityItemID& yNNeighborID)
override;
114 virtual void setZNNeighborID(
const EntityItemID& zNNeighborID)
override;
116 virtual void setXPNeighborID(
const EntityItemID& xPNeighborID)
override;
117 virtual void setYPNeighborID(
const EntityItemID& yPNeighborID)
override;
118 virtual void setZPNeighborID(
const EntityItemID& zPNeighborID)
override;
120 std::shared_ptr<RenderablePolyVoxEntityItem> getXNNeighbor();
121 std::shared_ptr<RenderablePolyVoxEntityItem> getYNNeighbor();
122 std::shared_ptr<RenderablePolyVoxEntityItem> getZNNeighbor();
123 std::shared_ptr<RenderablePolyVoxEntityItem> getXPNeighbor();
124 std::shared_ptr<RenderablePolyVoxEntityItem> getYPNeighbor();
125 std::shared_ptr<RenderablePolyVoxEntityItem> getZPNeighbor();
127 virtual void setRegistrationPoint(
const glm::vec3& value)
override;
129 void setVoxelsFromData(QByteArray uncompressedData, quint16 voxelXSize, quint16 voxelYSize, quint16 voxelZSize);
130 void forEachVoxelValue(
const ivec3& voxelSize, std::function<
void(
const ivec3&, uint8_t)> thunk);
131 QByteArray volDataToArray(quint16 voxelXSize, quint16 voxelYSize, quint16 voxelZSize)
const;
133 void setMesh(graphics::MeshPointer mesh);
134 void setCollisionPoints(ShapeInfo::PointCollection points, AABox box);
136 uint8_t getVoxelInternal(
const ivec3& v)
const;
137 bool setVoxelInternal(
const ivec3& v, uint8_t toValue);
138 void setVoxelMarkNeighbors(
int x,
int y,
int z, uint8_t toValue);
140 void compressVolumeDataFinished(
const QByteArray& voxelData);
141 void neighborXEdgeChanged() {
142 withWriteLock([&] { _updateFromNeighborXEdge =
true; });
145 void neighborYEdgeChanged() {
146 withWriteLock([&] { _updateFromNeighborYEdge =
true; });
149 void neighborZEdgeChanged() {
150 withWriteLock([&] { _updateFromNeighborZEdge =
true; });
154 bool getMeshes(MeshProxyList& result)
override;
155 virtual scriptable::ScriptableModelBase getScriptableModel()
override;
157 virtual void update(
const quint64& now)
override;
158 bool needsToCallUpdate()
const override {
return _updateNeeded; }
161 bool updateOnCount(
const ivec3& v, uint8_t toValue);
163 void changeUpdates(
bool value);
167 void recomputeMesh();
168 void cacheNeighbors();
169 void copyUpperEdgesFromNeighbors();
170 void tellNeighborsToRecopyEdges(
bool force);
171 bool updateDependents();
174 void uncompressVolumeData();
175 void compressVolumeDataAndSendEditPacket();
176 void computeShapeInfoWorker();
180 bool _meshReady{
false };
181 bool _voxelDataDirty{
false };
182 bool _volDataDirty{
false };
183 bool _shapeReady{
false };
184 PolyVoxState _state{ PolyVoxState::Ready };
185 bool _updateNeeded{
true };
187 graphics::MeshPointer _mesh;
189 ShapeInfo _shapeInfo;
191 std::shared_ptr<VoxelVolume> _volData;
194 bool _neighborXNeedsUpdate{
false };
195 bool _neighborYNeedsUpdate{
false };
196 bool _neighborZNeedsUpdate{
false };
198 bool _updateFromNeighborXEdge{
false };
199 bool _updateFromNeighborYEdge{
false };
200 bool _updateFromNeighborZEdge{
false };
203 EntityItemWeakPointer _xNNeighbor;
204 EntityItemWeakPointer _yNNeighbor;
205 EntityItemWeakPointer _zNNeighbor;
206 EntityItemWeakPointer _xPNeighbor;
207 EntityItemWeakPointer _yPNeighbor;
208 EntityItemWeakPointer _zPNeighbor;
211 namespace render {
namespace entities {
213 class PolyVoxEntityRenderer :
public TypedEntityRenderer<RenderablePolyVoxEntityItem> {
214 using Parent = TypedEntityRenderer<RenderablePolyVoxEntityItem>;
215 friend class EntityRenderer;
218 PolyVoxEntityRenderer(
const EntityItemPointer& entity);
220 virtual scriptable::ScriptableModelBase getScriptableModel()
override;
223 virtual ShapeKey getShapeKey()
override;
224 virtual bool isTransparent()
const override;
225 virtual Item::Bound getBound(
RenderArgs* args)
override;
226 virtual bool needsRenderUpdate()
const override;
227 virtual bool needsRenderUpdateFromTypedEntity(
const TypedEntityPointer& entity)
const override;
228 virtual void doRenderUpdateAsynchronousTyped(
const TypedEntityPointer& entity)
override;
229 virtual void doRender(
RenderArgs* args)
override;
232 graphics::MeshPointer _mesh;
233 gpu::BufferPointer _params;
234 std::array<NetworkTexturePointer, 3> _xyzTextures;
235 glm::vec3 _lastVoxelVolumeSize;
236 glm::mat4 _lastVoxelToLocalMatrix;
238 glm::quat _orientation;
239 PolyVoxEntityItem::PolyVoxSurfaceStyle _lastSurfaceStyle{ PolyVoxEntityItem::SURFACE_MARCHING_CUBES };
240 std::array<QString, 3> _xyzTextureUrls;
242 gpu::BufferPointer _colorBuffer{ std::make_shared<gpu::Buffer>(gpu::Buffer::VertexBuffer) };
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: RenderablePolyVoxEntityItem.cpp:185