浏览代码

added support for embedded textures defined with buffer views.

Marco Di Benedetto 7 年之前
父节点
当前提交
4b7cd97fea
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      code/glTF2Asset.inl

+ 13 - 1
code/glTF2Asset.inl

@@ -669,7 +669,7 @@ inline Image::Image()
 
 }
 
-inline void Image::Read(Value& obj, Asset& /*r*/)
+inline void Image::Read(Value& obj, Asset& r)
 {
     if (!mDataLength) {
         if (Value* uri = FindString(obj, "uri")) {
@@ -686,6 +686,18 @@ inline void Image::Read(Value& obj, Asset& /*r*/)
                 this->uri = uristr;
             }
         }
+        else if (Value* bufferViewVal = FindUInt(obj, "bufferView")) {
+            this->bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint());
+            Ref<Buffer> buffer = this->bufferView->buffer;
+
+            this->mDataLength = this->bufferView->byteLength;
+            this->mData = new uint8_t [this->mDataLength];
+            memcpy(this->mData, buffer->GetPointer(), this->mDataLength);
+
+            if (Value* mtype = FindString(obj, "mimeType")) {
+                this->mimeType = mtype->GetString();
+            }
+        }
     }
 }