mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Added more SceneUtils support cleaned up voxel-edit to use scene utils
- Added addCornersAndAxisLines() scene - Added addSurfaceScene() scene - moved improved addSphereScene() from voxel-edit to SceneUtils.cpp - added command line options to voxel-edit to create different scenes
This commit is contained in:
parent
cdf72711b5
commit
bc55c09ed7
3 changed files with 84 additions and 122 deletions
|
@ -7,36 +7,12 @@
|
|||
//
|
||||
|
||||
#include "SceneUtils.h"
|
||||
#include <glm/gtc/noise.hpp>
|
||||
|
||||
void addSphereScene(VoxelTree * tree) {
|
||||
printf("adding scene...\n");
|
||||
|
||||
void addCornersAndAxisLines(VoxelTree* tree) {
|
||||
// We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so...
|
||||
float voxelSize = 0.5f / TREE_SCALE;
|
||||
|
||||
// Here's an example of how to create a voxel.
|
||||
printf("creating corner points...\n");
|
||||
tree->createVoxel(0, 0, 0, voxelSize, 255, 255 ,255);
|
||||
|
||||
// Here's an example of how to test if a voxel exists
|
||||
VoxelNode* node = tree->getVoxelAt(0, 0, 0, voxelSize);
|
||||
if (node) {
|
||||
// and how to access it's color
|
||||
printf("corner point 0,0,0 exists... color is (%d,%d,%d) \n",
|
||||
node->getColor()[0], node->getColor()[1], node->getColor()[2]);
|
||||
}
|
||||
|
||||
// here's an example of how to delete a voxel
|
||||
printf("attempting to delete corner point 0,0,0\n");
|
||||
tree->deleteVoxelAt(0, 0, 0, voxelSize);
|
||||
|
||||
// Test to see that the delete worked... it should be FALSE...
|
||||
if (tree->getVoxelAt(0, 0, 0, voxelSize)) {
|
||||
printf("corner point 0,0,0 exists...\n");
|
||||
} else {
|
||||
printf("corner point 0,0,0 does not exists...\n");
|
||||
}
|
||||
|
||||
// Now some more examples... a little more complex
|
||||
printf("creating corner points...\n");
|
||||
tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255);
|
||||
|
@ -60,43 +36,71 @@ void addSphereScene(VoxelTree * tree) {
|
|||
tree->createLine(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0), lineVoxelSize, red);
|
||||
tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0), lineVoxelSize, green);
|
||||
printf("DONE creating lines...\n");
|
||||
}
|
||||
|
||||
void addSphereScene(VoxelTree * tree) {
|
||||
printf("adding sphere scene...\n");
|
||||
|
||||
// Now some more examples... creating some spheres using the sphere primitive
|
||||
// We want the smallest unit of our spheres to be about 1/16th of a meter tall
|
||||
float sphereVoxelSize = 1.f / (16 * TREE_SCALE);
|
||||
float sphereVoxelSize = 1.f / (8 * TREE_SCALE);
|
||||
printf("creating spheres... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.25, 0.5, 0.5, 0.5, sphereVoxelSize, true, NATURAL, true);
|
||||
printf("one sphere added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
|
||||
tree->createSphere(0.030625, 0.5, 0.5, (0.25 - 0.06125), sphereVoxelSize, true, RANDOM);
|
||||
printf("two spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), (0.75 - 0.06125), sphereVoxelSize, true, RANDOM);
|
||||
printf("three spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, 0.5, 0.5, (0.25 - 0.06125), sphereVoxelSize, true, NATURAL);
|
||||
printf("1 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("2 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), 0.06125, sphereVoxelSize, true, RANDOM);
|
||||
printf("four spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), 0.06125, (0.75 - 0.06125), sphereVoxelSize, true, RANDOM);
|
||||
printf("five spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.06125, 0.125, 0.125, (0.75 - 0.125), sphereVoxelSize, true, RANDOM);
|
||||
printf("3 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), 0.06125, (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("4 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.06125, 0.125, 0.125, (0.75 - 0.125), sphereVoxelSize, true, GRADIENT);
|
||||
|
||||
/**
|
||||
float radius = 0.0125f;
|
||||
printf("5 spheres added...\n");
|
||||
tree->createSphere(radius, 0.25, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("6 spheres added...\n");
|
||||
tree->createSphere(radius, 0.25, radius * 5.0f, 0.25, (1.0 / 4096), true, GRADIENT);
|
||||
tree->createSphere(radius, 0.125, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("7 spheres added...\n");
|
||||
tree->createSphere(radius, 0.125, radius * 5.0f, 0.25, (1.0 / 4096), true, GRADIENT);
|
||||
tree->createSphere(radius, 0.075, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("8 spheres added...\n");
|
||||
tree->createSphere(radius, 0.075, radius * 5.0f, 0.25, (1.0 / 4096), true, GRADIENT);
|
||||
tree->createSphere(radius, 0.05, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("9 spheres added...\n");
|
||||
tree->createSphere(radius, 0.05, radius * 5.0f, 0.25, (1.0 / 4096), true, GRADIENT);
|
||||
tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("10 spheres added...\n");
|
||||
tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, (1.0 / 4096), true, GRADIENT);
|
||||
printf("11 spheres added...\n");
|
||||
|
||||
printf("DONE creating spheres...\n");
|
||||
// Here's an example of how to recurse the tree and do some operation on the nodes as you recurse them.
|
||||
// This one is really simple, it just couts them...
|
||||
// Look at the function countVoxelsOperation() for an example of how you could use this function
|
||||
unsigned long nodeCount = tree->getVoxelCount();
|
||||
printf("Nodes after adding scene %ld nodes\n", nodeCount);
|
||||
*/
|
||||
float largeRadius = 0.1875f;
|
||||
tree->createSphere(largeRadius, 0.5, 0.5, 0.5, sphereVoxelSize, true, NATURAL);
|
||||
printf("11 - last large sphere added... largeRadius=%f sphereVoxelSize=%f\n", largeRadius, sphereVoxelSize);
|
||||
|
||||
printf("DONE adding scene of spheres...\n");
|
||||
}
|
||||
|
||||
void addSurfaceScene(VoxelTree * tree) {
|
||||
printf("adding surface scene...\n");
|
||||
float voxelSize = 1.f / (8 * TREE_SCALE);
|
||||
|
||||
// color 1= blue, color 2=green
|
||||
unsigned char r1, g1, b1, r2, g2, b2, red, green, blue;
|
||||
r1 = r2 = b2 = g1 = 0;
|
||||
b1 = g2 = 255;
|
||||
|
||||
for (float x = 0.0; x < 1.0; x += voxelSize) {
|
||||
for (float z = 0.0; z < 1.0; z += voxelSize) {
|
||||
|
||||
glm::vec2 position = glm::vec2(x, z);
|
||||
float perlin = glm::perlin(position) + .25f * glm::perlin(position * 4.f) + .125f * glm::perlin(position * 16.f);
|
||||
float gradient = (1.0f + perlin)/ 2.0f;
|
||||
red = (unsigned char)std::min(255, std::max(0, (int)(r1 + ((r2 - r1) * gradient))));
|
||||
green = (unsigned char)std::min(255, std::max(0, (int)(g1 + ((g2 - g1) * gradient))));
|
||||
blue = (unsigned char)std::min(255, std::max(0, (int)(b1 + ((b2 - b1) * gradient))));
|
||||
|
||||
int height = (4 * gradient)+1; // make it at least 4 thick, so we get some averaging
|
||||
for (int i = 0; i < height; i++) {
|
||||
tree->createVoxel(x, ((i+1) * voxelSize) , z, voxelSize, red, green, blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("DONE adding surface scene...\n");
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
#include "VoxelTree.h"
|
||||
#include <SharedUtil.h>
|
||||
|
||||
void addCornersAndAxisLines(VoxelTree* tree);
|
||||
void addSphereScene(VoxelTree * tree);
|
||||
void addSurfaceScene(VoxelTree * tree);
|
||||
|
||||
|
||||
#endif /* defined(__hifi__SceneUtil__) */
|
||||
|
|
|
@ -8,15 +8,14 @@
|
|||
|
||||
#include <VoxelTree.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <SceneUtils.h>
|
||||
|
||||
VoxelTree myTree;
|
||||
|
||||
void addScene(VoxelTree * tree) {
|
||||
printf("adding scene...\n");
|
||||
|
||||
void voxelTutorial(VoxelTree* tree) {
|
||||
// We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so...
|
||||
float voxelSize = 0.5f / TREE_SCALE;
|
||||
|
||||
|
||||
// Here's an example of how to create a voxel.
|
||||
printf("creating corner points...\n");
|
||||
tree->createVoxel(0, 0, 0, voxelSize, 255, 255 ,255);
|
||||
|
@ -39,75 +38,8 @@ void addScene(VoxelTree * tree) {
|
|||
} else {
|
||||
printf("corner point 0,0,0 does not exists...\n");
|
||||
}
|
||||
|
||||
// Now some more examples... a little more complex
|
||||
printf("creating corner points...\n");
|
||||
tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255);
|
||||
tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 );
|
||||
tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 );
|
||||
tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255);
|
||||
tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255);
|
||||
tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255);
|
||||
tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 );
|
||||
tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255);
|
||||
printf("DONE creating corner points...\n");
|
||||
|
||||
// Now some more examples... creating some lines using the line primitive
|
||||
printf("creating voxel lines...\n");
|
||||
// We want our line voxels to be about 1/32 meter high, and our TREE_SCALE is in meters, so...
|
||||
float lineVoxelSize = 1.f / (32 * TREE_SCALE);
|
||||
rgbColor red = {255, 0, 0};
|
||||
rgbColor green = {0, 255, 0};
|
||||
rgbColor blue = {0, 0, 255};
|
||||
tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, 1), lineVoxelSize, blue);
|
||||
tree->createLine(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0), lineVoxelSize, red);
|
||||
tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0), lineVoxelSize, green);
|
||||
printf("DONE creating lines...\n");
|
||||
|
||||
// Now some more examples... creating some spheres using the sphere primitive
|
||||
// We want the smallest unit of our spheres to be about 1/16th of a meter tall
|
||||
float sphereVoxelSize = 1.f / (8 * TREE_SCALE);
|
||||
printf("creating spheres... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
|
||||
tree->createSphere(0.030625, 0.5, 0.5, (0.25 - 0.06125), sphereVoxelSize, true, NATURAL);
|
||||
printf("1 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("2 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), 0.06125, sphereVoxelSize, true, RANDOM);
|
||||
printf("3 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), 0.06125, (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("4 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.06125, 0.125, 0.125, (0.75 - 0.125), sphereVoxelSize, true, GRADIENT);
|
||||
|
||||
/**
|
||||
float radius = 0.0125f;
|
||||
printf("5 spheres added...\n");
|
||||
tree->createSphere(radius, 0.25, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("6 spheres added...\n");
|
||||
tree->createSphere(radius, 0.125, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("7 spheres added...\n");
|
||||
tree->createSphere(radius, 0.075, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("8 spheres added...\n");
|
||||
tree->createSphere(radius, 0.05, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("9 spheres added...\n");
|
||||
tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("10 spheres added...\n");
|
||||
*/
|
||||
float largeRadius = 0.1875f;
|
||||
tree->createSphere(largeRadius, 0.5, 0.5, 0.5, sphereVoxelSize, true, NATURAL);
|
||||
printf("11 - last large sphere added... largeRadius=%f sphereVoxelSize=%f\n", largeRadius, sphereVoxelSize);
|
||||
|
||||
printf("DONE creating spheres...\n");
|
||||
// Here's an example of how to recurse the tree and do some operation on the nodes as you recurse them.
|
||||
// This one is really simple, it just couts them...
|
||||
// Look at the function countVoxelsOperation() for an example of how you could use this function
|
||||
unsigned long nodeCount = tree->getVoxelCount();
|
||||
printf("Nodes after adding scene %ld nodes\n", nodeCount);
|
||||
|
||||
printf("DONE adding scene of spheres...\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
const char* SAY_HELLO = "--sayHello";
|
||||
|
@ -122,8 +54,32 @@ int main(int argc, const char * argv[])
|
|||
printf("You asked us not to create a scene file, so we will not.\n");
|
||||
} else {
|
||||
printf("Creating Scene File...\n");
|
||||
addScene(&myTree);
|
||||
|
||||
const char* RUN_TUTORIAL = "--runTutorial";
|
||||
if (cmdOptionExists(argc, argv, RUN_TUTORIAL)) {
|
||||
voxelTutorial(&myTree);
|
||||
}
|
||||
|
||||
const char* ADD_CORNERS_AND_AXIS_LINES = "--addCornersAndAxisLines";
|
||||
if (cmdOptionExists(argc, argv, ADD_CORNERS_AND_AXIS_LINES)) {
|
||||
addCornersAndAxisLines(&myTree);
|
||||
}
|
||||
|
||||
const char* ADD_SPHERE_SCENE = "--addSphereScene";
|
||||
if (cmdOptionExists(argc, argv, ADD_SPHERE_SCENE)) {
|
||||
addSphereScene(&myTree);
|
||||
}
|
||||
|
||||
const char* ADD_SURFACE_SCENE = "--addSurfaceScene";
|
||||
if (cmdOptionExists(argc, argv, ADD_SURFACE_SCENE)) {
|
||||
addSurfaceScene(&myTree);
|
||||
}
|
||||
|
||||
unsigned long nodeCount = myTree.getVoxelCount();
|
||||
printf("Nodes after adding scenes: %ld nodes\n", nodeCount);
|
||||
|
||||
myTree.writeToFileV2("voxels.hio2");
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue