Showing the changes to libraries/script-engine/src/ModelScriptingInterface.cpp (1 of 1 file). Show all
Unified · Split
| @@ -60,20 +60,20 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 59 unmodified lines | ||
| 60 | 60 | |
| 61 | 61 | // alloc the resulting mesh |
| 62 | 62 | gpu::Resource::Size combinedVertexSize = totalVertexCount * sizeof(glm::vec3); |
| 63 | − unsigned char* combinedVertexData = new unsigned char[combinedVertexSize]; | |
| 64 | − unsigned char* combinedVertexDataCursor = combinedVertexData; | |
| 63 | + std::unique_ptr<unsigned char> combinedVertexData{ new unsigned char[combinedVertexSize] }; | |
| 64 | + unsigned char* combinedVertexDataCursor = combinedVertexData.get(); | |
| 65 | 65 | |
| 66 | 66 | gpu::Resource::Size combinedColorSize = totalColorCount * sizeof(glm::vec3); |
| 67 | − unsigned char* combinedColorData = new unsigned char[combinedColorSize]; | |
| 68 | − unsigned char* combinedColorDataCursor = combinedColorData; | |
| 67 | + std::unique_ptr<unsigned char> combinedColorData{ new unsigned char[combinedColorSize] }; | |
| 68 | + unsigned char* combinedColorDataCursor = combinedColorData.get(); | |
| 69 | 69 | |
| 70 | 70 | gpu::Resource::Size combinedNormalSize = totalNormalCount * sizeof(glm::vec3); |
| 71 | − unsigned char* combinedNormalData = new unsigned char[combinedNormalSize]; | |
| 72 | − unsigned char* combinedNormalDataCursor = combinedNormalData; | |
| 71 | + std::unique_ptr<unsigned char> combinedNormalData{ new unsigned char[combinedNormalSize] }; | |
| 72 | + unsigned char* combinedNormalDataCursor = combinedNormalData.get(); | |
| 73 | 73 | |
| 74 | 74 | gpu::Resource::Size combinedIndexSize = totalIndexCount * sizeof(uint32_t); |
| 75 | − unsigned char* combinedIndexData = new unsigned char[combinedIndexSize]; | |
| 76 | − unsigned char* combinedIndexDataCursor = combinedIndexData; | |
| 75 | + std::unique_ptr<unsigned char> combinedIndexData{ new unsigned char[combinedIndexSize] }; | |
| 76 | + unsigned char* combinedIndexDataCursor = combinedIndexData.get(); | |
| 77 | 77 | |
| 78 | 78 | uint32_t indexStartOffset { 0 }; |
| 79 | 79 | |
| @@ -105,27 +105,27 @@ QScriptValue ModelScriptingInterface::appendMeshes(MeshProxyList in) { · 25 unmodified lines | ||
| 105 | 105 | model::MeshPointer result(new model::Mesh()); |
| 106 | 106 | |
| 107 | 107 | gpu::Element vertexElement = gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ); |
| 108 | − gpu::Buffer* combinedVertexBuffer = new gpu::Buffer(combinedVertexSize, combinedVertexData); | |
| 108 | + gpu::Buffer* combinedVertexBuffer = new gpu::Buffer(combinedVertexSize, combinedVertexData.get()); | |
| 109 | 109 | gpu::BufferPointer combinedVertexBufferPointer(combinedVertexBuffer); |
| 110 | 110 | gpu::BufferView combinedVertexBufferView(combinedVertexBufferPointer, vertexElement); |
| 111 | 111 | result->setVertexBuffer(combinedVertexBufferView); |
| 112 | 112 | |
| 113 | 113 | int attributeTypeColor = gpu::Stream::InputSlot::COLOR; // libraries/gpu/src/gpu/Stream.h |
| 114 | 114 | gpu::Element colorElement = gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ); |
| 115 | − gpu::Buffer* combinedColorsBuffer = new gpu::Buffer(combinedColorSize, combinedColorData); | |
| 115 | + gpu::Buffer* combinedColorsBuffer = new gpu::Buffer(combinedColorSize, combinedColorData.get()); | |
| 116 | 116 | gpu::BufferPointer combinedColorsBufferPointer(combinedColorsBuffer); |
| 117 | 117 | gpu::BufferView combinedColorsBufferView(combinedColorsBufferPointer, colorElement); |
| 118 | 118 | result->addAttribute(attributeTypeColor, combinedColorsBufferView); |
| 119 | 119 | |
| 120 | 120 | int attributeTypeNormal = gpu::Stream::InputSlot::NORMAL; // libraries/gpu/src/gpu/Stream.h |
| 121 | 121 | gpu::Element normalElement = gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ); |
| 122 | − gpu::Buffer* combinedNormalsBuffer = new gpu::Buffer(combinedNormalSize, combinedNormalData); | |
| 122 | + gpu::Buffer* combinedNormalsBuffer = new gpu::Buffer(combinedNormalSize, combinedNormalData.get()); | |
| 123 | 123 | gpu::BufferPointer combinedNormalsBufferPointer(combinedNormalsBuffer); |
| 124 | 124 | gpu::BufferView combinedNormalsBufferView(combinedNormalsBufferPointer, normalElement); |
| 125 | 125 | result->addAttribute(attributeTypeNormal, combinedNormalsBufferView); |
| 126 | 126 | |
| 127 | 127 | gpu::Element indexElement = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW); |
| 128 | − gpu::Buffer* combinedIndexesBuffer = new gpu::Buffer(combinedIndexSize, combinedIndexData); | |
| 128 | + gpu::Buffer* combinedIndexesBuffer = new gpu::Buffer(combinedIndexSize, combinedIndexData.get()); | |
| 129 | 129 | gpu::BufferPointer combinedIndexesBufferPointer(combinedIndexesBuffer); |
| 130 | 130 | gpu::BufferView combinedIndexesBufferView(combinedIndexesBufferPointer, indexElement); |
| 131 | 131 | result->setIndexBuffer(combinedIndexesBufferView); |
| @@ -152,9 +152,10 @@ QScriptValue ModelScriptingInterface::transformMesh(glm::mat4 transform, MeshPro · 20 unmodified lines | ||
| 152 | 152 | return QScriptValue(false); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | + const auto inverseTransposeTransform = glm::inverse(glm::transpose(transform)); | |
| 155 | 156 | model::MeshPointer result = mesh->map([&](glm::vec3 position){ return glm::vec3(transform * glm::vec4(position, 1.0f)); }, |
| 156 | 157 | [&](glm::vec3 color){ return color; }, |
| 157 | − [&](glm::vec3 normal){ return glm::vec3(transform * glm::vec4(normal, 0.0f)); }, | |
| 158 | + [&](glm::vec3 normal){ return glm::vec3(inverseTransposeTransform * glm::vec4(normal, 0.0f)); }, | |
| 158 | 159 | [&](uint32_t index){ return index; }); |
| 159 | 160 | MeshProxy* resultProxy = new SimpleMeshProxy(result); |
| 160 | 161 | return meshToScriptValue(_modelScriptEngine, resultProxy); |