Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
9de227d1
Commit
9de227d1
authored
6 years ago
by
Marshall Quander
Browse files
Options
Downloads
Patches
Plain Diff
Clean up inflation algorithm a lot
parent
b08febb7
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
src/components/gltf-model-plus.js
+20
-35
20 additions, 35 deletions
src/components/gltf-model-plus.js
with
20 additions
and
35 deletions
src/components/gltf-model-plus.js
+
20
−
35
View file @
9de227d1
...
@@ -74,44 +74,34 @@ function cloneGltf(gltf) {
...
@@ -74,44 +74,34 @@ function cloneGltf(gltf) {
return
clone
;
return
clone
;
}
}
const
getBehaviorNodes
=
function
(
root
,
templates
)
{
/// Walks the tree of three.js objects starting at the given node, using the GLTF data
const
nodes
=
new
Set
();
/// and template data to construct A-Frame entities and components when necessary.
if
(
root
.
userData
.
components
||
root
.
name
in
templates
)
{
/// (It's unnecessary to construct entities for subtrees that have no component data
nodes
.
add
(
root
);
/// or templates associated with any of their nodes.)
}
///
for
(
const
child
of
root
.
children
)
{
/// Returns the A-Frame entity associated with the given node, if one was constructed.
for
(
const
other
of
getBehaviorNodes
(
child
,
templates
))
{
const
inflateEntities
=
function
(
node
,
templates
,
gltfPath
)
{
nodes
.
add
(
other
);
// inflate subtrees first so that we can determine whether or not this node needs to be inflated
const
childEntities
=
[];
const
children
=
node
.
children
.
slice
(
0
);
// setObject3D mutates the node's parent, so we have to copy
for
(
const
child
of
children
)
{
const
el
=
inflateEntities
(
child
,
templates
,
gltfPath
);
if
(
el
)
{
childEntities
.
push
(
el
);
}
}
}
}
return
nodes
;
};
const
markLeaves
=
function
(
root
,
behaviorNodes
)
{
const
nodeHasBehavior
=
node
.
userData
.
components
||
node
.
name
in
templates
;
root
.
userData
.
leaf
=
!
behaviorNodes
.
has
(
root
);
if
(
!
nodeHasBehavior
&&
!
childEntities
.
length
)
{
for
(
const
child
of
root
.
children
)
{
return
null
;
// we don't need an entity for this node
if
(
!
markLeaves
(
child
,
behaviorNodes
))
{
root
.
userData
.
leaf
=
false
;
}
}
}
return
root
.
userData
.
leaf
;
};
const
inflateEntities
=
function
(
parentEl
,
node
,
gltfPath
)
{
if
(
node
.
userData
.
leaf
)
{
// we don't need an entity for this node
return
null
;
}
// setObject3D mutates the node's parent, so we have to copy
const
children
=
node
.
children
.
slice
(
0
);
const
el
=
document
.
createElement
(
"
a-entity
"
);
const
el
=
document
.
createElement
(
"
a-entity
"
);
el
.
append
.
apply
(
el
,
childEntities
);
// Remove invalid CSS class name characters.
// Remove invalid CSS class name characters.
const
className
=
(
node
.
name
||
node
.
uuid
).
replace
(
/
[^\w
-
]
/g
,
""
);
const
className
=
(
node
.
name
||
node
.
uuid
).
replace
(
/
[^\w
-
]
/g
,
""
);
el
.
classList
.
add
(
className
);
el
.
classList
.
add
(
className
);
parentEl
.
appendChild
(
el
);
// AFRAME rotation component expects rotations in YXZ, convert it
// AFRAME rotation component expects rotations in YXZ, convert it
if
(
node
.
rotation
.
order
!==
"
YXZ
"
)
{
if
(
node
.
rotation
.
order
!==
"
YXZ
"
)
{
...
@@ -166,10 +156,6 @@ const inflateEntities = function(parentEl, node, gltfPath) {
...
@@ -166,10 +156,6 @@ const inflateEntities = function(parentEl, node, gltfPath) {
}
}
}
}
children
.
forEach
(
childNode
=>
{
inflateEntities
(
el
,
childNode
,
gltfPath
);
});
return
el
;
return
el
;
};
};
...
@@ -286,9 +272,8 @@ AFRAME.registerComponent("gltf-model-plus", {
...
@@ -286,9 +272,8 @@ AFRAME.registerComponent("gltf-model-plus", {
this
.
el
.
setObject3D
(
"
mesh
"
,
this
.
model
);
this
.
el
.
setObject3D
(
"
mesh
"
,
this
.
model
);
if
(
this
.
data
.
inflate
)
{
if
(
this
.
data
.
inflate
)
{
const
behaviorNodes
=
getBehaviorNodes
(
this
.
model
,
this
.
templates
);
this
.
inflatedEl
=
inflateEntities
(
this
.
model
,
this
.
templates
,
gltfPath
);
markLeaves
(
this
.
model
,
behaviorNodes
);
this
.
el
.
appendChild
(
this
.
inflatedEl
);
this
.
inflatedEl
=
inflateEntities
(
this
.
el
,
this
.
model
,
gltfPath
);
// TODO: Still don't fully understand the lifecycle here and how it differs between browsers, we should dig in more
// TODO: Still don't fully understand the lifecycle here and how it differs between browsers, we should dig in more
// Wait one tick for the appended custom elements to be connected before attaching templates
// Wait one tick for the appended custom elements to be connected before attaching templates
await
nextTick
();
await
nextTick
();
...
...
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