mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-06 03:54:25 +02:00
rendering wad entity
This commit is contained in:
parent
f3c5e2f321
commit
9dc6846eba
6 changed files with 178 additions and 23 deletions
|
@ -46,6 +46,7 @@
|
|||
#include "RenderableZoneEntityItem.h"
|
||||
#include "RenderableLineEntityItem.h"
|
||||
#include "RenderablePolyVoxEntityItem.h"
|
||||
#include "RenderableQuadEntityItem.h"
|
||||
#include "EntitiesRendererLogging.h"
|
||||
|
||||
#include "DependencyManager.h"
|
||||
|
@ -76,6 +77,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf
|
|||
REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(PolyVox, RenderablePolyVoxEntityItem::factory)
|
||||
REGISTER_ENTITY_TYPE_WITH_FACTORY(Quad, RenderableQuadEntityItem::factory)
|
||||
|
||||
_currentHoverOverEntityID = UNKNOWN_ENTITY_ID;
|
||||
_currentClickingOnEntityID = UNKNOWN_ENTITY_ID;
|
||||
|
|
58
libraries/entities-renderer/src/RenderableQuadEntityItem.cpp
Normal file
58
libraries/entities-renderer/src/RenderableQuadEntityItem.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// RenderableQuadEntityItem.cpp
|
||||
// libraries/entities-renderer/src/
|
||||
//
|
||||
// Created by Eric Levin on 6/22/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 <gpu/Batch.h>
|
||||
#include <GeometryCache.h>
|
||||
|
||||
#include <DeferredLightingEffect.h>
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include "RenderableQuadEntityItem.h"
|
||||
|
||||
EntityItemPointer RenderableQuadEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
return EntityItemPointer(new RenderableQuadEntityItem(entityID, properties));
|
||||
}
|
||||
|
||||
void RenderableQuadEntityItem::updateGeometry() {
|
||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
if (_lineVerticesID == GeometryCache::UNKNOWN_ID) {
|
||||
_lineVerticesID = geometryCache ->allocateID();
|
||||
}
|
||||
if (_pointsChanged) {
|
||||
glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha());
|
||||
geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor);
|
||||
_pointsChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableQuadEntityItem::render(RenderArgs* args) {
|
||||
PerformanceTimer perfTimer("RenderableQuadEntityItem::render");
|
||||
Q_ASSERT(getType() == EntityTypes::Quad);
|
||||
updateGeometry();
|
||||
|
||||
Q_ASSERT(args->_batch);
|
||||
gpu::Batch& batch = *args->_batch;
|
||||
Transform transform = Transform();
|
||||
transform.setTranslation(getPosition());
|
||||
batch.setModelTransform(transform);
|
||||
|
||||
batch._glLineWidth(getLineWidth());
|
||||
if (getLinePoints().size() > 1) {
|
||||
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch);
|
||||
DependencyManager::get<GeometryCache>()->renderVertices(batch, gpu::LINE_STRIP, _lineVerticesID);
|
||||
}
|
||||
batch._glLineWidth(1.0f);
|
||||
|
||||
RenderableDebugableEntityItem::render(this, args);
|
||||
};
|
40
libraries/entities-renderer/src/RenderableQuadEntityItem.h
Normal file
40
libraries/entities-renderer/src/RenderableQuadEntityItem.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// RenderableLineEntityItem.h
|
||||
// libraries/entities-renderer/src/
|
||||
//
|
||||
// Created by Seth Alves on 5/11/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_RenderableQuadEntityItem_h
|
||||
#define hifi_RenderableQuadEntityItem_h
|
||||
|
||||
#include <QuadEntityItem.h>
|
||||
#include "RenderableDebugableEntityItem.h"
|
||||
#include "RenderableEntityItem.h"
|
||||
#include <GeometryCache.h>
|
||||
|
||||
class RenderableQuadEntityItem : public QuadEntityItem {
|
||||
public:
|
||||
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
RenderableQuadEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
QuadEntityItem(entityItemID, properties),
|
||||
_lineVerticesID(GeometryCache::UNKNOWN_ID)
|
||||
{ }
|
||||
|
||||
virtual void render(RenderArgs* args);
|
||||
|
||||
SIMPLE_RENDERABLE();
|
||||
|
||||
protected:
|
||||
void updateGeometry();
|
||||
|
||||
int _lineVerticesID;
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_RenderableQuadEntityItem_h
|
|
@ -442,22 +442,11 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {
|
||||
bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(LineEntityItem&)> actor) {
|
||||
if (!_entityTree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
|
||||
if (!entity) {
|
||||
qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
|
||||
}
|
||||
|
||||
EntityTypes::EntityType entityType = entity->getType();
|
||||
|
||||
if (entityType != EntityTypes::Line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto now = usecTimestampNow();
|
||||
|
||||
LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get());
|
||||
|
@ -475,7 +464,33 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line
|
|||
properties.setLastEdited(now);
|
||||
|
||||
|
||||
queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
|
||||
queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(QuadEntityItem&)> actor) {
|
||||
if (!_entityTree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto now = usecTimestampNow();
|
||||
|
||||
QuadEntityItem* quadEntity = static_cast<QuadEntityItem*>(entity.get());
|
||||
_entityTree->lockForWrite();
|
||||
bool success = actor(*quadEntity);
|
||||
entity->setLastEdited(now);
|
||||
entity->setLastBroadcast(now);
|
||||
_entityTree->unlock();
|
||||
|
||||
_entityTree->lockForRead();
|
||||
EntityItemProperties properties = entity->getProperties();
|
||||
_entityTree->unlock();
|
||||
|
||||
properties.setLinePointsDirty();
|
||||
properties.setLastEdited(now);
|
||||
|
||||
|
||||
queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -498,17 +513,53 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
|||
}
|
||||
|
||||
bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {
|
||||
return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool
|
||||
{
|
||||
return lineEntity.setLinePoints(points);
|
||||
});
|
||||
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
|
||||
if (!entity) {
|
||||
qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
|
||||
}
|
||||
|
||||
EntityTypes::EntityType entityType = entity->getType();
|
||||
|
||||
if (entityType == EntityTypes::Line) {
|
||||
return setPoints(entity, [points](LineEntityItem& lineEntity) -> bool
|
||||
{
|
||||
return lineEntity.setLinePoints(points);
|
||||
});
|
||||
}
|
||||
|
||||
if (entityType == EntityTypes::Quad) {
|
||||
return setPoints(entity, [points](QuadEntityItem& quadEntity) -> bool
|
||||
{
|
||||
return quadEntity.setLinePoints(points);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) {
|
||||
return setPoints(entityID, [point](LineEntityItem& lineEntity) -> bool
|
||||
{
|
||||
return lineEntity.appendPoint(point);
|
||||
});
|
||||
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
|
||||
if (!entity) {
|
||||
qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
|
||||
}
|
||||
|
||||
EntityTypes::EntityType entityType = entity->getType();
|
||||
|
||||
if (entityType == EntityTypes::Line) {
|
||||
return setPoints(entity, [point](LineEntityItem& lineEntity) -> bool
|
||||
{
|
||||
return lineEntity.appendPoint(point);
|
||||
});
|
||||
}
|
||||
|
||||
if (entityType == EntityTypes::Quad) {
|
||||
return setPoints(entity, [point](QuadEntityItem& quadEntity) -> bool
|
||||
{
|
||||
return quadEntity.appendPoint(point);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <RegisteredMetaTypes.h>
|
||||
#include "PolyVoxEntityItem.h"
|
||||
#include "LineEntityItem.h"
|
||||
#include "QuadEntityItem.h"
|
||||
|
||||
#include "EntityEditPacketSender.h"
|
||||
|
||||
|
@ -161,7 +162,8 @@ signals:
|
|||
private:
|
||||
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
||||
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
||||
bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor);
|
||||
bool setPoints(EntityItemPointer entity, std::function<bool(LineEntityItem&)> actor);
|
||||
bool setPoints(EntityItemPointer entity, std::function<bool(QuadEntityItem&)> actor);
|
||||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||
|
||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||
|
|
|
@ -37,7 +37,7 @@ _lineWidth(DEFAULT_LINE_WIDTH),
|
|||
_pointsChanged(true),
|
||||
_points(QVector<glm::vec3>(0))
|
||||
{
|
||||
_type = EntityTypes::Line;
|
||||
_type = EntityTypes::Quad;
|
||||
_created = properties.getCreated();
|
||||
setProperties(properties);
|
||||
|
||||
|
@ -97,6 +97,7 @@ bool QuadEntityItem::appendPoint(const glm::vec3& point) {
|
|||
return false;
|
||||
}
|
||||
_points << point;
|
||||
qDebug()<<"points: " << point;
|
||||
_pointsChanged = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -115,6 +116,7 @@ bool QuadEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
_points = points;
|
||||
_pointsChanged = true;
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue