Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Spiros Tsalikis
VTK
Commits
3179646c
Verified
Commit
3179646c
authored
1 month ago
by
Sankhesh Jhaveri
Browse files
Options
Downloads
Patches
Plain Diff
Import glTF scene from a resource stream
parent
6bf4f034
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
IO/Import/vtkGLTFImporter.cxx
+43
-11
43 additions, 11 deletions
IO/Import/vtkGLTFImporter.cxx
IO/Import/vtkGLTFImporter.h
+44
-1
44 additions, 1 deletion
IO/Import/vtkGLTFImporter.h
with
87 additions
and
12 deletions
IO/Import/vtkGLTFImporter.cxx
+
43
−
11
View file @
3179646c
...
...
@@ -403,9 +403,9 @@ void vtkGLTFImporter::InitializeLoader()
int
vtkGLTFImporter
::
ImportBegin
()
{
// Make sure we have a file to read.
if
(
!
this
->
FileName
)
if
(
!
this
->
Stream
&&
!
this
->
FileName
)
{
vtkErrorMacro
(
"
A
FileName
must
be specified."
);
vtkErrorMacro
(
"
Neither
FileName
nor Stream has
be
en
specified."
);
return
0
;
}
...
...
@@ -422,21 +422,44 @@ int vtkGLTFImporter::ImportBegin()
// Check extension
std
::
vector
<
char
>
glbBuffer
;
std
::
string
extension
=
vtksys
::
SystemTools
::
GetFilenameLastExtension
(
this
->
FileName
);
if
(
extension
==
".glb"
)
if
(
this
->
Stream
!=
nullptr
)
{
if
(
!
this
->
Loader
->
LoadFileBuffer
(
this
->
FileName
,
glbBuffer
))
// this->Stream is defined.
if
(
this
->
StreamIsBinary
)
{
vtkErrorMacro
(
"Error loading binary data"
);
if
(
!
this
->
Loader
->
LoadStreamBuffer
(
this
->
Stream
,
glbBuffer
))
{
vtkErrorMacro
(
"Error loading binary data"
);
return
0
;
}
}
if
(
!
this
->
Loader
->
LoadModelMetaDataFromStream
(
this
->
Stream
,
this
->
StreamURILoader
))
{
vtkErrorMacro
(
"Error loading model metadata"
);
return
0
;
}
}
if
(
!
this
->
Loader
->
LoadModelMetaDataFromFile
(
this
->
FileName
))
else
{
vtkErrorMacro
(
"Error loading model metadata"
);
return
0
;
// this->FileName is defined.
std
::
string
extension
=
vtksys
::
SystemTools
::
GetFilenameLastExtension
(
this
->
FileName
);
if
(
extension
==
".glb"
)
{
if
(
!
this
->
Loader
->
LoadFileBuffer
(
this
->
FileName
,
glbBuffer
))
{
vtkErrorMacro
(
"Error loading binary data"
);
return
0
;
}
}
if
(
!
this
->
Loader
->
LoadModelMetaDataFromFile
(
this
->
FileName
))
{
vtkErrorMacro
(
"Error loading model metadata"
);
return
0
;
}
}
if
(
!
this
->
Loader
->
LoadModelData
(
glbBuffer
))
{
vtkErrorMacro
(
"Error loading model data"
);
...
...
@@ -1037,7 +1060,16 @@ bool vtkGLTFImporter::GetTemporalInformation(vtkIdType animationIndex, double fr
void
vtkGLTFImporter
::
PrintSelf
(
ostream
&
os
,
vtkIndent
indent
)
{
this
->
Superclass
::
PrintSelf
(
os
,
indent
);
os
<<
indent
<<
"File Name: "
<<
(
this
->
FileName
?
this
->
FileName
:
"(none)"
)
<<
"
\n
"
;
os
<<
indent
;
if
(
this
->
Stream
!=
nullptr
)
{
os
<<
"Stream ("
<<
(
this
->
StreamIsBinary
?
"binary"
:
"ascii"
)
<<
")"
;
}
else
{
os
<<
"File Name: "
<<
(
this
->
FileName
?
this
->
FileName
:
"(none)"
);
}
os
<<
"
\n
"
;
}
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
IO/Import/vtkGLTFImporter.h
+
44
−
1
View file @
3179646c
...
...
@@ -51,16 +51,22 @@
#include
"vtkIOImportModule.h"
// For export macro
#include
"vtkImporter.h"
#include
"vtkSmartPointer.h"
// For SmartPointer
#include
"vtkResourceStream.h"
// For Stream
#include
"vtkSmartPointer.h"
// For SmartPointer
#include
"vtkURILoader.h"
// For URILoader
#include
<map>
// For map
#include
<vector>
// For vector
VTK_ABI_NAMESPACE_BEGIN
// Forward declarations
class
vtkActor
;
class
vtkCamera
;
class
vtkGLTFDocumentLoader
;
class
vtkResourceStream
;
class
vtkTexture
;
class
vtkURILoader
;
class
VTKIOIMPORT_EXPORT
vtkGLTFImporter
:
public
vtkImporter
{
...
...
@@ -78,6 +84,40 @@ public:
vtkGetFilePathMacro
(
FileName
);
///@}
///@{
/**
* Specify the glTF source stream to read from. When selecting the input method, `Stream` has a
* higher priority than `FileName` i.e. if a stream is provided, the filename is ignored.
*
* \note If the stream contains non-data URIs, specifying a custom uri loader is crucial.
* \sa SetStreamURILoader()
*
* \sa SetStreamIsBinary()
*/
vtkSetSmartPointerMacro
(
Stream
,
vtkResourceStream
);
vtkGetSmartPointerMacro
(
Stream
,
vtkResourceStream
);
///@}
///@{
/**
* Specify a custom URI loader for non-data URIs in the input stream.
* \sa SetStream(), SetStreamIsBinary()
*/
vtkSetSmartPointerMacro
(
StreamURILoader
,
vtkURILoader
);
vtkGetSmartPointerMacro
(
StreamURILoader
,
vtkURILoader
);
///@}
///@{
/**
* Set/Get whether the input stream is binary
*
* \sa SetStream()
*/
vtkSetMacro
(
StreamIsBinary
,
bool
);
vtkGetMacro
(
StreamIsBinary
,
bool
);
vtkBooleanMacro
(
StreamIsBinary
,
bool
);
///@}
/**
* glTF defines multiple camera objects, but no default behavior for which camera should be
* used. The importer will by default apply the asset's first camera. This accessor lets you use
...
...
@@ -167,6 +207,9 @@ protected:
virtual
void
ApplyArmatureProperties
(
vtkActor
*
actor
);
char
*
FileName
=
nullptr
;
vtkSmartPointer
<
vtkResourceStream
>
Stream
;
vtkSmartPointer
<
vtkURILoader
>
StreamURILoader
;
bool
StreamIsBinary
=
false
;
std
::
map
<
int
,
vtkSmartPointer
<
vtkCamera
>>
Cameras
;
std
::
map
<
int
,
vtkSmartPointer
<
vtkTexture
>>
Textures
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment