mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-08 23:19:35 +02:00
135 lines
6.3 KiB
C++
135 lines
6.3 KiB
C++
//
|
|
// Sphere3DOverlay.cpp
|
|
// interface/src/ui/overlays
|
|
//
|
|
// Copyright 2014 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 "Sphere3DOverlay.h"
|
|
|
|
#include <DependencyManager.h>
|
|
#include <GeometryCache.h>
|
|
#include <gpu/Batch.h>
|
|
#include <SharedUtil.h>
|
|
|
|
QString const Sphere3DOverlay::TYPE = "sphere";
|
|
|
|
// Sphere overlays should fit inside a cube of the specified dimensions, hence it needs to be a half unit sphere.
|
|
// However, the geometry cache renders a UNIT sphere, so we need to scale down.
|
|
static const float SPHERE_OVERLAY_SCALE = 0.5f;
|
|
|
|
Sphere3DOverlay::Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay) :
|
|
Volume3DOverlay(Sphere3DOverlay)
|
|
{
|
|
}
|
|
|
|
// If Sphere3DOverlay had a getProperty() method then it would go here; do JSDoc here.
|
|
/**jsdoc
|
|
* These are the properties of a <code>sphere</code> {@link Overlays.OverlayType|OverlayType}.
|
|
* @typedef {object} Overlays.SphereProperties
|
|
*
|
|
* @property {string} type=sphere - Has the value <code>"sphere"</code>. <em>Read-only.</em>
|
|
* @property {Vec3Color} color=255,255,255 - The color of the overlay.
|
|
* @property {number} alpha=0.7 - The opacity of the overlay, <code>0.0</code> - <code>1.0</code>.
|
|
* @property {number} pulseMax=0 - The maximum value of the pulse multiplier.
|
|
* @property {number} pulseMin=0 - The minimum value of the pulse multiplier.
|
|
* @property {number} pulsePeriod=1 - The duration of the color and alpha pulse, in seconds. A pulse multiplier value goes from
|
|
* <code>pulseMin</code> to <code>pulseMax</code>, then <code>pulseMax</code> to <code>pulseMin</code> in one period.
|
|
* @property {number} alphaPulse=0 - If non-zero, the alpha of the overlay is pulsed: the alpha value is multiplied by the
|
|
* current pulse multiplier value each frame. If > 0 the pulse multiplier is applied in phase with the pulse period; if < 0
|
|
* the pulse multiplier is applied out of phase with the pulse period. (The magnitude of the property isn't otherwise
|
|
* used.)
|
|
* @property {number} colorPulse=0 - If non-zero, the color of the overlay is pulsed: the color value is multiplied by the
|
|
* current pulse multiplier value each frame. If > 0 the pulse multiplier is applied in phase with the pulse period; if < 0
|
|
* the pulse multiplier is applied out of phase with the pulse period. (The magnitude of the property isn't otherwise
|
|
* used.)
|
|
* @property {boolean} visible=true - If <code>true</code>, the overlay is rendered, otherwise it is not rendered.
|
|
*
|
|
* @property {string} name="" - A friendly name for the overlay.
|
|
* @property {Vec3} position - The position of the overlay center. Synonyms: <code>p1</code>, <code>point</code>, and
|
|
* <code>start</code>.
|
|
* @property {Vec3} localPosition - The local position of the overlay relative to its parent if the overlay has a
|
|
* <code>parentID</code> set, otherwise the same value as <code>position</code>.
|
|
* @property {Quat} rotation - The orientation of the overlay. Synonym: <code>orientation</code>.
|
|
* @property {Quat} localRotation - The orientation of the overlay relative to its parent if the overlay has a
|
|
* <code>parentID</code> set, otherwise the same value as <code>rotation</code>.
|
|
* @property {boolean} isSolid=false - Synonyms: <ode>solid</code>, <code>isFilled</code>, and <code>filled</code>.
|
|
* Antonyms: <code>isWire</code> and <code>wire</code>.
|
|
* @property {boolean} isDashedLine=false - If <code>true</code>, a dashed line is drawn on the overlay's edges. Synonym:
|
|
* <code>dashed</code>.
|
|
* @property {boolean} ignorePickIntersection=false - If <code>true</code>, picks ignore the overlay. <code>ignoreRayIntersection</code> is a synonym.
|
|
* @property {boolean} drawInFront=false - If <code>true</code>, the overlay is rendered in front of other overlays that don't
|
|
* have <code>drawInFront</code> set to <code>true</code>, and in front of entities.
|
|
* @property {boolean} grabbable=false - Signal to grabbing scripts whether or not this overlay can be grabbed.
|
|
* @property {Uuid} parentID=null - The avatar, entity, or overlay that the overlay is parented to.
|
|
* @property {number} parentJointIndex=65535 - Integer value specifying the skeleton joint that the overlay is attached to if
|
|
* <code>parentID</code> is an avatar skeleton. A value of <code>65535</code> means "no joint".
|
|
*
|
|
* @property {Vec3} dimensions - The dimensions of the overlay. Synonyms: <code>scale</code>, <code>size</code>.
|
|
*/
|
|
|
|
void Sphere3DOverlay::render(RenderArgs* args) {
|
|
if (!_renderVisible) {
|
|
return; // do nothing if we're not visible
|
|
}
|
|
|
|
float alpha = getAlpha();
|
|
glm::u8vec3 color = getColor();
|
|
glm::vec4 sphereColor(toGlm(color), alpha);
|
|
|
|
auto batch = args->_batch;
|
|
|
|
if (batch) {
|
|
batch->setModelTransform(getRenderTransform());
|
|
|
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
|
auto shapePipeline = args->_shapePipeline;
|
|
if (!shapePipeline) {
|
|
shapePipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline();
|
|
}
|
|
|
|
if (_isSolid) {
|
|
geometryCache->renderSolidSphereInstance(args, *batch, sphereColor, shapePipeline);
|
|
} else {
|
|
geometryCache->renderWireSphereInstance(args, *batch, sphereColor, shapePipeline);
|
|
}
|
|
}
|
|
}
|
|
|
|
const render::ShapeKey Sphere3DOverlay::getShapeKey() {
|
|
auto builder = render::ShapeKey::Builder();
|
|
if (isTransparent()) {
|
|
builder.withTranslucent();
|
|
}
|
|
if (!getIsSolid()) {
|
|
builder.withUnlit().withDepthBias();
|
|
}
|
|
return builder.build();
|
|
}
|
|
|
|
Sphere3DOverlay* Sphere3DOverlay::createClone() const {
|
|
return new Sphere3DOverlay(this);
|
|
}
|
|
|
|
Transform Sphere3DOverlay::evalRenderTransform() {
|
|
Transform transform = getTransform();
|
|
transform.setScale(1.0f); // ignore inherited scale from SpatiallyNestable
|
|
transform.postScale(getDimensions() * SPHERE_OVERLAY_SCALE);
|
|
|
|
return transform;
|
|
}
|
|
|
|
|
|
scriptable::ScriptableModelBase Sphere3DOverlay::getScriptableModel() {
|
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
|
auto vertexColor = ColorUtils::toVec3(_color);
|
|
scriptable::ScriptableModelBase result;
|
|
if (auto mesh = geometryCache->meshFromShape(GeometryCache::Sphere, vertexColor)) {
|
|
result.objectID = getID();
|
|
result.append(mesh);
|
|
}
|
|
return result;
|
|
}
|