This commit is contained in:
Philip Rosedale 2014-02-23 21:08:54 -08:00
commit 26541e12b6
5 changed files with 625 additions and 190 deletions

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,12 @@ function mouseMoveEvent(event) {
print("intersection distance=" + intersection.distance); print("intersection distance=" + intersection.distance);
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", " print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
+ intersection.intersection.y + ", " + intersection.intersection.z); + intersection.intersection.y + ", " + intersection.intersection.z);
// also test the getVoxelAt() api which should find and return same voxel
var voxelAt = Voxels.getVoxelAt(intersection.voxel.x, intersection.voxel.y, intersection.voxel.z, intersection.voxel.s);
print("voxelAt.x/y/z/s=" + voxelAt.x + ", " + voxelAt.y + ", " + voxelAt.z + ": " + voxelAt.s);
print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue);
} }
} }

View file

@ -52,8 +52,8 @@ bool Model::isLoadedWithTextures() const {
} }
foreach (const NetworkMesh& mesh, _geometry->getMeshes()) { foreach (const NetworkMesh& mesh, _geometry->getMeshes()) {
foreach (const NetworkMeshPart& part, mesh.parts) { foreach (const NetworkMeshPart& part, mesh.parts) {
if (part.diffuseTexture && !part.diffuseTexture->isLoaded() || if ((part.diffuseTexture && !part.diffuseTexture->isLoaded()) ||
part.normalTexture && !part.normalTexture->isLoaded()) { (part.normalTexture && !part.normalTexture->isLoaded())) {
return false; return false;
} }
} }

View file

@ -12,14 +12,45 @@ void VoxelsScriptingInterface::queueVoxelAdd(PacketType addPacketType, VoxelDeta
getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails); getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails);
} }
VoxelDetail VoxelsScriptingInterface::getVoxelAt(float x, float y, float z, float scale) {
// setup a VoxelDetail struct with the data
VoxelDetail result = {0,0,0,0,0,0,0};
if (_tree) {
_tree->lockForRead();
VoxelTreeElement* voxel = static_cast<VoxelTreeElement*>(_tree->getOctreeElementAt(x / (float)TREE_SCALE, y / (float)TREE_SCALE,
z / (float)TREE_SCALE, scale / (float)TREE_SCALE));
_tree->unlock();
if (voxel) {
// Note: these need to be in voxel space because the VoxelDetail -> js converter will upscale
result.x = voxel->getCorner().x;
result.y = voxel->getCorner().y;
result.z = voxel->getCorner().z;
result.s = voxel->getScale();
result.red = voxel->getColor()[RED_INDEX];
result.green = voxel->getColor()[GREEN_INDEX];
result.blue = voxel->getColor()[BLUE_INDEX];
}
}
return result;
}
void VoxelsScriptingInterface::setVoxelNonDestructive(float x, float y, float z, float scale, void VoxelsScriptingInterface::setVoxelNonDestructive(float x, float y, float z, float scale,
uchar red, uchar green, uchar blue) { uchar red, uchar green, uchar blue) {
// setup a VoxelDetail struct with the data // setup a VoxelDetail struct with the data
VoxelDetail addVoxelDetail = {x / (float)TREE_SCALE, y / (float)TREE_SCALE, z / (float)TREE_SCALE, VoxelDetail addVoxelDetail = {x / (float)TREE_SCALE, y / (float)TREE_SCALE, z / (float)TREE_SCALE,
scale / (float)TREE_SCALE, red, green, blue}; scale / (float)TREE_SCALE, red, green, blue};
// queue the packet // queue the add packet
queueVoxelAdd(PacketTypeVoxelSet, addVoxelDetail); queueVoxelAdd(PacketTypeVoxelSet, addVoxelDetail);
// handle the local tree also...
if (_tree) {
_tree->lockForWrite();
_tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, false);
_tree->unlock();
}
} }
void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale, void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale,
@ -30,6 +61,13 @@ void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale,
// queue the destructive add // queue the destructive add
queueVoxelAdd(PacketTypeVoxelSetDestructive, addVoxelDetail); queueVoxelAdd(PacketTypeVoxelSetDestructive, addVoxelDetail);
// handle the local tree also...
if (_tree) {
_tree->lockForWrite();
_tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, true);
_tree->unlock();
}
} }
void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale) { void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale) {
@ -39,6 +77,13 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale
scale / (float)TREE_SCALE, 0, 0, 0}; scale / (float)TREE_SCALE, 0, 0, 0};
getVoxelPacketSender()->queueVoxelEditMessages(PacketTypeVoxelErase, 1, &deleteVoxelDetail); getVoxelPacketSender()->queueVoxelEditMessages(PacketTypeVoxelErase, 1, &deleteVoxelDetail);
// handle the local tree also...
if (_tree) {
_tree->lockForWrite();
_tree->deleteVoxelAt(deleteVoxelDetail.x, deleteVoxelDetail.y, deleteVoxelDetail.z, deleteVoxelDetail.s);
_tree->unlock();
}
} }
@ -64,3 +109,21 @@ RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersection(const
} }
return result; return result;
} }
glm::vec3 VoxelsScriptingInterface::getFaceVector(const QString& face) {
if (face == "MIN_X_FACE") {
return glm::vec3(-1, 0, 0);
} else if (face == "MAX_X_FACE") {
return glm::vec3(1, 0, 0);
} else if (face == "MIN_Y_FACE") {
return glm::vec3(0, -1, 0);
} else if (face == "MAX_Y_FACE") {
return glm::vec3(0, 1, 0);
} else if (face == "MIN_Z_FACE") {
return glm::vec3(0, 0, -1);
} else if (face == "MAX_Z_FACE") {
return glm::vec3(0, 0, 1);
}
return glm::vec3(0, 0, 0); //error case
}

View file

@ -30,6 +30,14 @@ public:
void setVoxelTree(VoxelTree* tree) { _tree = tree; } void setVoxelTree(VoxelTree* tree) { _tree = tree; }
public slots: public slots:
/// checks the local voxel tree for a voxel at the specified location and scale
/// \param x the x-coordinate of the voxel (in meter units)
/// \param y the y-coordinate of the voxel (in meter units)
/// \param z the z-coordinate of the voxel (in meter units)
/// \param scale the scale of the voxel (in meter units)
VoxelDetail getVoxelAt(float x, float y, float z, float scale);
/// queues the creation of a voxel which will be sent by calling process on the PacketSender /// queues the creation of a voxel which will be sent by calling process on the PacketSender
/// \param x the x-coordinate of the voxel (in meter units) /// \param x the x-coordinate of the voxel (in meter units)
/// \param y the y-coordinate of the voxel (in meter units) /// \param y the y-coordinate of the voxel (in meter units)
@ -60,6 +68,9 @@ public slots:
/// If the scripting context has visible voxels, this will determine a ray intersection /// If the scripting context has visible voxels, this will determine a ray intersection
RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray); RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray);
/// returns a voxel space axis aligned vector for the face, useful in doing voxel math
glm::vec3 getFaceVector(const QString& face);
private: private:
void queueVoxelAdd(PacketType addPacketType, VoxelDetail& addVoxelDetails); void queueVoxelAdd(PacketType addPacketType, VoxelDetail& addVoxelDetails);
VoxelTree* _tree; VoxelTree* _tree;