mirror of
https://github.com/overte-org/overte.git
synced 2025-07-22 20:46:42 +02:00
ONe more file to deal with the Model rendering
This commit is contained in:
parent
1799322c67
commit
fd232b7d32
3 changed files with 124 additions and 75 deletions
|
@ -20,13 +20,12 @@
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
#include <ViewFrustum.h>
|
#include <ViewFrustum.h>
|
||||||
#include <render/Scene.h>
|
|
||||||
#include <gpu/Batch.h>
|
|
||||||
|
|
||||||
#include "AbstractViewStateInterface.h"
|
#include "AbstractViewStateInterface.h"
|
||||||
#include "AnimationHandle.h"
|
#include "AnimationHandle.h"
|
||||||
#include "DeferredLightingEffect.h"
|
#include "DeferredLightingEffect.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
#include "ModelRenderPayload.h"
|
||||||
|
|
||||||
#include "model_vert.h"
|
#include "model_vert.h"
|
||||||
#include "model_shadow_vert.h"
|
#include "model_shadow_vert.h"
|
||||||
|
@ -744,79 +743,6 @@ void Model::renderSetup(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class MeshPartPayload {
|
|
||||||
public:
|
|
||||||
MeshPartPayload(Model* model, int meshIndex, int partIndex, int shapeIndex) :
|
|
||||||
model(model), url(model->getURL()), meshIndex(meshIndex), partIndex(partIndex), _shapeID(shapeIndex) { }
|
|
||||||
|
|
||||||
typedef render::Payload<MeshPartPayload> Payload;
|
|
||||||
typedef Payload::DataPointer Pointer;
|
|
||||||
|
|
||||||
Model* model;
|
|
||||||
QUrl url;
|
|
||||||
int meshIndex;
|
|
||||||
int partIndex;
|
|
||||||
int _shapeID;
|
|
||||||
|
|
||||||
// Render Item interface
|
|
||||||
render::Item::Bound getBound() const;
|
|
||||||
void render(RenderArgs* args) const;
|
|
||||||
|
|
||||||
|
|
||||||
mutable render::Item::Bound _bound;
|
|
||||||
mutable bool _isBoundInvalid = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
render::Item::Bound MeshPartPayload::getBound() const {
|
|
||||||
if (_isBoundInvalid) {
|
|
||||||
model->getPartBounds(meshIndex, partIndex);
|
|
||||||
_isBoundInvalid = false;
|
|
||||||
}
|
|
||||||
return _bound;
|
|
||||||
}
|
|
||||||
void MeshPartPayload::render(RenderArgs* args) const {
|
|
||||||
return model->renderPart(args, meshIndex, partIndex, _shapeID);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace render {
|
|
||||||
template <> const ItemKey payloadGetKey(const MeshPartPayload::Pointer& payload) {
|
|
||||||
if (!payload->model->isVisible()) {
|
|
||||||
return ItemKey::Builder().withInvisible().build();
|
|
||||||
}
|
|
||||||
auto geometry = payload->model->getGeometry();
|
|
||||||
if (!geometry.isNull()) {
|
|
||||||
auto drawMaterial = geometry->getShapeMaterial(payload->_shapeID);
|
|
||||||
if (drawMaterial) {
|
|
||||||
auto matKey = drawMaterial->_material->getKey();
|
|
||||||
if (matKey.isTransparent() || matKey.isTransparentMap()) {
|
|
||||||
return ItemKey::Builder::transparentShape();
|
|
||||||
} else {
|
|
||||||
return ItemKey::Builder::opaqueShape();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return opaque for lack of a better idea
|
|
||||||
return ItemKey::Builder::opaqueShape();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> const Item::Bound payloadGetBound(const MeshPartPayload::Pointer& payload) {
|
|
||||||
if (payload) {
|
|
||||||
return payload->getBound();
|
|
||||||
}
|
|
||||||
return render::Item::Bound();
|
|
||||||
}
|
|
||||||
template <> void payloadRender(const MeshPartPayload::Pointer& payload, RenderArgs* args) {
|
|
||||||
return payload->render(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* template <> const model::MaterialKey& shapeGetMaterialKey(const MeshPartPayload::Pointer& payload) {
|
|
||||||
return payload->model->getPartMaterial(payload->meshIndex, payload->partIndex);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void Model::setVisibleInScene(bool newValue, std::shared_ptr<render::Scene> scene) {
|
void Model::setVisibleInScene(bool newValue, std::shared_ptr<render::Scene> scene) {
|
||||||
if (_isVisible != newValue) {
|
if (_isVisible != newValue) {
|
||||||
_isVisible = newValue;
|
_isVisible = newValue;
|
||||||
|
|
55
libraries/render-utils/src/ModelRenderPayload.cpp
Normal file
55
libraries/render-utils/src/ModelRenderPayload.cpp
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
//
|
||||||
|
// ModelRenderPayload.cpp
|
||||||
|
// interface/src/renderer
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/3/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 "ModelRenderPayload.h"
|
||||||
|
|
||||||
|
#include "Model.h"
|
||||||
|
|
||||||
|
using namespace render;
|
||||||
|
|
||||||
|
MeshPartPayload::MeshPartPayload(Model* model, int meshIndex, int partIndex, int shapeIndex) :
|
||||||
|
model(model), url(model->getURL()), meshIndex(meshIndex), partIndex(partIndex), _shapeID(shapeIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
render::ItemKey MeshPartPayload::getKey() const {
|
||||||
|
if (!model->isVisible()) {
|
||||||
|
return ItemKey::Builder().withInvisible().build();
|
||||||
|
}
|
||||||
|
auto geometry = model->getGeometry();
|
||||||
|
if (!geometry.isNull()) {
|
||||||
|
auto drawMaterial = geometry->getShapeMaterial(_shapeID);
|
||||||
|
if (drawMaterial) {
|
||||||
|
auto matKey = drawMaterial->_material->getKey();
|
||||||
|
if (matKey.isTransparent() || matKey.isTransparentMap()) {
|
||||||
|
return ItemKey::Builder::transparentShape();
|
||||||
|
} else {
|
||||||
|
return ItemKey::Builder::opaqueShape();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return opaque for lack of a better idea
|
||||||
|
return ItemKey::Builder::opaqueShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
render::Item::Bound MeshPartPayload::getBound() const {
|
||||||
|
if (_isBoundInvalid) {
|
||||||
|
model->getPartBounds(meshIndex, partIndex);
|
||||||
|
_isBoundInvalid = false;
|
||||||
|
}
|
||||||
|
return _bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshPartPayload::render(RenderArgs* args) const {
|
||||||
|
return model->renderPart(args, meshIndex, partIndex, _shapeID);
|
||||||
|
}
|
||||||
|
|
68
libraries/render-utils/src/ModelRenderPayload.h
Normal file
68
libraries/render-utils/src/ModelRenderPayload.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
// ModelRenderPayload.h
|
||||||
|
// interface/src/renderer
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 10/3/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_ModelRenderPayload_h
|
||||||
|
#define hifi_ModelRenderPayload_h
|
||||||
|
|
||||||
|
#include <render/Scene.h>
|
||||||
|
#include <gpu/Batch.h>
|
||||||
|
|
||||||
|
class Model;
|
||||||
|
|
||||||
|
class MeshPartPayload {
|
||||||
|
public:
|
||||||
|
MeshPartPayload(Model* model, int meshIndex, int partIndex, int shapeIndex);
|
||||||
|
|
||||||
|
typedef render::Payload<MeshPartPayload> Payload;
|
||||||
|
typedef Payload::DataPointer Pointer;
|
||||||
|
|
||||||
|
Model* model;
|
||||||
|
QUrl url;
|
||||||
|
int meshIndex;
|
||||||
|
int partIndex;
|
||||||
|
int _shapeID;
|
||||||
|
|
||||||
|
// Render Item interface
|
||||||
|
render::ItemKey getKey() const;
|
||||||
|
render::Item::Bound getBound() const;
|
||||||
|
void render(RenderArgs* args) const;
|
||||||
|
|
||||||
|
|
||||||
|
mutable render::Item::Bound _bound;
|
||||||
|
mutable bool _isBoundInvalid = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace render {
|
||||||
|
template <> const ItemKey payloadGetKey(const MeshPartPayload::Pointer& payload) {
|
||||||
|
if (payload) {
|
||||||
|
return payload->getKey();
|
||||||
|
}
|
||||||
|
// Return opaque for lack of a better idea
|
||||||
|
return ItemKey::Builder::opaqueShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> const Item::Bound payloadGetBound(const MeshPartPayload::Pointer& payload) {
|
||||||
|
if (payload) {
|
||||||
|
return payload->getBound();
|
||||||
|
}
|
||||||
|
return render::Item::Bound();
|
||||||
|
}
|
||||||
|
template <> void payloadRender(const MeshPartPayload::Pointer& payload, RenderArgs* args) {
|
||||||
|
return payload->render(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* template <> const model::MaterialKey& shapeGetMaterialKey(const MeshPartPayload::Pointer& payload) {
|
||||||
|
return payload->model->getPartMaterial(payload->meshIndex, payload->partIndex);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // hifi_ModelRenderPayload_h
|
Loading…
Reference in a new issue