mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 23:29:39 +02:00
first cut at ray cast scripting
This commit is contained in:
parent
2157349804
commit
c64b934d33
6 changed files with 95 additions and 3 deletions
|
@ -81,7 +81,6 @@ QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay)
|
|||
QScriptValue direction = vec3toScriptValue(engine, pickRay.direction);
|
||||
obj.setProperty("direction", direction);
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay) {
|
||||
|
|
|
@ -46,5 +46,4 @@ Q_DECLARE_METATYPE(PickRay)
|
|||
QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay);
|
||||
void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
void registerVoxelMetaTypes(QScriptEngine* engine) {
|
||||
qScriptRegisterMetaType(engine, voxelDetailToScriptValue, voxelDetailFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, rayToVoxelIntersectionResultToScriptValue, rayToVoxelIntersectionResultFromScriptValue);
|
||||
}
|
||||
|
||||
QScriptValue voxelDetailToScriptValue(QScriptEngine* engine, const VoxelDetail& voxelDetail) {
|
||||
|
@ -33,5 +34,71 @@ void voxelDetailFromScriptValue(const QScriptValue &object, VoxelDetail& voxelDe
|
|||
voxelDetail.blue = object.property("blue").toVariant().toInt();
|
||||
}
|
||||
|
||||
RayToVoxelIntersectionResult::RayToVoxelIntersectionResult() :
|
||||
intersects(false),
|
||||
voxel(),
|
||||
distance(0),
|
||||
face()
|
||||
{
|
||||
};
|
||||
|
||||
QScriptValue rayToVoxelIntersectionResultToScriptValue(QScriptEngine* engine, const RayToVoxelIntersectionResult& value) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("intersects", value.intersects);
|
||||
QScriptValue voxelValue = voxelDetailToScriptValue(engine, value.voxel);
|
||||
obj.setProperty("voxel", voxelValue);
|
||||
obj.setProperty("distance", value.distance);
|
||||
|
||||
QString faceName = "";
|
||||
// handle BoxFace
|
||||
switch (value.face) {
|
||||
case MIN_X_FACE:
|
||||
faceName = "MIN_X_FACE";
|
||||
break;
|
||||
case MAX_X_FACE:
|
||||
faceName = "MAX_X_FACE";
|
||||
break;
|
||||
case MIN_Y_FACE:
|
||||
faceName = "MIN_Y_FACE";
|
||||
break;
|
||||
case MAX_Y_FACE:
|
||||
faceName = "MAX_Y_FACE";
|
||||
break;
|
||||
case MIN_Z_FACE:
|
||||
faceName = "MIN_Z_FACE";
|
||||
break;
|
||||
case MAX_Z_FACE:
|
||||
faceName = "MAX_Z_FACE";
|
||||
break;
|
||||
}
|
||||
obj.setProperty("face", faceName);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void rayToVoxelIntersectionResultFromScriptValue(const QScriptValue& object, RayToVoxelIntersectionResult& value) {
|
||||
value.intersects = object.property("intersects").toVariant().toBool();
|
||||
QScriptValue voxelValue = object.property("voxel");
|
||||
if (voxelValue.isValid()) {
|
||||
voxelDetailFromScriptValue(voxelValue, value.voxel);
|
||||
}
|
||||
value.distance = object.property("distance").toVariant().toFloat();
|
||||
|
||||
QString faceName = object.property("face").toVariant().toString();
|
||||
if (faceName == "MIN_X_FACE") {
|
||||
value.face = MIN_X_FACE;
|
||||
} else if (faceName == "MAX_X_FACE") {
|
||||
value.face = MAX_X_FACE;
|
||||
} else if (faceName == "MIN_Y_FACE") {
|
||||
value.face = MIN_Y_FACE;
|
||||
} else if (faceName == "MAX_Y_FACE") {
|
||||
value.face = MAX_Y_FACE;
|
||||
} else if (faceName == "MIN_Z_FACE") {
|
||||
value.face = MIN_Z_FACE;
|
||||
} else {
|
||||
value.face = MAX_Z_FACE;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <SharedUtil.h>
|
||||
#include "VoxelConstants.h"
|
||||
|
||||
|
@ -32,5 +33,18 @@ void registerVoxelMetaTypes(QScriptEngine* engine);
|
|||
QScriptValue voxelDetailToScriptValue(QScriptEngine* engine, const VoxelDetail& color);
|
||||
void voxelDetailFromScriptValue(const QScriptValue &object, VoxelDetail& color);
|
||||
|
||||
class RayToVoxelIntersectionResult {
|
||||
public:
|
||||
RayToVoxelIntersectionResult();
|
||||
bool intersects;
|
||||
VoxelDetail voxel;
|
||||
float distance;
|
||||
BoxFace face;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(RayToVoxelIntersectionResult)
|
||||
|
||||
QScriptValue rayToVoxelIntersectionResultToScriptValue(QScriptEngine* engine, const RayToVoxelIntersectionResult& results);
|
||||
void rayToVoxelIntersectionResultFromScriptValue(const QScriptValue& object, RayToVoxelIntersectionResult& results);
|
||||
|
||||
#endif /* defined(__hifi__VoxelDetail__) */
|
|
@ -41,3 +41,8 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale
|
|||
getVoxelPacketSender()->queueVoxelEditMessages(PacketTypeVoxelErase, 1, &deleteVoxelDetail);
|
||||
}
|
||||
|
||||
|
||||
RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersection(const PickRay& ray) {
|
||||
RayToVoxelIntersectionResult result;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -12,18 +12,22 @@
|
|||
#include <QtCore/QObject>
|
||||
|
||||
#include <OctreeScriptingInterface.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include "VoxelConstants.h"
|
||||
#include "VoxelEditPacketSender.h"
|
||||
#include "VoxelTree.h"
|
||||
|
||||
/// handles scripting of voxel commands from JS passed to assigned clients
|
||||
class VoxelsScriptingInterface : public OctreeScriptingInterface {
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
VoxelsScriptingInterface() : _tree(NULL) {};
|
||||
VoxelEditPacketSender* getVoxelPacketSender() { return (VoxelEditPacketSender*)getPacketSender(); }
|
||||
|
||||
virtual NodeType_t getServerNodeType() const { return NodeType::VoxelServer; }
|
||||
virtual OctreeEditPacketSender* createPacketSender() { return new VoxelEditPacketSender(); }
|
||||
void setVoxelTree(VoxelTree* tree) { _tree = tree; }
|
||||
|
||||
public slots:
|
||||
/// queues the creation of a voxel which will be sent by calling process on the PacketSender
|
||||
|
@ -53,8 +57,12 @@ public slots:
|
|||
/// \param scale the scale of the voxel (in meter units)
|
||||
void eraseVoxel(float x, float y, float z, float scale);
|
||||
|
||||
/// If the scripting context has visible voxels, this will determine a ray intersection
|
||||
RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray);
|
||||
|
||||
private:
|
||||
void queueVoxelAdd(PacketType addPacketType, VoxelDetail& addVoxelDetails);
|
||||
VoxelTree* _tree;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelsScriptingInterface__) */
|
||||
|
|
Loading…
Reference in a new issue