mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
derieve PolyVox Entity from Model Entity
This commit is contained in:
parent
4166c3224f
commit
4b263cf5c8
11 changed files with 157 additions and 9 deletions
|
@ -39,6 +39,7 @@
|
|||
#include "RenderableWebEntityItem.h"
|
||||
#include "RenderableZoneEntityItem.h"
|
||||
#include "RenderableLineEntityItem.h"
|
||||
#include "RenderablePolyVoxEntityItem.h"
|
||||
#include "EntitiesRendererLogging.h"
|
||||
|
||||
EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState,
|
||||
|
@ -65,6 +66,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf
|
|||
REGISTER_ENTITY_TYPE_WITH_FACTORY(ParticleEffect, RenderableParticleEffectEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(PolyVox, RenderablePolyVoxEntityItem::factory)
|
||||
|
||||
_currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID
|
||||
_currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID
|
||||
|
|
|
@ -110,7 +110,7 @@ void RenderableModelEntityItem::remapTextures() {
|
|||
|
||||
void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||
PerformanceTimer perfTimer("RMEIrender");
|
||||
assert(getType() == EntityTypes::Model);
|
||||
assert(getType() == EntityTypes::Model || getType() == EntityTypes::PolyVox);
|
||||
|
||||
bool drawAsModel = hasModel();
|
||||
|
||||
|
@ -199,6 +199,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
RenderableDebugableEntityItem::render(this, args);
|
||||
}
|
||||
|
||||
// virtual
|
||||
Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
||||
Model* result = NULL;
|
||||
|
||||
|
@ -207,11 +208,11 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
|||
_myRenderer = renderer;
|
||||
}
|
||||
assert(_myRenderer == renderer); // you should only ever render on one renderer
|
||||
|
||||
|
||||
if (QThread::currentThread() != _myRenderer->thread()) {
|
||||
return _model;
|
||||
}
|
||||
|
||||
|
||||
_needsModelReload = false; // this is the reload
|
||||
|
||||
// if we have a URL, then we will want to end up returning a model...
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
Model* getModel(EntityTreeRenderer* renderer);
|
||||
virtual Model* getModel(EntityTreeRenderer* renderer);
|
||||
|
||||
bool needsToCallUpdate() const;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
|
||||
virtual bool contains(const glm::vec3& point) const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
void remapTextures();
|
||||
|
||||
Model* _model;
|
||||
|
|
108
libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp
Normal file
108
libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
//
|
||||
// RenderablePolyVoxEntityItem.cpp
|
||||
// libraries/entities-renderer/src/
|
||||
//
|
||||
// Created by Seth Alves on 5/19/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <gpu/GPUConfig.h>
|
||||
|
||||
#include <DeferredLightingEffect.h>
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include <PolyVoxCore/CubicSurfaceExtractorWithNormals.h>
|
||||
#include <PolyVoxCore/MarchingCubesSurfaceExtractor.h>
|
||||
#include <PolyVoxCore/SurfaceMesh.h>
|
||||
#include <PolyVoxCore/SimpleVolume.h>
|
||||
|
||||
#include "EntityTreeRenderer.h"
|
||||
#include "RenderablePolyVoxEntityItem.h"
|
||||
|
||||
EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
return new RenderablePolyVoxEntityItem(entityID, properties);
|
||||
}
|
||||
|
||||
|
||||
void createSphereInVolume(PolyVox::SimpleVolume<uint8_t>& volData, float fRadius) {
|
||||
// This vector hold the position of the center of the volume
|
||||
PolyVox::Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
|
||||
|
||||
// This three-level for loop iterates over every voxel in the volume
|
||||
for (int z = 0; z < volData.getDepth(); z++) {
|
||||
for (int y = 0; y < volData.getHeight(); y++) {
|
||||
for (int x = 0; x < volData.getWidth(); x++) {
|
||||
// Store our current position as a vector...
|
||||
PolyVox::Vector3DFloat v3dCurrentPos(x,y,z);
|
||||
// And compute how far the current position is from the center of the volume
|
||||
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||
|
||||
uint8_t uVoxelValue = 0;
|
||||
|
||||
// If the current voxel is less than 'radius' units from the center then we make it solid.
|
||||
if(fDistToCenter <= fRadius) {
|
||||
// Our new voxel value
|
||||
uVoxelValue = 255;
|
||||
}
|
||||
|
||||
// Wrte the voxel value into the volume
|
||||
volData.setVoxelAt(x, y, z, uVoxelValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// virtual
|
||||
Model* RenderablePolyVoxEntityItem::getModel(EntityTreeRenderer* renderer) {
|
||||
PolyVox::SimpleVolume<uint8_t> volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0),
|
||||
PolyVox::Vector3DInt32(63, 63, 63)));
|
||||
createSphereInVolume(volData, 15);
|
||||
|
||||
// A mesh object to hold the result of surface extraction
|
||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh;
|
||||
|
||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
||||
PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||
(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
// MarchingCubesSurfaceExtractor<SimpleVolume<uint8_t>> surfaceExtractor(&volData,
|
||||
// volData.getEnclosingRegion(),
|
||||
// &mesh);
|
||||
|
||||
//Execute the surface extractor.
|
||||
surfaceExtractor.execute();
|
||||
|
||||
const std::vector<uint32_t>& vecIndices = mesh.getIndices();
|
||||
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices();
|
||||
|
||||
qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------";
|
||||
qDebug() << "---- vecIndices.size() =" << vecIndices.size();
|
||||
qDebug() << "---- vecVertices.size() =" << vecVertices.size();
|
||||
|
||||
|
||||
// [DEBUG] [05/19 20:46:38] ---- vecIndices.size() = 101556
|
||||
// [DEBUG] [05/19 20:46:38] ---- vecVertices.size() = 67704
|
||||
|
||||
|
||||
Model* result = NULL;
|
||||
// make sure our renderer is setup
|
||||
if (!_myRenderer) {
|
||||
_myRenderer = renderer;
|
||||
}
|
||||
assert(_myRenderer == renderer); // you should only ever render on one renderer
|
||||
|
||||
result = _model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL());
|
||||
assert(_model);
|
||||
|
||||
_needsInitialSimulation = true;
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// RenderablePolyVoxEntityItem.h
|
||||
// libraries/entities-renderer/src/
|
||||
//
|
||||
// Created by Seth Alves on 5/19/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_RenderablePolyVoxEntityItem_h
|
||||
#define hifi_RenderablePolyVoxEntityItem_h
|
||||
|
||||
#include <PolyVoxCore/SimpleVolume.h>
|
||||
|
||||
#include "RenderableModelEntityItem.h"
|
||||
#include "RenderableDebugableEntityItem.h"
|
||||
|
||||
class RenderablePolyVoxEntityItem : public RenderableModelEntityItem {
|
||||
public:
|
||||
static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
RenderableModelEntityItem(entityItemID, properties) { }
|
||||
|
||||
virtual bool hasModel() const { return true; }
|
||||
virtual Model* getModel(EntityTreeRenderer* renderer);
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_RenderablePolyVoxEntityItem_h
|
|
@ -14,7 +14,7 @@ target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
|
|||
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
|
||||
|
||||
find_package(PolyVox REQUIRED)
|
||||
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${POLYVOX_INCLUDE_DIRS})
|
||||
target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES})
|
||||
|
||||
link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment)
|
||||
|
|
|
@ -54,6 +54,7 @@ class EntityItemProperties {
|
|||
friend class ZoneEntityItem; // TODO: consider removing this friend relationship and use public methods
|
||||
friend class WebEntityItem; // TODO: consider removing this friend relationship and use public methods
|
||||
friend class LineEntityItem; // TODO: consider removing this friend relationship and use public methods
|
||||
friend class PolyVoxEntityItem; // TODO: consider removing this friend relationship and use public methods
|
||||
public:
|
||||
EntityItemProperties();
|
||||
virtual ~EntityItemProperties();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "WebEntityItem.h"
|
||||
#include "ZoneEntityItem.h"
|
||||
#include "LineEntityItem.h"
|
||||
#include "PolyVoxEntityItem.h"
|
||||
|
||||
QMap<EntityTypes::EntityType, QString> EntityTypes::_typeToNameMap;
|
||||
QMap<QString, EntityTypes::EntityType> EntityTypes::_nameToTypeMap;
|
||||
|
@ -45,6 +46,7 @@ REGISTER_ENTITY_TYPE(Text)
|
|||
REGISTER_ENTITY_TYPE(ParticleEffect)
|
||||
REGISTER_ENTITY_TYPE(Zone)
|
||||
REGISTER_ENTITY_TYPE(Line)
|
||||
REGISTER_ENTITY_TYPE(PolyVox)
|
||||
|
||||
const QString& EntityTypes::getEntityTypeName(EntityType entityType) {
|
||||
QMap<EntityType, QString>::iterator matchedTypeName = _typeToNameMap.find(entityType);
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
Zone,
|
||||
Web,
|
||||
Line,
|
||||
LAST = Line
|
||||
PolyVox,
|
||||
LAST = PolyVox
|
||||
} EntityType;
|
||||
|
||||
static const QString& getEntityTypeName(EntityType entityType);
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
const rgbColor& getColor() const { return _color; }
|
||||
xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; }
|
||||
bool hasModel() const { return !_modelURL.isEmpty(); }
|
||||
virtual bool hasModel() const { return !_modelURL.isEmpty(); }
|
||||
virtual bool hasCompoundShapeURL() const { return !_compoundShapeURL.isEmpty(); }
|
||||
|
||||
static const QString DEFAULT_MODEL_URL;
|
||||
|
|
|
@ -32,7 +32,8 @@ enum ShapeType {
|
|||
SHAPE_TYPE_CYLINDER_X,
|
||||
SHAPE_TYPE_CYLINDER_Y,
|
||||
SHAPE_TYPE_CYLINDER_Z,
|
||||
SHAPE_TYPE_LINE
|
||||
SHAPE_TYPE_LINE,
|
||||
SHAPE_TYPE_POLYVOX
|
||||
};
|
||||
|
||||
class ShapeInfo {
|
||||
|
|
Loading…
Reference in a new issue