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
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Christopher Steward
VTK
Commits
797b02c5
Commit
797b02c5
authored
6 years ago
by
Ken Martin
Browse files
Options
Downloads
Patches
Plain Diff
add output for verts and lines into gltf
Previously it only handled polys and strips
parent
749e0a90
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
IO/Export/vtkGLTFExporter.cxx
+108
-28
108 additions, 28 deletions
IO/Export/vtkGLTFExporter.cxx
with
108 additions
and
28 deletions
IO/Export/vtkGLTFExporter.cxx
+
108
−
28
View file @
797b02c5
...
...
@@ -231,28 +231,8 @@ void WriteMesh(
trif
->
Update
();
vtkPolyData
*
tris
=
trif
->
GetOutput
();
// write out the mesh
Json
::
Value
aprim
;
aprim
[
"mode"
]
=
4
;
Json
::
Value
attribs
;
// write the triangles
{
vtkCellArray
*
da
=
tris
->
GetPolys
();
WriteBufferAndView
(
da
,
fileName
,
inlineData
,
buffers
,
bufferViews
);
// write the accessor
Json
::
Value
acc
;
acc
[
"bufferView"
]
=
bufferViews
.
size
()
-
1
;
acc
[
"byteOffset"
]
=
0
;
acc
[
"type"
]
=
"SCALAR"
;
acc
[
"componentType"
]
=
GL_UNSIGNED_INT
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfCells
()
*
3
);
aprim
[
"indices"
]
=
accessors
.
size
();
accessors
.
append
(
acc
);
}
// write the point locations
int
pointAccessor
=
0
;
{
vtkDataArray
*
da
=
tris
->
GetPoints
()
->
GetData
();
WriteBufferAndView
(
da
,
fileName
,
inlineData
,
buffers
,
bufferViews
);
...
...
@@ -276,11 +256,12 @@ void WriteMesh(
maxs
.
append
(
range
[
5
]);
acc
[
"min"
]
=
mins
;
acc
[
"max"
]
=
maxs
;
attribs
[
"POSITION"
]
=
accessors
.
size
();
pointAccessor
=
accessors
.
size
();
accessors
.
append
(
acc
);
}
// if we have vertex colors then write them out
int
vertColorAccessor
=
-
1
;
aPart
->
GetMapper
()
->
MapScalars
(
tris
,
1.0
);
if
(
aPart
->
GetMapper
()
->
GetColorMapColors
())
{
...
...
@@ -295,12 +276,13 @@ void WriteMesh(
acc
[
"componentType"
]
=
GL_UNSIGNED_BYTE
;
acc
[
"normalized"
]
=
true
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfTuples
());
attribs
[
"COLOR_0"
]
=
accessors
.
size
();
vertColorAccessor
=
accessors
.
size
();
accessors
.
append
(
acc
);
}
// if we have tcoords then write them out
// first check for colortcoords
int
tcoordAccessor
=
-
1
;
vtkFloatArray
*
tcoords
=
aPart
->
GetMapper
()
->
GetColorCoordinates
();
if
(
!
tcoords
)
...
...
@@ -321,15 +303,113 @@ void WriteMesh(
acc
[
"componentType"
]
=
GL_FLOAT
;
acc
[
"normalized"
]
=
false
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfTuples
());
attribs
[
"TEXCOORD_0"
]
=
accessors
.
size
();
tcoordAccessor
=
accessors
.
size
();
accessors
.
append
(
acc
);
}
aprim
[
"attributes"
]
=
attribs
;
// to store the primitives
Json
::
Value
prims
;
// write out the verts
if
(
tris
->
GetVerts
()
&&
tris
->
GetVerts
()
->
GetNumberOfCells
())
{
Json
::
Value
aprim
;
aprim
[
"mode"
]
=
0
;
Json
::
Value
attribs
;
vtkCellArray
*
da
=
tris
->
GetVerts
();
WriteBufferAndView
(
da
,
fileName
,
inlineData
,
buffers
,
bufferViews
);
// write the accessor
Json
::
Value
acc
;
acc
[
"bufferView"
]
=
bufferViews
.
size
()
-
1
;
acc
[
"byteOffset"
]
=
0
;
acc
[
"type"
]
=
"SCALAR"
;
acc
[
"componentType"
]
=
GL_UNSIGNED_INT
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfCells
());
aprim
[
"indices"
]
=
accessors
.
size
();
accessors
.
append
(
acc
);
attribs
[
"POSITION"
]
=
pointAccessor
;
if
(
vertColorAccessor
>=
0
)
{
attribs
[
"COLOR_0"
]
=
vertColorAccessor
;
}
if
(
tcoordAccessor
>=
0
)
{
attribs
[
"TEXCOORD_0"
]
=
tcoordAccessor
;
}
aprim
[
"attributes"
]
=
attribs
;
prims
.
append
(
aprim
);
}
// write out the lines
if
(
tris
->
GetLines
()
&&
tris
->
GetLines
()
->
GetNumberOfCells
())
{
Json
::
Value
aprim
;
aprim
[
"mode"
]
=
1
;
Json
::
Value
attribs
;
vtkCellArray
*
da
=
tris
->
GetLines
();
WriteBufferAndView
(
da
,
fileName
,
inlineData
,
buffers
,
bufferViews
);
// write the accessor
Json
::
Value
acc
;
acc
[
"bufferView"
]
=
bufferViews
.
size
()
-
1
;
acc
[
"byteOffset"
]
=
0
;
acc
[
"type"
]
=
"SCALAR"
;
acc
[
"componentType"
]
=
GL_UNSIGNED_INT
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfCells
()
*
2
);
aprim
[
"indices"
]
=
accessors
.
size
();
accessors
.
append
(
acc
);
attribs
[
"POSITION"
]
=
pointAccessor
;
if
(
vertColorAccessor
>=
0
)
{
attribs
[
"COLOR_0"
]
=
vertColorAccessor
;
}
if
(
tcoordAccessor
>=
0
)
{
attribs
[
"TEXCOORD_0"
]
=
tcoordAccessor
;
}
aprim
[
"attributes"
]
=
attribs
;
prims
.
append
(
aprim
);
}
// write out the triangles
if
(
tris
->
GetPolys
()
&&
tris
->
GetPolys
()
->
GetNumberOfCells
())
{
Json
::
Value
aprim
;
aprim
[
"mode"
]
=
4
;
Json
::
Value
attribs
;
vtkCellArray
*
da
=
tris
->
GetPolys
();
WriteBufferAndView
(
da
,
fileName
,
inlineData
,
buffers
,
bufferViews
);
// write the accessor
Json
::
Value
acc
;
acc
[
"bufferView"
]
=
bufferViews
.
size
()
-
1
;
acc
[
"byteOffset"
]
=
0
;
acc
[
"type"
]
=
"SCALAR"
;
acc
[
"componentType"
]
=
GL_UNSIGNED_INT
;
acc
[
"count"
]
=
static_cast
<
Json
::
Value
::
Int64
>
(
da
->
GetNumberOfCells
()
*
3
);
aprim
[
"indices"
]
=
accessors
.
size
();
accessors
.
append
(
acc
);
attribs
[
"POSITION"
]
=
pointAccessor
;
if
(
vertColorAccessor
>=
0
)
{
attribs
[
"COLOR_0"
]
=
vertColorAccessor
;
}
if
(
tcoordAccessor
>=
0
)
{
attribs
[
"TEXCOORD_0"
]
=
tcoordAccessor
;
}
aprim
[
"attributes"
]
=
attribs
;
prims
.
append
(
aprim
);
}
Json
::
Value
amesh
;
Json
::
Value
prims
;
prims
.
append
(
aprim
);
amesh
[
"primitives"
]
=
prims
;
meshes
.
append
(
amesh
);
...
...
@@ -598,7 +678,7 @@ void vtkGLTFExporter::WriteToStream(ostream &output)
{
aPart
->
GetMapper
()
->
GetInputAlgorithm
()
->
Update
();
vtkPolyData
*
pd
=
findPolyData
(
aPart
->
GetMapper
()
->
GetInputDataObject
(
0
,
0
));
if
(
pd
&&
pd
->
GetPolys
()
&&
pd
->
GetPolys
()
->
GetNumberOfCells
()
>
0
)
if
(
pd
&&
pd
->
GetNumberOfCells
()
>
0
)
{
foundVisibleProp
=
true
;
WriteMesh
(
accessors
,
buffers
,
bufferViews
,
...
...
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