Showing the changes to libraries/script-engine/src/ModelScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -38,16 +38,22 @@ QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) { · 37 unmodified lines | ||
| 38 | 38 | QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { |
| 39 | 39 | // figure out the size of the resulting mesh |
| 40 | 40 | size_t totalVertexCount { 0 }; |
| 41 | − size_t totalAttributeCount { 0 }; | |
| 41 | + size_t totalColorCount { 0 }; | |
| 42 | + size_t totalNormalCount { 0 }; | |
| 42 | 43 | size_t totalIndexCount { 0 }; |
| 43 | 44 | foreach (const MeshProxy* meshProxy, in) { |
| 44 | 45 | MeshPointer mesh = meshProxy->getMeshPointer(); |
| 45 | 46 | totalVertexCount += mesh->getNumVertices(); |
| 46 | 47 | |
| 48 | + int attributeTypeColor = gpu::Stream::InputSlot::COLOR; // libraries/gpu/src/gpu/Stream.h | |
| 49 | + const gpu::BufferView& colorsBufferView = mesh->getAttributeBuffer(attributeTypeColor); | |
| 50 | + gpu::BufferView::Index numColors = (gpu::BufferView::Index)colorsBufferView.getNumElements(); | |
| 51 | + totalColorCount += numColors; | |
| 52 | + | |
| 47 | 53 | int attributeTypeNormal = gpu::Stream::InputSlot::NORMAL; // libraries/gpu/src/gpu/Stream.h |
| 48 | 54 | const gpu::BufferView& normalsBufferView = mesh->getAttributeBuffer(attributeTypeNormal); |
| 49 | 55 | gpu::BufferView::Index numNormals = (gpu::BufferView::Index)normalsBufferView.getNumElements(); |
| 50 | − totalAttributeCount += numNormals; | |
| 56 | + totalNormalCount += numNormals; | |
| 51 | 57 | |
| 52 | 58 | totalIndexCount += mesh->getNumIndices(); |
| 53 | 59 | } |
| @@ -57,7 +63,11 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 3 unmodified lines | ||
| 57 | 63 | unsigned char* combinedVertexData = new unsigned char[combinedVertexSize]; |
| 58 | 64 | unsigned char* combinedVertexDataCursor = combinedVertexData; |
| 59 | 65 | |
| 60 | − gpu::Resource::Size combinedNormalSize = totalAttributeCount * sizeof(glm::vec3); | |
| 66 | + gpu::Resource::Size combinedColorSize = totalColorCount * sizeof(glm::vec3); | |
| 67 | + unsigned char* combinedColorData = new unsigned char[combinedColorSize]; | |
| 68 | + unsigned char* combinedColorDataCursor = combinedColorData; | |
| 69 | + | |
| 70 | + gpu::Resource::Size combinedNormalSize = totalNormalCount * sizeof(glm::vec3); | |
| 61 | 71 | unsigned char* combinedNormalData = new unsigned char[combinedNormalSize]; |
| 62 | 72 | unsigned char* combinedNormalDataCursor = combinedNormalData; |
| 63 | 73 | |
| @@ -74,6 +84,10 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 10 unmodified lines | ||
| 74 | 84 | memcpy(combinedVertexDataCursor, &position, sizeof(position)); |
| 75 | 85 | combinedVertexDataCursor += sizeof(position); |
| 76 | 86 | }, |
| 87 | + [&](glm::vec3 color){ | |
| 88 | + memcpy(combinedColorDataCursor, &color, sizeof(color)); | |
| 89 | + combinedColorDataCursor += sizeof(color); | |
| 90 | + }, | |
| 77 | 91 | [&](glm::vec3 normal){ |
| 78 | 92 | memcpy(combinedNormalDataCursor, &normal, sizeof(normal)); |
| 79 | 93 | combinedNormalDataCursor += sizeof(normal); |
| @@ -96,6 +110,13 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 16 unmodified lines | ||
| 96 | 110 | gpu::BufferView combinedVertexBufferView(combinedVertexBufferPointer, vertexElement); |
| 97 | 111 | result->setVertexBuffer(combinedVertexBufferView); |
| 98 | 112 | |
| 113 | + int attributeTypeColor = gpu::Stream::InputSlot::COLOR; // libraries/gpu/src/gpu/Stream.h | |
| 114 | + gpu::Element colorElement = gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ); | |
| 115 | + gpu::Buffer* combinedColorsBuffer = new gpu::Buffer(combinedColorSize, combinedColorData); | |
| 116 | + gpu::BufferPointer combinedColorsBufferPointer(combinedColorsBuffer); | |
| 117 | + gpu::BufferView combinedColorsBufferView(combinedColorsBufferPointer, colorElement); | |
| 118 | + result->addAttribute(attributeTypeColor, combinedColorsBufferView); | |
| 119 | + | |
| 99 | 120 | int attributeTypeNormal = gpu::Stream::InputSlot::NORMAL; // libraries/gpu/src/gpu/Stream.h |
| 100 | 121 | gpu::Element normalElement = gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ); |
| 101 | 122 | gpu::Buffer* combinedNormalsBuffer = new gpu::Buffer(combinedNormalSize, combinedNormalData); |
| @@ -132,6 +153,7 @@ QScriptValue ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshPro · 30 unmodified lines | ||
| 132 | 153 | } |
| 133 | 154 | |
| 134 | 155 | model::MeshPointer result = mesh->map([&](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); }, |
| 156 | + [&](glm::vec3 color){ return color; }, | |
| 135 | 157 | [&](glm::vec3 normal){ return glm::vec3(transform * glm::vec4(normal, 0.0f)); }, |
| 136 | 158 | [&](uint32_t index){ return index; }); |
| 137 | 159 | MeshProxy* resultProxy = new SimpleMeshProxy(result); |