| 237 | } |
| 238 | |
| 239 | inline Ref<Accessor> ExportData(Asset &a, std::string &meshName, Ref<Buffer> &buffer, |
| 240 | unsigned int count, void *data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE) { |
| 241 | if (!count || !data) return Ref<Accessor>(); |
| 242 | |
| 243 | unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); |
| 244 | unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); |
| 245 | unsigned int bytesPerComp = ComponentTypeSize(compType); |
| 246 | |
| 247 | size_t offset = buffer->byteLength; |
| 248 | // make sure offset is correctly byte-aligned, as required by spec |
| 249 | size_t padding = offset % bytesPerComp; |
| 250 | offset += padding; |
| 251 | size_t length = count * numCompsOut * bytesPerComp; |
| 252 | buffer->Grow(length + padding); |
| 253 | |
| 254 | // bufferView |
| 255 | Ref<BufferView> bv = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); |
| 256 | bv->buffer = buffer; |
| 257 | bv->byteOffset = unsigned(offset); |
| 258 | bv->byteLength = length; //! The target that the WebGL buffer should be bound to. |
| 259 | bv->target = target; |
| 260 | |
| 261 | // accessor |
| 262 | Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor")); |
| 263 | acc->bufferView = bv; |
| 264 | acc->byteOffset = 0; |
| 265 | acc->byteStride = 0; |
| 266 | acc->componentType = compType; |
| 267 | acc->count = count; |
| 268 | acc->type = typeOut; |
| 269 | |
| 270 | // calculate min and max values |
| 271 | SetAccessorRange(compType, acc, data, count, numCompsIn, numCompsOut); |
| 272 | |
| 273 | // copy the data |
| 274 | acc->WriteData(count, data, numCompsIn*bytesPerComp); |
| 275 | |
| 276 | return acc; |
| 277 | } |
| 278 | |
| 279 | namespace { |
| 280 | void GetMatScalar(const aiMaterial* mat, float& val, const char* propName, int type, int idx) { |
no test coverage detected