Skip to content

Commit

Permalink
base64
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Oct 14, 2023
1 parent 5d8175d commit 766bceb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ofbx::Object* g_selected_object = nullptr;
template <int N>
void catProperty(char(&out)[N], const ofbx::IElementProperty& prop)
{
char tmp[128];
char tmp[127];
switch (prop.getType())
{
case ofbx::IElementProperty::DOUBLE: sprintf_s(tmp, "%f", prop.getValue().toDouble()); break;
Expand All @@ -30,7 +30,7 @@ void catProperty(char(&out)[N], const ofbx::IElementProperty& prop)
void gui(const ofbx::IElement& parent) {
for (const ofbx::IElement* element = parent.getFirstChild(); element; element = element->getSibling()) {
auto id = element->getID();
char label[128];
char label[1024];
id.toString(label);
strcat_s(label, " (");
ofbx::IElementProperty* prop = element->getFirstProperty();
Expand Down
18 changes: 7 additions & 11 deletions src/ofbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct Allocator {

struct Video
{
IElementProperty* base64_property = nullptr;
DataView filename;
DataView content;
DataView media;
Expand Down Expand Up @@ -1957,6 +1958,10 @@ struct Scene : IScene
return m_videos[index].is_base_64;
}

const IElementProperty* getEmbeddedBase64Data(int index) const override {
return m_videos[index].base64_property;
}

DataView getEmbeddedFilename(int index) const override {
return m_videos[index].filename;
}
Expand Down Expand Up @@ -2256,16 +2261,6 @@ void parseVideo(Scene& scene, const Element& element, Allocator& allocator)
if (!content_element->first_property) return;
const Property* content_property = content_element->first_property;
if (content_element->first_property->getType() != IElementProperty::BINARY) {
/*
if this happens in text format:
Content: ,
"iVBORw0KGgoA...
this is not a proper solution, but keep doing this until it become an issue
*/
if (content_element->first_property->getType() != IElementProperty::NONE) return;
if (!content_element->first_property->next) return;
if (content_element->first_property->next->getType() != IElementProperty::STRING) return;
content_property = content_element->first_property->next;
is_base64 = true;
}

Expand All @@ -2276,7 +2271,8 @@ void parseVideo(Scene& scene, const Element& element, Allocator& allocator)

Video video;
video.is_base_64 = is_base64;
video.content = content_property->value;
video.base64_property = is_base64 ? content_element->first_property->next : nullptr;
video.content = is_base64 ? DataView{} : content_element->first_property->value;
video.filename = filename_element->first_property->value;
video.media = element.first_property->next->value;
scene.m_videos.push_back(video);
Expand Down
2 changes: 2 additions & 0 deletions src/ofbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ struct IScene
virtual DataView getEmbeddedData(int index) const = 0;
virtual DataView getEmbeddedFilename(int index) const = 0;
virtual bool isEmbeddedBase64(int index) const = 0;
// data are encoded in returned property and all ->next properties
virtual const IElementProperty* getEmbeddedBase64Data(int index) const = 0;

// Scene Misc
virtual const TakeInfo* getTakeInfo(const char* name) const = 0;
Expand Down

0 comments on commit 766bceb

Please sign in to comment.