From 362e08a90d4f7861f08db2ef28444aecd3f9f064 Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 10:23:28 -0700 Subject: [PATCH 1/7] Add extrudePolygon for cylinder --- libraries/render-utils/src/GeometryCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f1c995b943..f0e132ab7a 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -366,8 +366,6 @@ void GeometryCache::buildShapes() { shapeData.setupIndices(_shapeIndices, IndexVector(), wireIndices); } - // Not implememented yet: - //Triangle, extrudePolygon<3>(_shapes[Triangle], _shapeVertices, _shapeIndices); //Hexagon, @@ -375,11 +373,13 @@ void GeometryCache::buildShapes() { //Octagon, extrudePolygon<8>(_shapes[Octagon], _shapeVertices, _shapeIndices); + // Not implememented yet: //Quad, //Circle, //Torus, //Cone, - //Cylinder, + //Cylinder + extrudePolygon<48>(_shapes[Cylinder], _shapeVertices, _shapeIndices); } gpu::Stream::FormatPointer& getSolidStreamFormat() { From 417d9ec80b93766962dd44431cae9f2655bc731c Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 11:04:25 -0700 Subject: [PATCH 2/7] Surface cylinder option for primitive shape to html --- libraries/render-utils/src/GeometryCache.cpp | 5 +++-- libraries/render-utils/src/GeometryCache.h | 2 +- scripts/system/html/entityProperties.html | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f0e132ab7a..41731a76df 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -372,14 +372,15 @@ void GeometryCache::buildShapes() { extrudePolygon<6>(_shapes[Hexagon], _shapeVertices, _shapeIndices); //Octagon, extrudePolygon<8>(_shapes[Octagon], _shapeVertices, _shapeIndices); + //Cylinder, + extrudePolygon<48>(_shapes[Cylinder], _shapeVertices, _shapeIndices); // Not implememented yet: //Quad, //Circle, //Torus, //Cone, - //Cylinder - extrudePolygon<48>(_shapes[Cylinder], _shapeVertices, _shapeIndices); + } gpu::Stream::FormatPointer& getSolidStreamFormat() { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index e0a610a095..798c71317c 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -143,7 +143,7 @@ public: Icosahedron, Torus, // not yet implemented Cone, // not yet implemented - Cylinder, // not yet implemented + Cylinder, NUM_SHAPES, }; diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 35accdd0df..f15f7eed30 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -51,6 +51,7 @@ +
From d3e900e42f6e53b5adf169a98f1c33d5f07cdaca Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 12:54:49 -0700 Subject: [PATCH 3/7] Adding first pass on cone shape --- libraries/render-utils/src/GeometryCache.cpp | 82 +++++++++++++++++++- scripts/system/html/entityProperties.html | 1 + 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 41731a76df..58bae05ad4 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -324,6 +324,80 @@ void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& ver shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); } +template +void extrudeConical(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer) { + using namespace geometry; + Index baseVertex = (Index)(vertexBuffer->getSize() / SHAPE_VERTEX_STRIDE); + VertexVector vertices; + IndexVector solidIndices, wireIndices; + + std::vector base = polygon(); + + for (const vec3& v : base) { + vertices.push_back(vec3(0, 0.5f, 0)); + vertices.push_back(vec3(0, 1, 0)); + } + + for (const vec3& v : base) { + vertices.push_back(vec3(v.x, -0.5f, v.z)); + vertices.push_back(vec3(0, -1, 0)); + } + + + for (uint32_t i = 2; i < N; ++i) { + solidIndices.push_back(baseVertex + 0); + solidIndices.push_back(baseVertex + i); + solidIndices.push_back(baseVertex + i - 1); + solidIndices.push_back(baseVertex + N); + solidIndices.push_back(baseVertex + i + N - 1); + solidIndices.push_back(baseVertex + i + N); + } + for (uint32_t i = 1; i <= N; ++i) { + wireIndices.push_back(baseVertex + (i % N)); + wireIndices.push_back(baseVertex + i - 1); + wireIndices.push_back(baseVertex + (i % N) + N); + wireIndices.push_back(baseVertex + (i - 1) + N); + } + + // Now do the sides + baseVertex += 2 * N; + + for (uint32_t i = 0; i < N; ++i) { + vec3 left = base[i]; + vec3 right = base[(i + 1) % N]; + vec3 normal = glm::normalize(left + right); + vec3 topLeft = vec3(0.0, 0.5f, 0.0); + vec3 topRight = vec3(0.0, 0.5f, 0.0); + vec3 bottomLeft = vec3(left.x, -0.5f, left.z); + vec3 bottomRight = vec3(right.x, -0.5f, right.z); + + vertices.push_back(topLeft); + vertices.push_back(normal); + vertices.push_back(bottomLeft); + vertices.push_back(normal); + vertices.push_back(topRight); + vertices.push_back(normal); + vertices.push_back(bottomRight); + vertices.push_back(normal); + + solidIndices.push_back(baseVertex + 0); + solidIndices.push_back(baseVertex + 2); + solidIndices.push_back(baseVertex + 1); + solidIndices.push_back(baseVertex + 1); + solidIndices.push_back(baseVertex + 2); + solidIndices.push_back(baseVertex + 3); + wireIndices.push_back(baseVertex + 0); + wireIndices.push_back(baseVertex + 1); + wireIndices.push_back(baseVertex + 3); + wireIndices.push_back(baseVertex + 2); + baseVertex += 4; + } + + shapeData.setupVertices(vertexBuffer, vertices); + shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); + +} + // FIXME solids need per-face vertices, but smooth shaded // components do not. Find a way to support using draw elements // or draw arrays as appropriate @@ -373,13 +447,15 @@ void GeometryCache::buildShapes() { //Octagon, extrudePolygon<8>(_shapes[Octagon], _shapeVertices, _shapeIndices); //Cylinder, - extrudePolygon<48>(_shapes[Cylinder], _shapeVertices, _shapeIndices); - + extrudePolygon<64>(_shapes[Cylinder], _shapeVertices, _shapeIndices); + //Cone, + extrudeConical<64>(_shapes[Cone], _shapeVertices, _shapeIndices); + // Not implememented yet: //Quad, //Circle, //Torus, - //Cone, + } diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index f15f7eed30..a740306c92 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -52,6 +52,7 @@ +
From ffbe39df0a36b9c1032f76c0b3fb435a6294f4cd Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 13:06:24 -0700 Subject: [PATCH 4/7] Refactor to add optional conical parameter to existing extrude polygon function --- libraries/render-utils/src/GeometryCache.cpp | 98 ++++---------------- 1 file changed, 16 insertions(+), 82 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 58bae05ad4..11b330a9cf 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -255,17 +255,25 @@ void setupSmoothShape(GeometryCache::ShapeData& shapeData, const geometry::Solid } template -void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer) { +void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer, bool conical=false) { using namespace geometry; Index baseVertex = (Index)(vertexBuffer->getSize() / SHAPE_VERTEX_STRIDE); VertexVector vertices; IndexVector solidIndices, wireIndices; - // Top and bottom faces + // Top (if not conical) and bottom faces std::vector shape = polygon(); - for (const vec3& v : shape) { - vertices.push_back(vec3(v.x, 0.5f, v.z)); - vertices.push_back(vec3(0, 1, 0)); + if (conical) { + for (const vec3& v : shape) { + vertices.push_back(vec3(0, 0.5f, 0)); + vertices.push_back(vec3(0, 1, 0)); + } + } + else { + for (const vec3& v : shape) { + vertices.push_back(vec3(v.x, 0.5f, v.z)); + vertices.push_back(vec3(0, 1, 0)); + } } for (const vec3& v : shape) { vertices.push_back(vec3(v.x, -0.5f, v.z)); @@ -293,8 +301,8 @@ void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& ver vec3 left = shape[i]; vec3 right = shape[(i + 1) % N]; vec3 normal = glm::normalize(left + right); - vec3 topLeft = vec3(left.x, 0.5f, left.z); - vec3 topRight = vec3(right.x, 0.5f, right.z); + vec3 topLeft = (conical ? vec3(0.0, 0.5f, 0.0) : vec3(left.x, 0.5f, left.z)); + vec3 topRight = (conical? vec3(0.0, 0.5f, 0.0) : vec3(right.x, 0.5f, right.z)); vec3 bottomLeft = vec3(left.x, -0.5f, left.z); vec3 bottomRight = vec3(right.x, -0.5f, right.z); @@ -324,80 +332,6 @@ void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& ver shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); } -template -void extrudeConical(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer) { - using namespace geometry; - Index baseVertex = (Index)(vertexBuffer->getSize() / SHAPE_VERTEX_STRIDE); - VertexVector vertices; - IndexVector solidIndices, wireIndices; - - std::vector base = polygon(); - - for (const vec3& v : base) { - vertices.push_back(vec3(0, 0.5f, 0)); - vertices.push_back(vec3(0, 1, 0)); - } - - for (const vec3& v : base) { - vertices.push_back(vec3(v.x, -0.5f, v.z)); - vertices.push_back(vec3(0, -1, 0)); - } - - - for (uint32_t i = 2; i < N; ++i) { - solidIndices.push_back(baseVertex + 0); - solidIndices.push_back(baseVertex + i); - solidIndices.push_back(baseVertex + i - 1); - solidIndices.push_back(baseVertex + N); - solidIndices.push_back(baseVertex + i + N - 1); - solidIndices.push_back(baseVertex + i + N); - } - for (uint32_t i = 1; i <= N; ++i) { - wireIndices.push_back(baseVertex + (i % N)); - wireIndices.push_back(baseVertex + i - 1); - wireIndices.push_back(baseVertex + (i % N) + N); - wireIndices.push_back(baseVertex + (i - 1) + N); - } - - // Now do the sides - baseVertex += 2 * N; - - for (uint32_t i = 0; i < N; ++i) { - vec3 left = base[i]; - vec3 right = base[(i + 1) % N]; - vec3 normal = glm::normalize(left + right); - vec3 topLeft = vec3(0.0, 0.5f, 0.0); - vec3 topRight = vec3(0.0, 0.5f, 0.0); - vec3 bottomLeft = vec3(left.x, -0.5f, left.z); - vec3 bottomRight = vec3(right.x, -0.5f, right.z); - - vertices.push_back(topLeft); - vertices.push_back(normal); - vertices.push_back(bottomLeft); - vertices.push_back(normal); - vertices.push_back(topRight); - vertices.push_back(normal); - vertices.push_back(bottomRight); - vertices.push_back(normal); - - solidIndices.push_back(baseVertex + 0); - solidIndices.push_back(baseVertex + 2); - solidIndices.push_back(baseVertex + 1); - solidIndices.push_back(baseVertex + 1); - solidIndices.push_back(baseVertex + 2); - solidIndices.push_back(baseVertex + 3); - wireIndices.push_back(baseVertex + 0); - wireIndices.push_back(baseVertex + 1); - wireIndices.push_back(baseVertex + 3); - wireIndices.push_back(baseVertex + 2); - baseVertex += 4; - } - - shapeData.setupVertices(vertexBuffer, vertices); - shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); - -} - // FIXME solids need per-face vertices, but smooth shaded // components do not. Find a way to support using draw elements // or draw arrays as appropriate @@ -449,7 +383,7 @@ void GeometryCache::buildShapes() { //Cylinder, extrudePolygon<64>(_shapes[Cylinder], _shapeVertices, _shapeIndices); //Cone, - extrudeConical<64>(_shapes[Cone], _shapeVertices, _shapeIndices); + extrudePolygon<64>(_shapes[Cone], _shapeVertices, _shapeIndices, true); // Not implememented yet: //Quad, From fee26c3976888d6f4b8e6423529d475831cffbee Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 13:12:08 -0700 Subject: [PATCH 5/7] Remove not yet implemented comment from Cone shape --- libraries/render-utils/src/GeometryCache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 798c71317c..9853269280 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -142,7 +142,7 @@ public: Dodecahedron, Icosahedron, Torus, // not yet implemented - Cone, // not yet implemented + Cone, Cylinder, NUM_SHAPES, }; From 10408a0fe4a62b9d91bb78f2c81a6e1f3359e279 Mon Sep 17 00:00:00 2001 From: Liv Date: Thu, 25 May 2017 15:32:49 -0700 Subject: [PATCH 6/7] basic circle function to be used as base for torus --- libraries/render-utils/src/GeometryCache.cpp | 40 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 11b330a9cf..4f86f64c96 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -332,6 +332,39 @@ void extrudePolygon(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& ver shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); } +void drawCircle(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer) { + // Draw a circle with radius 1/4th the size of the bounding box + using namespace geometry; + + Index baseVertex = (Index)(vertexBuffer->getSize() / SHAPE_VERTEX_STRIDE); + VertexVector vertices; + IndexVector solidIndices, wireIndices; + + std::vector shape = polygon<64>(); + for (const vec3& v : shape) { + vertices.push_back(vec3(v.x, 0, v.z)); + vertices.push_back(vec3(0, 0, 0)); + } + + for (uint32_t i = 2; i < 64; ++i) { + solidIndices.push_back(baseVertex + 0); + solidIndices.push_back(baseVertex + i); + solidIndices.push_back(baseVertex + i - 1); + solidIndices.push_back(baseVertex + 64); + solidIndices.push_back(baseVertex + i + 64 - 1); + solidIndices.push_back(baseVertex + i + 64); + } + for (uint32_t i = 1; i <= 64; ++i) { + wireIndices.push_back(baseVertex + (i % 64)); + wireIndices.push_back(baseVertex + i - 1); + wireIndices.push_back(baseVertex + (i % 64) + 64); + wireIndices.push_back(baseVertex + (i - 1) + 64); + } + + shapeData.setupVertices(vertexBuffer, vertices); + shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); +} + // FIXME solids need per-face vertices, but smooth shaded // components do not. Find a way to support using draw elements // or draw arrays as appropriate @@ -384,13 +417,12 @@ void GeometryCache::buildShapes() { extrudePolygon<64>(_shapes[Cylinder], _shapeVertices, _shapeIndices); //Cone, extrudePolygon<64>(_shapes[Cone], _shapeVertices, _shapeIndices, true); - + //Circle + drawCircle(_shapes[Circle], _shapeVertices, _shapeIndices); // Not implememented yet: //Quad, //Circle, - //Torus, - - + //Torus, } gpu::Stream::FormatPointer& getSolidStreamFormat() { From 2808ab4865611a1d01ca966f105c0939c5eb999b Mon Sep 17 00:00:00 2001 From: Liv Date: Fri, 26 May 2017 10:45:29 -0700 Subject: [PATCH 7/7] Sort of making progress on torus vertex buffer --- libraries/render-utils/src/GeometryCache.cpp | 49 +++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 4f86f64c96..e59046c14a 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -365,6 +365,52 @@ void drawCircle(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexB shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); } +template +void drawTorus(GeometryCache::ShapeData& shapeData, gpu::BufferPointer& vertexBuffer, gpu::BufferPointer& indexBuffer) { + using namespace geometry; + Index baseVertex = (Index)(vertexBuffer->getSize() / SHAPE_VERTEX_STRIDE); + VertexVector vertices; + IndexVector solidIndices, wireIndices; + + float MAJOR_RADIUS = 0.75f; + float MINOR_RADIUS = 0.25f; + + // Minor segments + for (uint32_t j = 0; j < sMinor; j++) { + // Major segments + for (uint32_t i = 0; i < sMajor; i++) { + float_t u = float_t(i) / float_t(sMajor) * M_PI * 2; + float_t v = float_t(j + u) / float_t(sMinor) * M_PI * 2; + + vec3 vertex((MAJOR_RADIUS + MINOR_RADIUS * glm::cos(v)) * glm::cos(u), + (MAJOR_RADIUS + MINOR_RADIUS * glm::cos(v)) * glm::sin(u), + MINOR_RADIUS * glm::sin(v)); + + vertices.push_back(vertex); + } + } + + for (uint32_t x = 1; x <= sMinor; x++) { + for (uint32_t y = 1; y <= sMajor; y++) { + uint32_t a = (sMajor) * x + y - 1; + uint32_t b = (sMajor) * (x - 1) + y - 1; + uint32_t c = (sMajor) * (x - 1) + y; + uint32_t d = (sMajor) * x + y; + + solidIndices.push_back(a); + solidIndices.push_back(b); + solidIndices.push_back(d); + solidIndices.push_back(b); + solidIndices.push_back(c); + solidIndices.push_back(d); + + } + } + + shapeData.setupVertices(vertexBuffer, vertices); + shapeData.setupIndices(indexBuffer, solidIndices, wireIndices); +} + // FIXME solids need per-face vertices, but smooth shaded // components do not. Find a way to support using draw elements // or draw arrays as appropriate @@ -422,7 +468,8 @@ void GeometryCache::buildShapes() { // Not implememented yet: //Quad, //Circle, - //Torus, + //Torus, + drawTorus<6, 4>(_shapes[Torus], _shapeVertices, _shapeIndices); } gpu::Stream::FormatPointer& getSolidStreamFormat() {