vec3 conversion

This commit is contained in:
SamGondelman 2018-07-11 14:18:22 -07:00
parent 5bbd5b9e52
commit 9929529f30
71 changed files with 870 additions and 662 deletions

View file

@ -4748,7 +4748,7 @@ bool Application::exportEntities(const QString& filename,
properties.setParentID(AVATAR_SELF_ID);
} else {
if (parentID.isInvalidID()) {
properties.setPosition(properties.getPosition() - root);
properties.setPosition(properties.getPosition().toGlm() - root);
} else if (!entities.contains(parentID)) {
entityDatum->globalizeProperties(properties, "Parent %3 of %2 %1 is not selected for export.", -root);
} // else valid parent -- don't offset
@ -5396,9 +5396,9 @@ void Application::updateSecondaryCameraViewFrustum() {
if (camera->mirrorProjection && !camera->attachedEntityId.isNull()) {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId);
glm::vec3 mirrorPropertiesPosition = entityProperties.getPosition();
glm::vec3 mirrorPropertiesPosition = entityProperties.getPosition().toGlm();
glm::quat mirrorPropertiesRotation = entityProperties.getRotation();
glm::vec3 mirrorPropertiesDimensions = entityProperties.getDimensions();
glm::vec3 mirrorPropertiesDimensions = entityProperties.getDimensions().toGlm();
glm::vec3 halfMirrorPropertiesDimensions = 0.5f * mirrorPropertiesDimensions;
// setup mirror from world as inverse of world from mirror transformation using inverted x and z for mirrored image
@ -5430,7 +5430,7 @@ void Application::updateSecondaryCameraViewFrustum() {
if (!camera->attachedEntityId.isNull()) {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto entityProperties = entityScriptingInterface->getEntityProperties(camera->attachedEntityId);
secondaryViewFrustum.setPosition(entityProperties.getPosition());
secondaryViewFrustum.setPosition(entityProperties.getPosition().toGlm());
secondaryViewFrustum.setOrientation(entityProperties.getRotation());
} else {
secondaryViewFrustum.setPosition(camera->position);
@ -7270,7 +7270,7 @@ void Application::addAssetToWorldCheckModelSize() {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto properties = entityScriptingInterface->getEntityProperties(entityID, propertyFlags);
auto name = properties.getName();
auto dimensions = properties.getDimensions();
auto dimensions = properties.getDimensions().toGlm();
const QString GRABBABLE_USER_DATA = "{\"grabbableKey\":{\"grabbable\":true}}";
bool doResize = false;

View file

@ -101,12 +101,12 @@ PickResultPointer LaserPointer::getVisualPickResult(const PickResultPointer& pic
registrationPoint = glm::vec3(0.5f);
} else {
EntityItemProperties props = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(_lockEndObject.id);
glm::mat4 entityMat = createMatFromQuatAndPos(props.getRotation(), props.getPosition());
glm::mat4 entityMat = createMatFromQuatAndPos(props.getRotation(), props.getPosition().toGlm());
glm::mat4 finalPosAndRotMat = entityMat * _lockEndObject.offsetMat;
pos = extractTranslation(finalPosAndRotMat);
rot = glmExtractRotation(finalPosAndRotMat);
dim = props.getDimensions();
registrationPoint = props.getRegistrationPoint();
dim = props.getDimensions().toGlm();
registrationPoint = props.getRegistrationPoint().toGlm();
}
const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f);
endVec = pos + rot * (dim * (DEFAULT_REGISTRATION_POINT - registrationPoint));
@ -119,7 +119,7 @@ PickResultPointer LaserPointer::getVisualPickResult(const PickResultPointer& pic
rayPickResult->intersection = endVec;
rayPickResult->distance = distance;
rayPickResult->surfaceNormal = -normalizedDirection;
rayPickResult->pickVariant["direction"] = vec3toVariant(normalizedDirection);
rayPickResult->pickVariant["direction"] = vec3ToVariant(normalizedDirection);
} else if (type != IntersectionType::NONE && _lockEnd) {
if (type == IntersectionType::ENTITY) {
endVec = DependencyManager::get<EntityScriptingInterface>()->getEntityTransform(rayPickResult->objectID)[3];
@ -134,7 +134,7 @@ PickResultPointer LaserPointer::getVisualPickResult(const PickResultPointer& pic
rayPickResult->intersection = endVec;
rayPickResult->distance = distance;
rayPickResult->surfaceNormal = -normalizedDirection;
rayPickResult->pickVariant["direction"] = vec3toVariant(normalizedDirection);
rayPickResult->pickVariant["direction"] = vec3ToVariant(normalizedDirection);
}
}
return visualPickResult;
@ -151,17 +151,17 @@ void LaserPointer::updateRenderStateOverlay(const OverlayID& id, const QVariant&
void LaserPointer::updateRenderState(const RenderState& renderState, const IntersectionType type, float distance, const QUuid& objectID, const PickRay& pickRay) {
if (!renderState.getStartID().isNull()) {
QVariantMap startProps;
startProps.insert("position", vec3toVariant(pickRay.origin));
startProps.insert("position", vec3ToVariant(pickRay.origin));
startProps.insert("visible", true);
startProps.insert("ignoreRayIntersection", renderState.doesStartIgnoreRays());
qApp->getOverlays().editOverlay(renderState.getStartID(), startProps);
}
glm::vec3 endVec = pickRay.origin + pickRay.direction * distance;
QVariant end = vec3toVariant(endVec);
QVariant end = vec3ToVariant(endVec);
if (!renderState.getPathID().isNull()) {
QVariantMap pathProps;
pathProps.insert("start", vec3toVariant(pickRay.origin));
pathProps.insert("start", vec3ToVariant(pickRay.origin));
pathProps.insert("end", end);
pathProps.insert("visible", true);
pathProps.insert("ignoreRayIntersection", renderState.doesPathIgnoreRays());
@ -176,13 +176,13 @@ void LaserPointer::updateRenderState(const RenderState& renderState, const Inter
glm::vec3 dim = vec3FromVariant(qApp->getOverlays().getProperty(renderState.getEndID(), "dimensions").value);
if (_distanceScaleEnd) {
dim = renderState.getEndDim() * glm::distance(pickRay.origin, endVec);
endProps.insert("dimensions", vec3toVariant(dim));
endProps.insert("dimensions", vec3ToVariant(dim));
}
if (_centerEndY) {
endProps.insert("position", end);
} else {
glm::vec3 currentUpVector = faceAvatarRotation * Vectors::UP;
endProps.insert("position", vec3toVariant(endVec + glm::vec3(currentUpVector.x * 0.5f * dim.y, currentUpVector.y * 0.5f * dim.y, currentUpVector.z * 0.5f * dim.y)));
endProps.insert("position", vec3ToVariant(endVec + glm::vec3(currentUpVector.x * 0.5f * dim.y, currentUpVector.y * 0.5f * dim.y, currentUpVector.z * 0.5f * dim.y)));
}
if (_faceAvatar) {
endProps.insert("rotation", quatToVariant(faceAvatarRotation));

View file

@ -65,7 +65,7 @@ glm::vec3 RayPick::intersectRayWithOverlayXYPlane(const QUuid& overlayID, const
glm::vec3 RayPick::intersectRayWithEntityXYPlane(const QUuid& entityID, const glm::vec3& origin, const glm::vec3& direction) {
auto props = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(entityID);
return intersectRayWithXYPlane(origin, direction, props.getPosition(), props.getRotation(), props.getRegistrationPoint());
return intersectRayWithXYPlane(origin, direction, props.getPosition().toGlm(), props.getRotation(), props.getRegistrationPoint().toGlm());
}
glm::vec2 RayPick::projectOntoXYPlane(const glm::vec3& worldPos, const glm::vec3& position, const glm::quat& rotation, const glm::vec3& dimensions, const glm::vec3& registrationPoint, bool unNormalized) {
@ -91,5 +91,5 @@ glm::vec2 RayPick::projectOntoOverlayXYPlane(const QUuid& overlayID, const glm::
glm::vec2 RayPick::projectOntoEntityXYPlane(const QUuid& entityID, const glm::vec3& worldPos, bool unNormalized) {
auto props = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(entityID);
return projectOntoXYPlane(worldPos, props.getPosition(), props.getRotation(), props.getDimensions(), props.getRegistrationPoint(), unNormalized);
return projectOntoXYPlane(worldPos, props.getPosition().toGlm(), props.getRotation(), props.getDimensions().toGlm(), props.getRegistrationPoint().toGlm(), unNormalized);
}

View file

@ -46,8 +46,8 @@ public:
toReturn["intersects"] = intersects;
toReturn["objectID"] = objectID;
toReturn["distance"] = distance;
toReturn["intersection"] = vec3toVariant(intersection);
toReturn["surfaceNormal"] = vec3toVariant(surfaceNormal);
toReturn["intersection"] = vec3ToVariant(intersection);
toReturn["surfaceNormal"] = vec3ToVariant(surfaceNormal);
toReturn["searchRay"] = PickResult::toVariantMap();
toReturn["extraInfo"] = extraInfo;
return toReturn;

View file

@ -44,8 +44,8 @@ public:
toReturn["intersects"] = intersects;
toReturn["objectID"] = objectID;
toReturn["distance"] = distance;
toReturn["intersection"] = vec3toVariant(intersection);
toReturn["surfaceNormal"] = vec3toVariant(surfaceNormal);
toReturn["intersection"] = vec3ToVariant(intersection);
toReturn["surfaceNormal"] = vec3ToVariant(surfaceNormal);
toReturn["stylusTip"] = PickResult::toVariantMap();
return toReturn;
}

View file

@ -74,9 +74,9 @@ void StylusPointer::show(const StylusTip& tip) {
auto modelOrientation = tip.orientation * X_ROT_NEG_90;
auto sensorToWorldScale = DependencyManager::get<AvatarManager>()->getMyAvatar()->getSensorToWorldScale();
auto modelPositionOffset = modelOrientation * (vec3(0.0f, 0.0f, -WEB_STYLUS_LENGTH / 2.0f) * sensorToWorldScale);
props["position"] = vec3toVariant(tip.position + modelPositionOffset);
props["position"] = vec3ToVariant(tip.position + modelPositionOffset);
props["rotation"] = quatToVariant(modelOrientation);
props["dimensions"] = vec3toVariant(sensorToWorldScale * vec3(0.01f, 0.01f, WEB_STYLUS_LENGTH));
props["dimensions"] = vec3ToVariant(sensorToWorldScale * vec3(0.01f, 0.01f, WEB_STYLUS_LENGTH));
props["visible"] = true;
qApp->getOverlays().editOverlay(_stylusOverlay, props);
}

View file

@ -59,7 +59,7 @@ QVariantMap convertOverlayLocationFromScriptSemantics(const QVariantMap& propert
glm::vec3 localPosition = SpatiallyNestable::worldToLocal(vec3FromVariant(result["position"]),
parentID, parentJointIndex, scalesWithParent, success);
if (success) {
result["position"] = vec3toVariant(localPosition);
result["position"] = vec3ToVariant(localPosition);
}
}
@ -112,7 +112,7 @@ void Base3DOverlay::setProperties(const QVariantMap& originalProperties) {
properties["parentJointIndex"] = getParentJointIndex();
}
if (!properties["position"].isValid() && !properties["localPosition"].isValid()) {
properties["position"] = vec3toVariant(getWorldPosition());
properties["position"] = vec3ToVariant(getWorldPosition());
}
if (!properties["orientation"].isValid() && !properties["localOrientation"].isValid()) {
properties["orientation"] = quatToVariant(getWorldOrientation());
@ -240,10 +240,10 @@ QVariant Base3DOverlay::getProperty(const QString& property) {
return _name;
}
if (property == "position" || property == "start" || property == "p1" || property == "point") {
return vec3toVariant(getWorldPosition());
return vec3ToVariant(getWorldPosition());
}
if (property == "localPosition") {
return vec3toVariant(getLocalPosition());
return vec3ToVariant(getLocalPosition());
}
if (property == "rotation" || property == "orientation") {
return quatToVariant(getWorldOrientation());

View file

@ -62,7 +62,7 @@ ContextOverlayInterface::ContextOverlayInterface() {
glm::quat cameraOrientation = qApp->getCamera().getOrientation();
QVariantMap props;
float sensorToWorldScale = myAvatar->getSensorToWorldScale();
props.insert("position", vec3toVariant(myAvatar->getEyePosition() + glm::quat(glm::radians(glm::vec3(0.0f, CONTEXT_OVERLAY_TABLET_OFFSET, 0.0f))) * ((CONTEXT_OVERLAY_TABLET_DISTANCE * sensorToWorldScale) * (cameraOrientation * Vectors::FRONT))));
props.insert("position", vec3ToVariant(myAvatar->getEyePosition() + glm::quat(glm::radians(glm::vec3(0.0f, CONTEXT_OVERLAY_TABLET_OFFSET, 0.0f))) * ((CONTEXT_OVERLAY_TABLET_DISTANCE * sensorToWorldScale) * (cameraOrientation * Vectors::FRONT))));
props.insert("orientation", quatToVariant(cameraOrientation * glm::quat(glm::radians(glm::vec3(0.0f, CONTEXT_OVERLAY_TABLET_ORIENTATION, 0.0f)))));
qApp->getOverlays().editOverlay(tabletFrameID, props);
_contextOverlayJustClicked = false;
@ -136,16 +136,17 @@ bool ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
// Add all necessary variables to the stack
EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(entityItemID, _entityPropertyFlags);
glm::vec3 cameraPosition = qApp->getCamera().getPosition();
glm::vec3 entityDimensions = entityProperties.getDimensions();
glm::vec3 entityPosition = entityProperties.getPosition();
glm::vec3 contextOverlayPosition = entityProperties.getPosition();
glm::vec3 entityDimensions = entityProperties.getDimensions().toGlm();
glm::vec3 entityPosition = entityProperties.getPosition().toGlm();
glm::vec3 registrationPoint = entityProperties.getRegistrationPoint().toGlm();
glm::vec3 contextOverlayPosition = entityProperties.getPosition().toGlm();
glm::vec2 contextOverlayDimensions;
// Update the position of the overlay if the registration point of the entity
// isn't default
if (entityProperties.getRegistrationPoint() != glm::vec3(0.5f)) {
glm::vec3 adjustPos = entityProperties.getRegistrationPoint() - glm::vec3(0.5f);
entityPosition = entityPosition - (entityProperties.getRotation() * (adjustPos * entityProperties.getDimensions()));
if (registrationPoint != glm::vec3(0.5f)) {
glm::vec3 adjustPos = registrationPoint - glm::vec3(0.5f);
entityPosition = entityPosition - (entityProperties.getRotation() * (adjustPos * entityDimensions));
}
enableEntityHighlight(entityItemID);

View file

@ -243,7 +243,7 @@ QVariant Image3DOverlay::getProperty(const QString& property) {
return _fromImage;
}
if (property == "offsetPosition") {
return vec3toVariant(getOffsetPosition());
return vec3ToVariant(getOffsetPosition());
}
if (property == "emissive") {
return _emissive;

View file

@ -314,10 +314,10 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) {
*/
QVariant Line3DOverlay::getProperty(const QString& property) {
if (property == "start" || property == "startPoint" || property == "p1") {
return vec3toVariant(getStart());
return vec3ToVariant(getStart());
}
if (property == "end" || property == "endPoint" || property == "p2") {
return vec3toVariant(getEnd());
return vec3ToVariant(getEnd());
}
if (property == "length") {
return QVariant(getLength());
@ -329,10 +329,10 @@ QVariant Line3DOverlay::getProperty(const QString& property) {
return _endParentJointIndex;
}
if (property == "localStart") {
return vec3toVariant(getLocalStart());
return vec3ToVariant(getLocalStart());
}
if (property == "localEnd") {
return vec3toVariant(getLocalEnd());
return vec3ToVariant(getLocalEnd());
}
if (property == "glow") {
return getGlow();

View file

@ -416,10 +416,10 @@ QVariant ModelOverlay::getProperty(const QString& property) {
return _url.toString();
}
if (property == "dimensions" || property == "size") {
return vec3toVariant(getDimensions());
return vec3ToVariant(getDimensions());
}
if (property == "scale") {
return vec3toVariant(getSNScale());
return vec3ToVariant(getSNScale());
}
if (property == "textures") {
if (_modelTextures.size() > 0) {
@ -463,7 +463,7 @@ QVariant ModelOverlay::getProperty(const QString& property) {
[this](int jointIndex) -> QVariant {
glm::vec3 translation;
_model->getJointTranslation(jointIndex, translation);
return vec3toVariant(translation);
return vec3ToVariant(translation);
});
}
@ -483,7 +483,7 @@ QVariant ModelOverlay::getProperty(const QString& property) {
[this](int jointIndex) -> QVariant {
glm::vec3 position;
_model->getJointPositionInWorldFrame(jointIndex, position);
return vec3toVariant(position);
return vec3ToVariant(position);
});
}

View file

@ -606,7 +606,7 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine,
break;
}
obj.setProperty("face", faceName);
auto intersection = vec3toScriptValue(engine, value.intersection);
auto intersection = vec3ToScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;

View file

@ -21,13 +21,13 @@ bool PanelAttachable::getParentVisible() const {
// No JSDoc because these properties are not actually used.
QVariant PanelAttachable::getProperty(const QString& property) {
if (property == "offsetPosition") {
return vec3toVariant(getOffsetPosition());
return vec3ToVariant(getOffsetPosition());
}
if (property == "offsetRotation") {
return quatToVariant(getOffsetRotation());
}
if (property == "offsetScale") {
return vec3toVariant(getOffsetScale());
return vec3ToVariant(getOffsetScale());
}
return QVariant();
}

View file

@ -64,7 +64,7 @@ void Planar3DOverlay::setProperties(const QVariantMap& properties) {
*/
QVariant Planar3DOverlay::getProperty(const QString& property) {
if (property == "dimensions" || property == "scale" || property == "size") {
return vec2toVariant(getDimensions());
return vec2ToVariant(getDimensions());
}
return Base3DOverlay::getProperty(property);

View file

@ -83,12 +83,12 @@ void Rectangle3DOverlay::render(RenderArgs* args) {
geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor, _rectGeometryIds[3]);
} else {
if (halfDimensions != _previousHalfDimensions) {
QVector<glm::vec3> border;
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
QVector<ScriptVec3Float> border;
border << ScriptVec3Float(-halfDimensions.x, -halfDimensions.y, 0.0f);
border << ScriptVec3Float(halfDimensions.x, -halfDimensions.y, 0.0f);
border << ScriptVec3Float(halfDimensions.x, halfDimensions.y, 0.0f);
border << ScriptVec3Float(-halfDimensions.x, halfDimensions.y, 0.0f);
border << ScriptVec3Float(-halfDimensions.x, -halfDimensions.y, 0.0f);
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
_previousHalfDimensions = halfDimensions;

View file

@ -69,7 +69,7 @@ void Volume3DOverlay::setProperties(const QVariantMap& properties) {
*/
QVariant Volume3DOverlay::getProperty(const QString& property) {
if (property == "dimensions" || property == "scale" || property == "size") {
return vec3toVariant(getDimensions());
return vec3ToVariant(getDimensions());
}
return Base3DOverlay::getProperty(property);

View file

@ -186,7 +186,7 @@ void Web3DOverlay::buildWebSurface() {
_cachedWebSurface = false;
setupQmlSurface();
}
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3toVariant(getWorldPosition()));
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3ToVariant(getWorldPosition()));
onResizeWebSurface();
_webSurface->resume();
});
@ -198,7 +198,7 @@ void Web3DOverlay::buildWebSurface() {
void Web3DOverlay::update(float deltatime) {
if (_webSurface) {
// update globalPosition
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3toVariant(getWorldPosition()));
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3ToVariant(getWorldPosition()));
}
Parent::update(deltatime);
}

View file

@ -40,7 +40,7 @@ QScriptValue AnimVariantMap::animVariantMapToScriptValue(QScriptEngine* engine,
target.setProperty(name, value.getString());
break;
case AnimVariant::Type::Vec3:
target.setProperty(name, vec3toScriptValue(engine, value.getVec3()));
target.setProperty(name, vec3ToScriptValue(engine, value.getVec3()));
break;
case AnimVariant::Type::Quat:
target.setProperty(name, quatToScriptValue(engine, value.getQuat()));

View file

@ -34,7 +34,7 @@ AudioInjectorOptions::AudioInjectorOptions() :
QScriptValue injectorOptionsToScriptValue(QScriptEngine* engine, const AudioInjectorOptions& injectorOptions) {
QScriptValue obj = engine->newObject();
obj.setProperty("position", vec3toScriptValue(engine, injectorOptions.position));
obj.setProperty("position", vec3ToScriptValue(engine, injectorOptions.position));
obj.setProperty("volume", injectorOptions.volume);
obj.setProperty("loop", injectorOptions.loop);
obj.setProperty("orientation", quatToScriptValue(engine, injectorOptions.orientation));

View file

@ -1486,7 +1486,7 @@ void Avatar::renderJointConnectingCone(gpu::Batch& batch, glm::vec3 position1, g
perpSin = glm::cross(perpCos, axis);
float angleb = 0.0f;
QVector<glm::vec3> points;
QVector<ScriptVec3Float> points;
for (int i = 0; i < NUM_BODY_CONE_SIDES; i ++) {

View file

@ -2562,7 +2562,7 @@ QScriptValue RayToAvatarIntersectionResultToScriptValue(QScriptEngine* engine, c
QScriptValue avatarIDValue = quuidToScriptValue(engine, value.avatarID);
obj.setProperty("avatarID", avatarIDValue);
obj.setProperty("distance", value.distance);
QScriptValue intersection = vec3toScriptValue(engine, value.intersection);
QScriptValue intersection = vec3ToScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;

View file

@ -41,10 +41,10 @@ namespace controller {
*/
QScriptValue Pose::toScriptValue(QScriptEngine* engine, const Pose& pose) {
QScriptValue obj = engine->newObject();
obj.setProperty("translation", vec3toScriptValue(engine, pose.translation));
obj.setProperty("translation", vec3ToScriptValue(engine, pose.translation));
obj.setProperty("rotation", quatToScriptValue(engine, pose.rotation));
obj.setProperty("velocity", vec3toScriptValue(engine, pose.velocity));
obj.setProperty("angularVelocity", vec3toScriptValue(engine, pose.angularVelocity));
obj.setProperty("velocity", vec3ToScriptValue(engine, pose.velocity));
obj.setProperty("angularVelocity", vec3ToScriptValue(engine, pose.angularVelocity));
obj.setProperty("valid", pose.valid);
return obj;
}

View file

@ -475,7 +475,7 @@ glm::mat4 CompositorHelper::getPoint2DTransform(const glm::vec2& point, float si
QVariant ReticleInterface::getPosition() const {
return vec2toVariant(_compositor->getReticlePosition());
return vec2ToVariant(_compositor->getReticlePosition());
}
void ReticleInterface::setPosition(QVariant position) {

View file

@ -34,7 +34,7 @@ protected:
private:
int _lineVerticesID { GeometryCache::UNKNOWN_ID };
QVector<glm::vec3> _linePoints;
QVector<ScriptVec3Float> _linePoints;
};
} } // namespace

View file

@ -913,7 +913,7 @@ void RenderableModelEntityItem::setJointRotationsSet(const QVector<bool>& rotati
_needsJointSimulation = true;
}
void RenderableModelEntityItem::setJointTranslations(const QVector<glm::vec3>& translations) {
void RenderableModelEntityItem::setJointTranslations(const QVector<ScriptVec3Float>& translations) {
ModelEntityItem::setJointTranslations(translations);
_needsJointSimulation = true;
}
@ -1029,7 +1029,7 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() {
changed = true;
}
if (jointData.translationDirty) {
model->setJointTranslation(index, true, jointData.joint.translation, 1.0f);
model->setJointTranslation(index, true, jointData.joint.translation.toGlm(), 1.0f);
jointData.translationDirty = false;
changed = true;
}

View file

@ -103,7 +103,7 @@ public:
virtual void setJointRotations(const QVector<glm::quat>& rotations) override;
virtual void setJointRotationsSet(const QVector<bool>& rotationsSet) override;
virtual void setJointTranslations(const QVector<glm::vec3>& translations) override;
virtual void setJointTranslations(const QVector<ScriptVec3Float>& translations) override;
virtual void setJointTranslationsSet(const QVector<bool>& translationsSet) override;
virtual void locationChanged(bool tellPhysics = true) override;

View file

@ -175,7 +175,7 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo
}
if (strokeColorsChanged) {
_lastStrokeColors = entity->getStrokeColors();
_lastStrokeColors = _lastNormals.size() == _lastStrokeColors.size() ? _lastStrokeColors : QVector<glm::vec3>({ toGlm(entity->getXColor()) });
_lastStrokeColors = _lastNormals.size() == _lastStrokeColors.size() ? _lastStrokeColors : QVector<ScriptVec3Float>({ toGlm(entity->getXColor()) });
}
if (pointsChanged || strokeWidthsChanged || normalsChanged || strokeColorsChanged) {
_empty = std::min(_lastPoints.size(), std::min(_lastNormals.size(), _lastStrokeWidths.size())) < 2;
@ -194,10 +194,10 @@ void PolyLineEntityRenderer::updateGeometry(const std::vector<Vertex>& vertices)
_verticesBuffer->setSubData(0, vertices);
}
std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertices(const QVector<glm::vec3>& points,
const QVector<glm::vec3>& normals,
std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertices(const QVector<ScriptVec3Float>& points,
const QVector<ScriptVec3Float>& normals,
const QVector<float>& strokeWidths,
const QVector<glm::vec3>& strokeColors,
const QVector<ScriptVec3Float>& strokeColors,
const bool isUVModeStretch,
const float textureAspectRatio) {
// Calculate the minimum vector size out of normals, points, and stroke widths
@ -230,14 +230,14 @@ std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertic
for (int i = 0; i <= finalIndex; i++) {
const float& width = strokeWidths.at(i);
const auto& point = points.at(i);
const auto& normal = normals.at(i);
const auto& color = strokeColors.size() == normals.size() ? strokeColors.at(i) : strokeColors.at(0);
const auto& point = points.at(i).toGlm();
const auto& normal = normals.at(i).toGlm();
const auto& color = strokeColors.size() == normals.size() ? strokeColors.at(i).toGlm() : strokeColors.at(0).toGlm();
int vertexIndex = i * 2;
if (!isUVModeStretch && i >= 1) {
distanceToLastPoint = glm::distance(points.at(i), points.at(i - 1));
distanceToLastPoint = glm::distance(points.at(i).toGlm(), points.at(i - 1).toGlm());
accumulatedDistance += distanceToLastPoint;
strokeWidth = 2 * strokeWidths[i];
@ -263,7 +263,7 @@ std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertic
// For last point we can assume binormals are the same since it represents the last two vertices of quad
if (i < finalIndex) {
const auto tangent = points.at(i + 1) - point;
const auto tangent = points.at(i + 1).toGlm() - point;
binormal = glm::normalize(glm::cross(tangent, normal)) * width;
// Check to make sure binormal is not a NAN. If it is, don't add to vertices vector
@ -272,8 +272,8 @@ std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertic
}
}
const auto v1 = points.at(i) + binormal;
const auto v2 = points.at(i) - binormal;
const auto v1 = points.at(i).toGlm() + binormal;
const auto v2 = points.at(i).toGlm() - binormal;
vertices.emplace_back(v1, normal, vec2(uCoord, 0.0f), color);
vertices.emplace_back(v2, normal, vec2(uCoord, 1.0f), color);
}

View file

@ -52,17 +52,17 @@ protected:
};
void updateGeometry(const std::vector<Vertex>& vertices);
static std::vector<Vertex> updateVertices(const QVector<glm::vec3>& points,
const QVector<glm::vec3>& normals,
static std::vector<Vertex> updateVertices(const QVector<ScriptVec3Float>& points,
const QVector<ScriptVec3Float>& normals,
const QVector<float>& strokeWidths,
const QVector<glm::vec3>& strokeColors,
const QVector<ScriptVec3Float>& strokeColors,
const bool isUVModeStretch,
const float textureAspectRatio);
Transform _polylineTransform;
QVector<glm::vec3> _lastPoints;
QVector<glm::vec3> _lastNormals;
QVector<glm::vec3> _lastStrokeColors;
QVector<ScriptVec3Float> _lastPoints;
QVector<ScriptVec3Float> _lastNormals;
QVector<ScriptVec3Float> _lastStrokeColors;
QVector<float> _lastStrokeWidths;
gpu::BufferPointer _verticesBuffer;
gpu::BufferView _uniformBuffer;

View file

@ -215,7 +215,7 @@ void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxel
glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const {
glm::vec3 result;
withReadLock([&] {
glm::vec3 scale = getScaledDimensions() / _voxelVolumeSize; // meters / voxel-units
glm::vec3 scale = getScaledDimensions() / _voxelVolumeSize.toGlm(); // meters / voxel-units
if (isEdged(_voxelSurfaceStyle)) {
result = scale / -2.0f;
}
@ -227,7 +227,7 @@ glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const {
glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const {
glm::vec3 voxelVolumeSize;
withReadLock([&] {
voxelVolumeSize = _voxelVolumeSize;
voxelVolumeSize = _voxelVolumeSize.toGlm();
});
glm::vec3 dimensions = getScaledDimensions();
@ -313,7 +313,7 @@ bool RenderablePolyVoxEntityItem::setAll(uint8_t toValue) {
}
withWriteLock([&] {
loop3(ivec3(0), ivec3(_voxelVolumeSize), [&](const ivec3& v) {
loop3(ivec3(0), ivec3(_voxelVolumeSize.toGlm()), [&](const ivec3& v) {
result |= setVoxelInternal(v, toValue);
});
});
@ -332,7 +332,7 @@ bool RenderablePolyVoxEntityItem::setCuboid(const glm::vec3& lowPosition, const
ivec3 iLowPosition = ivec3{ glm::round(lowPosition) };
ivec3 iCuboidSize = ivec3{ glm::round(cuboidSize) };
ivec3 iVoxelVolumeSize = ivec3{ glm::round(_voxelVolumeSize) };
ivec3 iVoxelVolumeSize = ivec3{ glm::round(_voxelVolumeSize.toGlm()) };
ivec3 low = glm::max(glm::min(iLowPosition, iVoxelVolumeSize - 1), ivec3(0));
ivec3 high = glm::max(glm::min(low + iCuboidSize, iVoxelVolumeSize), low);
@ -368,7 +368,7 @@ bool RenderablePolyVoxEntityItem::setSphereInVolume(const vec3& center, float ra
float radiusSquared = radius * radius;
// This three-level for loop iterates over every voxel in the volume
withWriteLock([&] {
loop3(ivec3(0), ivec3(_voxelVolumeSize), [&](const ivec3& v) {
loop3(ivec3(0), ivec3(_voxelVolumeSize.toGlm()), [&](const ivec3& v) {
// Store our current position as a vector...
glm::vec3 pos = vec3(v) + 0.5f; // consider voxels cenetered on their coordinates
// And compute how far the current position is from the center of the volume
@ -396,7 +396,7 @@ bool RenderablePolyVoxEntityItem::setSphere(const vec3& centerWorldCoords, float
glm::mat4 wtvMatrix = glm::inverse(vtwMatrix);
glm::vec3 dimensions = getScaledDimensions();
glm::vec3 voxelSize = dimensions / _voxelVolumeSize;
glm::vec3 voxelSize = dimensions / _voxelVolumeSize.toGlm();
float smallestDimensionSize = voxelSize.x;
smallestDimensionSize = glm::min(smallestDimensionSize, voxelSize.y);
smallestDimensionSize = glm::min(smallestDimensionSize, voxelSize.z);
@ -410,8 +410,8 @@ bool RenderablePolyVoxEntityItem::setSphere(const vec3& centerWorldCoords, float
glm::vec3 low = glm::floor(centerInVoxelCoords - maxRadiusInVoxelCoords);
glm::vec3 high = glm::ceil(centerInVoxelCoords + maxRadiusInVoxelCoords);
glm::ivec3 lowI = glm::clamp(low, glm::vec3(0.0f), _voxelVolumeSize);
glm::ivec3 highI = glm::clamp(high, glm::vec3(0.0f), _voxelVolumeSize);
glm::ivec3 lowI = glm::clamp(low, glm::vec3(0.0f), _voxelVolumeSize.toGlm());
glm::ivec3 highI = glm::clamp(high, glm::vec3(0.0f), _voxelVolumeSize.toGlm());
glm::vec3 radials(radiusWorldCoords / voxelSize.x,
radiusWorldCoords / voxelSize.y,
@ -457,7 +457,7 @@ bool RenderablePolyVoxEntityItem::setCapsule(const vec3& startWorldCoords, const
glm::mat4 wtvMatrix = glm::inverse(vtwMatrix);
glm::vec3 dimensions = getScaledDimensions();
glm::vec3 voxelSize = dimensions / _voxelVolumeSize;
glm::vec3 voxelSize = dimensions / _voxelVolumeSize.toGlm();
float smallestDimensionSize = voxelSize.x;
smallestDimensionSize = glm::min(smallestDimensionSize, voxelSize.y);
smallestDimensionSize = glm::min(smallestDimensionSize, voxelSize.z);
@ -472,8 +472,8 @@ bool RenderablePolyVoxEntityItem::setCapsule(const vec3& startWorldCoords, const
glm::vec3 high = glm::max(glm::ceil(startInVoxelCoords + maxRadiusInVoxelCoords),
glm::ceil(endInVoxelCoords + maxRadiusInVoxelCoords));
glm::ivec3 lowI = glm::clamp(low, glm::vec3(0.0f), _voxelVolumeSize);
glm::ivec3 highI = glm::clamp(high, glm::vec3(0.0f), _voxelVolumeSize);
glm::ivec3 lowI = glm::clamp(low, glm::vec3(0.0f), _voxelVolumeSize.toGlm());
glm::ivec3 highI = glm::clamp(high, glm::vec3(0.0f), _voxelVolumeSize.toGlm());
// This three-level for loop iterates over every voxel in the volume that might be in the capsule
withWriteLock([&] {
@ -703,7 +703,7 @@ bool RenderablePolyVoxEntityItem::updateDependents() {
return !volDataDirty;
}
void RenderablePolyVoxEntityItem::setVoxelVolumeSize(const glm::vec3& voxelVolumeSize) {
void RenderablePolyVoxEntityItem::setVoxelVolumeSize(const ScriptVec3Float& voxelVolumeSize) {
// This controls how many individual voxels are in the entity. This is unrelated to
// the dimentions of the entity -- it defines the sizes of the arrays that hold voxel values.
// In addition to setting the number of voxels, this is used in a few places for its
@ -1170,7 +1170,7 @@ void RenderablePolyVoxEntityItem::computeShapeInfoWorker() {
withReadLock([&] {
voxelSurfaceStyle = _voxelSurfaceStyle;
voxelVolumeSize = _voxelVolumeSize;
voxelVolumeSize = _voxelVolumeSize.toGlm();
mesh = _mesh;
});

View file

@ -58,7 +58,7 @@ public:
QVariantMap& extraInfo, bool precisionPicking) const override;
virtual void setVoxelData(const QByteArray& voxelData) override;
virtual void setVoxelVolumeSize(const glm::vec3& voxelVolumeSize) override;
virtual void setVoxelVolumeSize(const ScriptVec3Float& voxelVolumeSize) override;
virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) override;
glm::vec3 getSurfacePositionAdjustment() const;

View file

@ -198,7 +198,7 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
if (_contextPosition != entity->getWorldPosition()) {
// update globalPosition
_contextPosition = entity->getWorldPosition();
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3toVariant(_contextPosition));
_webSurface->getSurfaceContext()->setContextProperty("globalPosition", vec3ToVariant(_contextPosition));
}
_lastDPI = entity->getDPI();

View file

@ -333,7 +333,7 @@ void ZoneEntityRenderer::updateKeySunFromEntity(const TypedEntityPointer& entity
// Set the keylight
sunLight->setColor(ColorUtils::toVec3(_keyLightProperties.getColor()));
sunLight->setIntensity(_keyLightProperties.getIntensity());
sunLight->setDirection(entity->getTransform().getRotation() * _keyLightProperties.getDirection());
sunLight->setDirection(entity->getTransform().getRotation() * _keyLightProperties.getDirection().toGlm());
sunLight->setCastShadows(_keyLightProperties.getCastShadows());
}

View file

@ -104,10 +104,10 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
AABox aaBox = zoneEntity->getAABox(success);
if (success) {
QScriptValue boundingBox = filterData.engine->newObject();
QScriptValue bottomRightNear = vec3toScriptValue(filterData.engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3toScriptValue(filterData.engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3toScriptValue(filterData.engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3toScriptValue(filterData.engine, aaBox.getDimensions());
QScriptValue bottomRightNear = vec3ToScriptValue(filterData.engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3ToScriptValue(filterData.engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3ToScriptValue(filterData.engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3ToScriptValue(filterData.engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);

View file

@ -238,15 +238,15 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
// PROP_CUSTOM_PROPERTIES_INCLUDED,
APPEND_ENTITY_PROPERTY(PROP_SIMULATION_OWNER, _simulationOwner.toByteArray());
APPEND_ENTITY_PROPERTY(PROP_POSITION, getLocalPosition());
APPEND_ENTITY_PROPERTY(PROP_POSITION, getScriptLocalPosition());
APPEND_ENTITY_PROPERTY(PROP_ROTATION, getLocalOrientation());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getLocalVelocity());
APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getLocalAngularVelocity());
APPEND_ENTITY_PROPERTY(PROP_ACCELERATION, getAcceleration());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getScriptLocalVelocity());
APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getScriptLocalAngularVelocity());
APPEND_ENTITY_PROPERTY(PROP_ACCELERATION, getScriptAcceleration());
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, getUnscaledDimensions());
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, getScriptUnscaledDimensions());
APPEND_ENTITY_PROPERTY(PROP_DENSITY, getDensity());
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, getGravity());
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, getScriptGravity());
APPEND_ENTITY_PROPERTY(PROP_DAMPING, getDamping());
APPEND_ENTITY_PROPERTY(PROP_RESTITUTION, getRestitution());
APPEND_ENTITY_PROPERTY(PROP_FRICTION, getFriction());
@ -254,7 +254,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
APPEND_ENTITY_PROPERTY(PROP_SCRIPT, getScript());
APPEND_ENTITY_PROPERTY(PROP_SCRIPT_TIMESTAMP, getScriptTimestamp());
APPEND_ENTITY_PROPERTY(PROP_SERVER_SCRIPTS, getServerScripts());
APPEND_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, getRegistrationPoint());
APPEND_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, getScriptRegistrationPoint());
APPEND_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, getAngularDamping());
APPEND_ENTITY_PROPERTY(PROP_VISIBLE, getVisible());
APPEND_ENTITY_PROPERTY(PROP_CAN_CAST_SHADOW, getCanCastShadow());
@ -766,11 +766,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// Note: duplicate packets are expected and not wrong. They may be sent for any number of
// reasons and the contract is that the client handles them in an idempotent manner.
auto customUpdatePositionFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
auto customUpdatePositionFromNetwork = [this, shouldUpdate, lastEdited](ScriptVec3Float value){
if (shouldUpdate(_lastUpdatedPositionTimestamp, value != _lastUpdatedPositionValue)) {
setPosition(value);
_lastUpdatedPositionTimestamp = lastEdited;
_lastUpdatedPositionValue = value;
_lastUpdatedPositionValue = value.toGlm();
}
};
@ -782,40 +782,40 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
}
};
auto customUpdateVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
auto customUpdateVelocityFromNetwork = [this, shouldUpdate, lastEdited](ScriptVec3Float value){
if (shouldUpdate(_lastUpdatedVelocityTimestamp, value != _lastUpdatedVelocityValue)) {
setVelocity(value);
_lastUpdatedVelocityTimestamp = lastEdited;
_lastUpdatedVelocityValue = value;
_lastUpdatedVelocityValue = value.toGlm();
}
};
auto customUpdateAngularVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
auto customUpdateAngularVelocityFromNetwork = [this, shouldUpdate, lastEdited](ScriptVec3Float value){
if (shouldUpdate(_lastUpdatedAngularVelocityTimestamp, value != _lastUpdatedAngularVelocityValue)) {
setAngularVelocity(value);
_lastUpdatedAngularVelocityTimestamp = lastEdited;
_lastUpdatedAngularVelocityValue = value;
_lastUpdatedAngularVelocityValue = value.toGlm();
}
};
auto customSetAcceleration = [this, shouldUpdate, lastEdited](glm::vec3 value){
auto customSetAcceleration = [this, shouldUpdate, lastEdited](ScriptVec3Float value){
if (shouldUpdate(_lastUpdatedAccelerationTimestamp, value != _lastUpdatedAccelerationValue)) {
setAcceleration(value);
_lastUpdatedAccelerationTimestamp = lastEdited;
_lastUpdatedAccelerationValue = value;
_lastUpdatedAccelerationValue = value.toGlm();
}
};
READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, customUpdatePositionFromNetwork);
READ_ENTITY_PROPERTY(PROP_POSITION, ScriptVec3Float, customUpdatePositionFromNetwork);
READ_ENTITY_PROPERTY(PROP_ROTATION, glm::quat, customUpdateRotationFromNetwork);
READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, customUpdateVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, customUpdateAngularVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ACCELERATION, glm::vec3, customSetAcceleration);
READ_ENTITY_PROPERTY(PROP_VELOCITY, ScriptVec3Float, customUpdateVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, ScriptVec3Float, customUpdateAngularVelocityFromNetwork);
READ_ENTITY_PROPERTY(PROP_ACCELERATION, ScriptVec3Float, customSetAcceleration);
}
READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, setUnscaledDimensions);
READ_ENTITY_PROPERTY(PROP_DIMENSIONS, ScriptVec3Float, setUnscaledDimensions);
READ_ENTITY_PROPERTY(PROP_DENSITY, float, setDensity);
READ_ENTITY_PROPERTY(PROP_GRAVITY, glm::vec3, setGravity);
READ_ENTITY_PROPERTY(PROP_GRAVITY, ScriptVec3Float, setGravity);
READ_ENTITY_PROPERTY(PROP_DAMPING, float, setDamping);
READ_ENTITY_PROPERTY(PROP_RESTITUTION, float, setRestitution);
@ -836,7 +836,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
READ_ENTITY_PROPERTY(PROP_SERVER_SCRIPTS, QString, setServerScripts);
}
READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint);
READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, ScriptVec3Float, setRegistrationPoint);
READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, setAngularDamping);
READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, setVisible);
@ -1783,6 +1783,14 @@ void EntityItem::setUnscaledDimensions(const glm::vec3& value) {
}
}
glm::vec3 EntityItem::getUnscaledDimensions() const {
glm::vec3 result;
withReadLock([&] {
result = _unscaledDimensions;
});
return result;
}
void EntityItem::setRotation(glm::quat rotation) {
if (getLocalOrientation() != rotation) {
setLocalOrientation(rotation);

View file

@ -187,8 +187,10 @@ public:
virtual void setScaledDimensions(const glm::vec3& value);
virtual glm::vec3 getRaycastDimensions() const { return getScaledDimensions(); }
inline const glm::vec3 getUnscaledDimensions() const { return _unscaledDimensions; }
glm::vec3 getUnscaledDimensions() const;
ScriptVec3Float getScriptUnscaledDimensions() const { return getUnscaledDimensions(); }
virtual void setUnscaledDimensions(const glm::vec3& value);
void setUnscaledDimensions(const ScriptVec3Float& value) { setUnscaledDimensions(value.toGlm()); }
float getLocalRenderAlpha() const;
void setLocalRenderAlpha(float localRenderAlpha);
@ -203,11 +205,15 @@ public:
bool hasLocalVelocity() const { return getLocalVelocity() != ENTITY_ITEM_ZERO_VEC3; }
glm::vec3 getGravity() const; /// get gravity in meters
ScriptVec3Float getScriptGravity() const { return getGravity(); }
void setGravity(const glm::vec3& value); /// gravity in meters
void setGravity(const ScriptVec3Float& value) { setGravity(value.toGlm()); }
bool hasGravity() const { return getGravity() != ENTITY_ITEM_ZERO_VEC3; }
glm::vec3 getAcceleration() const; /// get acceleration in meters/second/second
ScriptVec3Float getScriptAcceleration() const { return getAcceleration(); }
void setAcceleration(const glm::vec3& value); /// acceleration in meters/second/second
void setAcceleration(const ScriptVec3Float& value) { setAcceleration(value.toGlm()); }
bool hasAcceleration() const { return getAcceleration() != ENTITY_ITEM_ZERO_VEC3; }
float getDamping() const;
@ -259,14 +265,16 @@ public:
void setCollisionSoundURL(const QString& value);
glm::vec3 getRegistrationPoint() const; /// registration point as ratio of entity
ScriptVec3Float getScriptRegistrationPoint() const { return getRegistrationPoint(); }
/// registration point as ratio of entity
virtual void setRegistrationPoint(const glm::vec3& value); // FIXME: this is suspicious!
virtual void setRegistrationPoint(const glm::vec3& value); // FIXME: this is suspicious!
void setRegistrationPoint(const ScriptVec3Float& value) { setRegistrationPoint(value.toGlm()); }
bool hasAngularVelocity() const { return getWorldAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; }
bool hasLocalAngularVelocity() const { return getLocalAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; }
virtual void setAngularVelocity(const glm::vec3& angularVelocity);
void setAngularVelocity(const ScriptVec3Float& angularVelocity) { setAngularVelocity(angularVelocity.toGlm()); }
float getAngularDamping() const;
void setAngularDamping(float value);
@ -381,11 +389,13 @@ public:
virtual void setCollisionShape(const btCollisionShape* shape) {}
void setPosition(const glm::vec3& value);
void setPosition(const ScriptVec3Float& value) { setPosition(value.toGlm()); }
virtual void setParentID(const QUuid& parentID) override;
virtual void setShapeType(ShapeType type) { /* do nothing */ }
void setRotation(glm::quat orientation);
void setVelocity(const glm::vec3& velocity);
void setVelocity(const ScriptVec3Float& velocity) { setVelocity(velocity.toGlm()); }
uint32_t getDirtyFlags() const;
void markDirtyFlags(uint32_t mask);

View file

@ -850,9 +850,9 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
* @property {number} emitSpeed=5 - The speed, in m/s, that each particle is emitted at.
* @property {number} speedSpread=1 - The spread in speeds at which particles are emitted at. If <code>emitSpeed == 5</code>
* and <code>speedSpread == 1</code>, particles will be emitted with speeds in the range 4m/s &ndash; 6m/s.
* @property {vec3} emitAcceleration=0,-9.8,0 - The acceleration that is applied to each particle during its lifetime. The
* @property {Vec3} emitAcceleration=0,-9.8,0 - The acceleration that is applied to each particle during its lifetime. The
* default is Earth's gravity value.
* @property {vec3} accelerationSpread=0,0,0 - The spread in accelerations that each particle is given. If
* @property {Vec3} accelerationSpread=0,0,0 - The spread in accelerations that each particle is given. If
* <code>emitAccelerations == {x: 0, y: -9.8, z: 0}</code> and <code>accelerationSpread ==
* {x: 0, y: 1, z: 0}</code>, each particle will have an acceleration in the range <code>{x: 0, y: -10.8, z: 0}</code>
* &ndash; <code>{x: 0, y: -8.8, z: 0}</code>.
@ -865,7 +865,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
* default, particles emit along the entity's local z-axis, and <code>azimuthStart</code> and <code>azimuthFinish</code>
* are relative to the entity's local x-axis. The default value is a rotation of -90 degrees about the local x-axis, i.e.,
* the particles emit vertically.
* @property {vec3} emitDimensions=0,0,0 - The dimensions of the ellipsoid from which particles are emitted.
* @property {Vec3} emitDimensions=0,0,0 - The dimensions of the ellipsoid from which particles are emitted.
* @property {number} emitRadiusStart=1 - The starting radius within the ellipsoid at which particles start being emitted;
* range <code>0.0</code> &ndash; <code>1.0</code> for the ellipsoid center to the ellipsoid surface, respectively.
* Particles are emitted from the portion of the ellipsoid that lies between <code>emitRadiusStart</code> and the
@ -1424,10 +1424,10 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
if (!skipDefaults && !strictSemantics) {
AABox aaBox = getAABox();
QScriptValue boundingBox = engine->newObject();
QScriptValue bottomRightNear = vec3toScriptValue(engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3toScriptValue(engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3toScriptValue(engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3toScriptValue(engine, aaBox.getDimensions());
QScriptValue bottomRightNear = vec3ToScriptValue(engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3ToScriptValue(engine, aaBox.calcTopFarLeft());
QScriptValue center = vec3ToScriptValue(engine, aaBox.calcCenter());
QScriptValue boundingBoxDimensions = vec3ToScriptValue(engine, aaBox.getDimensions());
boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("center", center);
@ -1504,13 +1504,13 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
}
COPY_PROPERTY_FROM_QSCRIPTVALUE(lastEditedBy, QUuid, setLastEditedBy);
COPY_PROPERTY_FROM_QSCRIPTVALUE(position, vec3, setPosition);
COPY_PROPERTY_FROM_QSCRIPTVALUE(dimensions, vec3, setDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(position, ScriptVec3Float, setPosition);
COPY_PROPERTY_FROM_QSCRIPTVALUE(dimensions, ScriptVec3Float, setDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(rotation, quat, setRotation);
COPY_PROPERTY_FROM_QSCRIPTVALUE(density, float, setDensity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(velocity, vec3, setVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(gravity, vec3, setGravity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(acceleration, vec3, setAcceleration);
COPY_PROPERTY_FROM_QSCRIPTVALUE(velocity, ScriptVec3Float, setVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(gravity, ScriptVec3Float, setGravity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(acceleration, ScriptVec3Float, setAcceleration);
COPY_PROPERTY_FROM_QSCRIPTVALUE(damping, float, setDamping);
COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution);
COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction);
@ -1518,15 +1518,15 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript);
COPY_PROPERTY_FROM_QSCRIPTVALUE(scriptTimestamp, quint64, setScriptTimestamp);
COPY_PROPERTY_FROM_QSCRIPTVALUE(serverScripts, QString, setServerScripts);
COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, vec3, setRegistrationPoint);
COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, vec3, setAngularVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, ScriptVec3Float, setRegistrationPoint);
COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, ScriptVec3Float, setAngularVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(angularDamping, float, setAngularDamping);
COPY_PROPERTY_FROM_QSCRIPTVALUE(visible, bool, setVisible);
COPY_PROPERTY_FROM_QSCRIPTVALUE(canCastShadow, bool, setCanCastShadow);
COPY_PROPERTY_FROM_QSCRIPTVALUE(color, xColor, setColor);
COPY_PROPERTY_FROM_QSCRIPTVALUE(colorSpread, xColor, setColorSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(colorStart, vec3, setColorStart);
COPY_PROPERTY_FROM_QSCRIPTVALUE(colorFinish, vec3, setColorFinish);
COPY_PROPERTY_FROM_QSCRIPTVALUE(colorStart, ScriptVec3Float, setColorStart);
COPY_PROPERTY_FROM_QSCRIPTVALUE(colorFinish, ScriptVec3Float, setColorFinish);
COPY_PROPERTY_FROM_QSCRIPTVALUE(alpha, float, setAlpha);
COPY_PROPERTY_FROM_QSCRIPTVALUE(alphaSpread, float, setAlphaSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(alphaStart, float, setAlphaStart);
@ -1561,14 +1561,14 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitSpeed, float, setEmitSpeed);
COPY_PROPERTY_FROM_QSCRIPTVALUE(speedSpread, float, setSpeedSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitOrientation, quat, setEmitOrientation);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitDimensions, vec3, setEmitDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitDimensions, ScriptVec3Float, setEmitDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitRadiusStart, float, setEmitRadiusStart);
COPY_PROPERTY_FROM_QSCRIPTVALUE(polarStart, float, setPolarStart);
COPY_PROPERTY_FROM_QSCRIPTVALUE(polarFinish, float, setPolarFinish);
COPY_PROPERTY_FROM_QSCRIPTVALUE(azimuthStart, float, setAzimuthStart);
COPY_PROPERTY_FROM_QSCRIPTVALUE(azimuthFinish, float, setAzimuthFinish);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitAcceleration, vec3, setEmitAcceleration);
COPY_PROPERTY_FROM_QSCRIPTVALUE(accelerationSpread, vec3, setAccelerationSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(emitAcceleration, ScriptVec3Float, setEmitAcceleration);
COPY_PROPERTY_FROM_QSCRIPTVALUE(accelerationSpread, ScriptVec3Float, setAccelerationSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(particleRadius, float, setParticleRadius);
COPY_PROPERTY_FROM_QSCRIPTVALUE(radiusSpread, float, setRadiusSpread);
COPY_PROPERTY_FROM_QSCRIPTVALUE(radiusStart, float, setRadiusStart);
@ -1606,7 +1606,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(skyboxMode, SkyboxMode);
COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl);
COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, vec3, setVoxelVolumeSize);
COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, ScriptVec3Float, setVoxelVolumeSize);
COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelData, QByteArray, setVoxelData);
COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelSurfaceStyle, uint16_t, setVoxelSurfaceStyle);
COPY_PROPERTY_FROM_QSCRIPTVALUE(lineWidth, float, setLineWidth);
@ -1653,11 +1653,11 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
COPY_PROPERTY_FROM_QSCRIPTVALUE(parentJointIndex, quint16, setParentJointIndex);
COPY_PROPERTY_FROM_QSCRIPTVALUE(queryAACube, AACube, setQueryAACube);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localPosition, vec3, setLocalPosition);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localPosition, ScriptVec3Float, setLocalPosition);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localRotation, quat, setLocalRotation);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localVelocity, vec3, setLocalVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localAngularVelocity, vec3, setLocalAngularVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localDimensions, vec3, setLocalDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localVelocity, ScriptVec3Float, setLocalVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localAngularVelocity, ScriptVec3Float, setLocalAngularVelocity);
COPY_PROPERTY_FROM_QSCRIPTVALUE(localDimensions, ScriptVec3Float, setLocalDimensions);
COPY_PROPERTY_FROM_QSCRIPTVALUE(jointRotationsSet, qVectorBool, setJointRotationsSet);
COPY_PROPERTY_FROM_QSCRIPTVALUE(jointRotations, qVectorQuat, setJointRotations);
@ -2453,7 +2453,7 @@ QByteArray EntityItemProperties::getPackedNormals() const {
return packNormals(getNormals());
}
QByteArray EntityItemProperties::packNormals(const QVector<glm::vec3>& normals) const {
QByteArray EntityItemProperties::packNormals(const QVector<ScriptVec3Float>& normals) const {
int normalsSize = normals.size();
QByteArray packedNormals = QByteArray(normalsSize * 6 + 1, '0');
// add size of the array
@ -2461,7 +2461,7 @@ QByteArray EntityItemProperties::packNormals(const QVector<glm::vec3>& normals)
int index = 1;
for (int i = 0; i < normalsSize; i++) {
int numBytes = packFloatVec3ToSignedTwoByteFixed((unsigned char*)packedNormals.data() + index, normals[i], 15);
int numBytes = packFloatVec3ToSignedTwoByteFixed((unsigned char*)packedNormals.data() + index, glm::vec3(normals[i].x, normals[i].y, normals[i].z), 15);
index += numBytes;
}
return packedNormals;
@ -2470,7 +2470,7 @@ QByteArray EntityItemProperties::packNormals(const QVector<glm::vec3>& normals)
QByteArray EntityItemProperties::getPackedStrokeColors() const {
return packStrokeColors(getStrokeColors());
}
QByteArray EntityItemProperties::packStrokeColors(const QVector<glm::vec3>& strokeColors) const {
QByteArray EntityItemProperties::packStrokeColors(const QVector<ScriptVec3Float>& strokeColors) const {
int strokeColorsSize = strokeColors.size();
QByteArray packedStrokeColors = QByteArray(strokeColorsSize * 3 + 1, '0');
@ -2480,9 +2480,9 @@ QByteArray EntityItemProperties::packStrokeColors(const QVector<glm::vec3>& stro
for (int i = 0; i < strokeColorsSize; i++) {
// add the color to the QByteArray
packedStrokeColors[i * 3 + 1] = strokeColors[i].r * 255;
packedStrokeColors[i * 3 + 2] = strokeColors[i].g * 255;
packedStrokeColors[i * 3 + 3] = strokeColors[i].b * 255;
packedStrokeColors[i * 3 + 1] = strokeColors[i].x * 255;
packedStrokeColors[i * 3 + 2] = strokeColors[i].y * 255;
packedStrokeColors[i * 3 + 3] = strokeColors[i].z * 255;
}
return packedStrokeColors;
}
@ -2571,13 +2571,13 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
processedBytes += propertyFlags.getEncodedLength();
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SIMULATION_OWNER, QByteArray, setSimulationOwner);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POSITION, glm::vec3, setPosition);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DIMENSIONS, glm::vec3, setDimensions);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POSITION, ScriptVec3Float, setPosition);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DIMENSIONS, ScriptVec3Float, setDimensions);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ROTATION, glm::quat, setRotation);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DENSITY, float, setDensity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VELOCITY, glm::vec3, setVelocity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_GRAVITY, glm::vec3, setGravity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACCELERATION, glm::vec3, setAcceleration);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VELOCITY, ScriptVec3Float, setVelocity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_GRAVITY, ScriptVec3Float, setGravity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACCELERATION, ScriptVec3Float, setAcceleration);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DAMPING, float, setDamping);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RESTITUTION, float, setRestitution);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_FRICTION, float, setFriction);
@ -2586,8 +2586,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SCRIPT_TIMESTAMP, quint64, setScriptTimestamp);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SERVER_SCRIPTS, QString, setServerScripts);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANGULAR_VELOCITY, glm::vec3, setAngularVelocity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_REGISTRATION_POINT, ScriptVec3Float, setRegistrationPoint);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANGULAR_VELOCITY, ScriptVec3Float, setAngularVelocity);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANGULAR_DAMPING, float, setAngularDamping);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VISIBLE, bool, setVisible);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CAN_CAST_SHADOW, bool, setCanCastShadow);
@ -2626,7 +2626,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_ROTATIONS_SET, QVector<bool>, setJointRotationsSet);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_ROTATIONS, QVector<glm::quat>, setJointRotations);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_TRANSLATIONS_SET, QVector<bool>, setJointTranslationsSet);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_TRANSLATIONS, QVector<glm::vec3>, setJointTranslations);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_JOINT_TRANSLATIONS, QVector<ScriptVec3Float>, setJointTranslations);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RELAY_PARENT_JOINTS, bool, setRelayParentJoints);
}
@ -2648,21 +2648,21 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_SPEED, float, setEmitSpeed);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SPEED_SPREAD, float, setSpeedSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_ORIENTATION, glm::quat, setEmitOrientation);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_DIMENSIONS, glm::vec3, setEmitDimensions);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_DIMENSIONS, ScriptVec3Float, setEmitDimensions);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_RADIUS_START, float, setEmitRadiusStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POLAR_START, float, setPolarStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POLAR_FINISH, float, setPolarFinish);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_AZIMUTH_START, float, setAzimuthStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_AZIMUTH_FINISH, float, setAzimuthFinish);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_ACCELERATION, glm::vec3, setEmitAcceleration);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACCELERATION_SPREAD, glm::vec3, setAccelerationSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EMIT_ACCELERATION, ScriptVec3Float, setEmitAcceleration);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACCELERATION_SPREAD, ScriptVec3Float, setAccelerationSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_PARTICLE_RADIUS, float, setParticleRadius);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RADIUS_SPREAD, float, setRadiusSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RADIUS_START, float, setRadiusStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_RADIUS_FINISH, float, setRadiusFinish);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR_SPREAD, xColor, setColorSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR_START, vec3, setColorStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR_FINISH, vec3, setColorFinish);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR_START, ScriptVec3Float, setColorStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR_FINISH, ScriptVec3Float, setColorFinish);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ALPHA_SPREAD, float, setAlphaSpread);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ALPHA_START, float, setAlphaStart);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ALPHA_FINISH, float, setAlphaFinish);
@ -2690,7 +2690,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
}
if (properties.getType() == EntityTypes::PolyVox) {
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, ScriptVec3Float, setVoxelVolumeSize);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_DATA, QByteArray, setVoxelData);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_X_TEXTURE_URL, QString, setXTextureURL);
@ -2706,13 +2706,13 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
if (properties.getType() == EntityTypes::Line) {
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector<ScriptVec3Float>, setLinePoints);
}
if (properties.getType() == EntityTypes::PolyLine) {
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector<ScriptVec3Float>, setLinePoints);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NORMALS, QByteArray, setPackedNormals);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_COLORS, QByteArray, setPackedStrokeColors);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
@ -2771,9 +2771,9 @@ void EntityItemProperties::setPackedNormals(const QByteArray& value) {
setNormals(unpackNormals(value));
}
QVector<glm::vec3> EntityItemProperties::unpackNormals(const QByteArray& normals) {
QVector<ScriptVec3Float> EntityItemProperties::unpackNormals(const QByteArray& normals) {
// the size of the vector is packed first
QVector<glm::vec3> unpackedNormals = QVector<glm::vec3>((int)normals[0]);
QVector<ScriptVec3Float> unpackedNormals = QVector<ScriptVec3Float>((int)normals[0]);
if ((int)normals[0] == normals.size() / 6) {
int j = 0;
@ -2794,9 +2794,9 @@ void EntityItemProperties::setPackedStrokeColors(const QByteArray& value) {
setStrokeColors(unpackStrokeColors(value));
}
QVector<glm::vec3> EntityItemProperties::unpackStrokeColors(const QByteArray& strokeColors) {
QVector<ScriptVec3Float> EntityItemProperties::unpackStrokeColors(const QByteArray& strokeColors) {
// the size of the vector is packed first
QVector<glm::vec3> unpackedStrokeColors = QVector<glm::vec3>((int)strokeColors[0]);
QVector<ScriptVec3Float> unpackedStrokeColors = QVector<ScriptVec3Float>((int)strokeColors[0]);
if ((int)strokeColors[0] == strokeColors.size() / 3) {
int j = 0;
@ -3061,15 +3061,17 @@ void EntityItemProperties::markAllChanged() {
AABox EntityItemProperties::getAABox() const {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
glm::vec3 registrationPoint = glm::vec3(_registrationPoint.x, _registrationPoint.y, _registrationPoint.z);
glm::vec3 registrationRemainder = glm::vec3(1.0f) - registrationPoint;
glm::vec3 unrotatedMinRelativeToEntity = - (_dimensions * _registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = _dimensions * registrationRemainder;
glm::vec3 dimensions = glm::vec3(_dimensions.x, _dimensions.y, _dimensions.z);
glm::vec3 unrotatedMinRelativeToEntity = - (dimensions * registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = dimensions * registrationRemainder;
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(_rotation);
// shift the extents to be relative to the position/registration point
rotatedExtentsRelativeToRegistrationPoint.shiftBy(_position);
rotatedExtentsRelativeToRegistrationPoint.shiftBy(glm::vec3(_position.x, _position.y, _position.z));
return AABox(rotatedExtentsRelativeToRegistrationPoint);
}

View file

@ -119,13 +119,13 @@ public:
DEFINE_PROPERTY(PROP_VISIBLE, Visible, visible, bool, ENTITY_ITEM_DEFAULT_VISIBLE);
DEFINE_PROPERTY(PROP_CAN_CAST_SHADOW, CanCastShadow, canCastShadow, bool, ENTITY_ITEM_DEFAULT_CAN_CAST_SHADOW);
DEFINE_PROPERTY_REF_WITH_SETTER(PROP_POSITION, Position, position, glm::vec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_DIMENSIONS, Dimensions, dimensions, glm::vec3, ENTITY_ITEM_DEFAULT_DIMENSIONS);
DEFINE_PROPERTY_REF_WITH_SETTER(PROP_POSITION, Position, position, ScriptVec3Float, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_DIMENSIONS, Dimensions, dimensions, ScriptVec3Float, ENTITY_ITEM_DEFAULT_DIMENSIONS);
DEFINE_PROPERTY_REF(PROP_ROTATION, Rotation, rotation, glm::quat, ENTITY_ITEM_DEFAULT_ROTATION);
DEFINE_PROPERTY(PROP_DENSITY, Density, density, float, ENTITY_ITEM_DEFAULT_DENSITY);
DEFINE_PROPERTY_REF(PROP_VELOCITY, Velocity, velocity, glm::vec3, ENTITY_ITEM_DEFAULT_VELOCITY);
DEFINE_PROPERTY_REF(PROP_GRAVITY, Gravity, gravity, glm::vec3, ENTITY_ITEM_DEFAULT_GRAVITY);
DEFINE_PROPERTY_REF(PROP_ACCELERATION, Acceleration, acceleration, glm::vec3, ENTITY_ITEM_DEFAULT_ACCELERATION);
DEFINE_PROPERTY_REF(PROP_VELOCITY, Velocity, velocity, ScriptVec3Float, ENTITY_ITEM_DEFAULT_VELOCITY);
DEFINE_PROPERTY_REF(PROP_GRAVITY, Gravity, gravity, ScriptVec3Float, ENTITY_ITEM_DEFAULT_GRAVITY);
DEFINE_PROPERTY_REF(PROP_ACCELERATION, Acceleration, acceleration, ScriptVec3Float, ENTITY_ITEM_DEFAULT_ACCELERATION);
DEFINE_PROPERTY(PROP_DAMPING, Damping, damping, float, ENTITY_ITEM_DEFAULT_DAMPING);
DEFINE_PROPERTY(PROP_RESTITUTION, Restitution, restitution, float, ENTITY_ITEM_DEFAULT_RESTITUTION);
DEFINE_PROPERTY(PROP_FRICTION, Friction, friction, float, ENTITY_ITEM_DEFAULT_FRICTION);
@ -136,16 +136,16 @@ public:
DEFINE_PROPERTY_REF(PROP_COLLISION_SOUND_URL, CollisionSoundURL, collisionSoundURL, QString, ENTITY_ITEM_DEFAULT_COLLISION_SOUND_URL);
DEFINE_PROPERTY_REF(PROP_COLOR, Color, color, xColor, ParticleEffectEntityItem::DEFAULT_XCOLOR);
DEFINE_PROPERTY_REF(PROP_COLOR_SPREAD, ColorSpread, colorSpread, xColor, ParticleEffectEntityItem::DEFAULT_XCOLOR_SPREAD);
DEFINE_PROPERTY_REF(PROP_COLOR_START, ColorStart, colorStart, vec3, particle::DEFAULT_COLOR_UNINITIALIZED);
DEFINE_PROPERTY_REF(PROP_COLOR_FINISH, ColorFinish, colorFinish, vec3, particle::DEFAULT_COLOR_UNINITIALIZED);
DEFINE_PROPERTY_REF(PROP_COLOR_START, ColorStart, colorStart, ScriptVec3Float, particle::DEFAULT_COLOR_UNINITIALIZED);
DEFINE_PROPERTY_REF(PROP_COLOR_FINISH, ColorFinish, colorFinish, ScriptVec3Float, particle::DEFAULT_COLOR_UNINITIALIZED);
DEFINE_PROPERTY(PROP_ALPHA, Alpha, alpha, float, particle::DEFAULT_ALPHA);
DEFINE_PROPERTY(PROP_ALPHA_SPREAD, AlphaSpread, alphaSpread, float, particle::DEFAULT_ALPHA_SPREAD);
DEFINE_PROPERTY(PROP_ALPHA_START, AlphaStart, alphaStart, float, particle::DEFAULT_ALPHA_START);
DEFINE_PROPERTY(PROP_ALPHA_FINISH, AlphaFinish, alphaFinish, float, particle::DEFAULT_ALPHA_FINISH);
DEFINE_PROPERTY_REF(PROP_MODEL_URL, ModelURL, modelURL, QString, "");
DEFINE_PROPERTY_REF(PROP_COMPOUND_SHAPE_URL, CompoundShapeURL, compoundShapeURL, QString, "");
DEFINE_PROPERTY_REF(PROP_REGISTRATION_POINT, RegistrationPoint, registrationPoint, glm::vec3, ENTITY_ITEM_DEFAULT_REGISTRATION_POINT);
DEFINE_PROPERTY_REF(PROP_ANGULAR_VELOCITY, AngularVelocity, angularVelocity, glm::vec3, ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY);
DEFINE_PROPERTY_REF(PROP_REGISTRATION_POINT, RegistrationPoint, registrationPoint, ScriptVec3Float, ENTITY_ITEM_DEFAULT_REGISTRATION_POINT);
DEFINE_PROPERTY_REF(PROP_ANGULAR_VELOCITY, AngularVelocity, angularVelocity, ScriptVec3Float, ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY);
DEFINE_PROPERTY(PROP_ANGULAR_DAMPING, AngularDamping, angularDamping, float, ENTITY_ITEM_DEFAULT_ANGULAR_DAMPING);
DEFINE_PROPERTY(PROP_COLLISIONLESS, Collisionless, collisionless, bool, ENTITY_ITEM_DEFAULT_COLLISIONLESS);
DEFINE_PROPERTY(PROP_COLLISION_MASK, CollisionMask, collisionMask, uint16_t, ENTITY_COLLISION_MASK_DEFAULT);
@ -171,14 +171,14 @@ public:
DEFINE_PROPERTY(PROP_EMIT_SPEED, EmitSpeed, emitSpeed, float, particle::DEFAULT_EMIT_SPEED);
DEFINE_PROPERTY(PROP_SPEED_SPREAD, SpeedSpread, speedSpread, float, particle::DEFAULT_SPEED_SPREAD);
DEFINE_PROPERTY_REF(PROP_EMIT_ORIENTATION, EmitOrientation, emitOrientation, glm::quat, particle::DEFAULT_EMIT_ORIENTATION);
DEFINE_PROPERTY_REF(PROP_EMIT_DIMENSIONS, EmitDimensions, emitDimensions, glm::vec3, particle::DEFAULT_EMIT_DIMENSIONS);
DEFINE_PROPERTY_REF(PROP_EMIT_DIMENSIONS, EmitDimensions, emitDimensions, ScriptVec3Float, particle::DEFAULT_EMIT_DIMENSIONS);
DEFINE_PROPERTY(PROP_EMIT_RADIUS_START, EmitRadiusStart, emitRadiusStart, float, particle::DEFAULT_EMIT_RADIUS_START);
DEFINE_PROPERTY(PROP_POLAR_START, PolarStart, polarStart, float, particle::DEFAULT_POLAR_START);
DEFINE_PROPERTY(PROP_POLAR_FINISH, PolarFinish, polarFinish, float, particle::DEFAULT_POLAR_FINISH);
DEFINE_PROPERTY(PROP_AZIMUTH_START, AzimuthStart, azimuthStart, float, particle::DEFAULT_AZIMUTH_START);
DEFINE_PROPERTY(PROP_AZIMUTH_FINISH, AzimuthFinish, azimuthFinish, float, particle::DEFAULT_AZIMUTH_FINISH);
DEFINE_PROPERTY_REF(PROP_EMIT_ACCELERATION, EmitAcceleration, emitAcceleration, glm::vec3, particle::DEFAULT_EMIT_ACCELERATION);
DEFINE_PROPERTY_REF(PROP_ACCELERATION_SPREAD, AccelerationSpread, accelerationSpread, glm::vec3, particle::DEFAULT_ACCELERATION_SPREAD);
DEFINE_PROPERTY_REF(PROP_EMIT_ACCELERATION, EmitAcceleration, emitAcceleration, ScriptVec3Float, particle::DEFAULT_EMIT_ACCELERATION);
DEFINE_PROPERTY_REF(PROP_ACCELERATION_SPREAD, AccelerationSpread, accelerationSpread, ScriptVec3Float, particle::DEFAULT_ACCELERATION_SPREAD);
DEFINE_PROPERTY(PROP_PARTICLE_RADIUS, ParticleRadius, particleRadius, float, particle::DEFAULT_PARTICLE_RADIUS);
DEFINE_PROPERTY(PROP_RADIUS_SPREAD, RadiusSpread, radiusSpread, float, particle::DEFAULT_RADIUS_SPREAD);
DEFINE_PROPERTY(PROP_RADIUS_START, RadiusStart, radiusStart, float, particle::DEFAULT_RADIUS_START);
@ -186,7 +186,7 @@ public:
DEFINE_PROPERTY(PROP_EMITTER_SHOULD_TRAIL, EmitterShouldTrail, emitterShouldTrail, bool, particle::DEFAULT_EMITTER_SHOULD_TRAIL);
DEFINE_PROPERTY_GROUP(KeyLight, keyLight, KeyLightPropertyGroup);
DEFINE_PROPERTY_GROUP(AmbientLight, ambientLight, AmbientLightPropertyGroup);
DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE);
DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, ScriptVec3Float, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE);
DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray, PolyVoxEntityItem::DEFAULT_VOXEL_DATA);
DEFINE_PROPERTY_REF(PROP_VOXEL_SURFACE_STYLE, VoxelSurfaceStyle, voxelSurfaceStyle, uint16_t, PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE);
DEFINE_PROPERTY_REF(PROP_NAME, Name, name, QString, ENTITY_ITEM_DEFAULT_NAME);
@ -201,13 +201,13 @@ public:
DEFINE_PROPERTY_GROUP(Animation, animation, AnimationPropertyGroup);
DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString, "");
DEFINE_PROPERTY(PROP_LINE_WIDTH, LineWidth, lineWidth, float, LineEntityItem::DEFAULT_LINE_WIDTH);
DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector<glm::vec3>, QVector<glm::vec3>());
DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector<ScriptVec3Float>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY_REF(PROP_HREF, Href, href, QString, "");
DEFINE_PROPERTY_REF(PROP_DESCRIPTION, Description, description, QString, "");
DEFINE_PROPERTY(PROP_FACE_CAMERA, FaceCamera, faceCamera, bool, TextEntityItem::DEFAULT_FACE_CAMERA);
DEFINE_PROPERTY_REF(PROP_ACTION_DATA, ActionData, actionData, QByteArray, QByteArray());
DEFINE_PROPERTY(PROP_NORMALS, Normals, normals, QVector<glm::vec3>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY(PROP_STROKE_COLORS, StrokeColors, strokeColors, QVector<glm::vec3>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY(PROP_NORMALS, Normals, normals, QVector<ScriptVec3Float>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY(PROP_STROKE_COLORS, StrokeColors, strokeColors, QVector<ScriptVec3Float>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY(PROP_STROKE_WIDTHS, StrokeWidths, strokeWidths, QVector<float>, QVector<float>());
DEFINE_PROPERTY(PROP_IS_UV_MODE_STRETCH, IsUVModeStretch, isUVModeStretch, bool, true);
DEFINE_PROPERTY_REF(PROP_X_TEXTURE_URL, XTextureURL, xTextureURL, QString, "");
@ -249,16 +249,16 @@ public:
DEFINE_PROPERTY_REF(PROP_STATIC_CERTIFICATE_VERSION, StaticCertificateVersion, staticCertificateVersion, quint32, ENTITY_ITEM_DEFAULT_STATIC_CERTIFICATE_VERSION);
// these are used when bouncing location data into and out of scripts
DEFINE_PROPERTY_REF(PROP_LOCAL_POSITION, LocalPosition, localPosition, vec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_POSITION, LocalPosition, localPosition, ScriptVec3Float, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_ROTATION, LocalRotation, localRotation, quat, ENTITY_ITEM_DEFAULT_ROTATION);
DEFINE_PROPERTY_REF(PROP_LOCAL_VELOCITY, LocalVelocity, localVelocity, vec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_ANGULAR_VELOCITY, LocalAngularVelocity, localAngularVelocity, vec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_DIMENSIONS, LocalDimensions, localDimensions, vec3, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_VELOCITY, LocalVelocity, localVelocity, ScriptVec3Float, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_ANGULAR_VELOCITY, LocalAngularVelocity, localAngularVelocity, ScriptVec3Float, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_LOCAL_DIMENSIONS, LocalDimensions, localDimensions, ScriptVec3Float, ENTITY_ITEM_ZERO_VEC3);
DEFINE_PROPERTY_REF(PROP_JOINT_ROTATIONS_SET, JointRotationsSet, jointRotationsSet, QVector<bool>, QVector<bool>());
DEFINE_PROPERTY_REF(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector<glm::quat>, QVector<glm::quat>());
DEFINE_PROPERTY_REF(PROP_JOINT_TRANSLATIONS_SET, JointTranslationsSet, jointTranslationsSet, QVector<bool>, QVector<bool>());
DEFINE_PROPERTY_REF(PROP_JOINT_TRANSLATIONS, JointTranslations, jointTranslations, QVector<glm::vec3>, QVector<glm::vec3>());
DEFINE_PROPERTY_REF(PROP_JOINT_TRANSLATIONS, JointTranslations, jointTranslations, QVector<ScriptVec3Float>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
DEFINE_PROPERTY(PROP_FLYING_ALLOWED, FlyingAllowed, flyingAllowed, bool, ZoneEntityItem::DEFAULT_FLYING_ALLOWED);
DEFINE_PROPERTY(PROP_GHOSTING_ALLOWED, GhostingAllowed, ghostingAllowed, bool, ZoneEntityItem::DEFAULT_GHOSTING_ALLOWED);
@ -287,7 +287,7 @@ public:
std::array<ComponentPair, COMPONENT_MODE_ITEM_COUNT>::const_iterator findComponent(const QString& mode);
public:
float getMaxDimension() const { return glm::compMax(_dimensions); }
float getMaxDimension() const { return glm::compMax(glm::vec3(_dimensions.x, _dimensions.y, _dimensions.z)); }
float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; }
bool hasCreatedTime() const { return (_created != UNKNOWN_CREATED_TIME); }
@ -314,10 +314,10 @@ public:
void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; }
void markAllChanged();
const glm::vec3& getNaturalDimensions() const { return _naturalDimensions; }
const glm::vec3& getNaturalDimensions() const { return glm::vec3(_naturalDimensions.x, _naturalDimensions.y, _naturalDimensions.z); }
void setNaturalDimensions(const glm::vec3& value) { _naturalDimensions = value; }
const glm::vec3& getNaturalPosition() const { return _naturalPosition; }
const glm::vec3& getNaturalPosition() const { return glm::vec3(_naturalPosition.x, _naturalPosition.y, _naturalPosition.z); }
void calculateNaturalPosition(const glm::vec3& min, const glm::vec3& max);
const QVariantMap& getTextureNames() const { return _textureNames; }
@ -364,16 +364,16 @@ public:
void setRenderInfoHasTransparent(bool value) { _renderInfoHasTransparent = value; }
void setPackedNormals(const QByteArray& value);
QVector<glm::vec3> unpackNormals(const QByteArray& normals);
QVector<ScriptVec3Float> unpackNormals(const QByteArray& normals);
void setPackedStrokeColors(const QByteArray& value);
QVector<glm::vec3> unpackStrokeColors(const QByteArray& strokeColors);
QVector<ScriptVec3Float> unpackStrokeColors(const QByteArray& strokeColors);
QByteArray getPackedNormals() const;
QByteArray packNormals(const QVector<glm::vec3>& normals) const;
QByteArray packNormals(const QVector<ScriptVec3Float>& normals) const;
QByteArray getPackedStrokeColors() const;
QByteArray packStrokeColors(const QVector<glm::vec3>& strokeColors) const;
QByteArray packStrokeColors(const QVector<ScriptVec3Float>& strokeColors) const;
QByteArray getStaticCertificateJSON() const;
QByteArray getStaticCertificateHash() const;
@ -401,8 +401,8 @@ private:
// NOTE: The following are pseudo client only properties. They are only used in clients which can access
// properties of model geometry. But these properties are not serialized like other properties.
QVariantMap _textureNames;
glm::vec3 _naturalDimensions;
glm::vec3 _naturalPosition;
ScriptVec3Float _naturalDimensions;
ScriptVec3Float _naturalPosition;
size_t _renderInfoVertexCount { 0 };
int _renderInfoTextureCount { 0 };
@ -425,8 +425,8 @@ void EntityPropertyFlagsFromScriptValue(const QScriptValue& object, EntityProper
// define these inline here so the macros work
inline void EntityItemProperties::setPosition(const glm::vec3& value)
{ _position = glm::clamp(value, (float)-HALF_TREE_SCALE, (float)HALF_TREE_SCALE); _positionChanged = true; }
inline void EntityItemProperties::setPosition(const ScriptVec3Float& value)
{ _position = glm::clamp(glm::vec3(value.x, value.y, value.z), (float)-HALF_TREE_SCALE, (float)HALF_TREE_SCALE); _positionChanged = true; }
inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
debug << "EntityItemProperties[" << "\n";

View file

@ -24,7 +24,7 @@ const glm::vec3 ENTITY_ITEM_ZERO_VEC3 = glm::vec3(0.0f);
const glm::vec3 ENTITY_ITEM_ONE_VEC3 = glm::vec3(1.0f);
const glm::vec3 ENTITY_ITEM_HALF_VEC3 = glm::vec3(0.5f);
const QVector<glm::vec3> ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC = QVector<glm::vec3>();
const QVector<ScriptVec3Float> ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC = QVector<ScriptVec3Float>();
const bool ENTITY_ITEM_DEFAULT_LOCKED = false;
const QString ENTITY_ITEM_DEFAULT_USER_DATA = QString("");

View file

@ -101,8 +101,9 @@
changedProperties += P; \
}
inline QScriptValue convertScriptValue(QScriptEngine* e, const ScriptVec2Float& v) { return vec2toScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::vec3& v) { return vec3toScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const ScriptVec2Float& v) { return vec2FloatToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const ScriptVec3Float& v) { return vec3FloatToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const ScriptVec3UInt& v) { return vec3UIntToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, float v) { return QScriptValue(v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, int v) { return QScriptValue(v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, bool v) { return QScriptValue(v); }
@ -114,7 +115,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const QString& v) { ret
inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { return xColorToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector<glm::vec3>& v) {return qVectorVec3ToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector<ScriptVec3Float>& v) {return qVectorVec3ToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector<glm::quat>& v) {return qVectorQuatToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector<bool>& v) {return qVectorBoolToScriptValue(e, v); }
inline QScriptValue convertScriptValue(QScriptEngine* e, const QVector<float>& v) { return qVectorFloatToScriptValue(e, v); }
@ -185,7 +186,7 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const AACube& v) { retu
properties.setProperty(#P, V); \
}
typedef QVector<glm::vec3> qVectorVec3;
typedef QVector<ScriptVec3Float> qVectorVec3;
typedef QVector<glm::quat> qVectorQuat;
typedef QVector<bool> qVectorBool;
typedef QVector<float> qVectorFloat;
@ -224,37 +225,22 @@ inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool&
inline ScriptVec2Float ScriptVec2Float_convertFromScriptValue(const QScriptValue& v, bool& isValid) {
isValid = true;
ScriptVec2Float vec2;
vec2FromScriptValue(v, vec2);
vec2FloatFromScriptValue(v, vec2);
return vec2;
}
inline glm::vec3 vec3_convertFromScriptValue(const QScriptValue& v, bool& isValid) {
isValid = false; /// assume it can't be converted
QScriptValue x = v.property("x");
QScriptValue y = v.property("y");
QScriptValue z = v.property("z");
if (!x.isValid()) {
x = v.property("red");
}
if (!y.isValid()) {
y = v.property("green");
}
if (!z.isValid()) {
z = v.property("blue");
}
if (x.isValid() && y.isValid() && z.isValid()) {
glm::vec3 newValue(0);
newValue.x = x.toVariant().toFloat();
newValue.y = y.toVariant().toFloat();
newValue.z = z.toVariant().toFloat();
isValid = !glm::isnan(newValue.x) &&
!glm::isnan(newValue.y) &&
!glm::isnan(newValue.z);
if (isValid) {
return newValue;
}
}
return glm::vec3(0);
inline ScriptVec3Float ScriptVec3Float_convertFromScriptValue(const QScriptValue& v, bool& isValid) {
isValid = true;
ScriptVec3Float vec3;
vec3FloatFromScriptValue(v, vec3);
return vec3;
}
inline ScriptVec3UInt ScriptVec3UInt_convertFromScriptValue(const QScriptValue& v, bool& isValid) {
isValid = true;
ScriptVec3UInt vec3;
vec3UIntFromScriptValue(v, vec3);
return vec3;
}
inline AACube AACube_convertFromScriptValue(const QScriptValue& v, bool& isValid) {

View file

@ -135,7 +135,7 @@ EntityItemProperties convertPropertiesToScriptSemantics(const EntityItemProperti
scriptSideProperties.setLocalDimensions(entitySideProperties.getDimensions());
bool success;
glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(),
glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent,
@ -145,17 +145,17 @@ EntityItemProperties convertPropertiesToScriptSemantics(const EntityItemProperti
entitySideProperties.getParentJointIndex(),
scalesWithParent,
success);
glm::vec3 worldVelocity = SpatiallyNestable::localToWorldVelocity(entitySideProperties.getVelocity(),
glm::vec3 worldVelocity = SpatiallyNestable::localToWorldVelocity(entitySideProperties.getVelocity().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent,
success);
glm::vec3 worldAngularVelocity = SpatiallyNestable::localToWorldAngularVelocity(entitySideProperties.getAngularVelocity(),
glm::vec3 worldAngularVelocity = SpatiallyNestable::localToWorldAngularVelocity(entitySideProperties.getAngularVelocity().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent,
success);
glm::vec3 worldDimensions = SpatiallyNestable::localToWorldDimensions(entitySideProperties.getDimensions(),
glm::vec3 worldDimensions = SpatiallyNestable::localToWorldDimensions(entitySideProperties.getDimensions().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent,
@ -184,7 +184,7 @@ EntityItemProperties convertPropertiesFromScriptSemantics(const EntityItemProper
if (scriptSideProperties.localPositionChanged()) {
entitySideProperties.setPosition(scriptSideProperties.getLocalPosition());
} else if (scriptSideProperties.positionChanged()) {
glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition(),
glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent, success);
@ -204,7 +204,7 @@ EntityItemProperties convertPropertiesFromScriptSemantics(const EntityItemProper
if (scriptSideProperties.localVelocityChanged()) {
entitySideProperties.setVelocity(scriptSideProperties.getLocalVelocity());
} else if (scriptSideProperties.velocityChanged()) {
glm::vec3 localVelocity = SpatiallyNestable::worldToLocalVelocity(entitySideProperties.getVelocity(),
glm::vec3 localVelocity = SpatiallyNestable::worldToLocalVelocity(entitySideProperties.getVelocity().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent, success);
@ -215,7 +215,7 @@ EntityItemProperties convertPropertiesFromScriptSemantics(const EntityItemProper
entitySideProperties.setAngularVelocity(scriptSideProperties.getLocalAngularVelocity());
} else if (scriptSideProperties.angularVelocityChanged()) {
glm::vec3 localAngularVelocity =
SpatiallyNestable::worldToLocalAngularVelocity(entitySideProperties.getAngularVelocity(),
SpatiallyNestable::worldToLocalAngularVelocity(entitySideProperties.getAngularVelocity().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent, success);
@ -225,7 +225,7 @@ EntityItemProperties convertPropertiesFromScriptSemantics(const EntityItemProper
if (scriptSideProperties.localDimensionsChanged()) {
entitySideProperties.setDimensions(scriptSideProperties.getLocalDimensions());
} else if (scriptSideProperties.dimensionsChanged()) {
glm::vec3 localDimensions = SpatiallyNestable::worldToLocalDimensions(entitySideProperties.getDimensions(),
glm::vec3 localDimensions = SpatiallyNestable::worldToLocalDimensions(entitySideProperties.getDimensions().toGlm(),
entitySideProperties.getParentID(),
entitySideProperties.getParentJointIndex(),
scalesWithParent, success);
@ -1091,10 +1091,10 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c
}
obj.setProperty("face", faceName);
QScriptValue intersection = vec3toScriptValue(engine, value.intersection);
QScriptValue intersection = vec3ToScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection);
QScriptValue surfaceNormal = vec3toScriptValue(engine, value.surfaceNormal);
QScriptValue surfaceNormal = vec3ToScriptValue(engine, value.surfaceNormal);
obj.setProperty("surfaceNormal", surfaceNormal);
obj.setProperty("extraInfo", engine->toScriptValue(value.extraInfo));
return obj;
@ -1243,7 +1243,7 @@ bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3
});
}
bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {
bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<ScriptVec3Float>& points) {
PROFILE_RANGE(script_entities, __FUNCTION__);
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));

View file

@ -832,7 +832,7 @@ public slots:
* ]);
* }, 2000);
*/
Q_INVOKABLE bool setAllPoints(QUuid entityID, const QVector<glm::vec3>& points);
Q_INVOKABLE bool setAllPoints(QUuid entityID, const QVector<ScriptVec3Float>& points);
/**jsdoc
* Append a point to a {@link Entities.EntityType|Line} entity.

View file

@ -1010,7 +1010,7 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
if (properties.velocityChanged()) {
int index = changedProperties.indexOf("velocity");
if (index >= 0) {
glm::vec3 value = properties.getVelocity();
glm::vec3 value = properties.getVelocity().toGlm();
changedProperties[index] = QString("velocity:") +
QString::number((int)value.x) + "," +
QString::number((int)value.y) + "," +
@ -1021,7 +1021,7 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
if (properties.gravityChanged()) {
int index = changedProperties.indexOf("gravity");
if (index >= 0) {
glm::vec3 value = properties.getGravity();
glm::vec3 value = properties.getGravity().toGlm();
QString changeHint = "0";
if (value.x + value.y + value.z > 0) {
changeHint = "+";
@ -1139,7 +1139,7 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
}
if (properties.positionChanged()) {
int index = changedProperties.indexOf("position");
glm::vec3 pos = properties.getPosition();
glm::vec3 pos = properties.getPosition().toGlm();
changedProperties[index] = QString("position:") +
QString::number((int)pos.x) + "," +
QString::number((int)pos.y) + "," +
@ -1161,7 +1161,7 @@ bool EntityTree::filterProperties(EntityItemPointer& existingEntity, EntityItemP
if (entityEditFilters) {
auto position = existingEntity ? existingEntity->getWorldPosition() : propertiesIn.getPosition();
auto entityID = existingEntity ? existingEntity->getEntityItemID() : EntityItemID();
accepted = entityEditFilters->filter(position, propertiesIn, propertiesOut, wasChanged, filterType, entityID, existingEntity);
accepted = entityEditFilters->filter(position.toGlm(), propertiesIn, propertiesOut, wasChanged, filterType, entityID, existingEntity);
}
return accepted;
@ -2318,7 +2318,7 @@ bool EntityTree::sendEntitiesOperation(const OctreeElementPointer& element, void
EntityItemID oldParentID = properties.getParentID();
if (oldParentID.isInvalidID()) { // no parent
properties.setPosition(properties.getPosition() + args->root);
properties.setPosition(properties.getPosition().toGlm() + args->root);
} else {
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
if (parentEntity || oldParentID == AVATAR_SELF_ID) { // map the parent

View file

@ -35,13 +35,13 @@ void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desired
void KeyLightPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, color, xColor, setColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, intensity, float, setIntensity);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, direction, vec3, setDirection);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, direction, ScriptVec3Float, setDirection);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, castShadows, bool, setCastShadows);
// legacy property support
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightColor, xColor, setColor, getColor);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightIntensity, float, setIntensity, getIntensity);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightDirection, vec3, setDirection, getDirection);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightDirection, ScriptVec3Float, setDirection, getDirection);
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightCastShadows, bool, setCastShadows, getCastShadows);
}
@ -101,7 +101,7 @@ bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFl
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, ScriptVec3Float, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOW, bool, setCastShadows);
DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_COLOR, Color);
@ -189,7 +189,7 @@ int KeyLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char*
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, ScriptVec3Float, setDirection);
READ_ENTITY_PROPERTY(PROP_KEYLIGHT_CAST_SHADOW, bool, setCastShadows);
return bytesRead;

View file

@ -92,7 +92,7 @@ public:
DEFINE_PROPERTY_REF(PROP_KEYLIGHT_COLOR, Color, color, xColor, DEFAULT_KEYLIGHT_COLOR);
DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, Intensity, intensity, float, DEFAULT_KEYLIGHT_INTENSITY);
DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, Direction, direction, glm::vec3, DEFAULT_KEYLIGHT_DIRECTION);
DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, Direction, direction, ScriptVec3Float, DEFAULT_KEYLIGHT_DIRECTION);
DEFINE_PROPERTY(PROP_KEYLIGHT_CAST_SHADOW, CastShadows, castShadows, bool, DEFAULT_KEYLIGHT_CAST_SHADOWS);
};

View file

@ -75,7 +75,7 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) {
return somethingChanged;
}
bool LineEntityItem::appendPoint(const glm::vec3& point) {
bool LineEntityItem::appendPoint(const ScriptVec3Float& point) {
if (_points.size() > MAX_POINTS_PER_LINE - 1) {
qCDebug(entities) << "MAX POINTS REACHED!";
return false;
@ -92,13 +92,13 @@ bool LineEntityItem::appendPoint(const glm::vec3& point) {
return true;
}
bool LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
bool LineEntityItem::setLinePoints(const QVector<ScriptVec3Float>& points) {
if (points.size() > MAX_POINTS_PER_LINE) {
return false;
}
glm::vec3 halfBox = getScaledDimensions() * 0.5f;
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
ScriptVec3Float point = points.at(i);
if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) {
qCDebug(entities) << "Point is outside entity's bounding box";
return false;
@ -122,7 +122,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor);
READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth);
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<ScriptVec3Float>, setLinePoints);
return bytesRead;
}
@ -201,8 +201,8 @@ float LineEntityItem::getLineWidth() const {
return result;
}
QVector<glm::vec3> LineEntityItem::getLinePoints() const {
QVector<glm::vec3> result;
QVector<ScriptVec3Float> LineEntityItem::getLinePoints() const {
QVector<ScriptVec3Float> result;
withReadLock([&] {
result = _points;
});

View file

@ -50,10 +50,10 @@ class LineEntityItem : public EntityItem {
void setLineWidth(float lineWidth);
float getLineWidth() const;
bool setLinePoints(const QVector<glm::vec3>& points);
bool appendPoint(const glm::vec3& point);
bool setLinePoints(const QVector<ScriptVec3Float>& points);
bool appendPoint(const ScriptVec3Float& point);
QVector<glm::vec3> getLinePoints() const;
QVector<ScriptVec3Float> getLinePoints() const;
virtual ShapeType getShapeType() const override { return SHAPE_TYPE_NONE; }
@ -73,7 +73,7 @@ class LineEntityItem : public EntityItem {
private:
rgbColor _color;
float _lineWidth { DEFAULT_LINE_WIDTH };
QVector<glm::vec3> _points;
QVector<ScriptVec3Float> _points;
bool _pointsChanged { true };
};

View file

@ -140,7 +140,7 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
READ_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS_SET, QVector<bool>, setJointRotationsSet);
READ_ENTITY_PROPERTY(PROP_JOINT_ROTATIONS, QVector<glm::quat>, setJointRotations);
READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS_SET, QVector<bool>, setJointTranslationsSet);
READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, QVector<glm::vec3>, setJointTranslations);
READ_ENTITY_PROPERTY(PROP_JOINT_TRANSLATIONS, QVector<ScriptVec3Float>, setJointTranslations);
return bytesRead;
}
@ -428,7 +428,7 @@ void ModelEntityItem::setJointRotationsSet(const QVector<bool>& rotationsSet) {
});
}
void ModelEntityItem::setJointTranslations(const QVector<glm::vec3>& translations) {
void ModelEntityItem::setJointTranslations(const QVector<ScriptVec3Float>& translations) {
resizeJointArrays(translations.size());
_jointDataLock.withWriteLock([&] {
_jointTranslationsExplicitlySet = translations.size() > 0;
@ -479,8 +479,8 @@ QVector<bool> ModelEntityItem::getJointRotationsSet() const {
return result;
}
QVector<glm::vec3> ModelEntityItem::getJointTranslations() const {
QVector<glm::vec3> result;
QVector<ScriptVec3Float> ModelEntityItem::getJointTranslations() const {
QVector<ScriptVec3Float> result;
_jointDataLock.withReadLock([&] {
if (_jointTranslationsExplicitlySet) {
result.resize(_localJointData.size());

View file

@ -119,14 +119,14 @@ public:
virtual void setJointRotations(const QVector<glm::quat>& rotations);
virtual void setJointRotationsSet(const QVector<bool>& rotationsSet);
virtual void setJointTranslations(const QVector<glm::vec3>& translations);
virtual void setJointTranslations(const QVector<ScriptVec3Float>& translations);
virtual void setJointTranslationsSet(const QVector<bool>& translationsSet);
virtual void setAnimationJointsData(const QVector<EntityJointData>& jointsData);
QVector<glm::quat> getJointRotations() const;
QVector<bool> getJointRotationsSet() const;
QVector<glm::vec3> getJointTranslations() const;
QVector<ScriptVec3Float> getJointTranslations() const;
QVector<bool> getJointTranslationsSet() const;
private:

View file

@ -486,8 +486,8 @@ int ParticleEffectEntityItem::readEntitySubclassDataFromBuffer(const unsigned ch
READ_ENTITY_PROPERTY(PROP_LIFESPAN, float, setLifespan);
READ_ENTITY_PROPERTY(PROP_EMIT_RATE, float, setEmitRate);
READ_ENTITY_PROPERTY(PROP_EMIT_ACCELERATION, vec3, setEmitAcceleration);
READ_ENTITY_PROPERTY(PROP_ACCELERATION_SPREAD, vec3, setAccelerationSpread);
READ_ENTITY_PROPERTY(PROP_EMIT_ACCELERATION, ScriptVec3Float, setEmitAcceleration);
READ_ENTITY_PROPERTY(PROP_ACCELERATION_SPREAD, ScriptVec3Float, setAccelerationSpread);
READ_ENTITY_PROPERTY(PROP_PARTICLE_RADIUS, float, setParticleRadius);
READ_ENTITY_PROPERTY(PROP_TEXTURES, QString, setTextures);
@ -496,8 +496,8 @@ int ParticleEffectEntityItem::readEntitySubclassDataFromBuffer(const unsigned ch
READ_ENTITY_PROPERTY(PROP_RADIUS_FINISH, float, setRadiusFinish);
READ_ENTITY_PROPERTY(PROP_COLOR_SPREAD, xColor, setColorSpread);
READ_ENTITY_PROPERTY(PROP_COLOR_START, vec3, setColorStart);
READ_ENTITY_PROPERTY(PROP_COLOR_FINISH, vec3, setColorFinish);
READ_ENTITY_PROPERTY(PROP_COLOR_START, ScriptVec3Float, setColorStart);
READ_ENTITY_PROPERTY(PROP_COLOR_FINISH, ScriptVec3Float, setColorFinish);
READ_ENTITY_PROPERTY(PROP_ALPHA, float, setAlpha);
READ_ENTITY_PROPERTY(PROP_ALPHA_SPREAD, float, setAlphaSpread);
READ_ENTITY_PROPERTY(PROP_ALPHA_START, float, setAlphaStart);
@ -506,7 +506,7 @@ int ParticleEffectEntityItem::readEntitySubclassDataFromBuffer(const unsigned ch
READ_ENTITY_PROPERTY(PROP_EMIT_SPEED, float, setEmitSpeed);
READ_ENTITY_PROPERTY(PROP_SPEED_SPREAD, float, setSpeedSpread);
READ_ENTITY_PROPERTY(PROP_EMIT_ORIENTATION, quat, setEmitOrientation);
READ_ENTITY_PROPERTY(PROP_EMIT_DIMENSIONS, vec3, setEmitDimensions);
READ_ENTITY_PROPERTY(PROP_EMIT_DIMENSIONS, ScriptVec3Float, setEmitDimensions);
READ_ENTITY_PROPERTY(PROP_EMIT_RADIUS_START, float, setEmitRadiusStart);
READ_ENTITY_PROPERTY(PROP_POLAR_START, float, setPolarStart);
READ_ENTITY_PROPERTY(PROP_POLAR_FINISH, float, setPolarFinish);
@ -570,16 +570,16 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
APPEND_ENTITY_PROPERTY(PROP_MAX_PARTICLES, getMaxParticles());
APPEND_ENTITY_PROPERTY(PROP_LIFESPAN, getLifespan());
APPEND_ENTITY_PROPERTY(PROP_EMIT_RATE, getEmitRate());
APPEND_ENTITY_PROPERTY(PROP_EMIT_ACCELERATION, getEmitAcceleration());
APPEND_ENTITY_PROPERTY(PROP_ACCELERATION_SPREAD, getAccelerationSpread());
APPEND_ENTITY_PROPERTY(PROP_EMIT_ACCELERATION, getScriptEmitAcceleration());
APPEND_ENTITY_PROPERTY(PROP_ACCELERATION_SPREAD, getScriptAccelerationSpread());
APPEND_ENTITY_PROPERTY(PROP_PARTICLE_RADIUS, getParticleRadius());
APPEND_ENTITY_PROPERTY(PROP_TEXTURES, getTextures());
APPEND_ENTITY_PROPERTY(PROP_RADIUS_SPREAD, getRadiusSpread());
APPEND_ENTITY_PROPERTY(PROP_RADIUS_START, getRadiusStart());
APPEND_ENTITY_PROPERTY(PROP_RADIUS_FINISH, getRadiusFinish());
APPEND_ENTITY_PROPERTY(PROP_COLOR_SPREAD, getColorSpread());
APPEND_ENTITY_PROPERTY(PROP_COLOR_START, getColorStart());
APPEND_ENTITY_PROPERTY(PROP_COLOR_FINISH, getColorFinish());
APPEND_ENTITY_PROPERTY(PROP_COLOR_START, getScriptColorStart());
APPEND_ENTITY_PROPERTY(PROP_COLOR_FINISH, getScriptColorFinish());
APPEND_ENTITY_PROPERTY(PROP_ALPHA, getAlpha());
APPEND_ENTITY_PROPERTY(PROP_ALPHA_SPREAD, getAlphaSpread());
APPEND_ENTITY_PROPERTY(PROP_ALPHA_START, getAlphaStart());
@ -587,7 +587,7 @@ void ParticleEffectEntityItem::appendSubclassData(OctreePacketData* packetData,
APPEND_ENTITY_PROPERTY(PROP_EMIT_SPEED, getEmitSpeed());
APPEND_ENTITY_PROPERTY(PROP_SPEED_SPREAD, getSpeedSpread());
APPEND_ENTITY_PROPERTY(PROP_EMIT_ORIENTATION, getEmitOrientation());
APPEND_ENTITY_PROPERTY(PROP_EMIT_DIMENSIONS, getEmitDimensions());
APPEND_ENTITY_PROPERTY(PROP_EMIT_DIMENSIONS, getScriptEmitDimensions());
APPEND_ENTITY_PROPERTY(PROP_EMIT_RADIUS_START, getEmitRadiusStart());
APPEND_ENTITY_PROPERTY(PROP_POLAR_START, getPolarStart());
APPEND_ENTITY_PROPERTY(PROP_POLAR_FINISH, getPolarFinish());

View file

@ -194,7 +194,7 @@ class ParticleEffectEntityItem : public EntityItem {
public:
ALLOW_INSTANTIATION // This class can be instantiated
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
ParticleEffectEntityItem(const EntityItemID& entityItemID);
@ -205,17 +205,17 @@ public:
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const override;
EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const override;
virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
bool& somethingChanged) override;
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
bool& somethingChanged) override;
xColor getXColor() const;
vec3 getColor() const { return _particleProperties.color.gradient.target; }
@ -224,10 +224,14 @@ public:
void setColor(const xColor& value);
void setColorStart(const vec3& colorStart);
void setColorStart(const ScriptVec3Float& colorStart) { setColorStart(colorStart.toGlm()); }
vec3 getColorStart() const { return _particleProperties.color.range.start; }
ScriptVec3Float getScriptColorStart() const { return getColorStart(); }
void setColorFinish(const vec3& colorFinish);
void setColorFinish(const ScriptVec3Float& colorFinish) { setColorFinish(colorFinish.toGlm()); }
vec3 getColorFinish() const { return _particleProperties.color.range.finish; }
ScriptVec3Float getScriptColorFinish() const { return getColorFinish(); }
void setColorSpread(const xColor& colorSpread);
xColor getColorSpread() const;
@ -271,7 +275,9 @@ public:
const glm::quat& getEmitOrientation() const { return _particleProperties.emission.orientation; }
void setEmitDimensions(const glm::vec3& emitDimensions);
void setEmitDimensions(const ScriptVec3Float& emitDimensions) { setEmitDimensions(emitDimensions.toGlm()); }
const glm::vec3& getEmitDimensions() const { return _particleProperties.emission.dimensions; }
ScriptVec3Float getScriptEmitDimensions() const { return getEmitDimensions(); }
void setEmitRadiusStart(float emitRadiusStart);
float getEmitRadiusStart() const { return _particleProperties.radiusStart; }
@ -289,10 +295,14 @@ public:
float getAzimuthFinish() const { return _particleProperties.azimuth.finish; }
void setEmitAcceleration(const glm::vec3& emitAcceleration);
void setEmitAcceleration(const ScriptVec3Float& emitAcceleration) { setEmitAcceleration(emitAcceleration.toGlm()); }
const glm::vec3& getEmitAcceleration() const { return _particleProperties.emission.acceleration.target; }
ScriptVec3Float getScriptEmitAcceleration() const { return getEmitAcceleration(); }
void setAccelerationSpread(const glm::vec3& accelerationSpread);
void setAccelerationSpread(const ScriptVec3Float& accelerationSpread) { setAccelerationSpread(accelerationSpread.toGlm()); }
const glm::vec3& getAccelerationSpread() const { return _particleProperties.emission.acceleration.spread; }
ScriptVec3Float getScriptAccelerationSpread() const { return getAccelerationSpread(); }
void setParticleRadius(float particleRadius);
float getParticleRadius() const { return _particleProperties.radius.gradient.target; }

View file

@ -83,7 +83,7 @@ bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
}
bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
bool PolyLineEntityItem::appendPoint(const ScriptVec3Float& point) {
if (_points.size() > MAX_POINTS_PER_LINE - 1) {
qCDebug(entities) << "MAX POINTS REACHED!";
return false;
@ -106,7 +106,7 @@ bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
return true;
}
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
bool PolyLineEntityItem::setNormals(const QVector<ScriptVec3Float>& normals) {
withWriteLock([&] {
_normals = normals;
_normalsChanged = true;
@ -114,7 +114,7 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
return true;
}
bool PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors) {
bool PolyLineEntityItem::setStrokeColors(const QVector<ScriptVec3Float>& strokeColors) {
withWriteLock([&] {
_strokeColors = strokeColors;
_strokeColorsChanged = true;
@ -123,7 +123,7 @@ bool PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors)
}
bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
bool PolyLineEntityItem::setLinePoints(const QVector<ScriptVec3Float>& points) {
if (points.size() > MAX_POINTS_PER_LINE) {
return false;
}
@ -165,10 +165,10 @@ void PolyLineEntityItem::calculateScaleAndRegistrationPoint() {
withReadLock([&] {
pointCount = _points.size();
if (pointCount > 0) {
firstPoint = _points.at(0);
firstPoint = _points.at(0).toGlm();
}
for (int i = 0; i < pointCount; i++) {
const glm::vec3& point = _points.at(i);
const glm::vec3& point = _points.at(i).toGlm();
high = glm::max(point, high);
low = glm::min(point, low);
}
@ -206,9 +206,9 @@ int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* da
READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor);
READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth);
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
READ_ENTITY_PROPERTY(PROP_STROKE_COLORS, QVector<glm::vec3>, setStrokeColors);
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<ScriptVec3Float>, setLinePoints);
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<ScriptVec3Float>, setNormals);
READ_ENTITY_PROPERTY(PROP_STROKE_COLORS, QVector<ScriptVec3Float>, setStrokeColors);
READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
READ_ENTITY_PROPERTY(PROP_TEXTURES, QString, setTextures);
READ_ENTITY_PROPERTY(PROP_IS_UV_MODE_STRETCH, bool, setIsUVModeStretch);
@ -261,24 +261,24 @@ void PolyLineEntityItem::debugDump() const {
QVector<glm::vec3> PolyLineEntityItem::getLinePoints() const {
QVector<glm::vec3> result;
QVector<ScriptVec3Float> PolyLineEntityItem::getLinePoints() const {
QVector<ScriptVec3Float> result;
withReadLock([&] {
result = _points;
});
return result;
}
QVector<glm::vec3> PolyLineEntityItem::getNormals() const {
QVector<glm::vec3> result;
QVector<ScriptVec3Float> PolyLineEntityItem::getNormals() const {
QVector<ScriptVec3Float> result;
withReadLock([&] {
result = _normals;
});
return result;
}
QVector<glm::vec3> PolyLineEntityItem::getStrokeColors() const {
QVector<glm::vec3> result;
QVector<ScriptVec3Float> PolyLineEntityItem::getStrokeColors() const {
QVector<ScriptVec3Float> result;
withReadLock([&] {
result = _strokeColors;
});

View file

@ -58,15 +58,15 @@ class PolyLineEntityItem : public EntityItem {
void setLineWidth(float lineWidth){ _lineWidth = lineWidth; }
float getLineWidth() const{ return _lineWidth; }
bool setLinePoints(const QVector<glm::vec3>& points);
bool appendPoint(const glm::vec3& point);
QVector<glm::vec3> getLinePoints() const;
bool setLinePoints(const QVector<ScriptVec3Float>& points);
bool appendPoint(const ScriptVec3Float& point);
QVector<ScriptVec3Float> getLinePoints() const;
bool setNormals(const QVector<glm::vec3>& normals);
QVector<glm::vec3> getNormals() const;
bool setNormals(const QVector<ScriptVec3Float>& normals);
QVector<ScriptVec3Float> getNormals() const;
bool setStrokeColors(const QVector<glm::vec3>& strokeColors);
QVector<glm::vec3> getStrokeColors() const;
bool setStrokeColors(const QVector<ScriptVec3Float>& strokeColors);
QVector<ScriptVec3Float> getStrokeColors() const;
bool setStrokeWidths(const QVector<float>& strokeWidths);
QVector<float> getStrokeWidths() const;
@ -111,9 +111,9 @@ private:
bool _normalsChanged { true };
bool _strokeColorsChanged { true };
bool _strokeWidthsChanged { true };
QVector<glm::vec3> _points;
QVector<glm::vec3> _normals;
QVector<glm::vec3> _strokeColors;
QVector<ScriptVec3Float> _points;
QVector<ScriptVec3Float> _normals;
QVector<ScriptVec3Float> _strokeColors;
QVector<float> _strokeWidths;
QString _textures;
bool _isUVModeStretch;

View file

@ -70,9 +70,9 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID) : EntityI
_type = EntityTypes::PolyVox;
}
void PolyVoxEntityItem::setVoxelVolumeSize(const vec3& voxelVolumeSize) {
void PolyVoxEntityItem::setVoxelVolumeSize(const ScriptVec3Float& voxelVolumeSize) {
withWriteLock([&] {
assert(!glm::any(glm::isnan(voxelVolumeSize)));
assert(!glm::any(glm::isnan(voxelVolumeSize.toGlm())));
_voxelVolumeSize = glm::vec3(roundf(voxelVolumeSize.x), roundf(voxelVolumeSize.y), roundf(voxelVolumeSize.z));
if (_voxelVolumeSize.x < 1) {
@ -104,8 +104,8 @@ void PolyVoxEntityItem::setVoxelVolumeSize(const vec3& voxelVolumeSize) {
});
}
glm::vec3 PolyVoxEntityItem::getVoxelVolumeSize() const {
glm::vec3 voxelVolumeSize;
ScriptVec3Float PolyVoxEntityItem::getVoxelVolumeSize() const {
ScriptVec3Float voxelVolumeSize;
withReadLock([&] {
voxelVolumeSize = _voxelVolumeSize;
});
@ -167,7 +167,7 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat
int bytesRead = 0;
const unsigned char* dataAt = data;
READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize);
READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, ScriptVec3Float, setVoxelVolumeSize);
READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData);
READ_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle);
READ_ENTITY_PROPERTY(PROP_X_TEXTURE_URL, QString, setXTextureURL);
@ -375,7 +375,7 @@ EntityItemID PolyVoxEntityItem::getZPNeighborID() const {
glm::vec3 PolyVoxEntityItem::getSurfacePositionAdjustment() const {
glm::vec3 result;
withReadLock([&] {
glm::vec3 scale = getScaledDimensions() / _voxelVolumeSize; // meters / voxel-units
glm::vec3 scale = getScaledDimensions() / _voxelVolumeSize.toGlm(); // meters / voxel-units
if (isEdged()) {
result = scale / -2.0f;
}
@ -387,7 +387,7 @@ glm::vec3 PolyVoxEntityItem::getSurfacePositionAdjustment() const {
glm::mat4 PolyVoxEntityItem::voxelToLocalMatrix() const {
glm::vec3 voxelVolumeSize;
withReadLock([&] {
voxelVolumeSize = _voxelVolumeSize;
voxelVolumeSize = _voxelVolumeSize.toGlm();
});
glm::vec3 dimensions = getScaledDimensions();

View file

@ -50,8 +50,8 @@ class PolyVoxEntityItem : public EntityItem {
virtual void debugDump() const override;
virtual void setVoxelVolumeSize(const vec3& voxelVolumeSize);
virtual glm::vec3 getVoxelVolumeSize() const;
virtual void setVoxelVolumeSize(const ScriptVec3Float& voxelVolumeSize);
virtual ScriptVec3Float getVoxelVolumeSize() const;
virtual void setVoxelData(const QByteArray& voxelData);
virtual QByteArray getVoxelData() const;
@ -172,7 +172,7 @@ class PolyVoxEntityItem : public EntityItem {
protected:
void setVoxelDataDirty(bool value) { withWriteLock([&] { _voxelDataDirty = value; }); }
glm::vec3 _voxelVolumeSize { DEFAULT_VOXEL_VOLUME_SIZE }; // this is always 3 bytes
ScriptVec3Float _voxelVolumeSize { DEFAULT_VOXEL_VOLUME_SIZE }; // this is always 3 bytes
QByteArray _voxelData { DEFAULT_VOXEL_DATA };
bool _voxelDataDirty { true }; // _voxelData has changed, things that depend on it should be updated

View file

@ -367,8 +367,8 @@ namespace scriptable {
obj.setProperty("metallic", material.metallic);
obj.setProperty("scattering", material.scattering);
obj.setProperty("unlit", material.unlit);
obj.setProperty("emissive", vec3toScriptValue(engine, material.emissive));
obj.setProperty("albedo", vec3toScriptValue(engine, material.albedo));
obj.setProperty("emissive", vec3ToScriptValue(engine, material.emissive));
obj.setProperty("albedo", vec3ToScriptValue(engine, material.albedo));
obj.setProperty("emissiveMap", material.emissiveMap);
obj.setProperty("albedoMap", material.albedoMap);
obj.setProperty("opacityMap", material.opacityMap);

View file

@ -393,7 +393,7 @@ bool OctreePacketData::appendValue(const ScriptVec2Float& value) {
return success;
}
bool OctreePacketData::appendValue(const glm::vec3& value) {
bool OctreePacketData::appendValue(const ScriptVec3Float& value) {
const unsigned char* data = (const unsigned char*)&value;
int length = sizeof(value);
bool success = append(data, length);
@ -404,14 +404,14 @@ bool OctreePacketData::appendValue(const glm::vec3& value) {
return success;
}
bool OctreePacketData::appendValue(const QVector<glm::vec3>& value) {
bool OctreePacketData::appendValue(const QVector<ScriptVec3Float>& value) {
uint16_t qVecSize = value.size();
bool success = appendValue(qVecSize);
if (success) {
success = append((const unsigned char*)value.constData(), qVecSize * sizeof(glm::vec3));
success = append((const unsigned char*)value.constData(), qVecSize * sizeof(ScriptVec3Float));
if (success) {
_bytesOfValues += qVecSize * sizeof(glm::vec3);
_totalBytesOfValues += qVecSize * sizeof(glm::vec3);
_bytesOfValues += qVecSize * sizeof(ScriptVec3Float);
_totalBytesOfValues += qVecSize * sizeof(ScriptVec3Float);
}
}
return success;
@ -703,19 +703,19 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, xColor
}
int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVector<glm::vec3>& result) {
int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVector<ScriptVec3Float>& result) {
uint16_t length;
memcpy(&length, dataBytes, sizeof(uint16_t));
dataBytes += sizeof(length);
// FIXME - this size check is wrong if we allow larger packets
if (length * sizeof(glm::vec3) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) {
if (length * sizeof(ScriptVec3Float) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) {
result.resize(0);
return sizeof(uint16_t);
}
result.resize(length);
memcpy(result.data(), dataBytes, length * sizeof(glm::vec3));
return sizeof(uint16_t) + length * sizeof(glm::vec3);
memcpy(result.data(), dataBytes, length * sizeof(ScriptVec3Float));
return sizeof(uint16_t) + length * sizeof(ScriptVec3Float);
}
int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVector<glm::quat>& result) {

View file

@ -168,10 +168,10 @@ public:
bool appendValue(const ScriptVec2Float& value);
/// appends a non-position vector to the end of the stream, may fail if new data stream is too long to fit in packet
bool appendValue(const glm::vec3& value);
bool appendValue(const ScriptVec3Float& value);
/// appends a QVector of vec3s to the end of the stream, may fail if new data stream is too long to fit in packet
bool appendValue(const QVector<glm::vec3>& value);
bool appendValue(const QVector<ScriptVec3Float>& value);
/// appends a QVector of quats to the end of the stream, may fail if new data stream is too long to fit in packet
bool appendValue(const QVector<glm::quat>& value);
@ -254,7 +254,7 @@ public:
static int unpackDataFromBytes(const unsigned char* dataBytes, float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, ScriptVec2Float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, glm::vec3& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, ScriptVec3Float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
static int unpackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); }
@ -267,7 +267,7 @@ public:
static int unpackDataFromBytes(const unsigned char* dataBytes, QString& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QUuid& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, xColor& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QVector<glm::vec3>& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QVector<ScriptVec3Float>& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QVector<glm::quat>& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QVector<float>& result);
static int unpackDataFromBytes(const unsigned char* dataBytes, QVector<bool>& result);

View file

@ -1073,7 +1073,7 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con
updateVertices(id, points, QVector<glm::vec4>({ color }));
}
void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec4>& colors) {
void GeometryCache::updateVertices(int id, const QVector<ScriptVec3Float>& points, const QVector<glm::vec4>& colors) {
BatchItemDetails& details = _registeredVertices[id];
if (details.isCreated) {
details.clear();
@ -1121,7 +1121,7 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con
auto pointCount = points.size();
auto colorCount = colors.size();
for (auto i = 0; i < pointCount; i++) {
const glm::vec3& point = points[i];
const glm::vec3& point = points[i].toGlm();
if (i < colorCount) {
const glm::vec4& color = colors[i];
compactColor = ((int(color.x * 255.0f) & 0xFF)) |
@ -1148,11 +1148,11 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con
#endif
}
void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) {
void GeometryCache::updateVertices(int id, const QVector<ScriptVec3Float>& points, const glm::vec4& color) {
updateVertices(id, points, QVector<glm::vec4>({ color }));
}
void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) {
void GeometryCache::updateVertices(int id, const QVector<ScriptVec3Float>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) {
BatchItemDetails& details = _registeredVertices[id];
if (details.isCreated) {
@ -1207,7 +1207,7 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con
const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f);
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points[i];
glm::vec3 point = points[i].toGlm();
glm::vec2 texCoord = texCoords[i];
*(vertex++) = point.x;
*(vertex++) = point.y;

View file

@ -346,9 +346,9 @@ public:
void updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color);
void updateVertices(int id, const QVector<glm::vec2>& points, const QVector<glm::vec4>& colors);
void updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color);
void updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec4>& colors);
void updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color);
void updateVertices(int id, const QVector<ScriptVec3Float>& points, const glm::vec4& color);
void updateVertices(int id, const QVector<ScriptVec3Float>& points, const QVector<glm::vec4>& colors);
void updateVertices(int id, const QVector<ScriptVec3Float>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color);
void renderVertices(gpu::Batch& batch, gpu::Primitive primitiveType, int id);
/// Set a batch to the simple pipeline, returning the previous pipeline

View file

@ -420,8 +420,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
face = triangleSetFace;
bestModelTriangle = triangleSetTriangle;
bestWorldTriangle = triangleSetTriangle * meshToWorldMatrix;
extraInfo["worldIntersectionPoint"] = vec3toVariant(worldIntersectionPoint);
extraInfo["meshIntersectionPoint"] = vec3toVariant(meshIntersectionPoint);
extraInfo["worldIntersectionPoint"] = vec3ToVariant(worldIntersectionPoint);
extraInfo["meshIntersectionPoint"] = vec3ToVariant(meshIntersectionPoint);
extraInfo["partIndex"] = partIndex;
extraInfo["shapeID"] = shapeID;
bestSubMeshIndex = subMeshIndex;
@ -440,15 +440,15 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
extraInfo["subMeshIndex"] = bestSubMeshIndex;
extraInfo["subMeshName"] = geometry.getModelNameOfMesh(bestSubMeshIndex);
extraInfo["subMeshTriangleWorld"] = QVariantMap{
{ "v0", vec3toVariant(bestWorldTriangle.v0) },
{ "v1", vec3toVariant(bestWorldTriangle.v1) },
{ "v2", vec3toVariant(bestWorldTriangle.v2) },
{ "v0", vec3ToVariant(bestWorldTriangle.v0) },
{ "v1", vec3ToVariant(bestWorldTriangle.v1) },
{ "v2", vec3ToVariant(bestWorldTriangle.v2) },
};
extraInfo["subMeshNormal"] = vec3toVariant(bestModelTriangle.getNormal());
extraInfo["subMeshNormal"] = vec3ToVariant(bestModelTriangle.getNormal());
extraInfo["subMeshTriangle"] = QVariantMap{
{ "v0", vec3toVariant(bestModelTriangle.v0) },
{ "v1", vec3toVariant(bestModelTriangle.v1) },
{ "v2", vec3toVariant(bestModelTriangle.v2) },
{ "v0", vec3ToVariant(bestModelTriangle.v0) },
{ "v1", vec3ToVariant(bestModelTriangle.v1) },
{ "v2", vec3ToVariant(bestModelTriangle.v2) },
};
}
}
@ -899,7 +899,7 @@ void Model::renderDebugMeshBoxes(gpu::Batch& batch) {
if (_debugMeshBoxesID == GeometryCache::UNKNOWN_ID) {
_debugMeshBoxesID = DependencyManager::get<GeometryCache>()->allocateID();
}
QVector<glm::vec3> points;
QVector<ScriptVec3Float> points;
glm::vec3 brn = box.getCorner();
glm::vec3 bln = brn + glm::vec3(box.getDimensions().x, 0, 0);

View file

@ -192,7 +192,7 @@ QScriptValue ModelScriptingInterface::getVertex(MeshProxy* meshProxy, int vertex
}
glm::vec3 pos = vertexBufferView.get<glm::vec3>(vertexIndex);
return vec3toScriptValue(_modelScriptEngine, pos);
return vec3ToScriptValue(_modelScriptEngine, pos);
}

View file

@ -33,9 +33,9 @@ SpatialEvent::SpatialEvent(const SpatialEvent& event) {
QScriptValue SpatialEvent::toScriptValue(QScriptEngine* engine, const SpatialEvent& event) {
QScriptValue obj = engine->newObject();
obj.setProperty("locTranslation", vec3toScriptValue(engine, event.locTranslation) );
obj.setProperty("locTranslation", vec3ToScriptValue(engine, event.locTranslation) );
obj.setProperty("locRotation", quatToScriptValue(engine, event.locRotation) );
obj.setProperty("absTranslation", vec3toScriptValue(engine, event.absTranslation) );
obj.setProperty("absTranslation", vec3ToScriptValue(engine, event.absTranslation) );
obj.setProperty("absRotation", quatToScriptValue(engine, event.absRotation) );
return obj;

View file

@ -219,7 +219,7 @@ QScriptValue TouchEvent::toScriptValue(QScriptEngine* engine, const TouchEvent&
QScriptValue pointsObj = engine->newArray();
int index = 0;
foreach (ScriptVec2Float point, event.points) {
QScriptValue thisPoint = vec2toScriptValue(engine, point);
QScriptValue thisPoint = vec2FloatToScriptValue(engine, point);
pointsObj.setProperty(index, thisPoint);
index++;
}

View file

@ -5,10 +5,12 @@
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include "RegisteredMetaTypes.h"
class EntityJointData {
public:
glm::quat rotation;
glm::vec3 translation;
ScriptVec3Float translation;
bool rotationSet = false;
bool translationSet = false;
};

View file

@ -229,7 +229,8 @@ void PointerEvent::fromScriptValue(const QScriptValue& object, PointerEvent& eve
QScriptValue id = object.property("id");
event._id = id.isNumber() ? (uint32_t)id.toNumber() : 0;
glm::vec2 pos2D = vec2FromVariant(object.property("pos2D").toVariant());
glm::vec2 pos2D;
vec2FromScriptValue(object.property("pos2D"), event._pos2D);
glm::vec3 pos3D;
vec3FromScriptValue(object.property("pos3D"), event._pos3D);

View file

@ -25,13 +25,16 @@
#include <QtScript/QScriptValue>
#include <QtScript/QScriptValueIterator>
int vec4MetaTypeId = qRegisterMetaType<glm::vec4>();
int vec3MetaTypeId = qRegisterMetaType<glm::vec3>();
int qVectorVec3MetaTypeId = qRegisterMetaType<QVector<glm::vec3>>();
int qVectorQuatMetaTypeId = qRegisterMetaType<QVector<glm::quat>>();
int qVectorBoolMetaTypeId = qRegisterMetaType<QVector<bool>>();
int glmVec2MetaTypeId = qRegisterMetaType<glm::vec2>();
int vec2FloatMetaTypeId = qRegisterMetaType<ScriptVec2Float>();
int glmVec3MetaTypeId = qRegisterMetaType<glm::vec3>();
int vec3FloatMetaTypeId = qRegisterMetaType<ScriptVec3Float>();
int vec3UintMetaTypeId = qRegisterMetaType<ScriptVec3UInt>();
int vec4MetaTypeId = qRegisterMetaType<glm::vec4>();
int qVectorVec3MetaTypeId = qRegisterMetaType<QVector<ScriptVec3Float>>();
int qVectorQuatMetaTypeId = qRegisterMetaType<QVector<glm::quat>>();
int qVectorBoolMetaTypeId = qRegisterMetaType<QVector<bool>>();
int quatMetaTypeId = qRegisterMetaType<glm::quat>();
int xColorMetaTypeId = qRegisterMetaType<xColor>();
int pickRayMetaTypeId = qRegisterMetaType<PickRay>();
@ -42,85 +45,214 @@ int voidLambdaType = qRegisterMetaType<std::function<void()>>();
int variantLambdaType = qRegisterMetaType<std::function<QVariant()>>();
void registerMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, mat4toScriptValue, mat4FromScriptValue);
qScriptRegisterMetaType(engine, vec2ToScriptValue, vec2FromScriptValue);
qScriptRegisterMetaType(engine, vec2FloatToScriptValue, vec2FloatFromScriptValue);
qScriptRegisterMetaType(engine, vec3ToScriptValue, vec3FromScriptValue);
qScriptRegisterMetaType(engine, vec3FloatToScriptValue, vec3FloatFromScriptValue);
qScriptRegisterMetaType(engine, vec3UIntToScriptValue, vec3UIntFromScriptValue);
qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue);
qScriptRegisterMetaType(engine, vec3toScriptValue, vec3FromScriptValue);
qScriptRegisterMetaType(engine, quatToScriptValue, quatFromScriptValue);
qScriptRegisterMetaType(engine, mat4toScriptValue, mat4FromScriptValue);
qScriptRegisterMetaType(engine, qVectorVec3ToScriptValue, qVectorVec3FromScriptValue);
qScriptRegisterMetaType(engine, qVectorQuatToScriptValue, qVectorQuatFromScriptValue);
qScriptRegisterMetaType(engine, qVectorBoolToScriptValue, qVectorBoolFromScriptValue);
qScriptRegisterMetaType(engine, qVectorFloatToScriptValue, qVectorFloatFromScriptValue);
qScriptRegisterMetaType(engine, qVectorIntToScriptValue, qVectorIntFromScriptValue);
qScriptRegisterMetaType(engine, glmVec2toScriptValue, glmVec2FromScriptValue);
qScriptRegisterMetaType(engine, vec2toScriptValue, vec2FromScriptValue);
qScriptRegisterMetaType(engine, quatToScriptValue, quatFromScriptValue);
qScriptRegisterMetaType(engine, qSizeFToScriptValue, qSizeFFromScriptValue);
qScriptRegisterMetaType(engine, qRectToScriptValue, qRectFromScriptValue);
qScriptRegisterMetaType(engine, xColorToScriptValue, xColorFromScriptValue);
qScriptRegisterMetaType(engine, qColorToScriptValue, qColorFromScriptValue);
qScriptRegisterMetaType(engine, qURLToScriptValue, qURLFromScriptValue);
qScriptRegisterMetaType(engine, qColorToScriptValue, qColorFromScriptValue);
qScriptRegisterMetaType(engine, xColorToScriptValue, xColorFromScriptValue);
qScriptRegisterMetaType(engine, pickRayToScriptValue, pickRayFromScriptValue);
qScriptRegisterMetaType(engine, collisionToScriptValue, collisionFromScriptValue);
qScriptRegisterMetaType(engine, quuidToScriptValue, quuidFromScriptValue);
qScriptRegisterMetaType(engine, qSizeFToScriptValue, qSizeFFromScriptValue);
qScriptRegisterMetaType(engine, aaCubeToScriptValue, aaCubeFromScriptValue);
}
QScriptValue mat4toScriptValue(QScriptEngine* engine, const glm::mat4& mat4) {
QScriptValue vec2FloatToScriptValue(QScriptEngine* engine, const ScriptVec2Float& vec2) {
return engine->newQObject(new ScriptVec2Float(vec2), QScriptEngine::ScriptOwnership);
}
void vec2FloatFromScriptValue(const QScriptValue& object, ScriptVec2Float& vec2) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec2 = *qobject_cast<ScriptVec2Float*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("u");
}
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("v");
}
if (!y.isValid()) {
y = object.property("height");
}
vec2.x = x.toVariant().toFloat();
vec2.y = y.toVariant().toFloat();
return;
}
vec2 = ScriptVec2Float();
}
QScriptValue vec2ToScriptValue(QScriptEngine* engine, const glm::vec2& vec2) {
QScriptValue obj = engine->newObject();
obj.setProperty("r0c0", mat4[0][0]);
obj.setProperty("r1c0", mat4[0][1]);
obj.setProperty("r2c0", mat4[0][2]);
obj.setProperty("r3c0", mat4[0][3]);
obj.setProperty("r0c1", mat4[1][0]);
obj.setProperty("r1c1", mat4[1][1]);
obj.setProperty("r2c1", mat4[1][2]);
obj.setProperty("r3c1", mat4[1][3]);
obj.setProperty("r0c2", mat4[2][0]);
obj.setProperty("r1c2", mat4[2][1]);
obj.setProperty("r2c2", mat4[2][2]);
obj.setProperty("r3c2", mat4[2][3]);
obj.setProperty("r0c3", mat4[3][0]);
obj.setProperty("r1c3", mat4[3][1]);
obj.setProperty("r2c3", mat4[3][2]);
obj.setProperty("r3c3", mat4[3][3]);
obj.setProperty("x", vec2.x);
obj.setProperty("y", vec2.y);
return obj;
}
void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4) {
mat4[0][0] = object.property("r0c0").toVariant().toFloat();
mat4[0][1] = object.property("r1c0").toVariant().toFloat();
mat4[0][2] = object.property("r2c0").toVariant().toFloat();
mat4[0][3] = object.property("r3c0").toVariant().toFloat();
mat4[1][0] = object.property("r0c1").toVariant().toFloat();
mat4[1][1] = object.property("r1c1").toVariant().toFloat();
mat4[1][2] = object.property("r2c1").toVariant().toFloat();
mat4[1][3] = object.property("r3c1").toVariant().toFloat();
mat4[2][0] = object.property("r0c2").toVariant().toFloat();
mat4[2][1] = object.property("r1c2").toVariant().toFloat();
mat4[2][2] = object.property("r2c2").toVariant().toFloat();
mat4[2][3] = object.property("r3c2").toVariant().toFloat();
mat4[3][0] = object.property("r0c3").toVariant().toFloat();
mat4[3][1] = object.property("r1c3").toVariant().toFloat();
mat4[3][2] = object.property("r2c3").toVariant().toFloat();
mat4[3][3] = object.property("r3c3").toVariant().toFloat();
void vec2FromScriptValue(const QScriptValue& object, glm::vec2& vec2) {
vec2.x = object.property("x").toVariant().toFloat();
vec2.y = object.property("y").toVariant().toFloat();
}
QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", vec4.x);
obj.setProperty("y", vec4.y);
obj.setProperty("z", vec4.z);
obj.setProperty("w", vec4.w);
return obj;
QVariant vec2ToVariant(const glm::vec2 &vec2) {
if (vec2.x != vec2.x || vec2.y != vec2.y) {
// if vec2 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec2.x;
result["y"] = vec2.y;
return result;
}
void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4) {
vec4.x = object.property("x").toVariant().toFloat();
vec4.y = object.property("y").toVariant().toFloat();
vec4.z = object.property("z").toVariant().toFloat();
vec4.w = object.property("w").toVariant().toFloat();
glm::vec2 vec2FromVariant(const QVariant &object, bool& isValid) {
isValid = false;
glm::vec2 result;
if (object.canConvert<float>()) {
result = glm::vec2(object.toFloat());
} else if (object.canConvert<QVector2D>()) {
auto qvec2 = qvariant_cast<QVector2D>(object);
result.x = qvec2.x();
result.y = qvec2.y();
} else {
auto map = object.toMap();
auto x = map["x"];
if (!x.isValid()) {
x = map["width"];
}
auto y = map["y"];
if (!y.isValid()) {
y = map["height"];
}
if (x.isValid() && y.isValid()) {
result.x = x.toFloat(&isValid);
if (isValid) {
result.y = y.toFloat(&isValid);
}
}
}
return result;
}
QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3) {
glm::vec2 vec2FromVariant(const QVariant &object) {
bool valid;
return vec2FromVariant(object, valid);
}
QScriptValue vec3FloatToScriptValue(QScriptEngine* engine, const ScriptVec3Float& vec3) {
return engine->newQObject(new ScriptVec3Float(vec3), QScriptEngine::ScriptOwnership);
}
void vec3FloatFromScriptValue(const QScriptValue& object, ScriptVec3Float& vec3) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec3 = *qobject_cast<ScriptVec3Float*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("r");
}
if (!x.isValid()) {
x = object.property("red");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("g");
}
if (!y.isValid()) {
y = object.property("green");
}
QScriptValue z = object.property("z");
if (!z.isValid()) {
z = object.property("b");
}
if (!z.isValid()) {
z = object.property("blue");
}
vec3.x = x.toVariant().toFloat();
vec3.y = y.toVariant().toFloat();
vec3.z = z.toVariant().toFloat();
return;
}
vec3 = ScriptVec3Float();
}
QScriptValue vec3UIntToScriptValue(QScriptEngine* engine, const ScriptVec3UInt& vec3) {
return engine->newQObject(new ScriptVec3UInt(vec3), QScriptEngine::ScriptOwnership);
}
void vec3UIntFromScriptValue(const QScriptValue& object, ScriptVec3UInt& vec3) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec3 = *qobject_cast<ScriptVec3UInt*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("r");
}
if (!x.isValid()) {
x = object.property("red");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("g");
}
if (!y.isValid()) {
y = object.property("green");
}
QScriptValue z = object.property("z");
if (!z.isValid()) {
z = object.property("b");
}
if (!z.isValid()) {
z = object.property("blue");
}
vec3.x = x.toVariant().toUInt();
vec3.y = y.toVariant().toUInt();
vec3.z = z.toVariant().toUInt();
return;
}
vec3 = ScriptVec3UInt();
}
QScriptValue vec3ToScriptValue(QScriptEngine* engine, const glm::vec3 &vec3) {
QScriptValue obj = engine->newObject();
if (vec3.x != vec3.x || vec3.y != vec3.y || vec3.z != vec3.z) {
// if vec3 contains a NaN don't try to convert it
@ -129,31 +261,16 @@ QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3) {
obj.setProperty("x", vec3.x);
obj.setProperty("y", vec3.y);
obj.setProperty("z", vec3.z);
obj.setProperty("red", vec3.x);
obj.setProperty("green", vec3.y);
obj.setProperty("blue", vec3.z);
return obj;
}
void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) {
auto x = object.property("x").toVariant();
if (!x.isValid()) {
x = object.property("red").toVariant();
}
auto y = object.property("y").toVariant();
if (!y.isValid()) {
y = object.property("green").toVariant();
}
auto z = object.property("z").toVariant();
if (!z.isValid()) {
z = object.property("blue").toVariant();
}
vec3.x = x.toFloat();
vec3.y = y.toFloat();
vec3.z = z.toFloat();
vec3.x = object.property("x").toVariant().toFloat();
vec3.y = object.property("y").toVariant().toFloat();
vec3.z = object.property("z").toVariant().toFloat();
}
QVariant vec3toVariant(const glm::vec3& vec3) {
QVariant vec3ToVariant(const glm::vec3& vec3) {
if (vec3.x != vec3.x || vec3.y != vec3.y || vec3.z != vec3.z) {
// if vec3 contains a NaN don't try to convert it
return QVariant();
@ -165,28 +282,6 @@ QVariant vec3toVariant(const glm::vec3& vec3) {
return result;
}
QVariant vec4toVariant(const glm::vec4& vec4) {
if (isNaN(vec4.x) || isNaN(vec4.y) || isNaN(vec4.z) || isNaN(vec4.w)) {
// if vec4 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec4.x;
result["y"] = vec4.y;
result["z"] = vec4.z;
result["w"] = vec4.w;
return result;
}
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector) {
QScriptValue array = engine->newArray();
for (int i = 0; i < vector.size(); i++) {
array.setProperty(i, vec3toScriptValue(engine, vector.at(i)));
}
return array;
}
glm::vec3 vec3FromVariant(const QVariant& object, bool& valid) {
glm::vec3 v;
valid = false;
@ -231,6 +326,35 @@ glm::vec3 vec3FromVariant(const QVariant& object) {
return vec3FromVariant(object, valid);
}
QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", vec4.x);
obj.setProperty("y", vec4.y);
obj.setProperty("z", vec4.z);
obj.setProperty("w", vec4.w);
return obj;
}
void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4) {
vec4.x = object.property("x").toVariant().toFloat();
vec4.y = object.property("y").toVariant().toFloat();
vec4.z = object.property("z").toVariant().toFloat();
vec4.w = object.property("w").toVariant().toFloat();
}
QVariant vec4toVariant(const glm::vec4& vec4) {
if (isNaN(vec4.x) || isNaN(vec4.y) || isNaN(vec4.z) || isNaN(vec4.w)) {
// if vec4 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec4.x;
result["y"] = vec4.y;
result["z"] = vec4.z;
result["w"] = vec4.w;
return result;
}
glm::vec4 vec4FromVariant(const QVariant& object, bool& valid) {
glm::vec4 v;
valid = false;
@ -268,6 +392,76 @@ glm::vec4 vec4FromVariant(const QVariant& object) {
return vec4FromVariant(object, valid);
}
QScriptValue mat4toScriptValue(QScriptEngine* engine, const glm::mat4& mat4) {
QScriptValue obj = engine->newObject();
obj.setProperty("r0c0", mat4[0][0]);
obj.setProperty("r1c0", mat4[0][1]);
obj.setProperty("r2c0", mat4[0][2]);
obj.setProperty("r3c0", mat4[0][3]);
obj.setProperty("r0c1", mat4[1][0]);
obj.setProperty("r1c1", mat4[1][1]);
obj.setProperty("r2c1", mat4[1][2]);
obj.setProperty("r3c1", mat4[1][3]);
obj.setProperty("r0c2", mat4[2][0]);
obj.setProperty("r1c2", mat4[2][1]);
obj.setProperty("r2c2", mat4[2][2]);
obj.setProperty("r3c2", mat4[2][3]);
obj.setProperty("r0c3", mat4[3][0]);
obj.setProperty("r1c3", mat4[3][1]);
obj.setProperty("r2c3", mat4[3][2]);
obj.setProperty("r3c3", mat4[3][3]);
return obj;
}
void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4) {
mat4[0][0] = object.property("r0c0").toVariant().toFloat();
mat4[0][1] = object.property("r1c0").toVariant().toFloat();
mat4[0][2] = object.property("r2c0").toVariant().toFloat();
mat4[0][3] = object.property("r3c0").toVariant().toFloat();
mat4[1][0] = object.property("r0c1").toVariant().toFloat();
mat4[1][1] = object.property("r1c1").toVariant().toFloat();
mat4[1][2] = object.property("r2c1").toVariant().toFloat();
mat4[1][3] = object.property("r3c1").toVariant().toFloat();
mat4[2][0] = object.property("r0c2").toVariant().toFloat();
mat4[2][1] = object.property("r1c2").toVariant().toFloat();
mat4[2][2] = object.property("r2c2").toVariant().toFloat();
mat4[2][3] = object.property("r3c2").toVariant().toFloat();
mat4[3][0] = object.property("r0c3").toVariant().toFloat();
mat4[3][1] = object.property("r1c3").toVariant().toFloat();
mat4[3][2] = object.property("r2c3").toVariant().toFloat();
mat4[3][3] = object.property("r3c3").toVariant().toFloat();
}
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<ScriptVec3Float>& vector) {
QScriptValue array = engine->newArray();
for (int i = 0; i < vector.size(); i++) {
array.setProperty(i, vec3FloatToScriptValue(engine, vector.at(i)));
}
return array;
}
QVector<ScriptVec3Float> qVectorVec3FromScriptValue(const QScriptValue& array) {
QVector<ScriptVec3Float> newVector;
int length = array.property("length").toInteger();
for (int i = 0; i < length; i++) {
ScriptVec3Float newVec3 = ScriptVec3Float();
vec3FloatFromScriptValue(array.property(i), newVec3);
newVector << newVec3;
}
return newVector;
}
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<ScriptVec3Float>& vector) {
int length = array.property("length").toInteger();
for (int i = 0; i < length; i++) {
ScriptVec3Float newVec3 = ScriptVec3Float();
vec3FloatFromScriptValue(array.property(i), newVec3);
vector << newVec3;
}
}
QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat& quat) {
QScriptValue obj = engine->newObject();
if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z || quat.w != quat.w) {
@ -299,11 +493,11 @@ void quatFromScriptValue(const QScriptValue& object, glm::quat &quat) {
glm::quat quatFromVariant(const QVariant &object, bool& isValid) {
glm::quat q;
if (object.canConvert<QQuaternion>()) {
auto qvec3 = qvariant_cast<QQuaternion>(object);
q.x = qvec3.x();
q.y = qvec3.y();
q.z = qvec3.z();
q.w = qvec3.scalar();
auto qquat = qvariant_cast<QQuaternion>(object);
q.x = qquat.x();
q.y = qquat.y();
q.z = qquat.z();
q.w = qquat.scalar();
// enforce normalized quaternion
float length = glm::length(q);
@ -342,7 +536,7 @@ glm::quat quatFromVariant(const QVariant& object) {
QVariant quatToVariant(const glm::quat& quat) {
if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z) {
// if vec3 contains a NaN don't try to convert it
// if quat contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
@ -434,29 +628,6 @@ void qVectorIntFromScriptValue(const QScriptValue& array, QVector<uint32_t>& vec
}
}
//
QVector<glm::vec3> qVectorVec3FromScriptValue(const QScriptValue& array){
QVector<glm::vec3> newVector;
int length = array.property("length").toInteger();
for (int i = 0; i < length; i++) {
glm::vec3 newVec3 = glm::vec3();
vec3FromScriptValue(array.property(i), newVec3);
newVector << newVec3;
}
return newVector;
}
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<glm::vec3>& vector ) {
int length = array.property("length").toInteger();
for (int i = 0; i < length; i++) {
glm::vec3 newVec3 = glm::vec3();
vec3FromScriptValue(array.property(i), newVec3);
vector << newVec3;
}
}
QVector<glm::quat> qVectorQuatFromScriptValue(const QScriptValue& array){
QVector<glm::quat> newVector;
int length = array.property("length").toInteger();
@ -497,98 +668,6 @@ void qVectorBoolFromScriptValue(const QScriptValue& array, QVector<bool>& vector
}
}
QScriptValue vec2toScriptValue(QScriptEngine* engine, const ScriptVec2Float& vec2) {
return engine->newQObject(new ScriptVec2Float(vec2), QScriptEngine::ScriptOwnership);
}
void vec2FromScriptValue(const QScriptValue& object, ScriptVec2Float& vec2) {
if (object.isQObject()) {
auto qObject = object.toQObject();
if (qObject) {
vec2 = *qobject_cast<ScriptVec2Float*>(qObject);
return;
}
} else {
QScriptValue x = object.property("x");
if (!x.isValid()) {
x = object.property("u");
}
if (!x.isValid()) {
x = object.property("width");
}
QScriptValue y = object.property("y");
if (!y.isValid()) {
y = object.property("v");
}
if (!y.isValid()) {
y = object.property("height");
}
vec2.x = x.toVariant().toFloat();
vec2.y = y.toVariant().toFloat();
return;
}
vec2 = ScriptVec2Float();
}
QScriptValue glmVec2toScriptValue(QScriptEngine* engine, const glm::vec2& vec2) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", vec2.x);
obj.setProperty("y", vec2.y);
return obj;
}
void glmVec2FromScriptValue(const QScriptValue& object, glm::vec2& vec2) {
vec2.x = object.property("x").toVariant().toFloat();
vec2.y = object.property("y").toVariant().toFloat();
}
QVariant vec2toVariant(const glm::vec2 &vec2) {
if (vec2.x != vec2.x || vec2.y != vec2.y) {
// if vec2 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec2.x;
result["y"] = vec2.y;
return result;
}
glm::vec2 vec2FromVariant(const QVariant &object, bool& isValid) {
isValid = false;
glm::vec2 result;
if (object.canConvert<float>()) {
result = glm::vec2(object.toFloat());
} else if (object.canConvert<QVector2D>()) {
auto qvec2 = qvariant_cast<QVector2D>(object);
result.x = qvec2.x();
result.y = qvec2.y();
} else {
auto map = object.toMap();
auto x = map["x"];
if (!x.isValid()) {
x = map["width"];
}
auto y = map["y"];
if (!y.isValid()) {
y = map["height"];
}
if (x.isValid() && y.isValid()) {
result.x = x.toFloat(&isValid);
if (isValid) {
result.y = y.toFloat(&isValid);
}
}
}
return result;
}
glm::vec2 vec2FromVariant(const QVariant &object) {
bool valid;
return vec2FromVariant(object, valid);
}
QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", rect.x());
@ -794,9 +873,9 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url) {
QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay) {
QScriptValue obj = engine->newObject();
QScriptValue origin = vec3toScriptValue(engine, pickRay.origin);
QScriptValue origin = vec3ToScriptValue(engine, pickRay.origin);
obj.setProperty("origin", origin);
QScriptValue direction = vec3toScriptValue(engine, pickRay.direction);
QScriptValue direction = vec3ToScriptValue(engine, pickRay.direction);
obj.setProperty("direction", direction);
return obj;
}
@ -840,9 +919,9 @@ QScriptValue collisionToScriptValue(QScriptEngine* engine, const Collision& coll
obj.setProperty("type", collision.type);
obj.setProperty("idA", quuidToScriptValue(engine, collision.idA));
obj.setProperty("idB", quuidToScriptValue(engine, collision.idB));
obj.setProperty("penetration", vec3toScriptValue(engine, collision.penetration));
obj.setProperty("contactPoint", vec3toScriptValue(engine, collision.contactPoint));
obj.setProperty("velocityChange", vec3toScriptValue(engine, collision.velocityChange));
obj.setProperty("penetration", vec3ToScriptValue(engine, collision.penetration));
obj.setProperty("contactPoint", vec3ToScriptValue(engine, collision.contactPoint));
obj.setProperty("velocityChange", vec3ToScriptValue(engine, collision.velocityChange));
return obj;
}

View file

@ -31,11 +31,9 @@ class QColor;
class QUrl;
Q_DECLARE_METATYPE(glm::vec4)
Q_DECLARE_METATYPE(glm::vec3)
Q_DECLARE_METATYPE(glm::quat)
Q_DECLARE_METATYPE(glm::mat4)
Q_DECLARE_METATYPE(xColor)
Q_DECLARE_METATYPE(QVector<glm::vec3>)
Q_DECLARE_METATYPE(QVector<float>)
Q_DECLARE_METATYPE(AACube)
Q_DECLARE_METATYPE(std::function<void()>);
@ -51,8 +49,8 @@ void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4);
* A 2-dimensional vector.
*
* @typedef {object} Vec2
* @property {number} x - X-coordinate of the vector.
* @property {number} y - Y-coordinate of the vector.
* @property {number} x - X-coordinate of the vector. Synonyms: <code>u</code> and <code>width</code>.
* @property {number} y - Y-coordinate of the vector. Synonyms: <code>v</code> and <code>height</code>.
*/
class ScriptVec2Float : public QObject {
Q_OBJECT
@ -74,6 +72,7 @@ public:
inline bool operator==(const glm::vec2& other) { return (x == other.x && y == other.y); }
inline bool operator!=(const glm::vec2& other) { return !(*this == other); }
glm::vec2 toGlm() const { return glm::vec2(x, y); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y" }).toObject().toVariantMap(); }
float x { 0.0f };
@ -90,36 +89,120 @@ inline QDebug operator<<(QDebug debug, const ScriptVec2Float& vec2) {
inline bool operator==(glm::vec2 glmVec2, const ScriptVec2Float& vec2) { return (glmVec2.x == vec2.x && glmVec2.y == vec2.y); }
inline bool operator!=(glm::vec2 glmVec2, const ScriptVec2Float& vec2) { return !(glmVec2 == vec2); }
Q_DECLARE_METATYPE(ScriptVec2Float)
QScriptValue vec2toScriptValue(QScriptEngine* engine, const ScriptVec2Float& vec2);
void vec2FromScriptValue(const QScriptValue& object, ScriptVec2Float& vec2);
QVariant vec2toVariant(const glm::vec2& vec2);
glm::vec2 vec2FromVariant(const QVariant& object, bool& valid);
glm::vec2 vec2FromVariant(const QVariant& object);
QScriptValue vec2FloatToScriptValue(QScriptEngine* engine, const ScriptVec2Float& vec2);
void vec2FloatFromScriptValue(const QScriptValue& object, ScriptVec2Float& vec2);
Q_DECLARE_METATYPE(glm::vec2)
QScriptValue glmVec2toScriptValue(QScriptEngine* engine, const glm::vec2& vec2);
void glmVec2FromScriptValue(const QScriptValue& object, glm::vec2& vec2);
QScriptValue vec2ToScriptValue(QScriptEngine* engine, const glm::vec2& vec2);
void vec2FromScriptValue(const QScriptValue& object, glm::vec2& vec2);
QVariant vec2ToVariant(const glm::vec2& vec2);
glm::vec2 vec2FromVariant(const QVariant& object, bool& valid);
glm::vec2 vec2FromVariant(const QVariant& object);
/**jsdoc
* A 3-dimensional vector. See also the {@link Vec3(0)|Vec3} object.
*
* @typedef {object} Vec3
* @property {number} x - X-coordinate of the vector.
* @property {number} y - Y-coordinate of the vector.
* @property {number} z - Z-coordinate of the vector.
* @property {number} x - X-coordinate of the vector. Synonyms: <code>r</code> and <code>red</code>.
* @property {number} y - Y-coordinate of the vector. Synonyms: <code>g</code> and <code>green</code>.
* @property {number} z - Z-coordinate of the vector. Synonyms: <code>b</code> and <code>blue</code>.
*/
class ScriptVec3Float : public QObject {
Q_OBJECT
Q_PROPERTY(float x MEMBER x)
Q_PROPERTY(float y MEMBER y)
Q_PROPERTY(float z MEMBER z)
Q_PROPERTY(float r MEMBER x)
Q_PROPERTY(float g MEMBER y)
Q_PROPERTY(float b MEMBER z)
Q_PROPERTY(float red MEMBER x)
Q_PROPERTY(float green MEMBER y)
Q_PROPERTY(float blue MEMBER z)
public:
ScriptVec3Float() {}
ScriptVec3Float(float xyz) : x(xyz), y(xyz), z(xyz) {}
ScriptVec3Float(float x, float y, float z) : x(x), y(y), z(z) {}
ScriptVec3Float(const ScriptVec3Float& other) : x(other.x), y(other.y), z(other.z) {}
ScriptVec3Float(const glm::vec3& other) : x(other.x), y(other.y), z(other.z) {}
void operator=(const ScriptVec3Float& other) { x = other.x; y = other.y; z = other.z; }
inline bool operator==(const ScriptVec3Float& other) const { return (x == other.x && y == other.y && z == other.z); }
inline bool operator!=(const ScriptVec3Float& other) const { return !(*this == other); }
inline bool operator==(const glm::vec3& other) { return (x == other.x && y == other.y && z == other.z); }
inline bool operator!=(const glm::vec3& other) { return !(*this == other); }
glm::vec3 toGlm() const { return glm::vec3(x, y, z); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y", "z" }).toObject().toVariantMap(); }
float x { 0.0f };
float y { 0.0f };
float z { 0.0f };
private:
friend QDebug operator<<(QDebug debug, const ScriptVec3Float& vec3);
friend bool operator==(glm::vec3 glmVec3, const ScriptVec3Float& vec3);
friend bool operator!=(glm::vec3 glmVec3, const ScriptVec3Float& vec3);
};
inline QDebug operator<<(QDebug debug, const ScriptVec3Float& vec3) {
debug << "(" << vec3.x << "," << vec3.y << "," << vec3.z << ")";
return debug;
}
inline bool operator==(glm::vec3 glmVec3, const ScriptVec3Float& vec3) { return (glmVec3.x == vec3.x && glmVec3.y == vec3.y && glmVec3.z == vec3.z); }
inline bool operator!=(glm::vec3 glmVec3, const ScriptVec3Float& vec3) { return !(glmVec3 == vec3); }
Q_DECLARE_METATYPE(ScriptVec3Float)
QScriptValue vec3FloatToScriptValue(QScriptEngine* engine, const ScriptVec3Float& vec3);
void vec3FloatFromScriptValue(const QScriptValue& object, ScriptVec3Float& vec3);
/**jsdoc
* A color vector. See also the {@link Vec3(0)|Vec3} object.
*
* @typedef {object} Vec3Color
* @property {number} x - Red component value. Integer in the range <code>0</code> - <code>255</code>.
* @property {number} y - Green component value. Integer in the range <code>0</code> - <code>255</code>.
* @property {number} z - Blue component value. Integer in the range <code>0</code> - <code>255</code>.
* @property {number} x - Red component value. Integer in the range <code>0</code> - <code>255</code>. Synonyms: <code>r</code> and <code>red</code>.
* @property {number} y - Green component value. Integer in the range <code>0</code> - <code>255</code>. Synonyms: <code>g</code> and <code>green</code>.
* @property {number} z - Blue component value. Integer in the range <code>0</code> - <code>255</code>. Synonyms: <code>b</code> and <code>blue</code>.
*/
QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3);
class ScriptVec3UInt : public QObject {
Q_OBJECT
Q_PROPERTY(unsigned int x MEMBER x)
Q_PROPERTY(unsigned int y MEMBER y)
Q_PROPERTY(unsigned int z MEMBER z)
Q_PROPERTY(unsigned int r MEMBER x)
Q_PROPERTY(unsigned int g MEMBER y)
Q_PROPERTY(unsigned int b MEMBER z)
Q_PROPERTY(unsigned int red MEMBER x)
Q_PROPERTY(unsigned int green MEMBER y)
Q_PROPERTY(unsigned int blue MEMBER z)
public:
ScriptVec3UInt() {}
ScriptVec3UInt(unsigned int xyz) : x(xyz), y(xyz), z(xyz) {}
ScriptVec3UInt(unsigned int x, unsigned int y, unsigned int z) : x(x), y(y), z(z) {}
ScriptVec3UInt(const ScriptVec3UInt& other) : x(other.x), y(other.y), z(other.z) {}
void operator=(const ScriptVec3UInt& other) { x = other.x; y = other.y; z = other.z; }
inline bool operator==(const ScriptVec3UInt& other) { return (x == other.x && y == other.y && z == other.z); }
inline bool operator!=(const ScriptVec3UInt& other) { return !(*this == other); }
Q_INVOKABLE QVariantMap toJSON() { return toJsonValue(*this, { "x", "y", "z" }).toObject().toVariantMap(); }
unsigned int x { 0 };
unsigned int y { 0 };
unsigned int z { 0 };
private:
friend QDebug operator<<(QDebug debug, const ScriptVec3UInt& vec3);
};
inline QDebug operator<<(QDebug debug, const ScriptVec3UInt& vec3) {
debug << "(" << vec3.x << "," << vec3.y << "," << vec3.z << ")";
return debug;
}
inline bool operator==(glm::vec3 glmVec3, const ScriptVec3UInt& vec3) { return (glmVec3.x == vec3.x && glmVec3.y == vec3.y && glmVec3.z == vec3.z); }
inline bool operator!=(glm::vec3 glmVec3, const ScriptVec3UInt& vec3) { return !(glmVec3 == vec3); }
Q_DECLARE_METATYPE(ScriptVec3UInt)
QScriptValue vec3UIntToScriptValue(QScriptEngine* engine, const ScriptVec3UInt& vec3);
void vec3UIntFromScriptValue(const QScriptValue& object, ScriptVec3UInt& vec3);
Q_DECLARE_METATYPE(glm::vec3)
QScriptValue vec3ToScriptValue(QScriptEngine* engine, const glm::vec3 &vec3);
void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3);
QVariant vec3toVariant(const glm::vec3& vec3);
QVariant vec3ToVariant(const glm::vec3& vec3);
glm::vec3 vec3FromVariant(const QVariant &object, bool& valid);
glm::vec3 vec3FromVariant(const QVariant &object);
@ -169,9 +252,10 @@ QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url);
void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
// vector<vec3>
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector);
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<glm::vec3>& vector);
QVector<glm::vec3> qVectorVec3FromScriptValue(const QScriptValue& array);
Q_DECLARE_METATYPE(QVector<ScriptVec3Float>)
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<ScriptVec3Float>& vector);
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<ScriptVec3Float>& vector);
QVector<ScriptVec3Float> qVectorVec3FromScriptValue(const QScriptValue& array);
// vector<quat>
QScriptValue qVectorQuatToScriptValue(QScriptEngine* engine, const QVector<glm::quat>& vector);
@ -229,8 +313,8 @@ public:
}
QVariantMap toVariantMap() const override {
QVariantMap pickRay;
pickRay["origin"] = vec3toVariant(origin);
pickRay["direction"] = vec3toVariant(direction);
pickRay["origin"] = vec3ToVariant(origin);
pickRay["direction"] = vec3ToVariant(direction);
return pickRay;
}
};
@ -267,9 +351,9 @@ public:
QVariantMap toVariantMap() const override {
QVariantMap stylusTip;
stylusTip["side"] = (int)side;
stylusTip["position"] = vec3toVariant(position);
stylusTip["position"] = vec3ToVariant(position);
stylusTip["orientation"] = quatToVariant(orientation);
stylusTip["velocity"] = vec3toVariant(velocity);
stylusTip["velocity"] = vec3ToVariant(velocity);
return stylusTip;
}
};

View file

@ -886,6 +886,14 @@ glm::vec3 SpatiallyNestable::getLocalPosition() const {
return result;
}
ScriptVec3Float SpatiallyNestable::getScriptLocalPosition() const {
ScriptVec3Float result;
_transformLock.withReadLock([&] {
result = _transform.getTranslation();
});
return result;
}
void SpatiallyNestable::setLocalPosition(const glm::vec3& position, bool tellPhysics) {
// guard against introducing NaN into the transform
if (isNaN(position)) {
@ -940,6 +948,14 @@ glm::vec3 SpatiallyNestable::getLocalVelocity() const {
return result;
}
ScriptVec3Float SpatiallyNestable::getScriptLocalVelocity() const {
ScriptVec3Float result;
_velocityLock.withReadLock([&] {
result = _velocity;
});
return result;
}
void SpatiallyNestable::setLocalVelocity(const glm::vec3& velocity) {
_velocityLock.withWriteLock([&] {
_velocity = velocity;
@ -954,6 +970,14 @@ glm::vec3 SpatiallyNestable::getLocalAngularVelocity() const {
return result;
}
ScriptVec3Float SpatiallyNestable::getScriptLocalAngularVelocity() const {
ScriptVec3Float result;
_angularVelocityLock.withReadLock([&] {
result = _angularVelocity;
});
return result;
}
void SpatiallyNestable::setLocalAngularVelocity(const glm::vec3& angularVelocity) {
_angularVelocityLock.withWriteLock([&] {
_angularVelocity = angularVelocity;

View file

@ -19,6 +19,7 @@
#include "SpatialParentFinder.h"
#include "shared/ReadWriteLockable.h"
#include "RegisteredMetaTypes.h"
class SpatiallyNestable;
using SpatiallyNestableWeakPointer = std::weak_ptr<SpatiallyNestable>;
@ -136,15 +137,18 @@ public:
virtual void setLocalTransform(const Transform& transform);
virtual glm::vec3 getLocalPosition() const;
virtual ScriptVec3Float getScriptLocalPosition() const;
virtual void setLocalPosition(const glm::vec3& position, bool tellPhysics = true);
virtual glm::quat getLocalOrientation() const;
virtual void setLocalOrientation(const glm::quat& orientation);
virtual glm::vec3 getLocalVelocity() const;
virtual ScriptVec3Float getScriptLocalVelocity() const;
virtual void setLocalVelocity(const glm::vec3& velocity);
virtual glm::vec3 getLocalAngularVelocity() const;
virtual ScriptVec3Float getScriptLocalAngularVelocity() const;
virtual void setLocalAngularVelocity(const glm::vec3& angularVelocity);
virtual glm::vec3 getLocalSNScale() const;

View file

@ -68,6 +68,26 @@ vec4 vec4FromJsonValue(const QJsonValue& v) {
return glmFromJson<vec4>(v);
}
QJsonValue toJsonValueHelper(const QVariant& variant, int type) {
// User-registered types need explicit conversion
if (type == qMetaTypeId<quat>()) {
return toJsonValue(variant.value<quat>());
} else if (type == qMetaTypeId<vec3>()) {
return toJsonValue(variant.value<vec3>());
} else if (type == qMetaTypeId<vec4>()) {
return toJsonValue(variant.value<vec4>());
} else if (type == qMetaTypeId<ScriptVec2Float>()) {
return toJsonValue(variant.value<ScriptVec2Float>(), {"x", "y"});
} else if (type == qMetaTypeId<ScriptVec3Float>()) {
return toJsonValue(variant.value<ScriptVec2Float>(), { "x", "y", "z" });
} else if (type == qMetaTypeId<ScriptVec3UInt>()) {
return toJsonValue(variant.value<ScriptVec3UInt>(), { "x", "y", "z" });
} else {
// Qt types are converted automatically
return QJsonValue::fromVariant(variant);
}
}
QJsonValue toJsonValue(const QObject& o) {
QJsonObject json{};
@ -76,20 +96,8 @@ QJsonValue toJsonValue(const QObject& o) {
for (int i = meta->propertyOffset(); i < meta->propertyCount(); ++i) {
QString name = QString::fromLatin1(meta->property(i).name());
auto type = meta->property(i).userType();
QVariant variant{ meta->property(i).read(&o) };
QJsonValue value;
// User-registered types need explicit conversion
if (type == qMetaTypeId<quat>()) {
value = toJsonValue(variant.value<quat>());
} else if (type == qMetaTypeId<vec3>()) {
value = toJsonValue(variant.value<vec3>());
} else if (type == qMetaTypeId<vec4>()) {
value = toJsonValue(variant.value<vec4>());
} else {
// Qt types are converted automatically
value = QJsonValue::fromVariant(variant);
}
QVariant variant { meta->property(i).read(&o) };
QJsonValue value = toJsonValueHelper(variant, type);
json.insert(name, value);
}
@ -116,19 +124,7 @@ QJsonValue toJsonValue(const QObject& o, const std::vector<QString>& props) {
QString name = QString::fromLatin1(meta->property(i).name());
auto type = meta->property(i).userType();
QVariant variant { meta->property(i).read(&o) };
QJsonValue value;
// User-registered types need explicit conversion
if (type == qMetaTypeId<quat>()) {
value = toJsonValue(variant.value<quat>());
} else if (type == qMetaTypeId<vec3>()) {
value = toJsonValue(variant.value<vec3>());
} else if (type == qMetaTypeId<vec4>()) {
value = toJsonValue(variant.value<vec4>());
} else {
// Qt types are converted automatically
value = QJsonValue::fromVariant(variant);
}
QJsonValue value = toJsonValueHelper(variant, type);
json.insert(name, value);
}

View file

@ -15,6 +15,7 @@
QJsonValue toJsonValue(const quat& q);
QJsonValue toJsonValue(const vec3& v);
QJsonValue toJsonValue(const vec4& v);
QJsonValue toJsonValueHelper(const QVariant& variant, int type);
QJsonValue toJsonValue(const QObject& o);
QJsonValue toJsonValue(const QObject& o, const std::vector<QString>& props);