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
b1391495
Commit
b1391495
authored
7 years ago
by
Robert Long
Browse files
Options
Downloads
Patches
Plain Diff
Split personal space bubble out into two components. Perf improvements.
parent
04be39d5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public/index.html
+3
-3
3 additions, 3 deletions
public/index.html
src/systems/personal-space-bubble.js
+57
-37
57 additions, 37 deletions
src/systems/personal-space-bubble.js
with
60 additions
and
40 deletions
public/index.html
+
3
−
3
View file @
b1391495
...
...
@@ -35,12 +35,12 @@
matcolor
-
audio
-
feedback
=
"
objectName: DodecAvatar_Head_0
"
scale
-
audio
-
feedback
avatar
-
customization
personal
-
space
-
bubble
personal
-
space
-
invader
><
/a-entity
>
</script>
<script
id=
"hand-template"
type=
"text/html"
>
<
a
-
box
class
=
"
hand
"
personal
-
space
-
bubble
scale
=
"
0.2 0.1 0.3
"
><
/a-box
>
<
a
-
box
class
=
"
hand
"
personal
-
space
-
invader
scale
=
"
0.2 0.1 0.3
"
><
/a-box
>
</script>
<script
id=
"nametag-template"
type=
"text/html"
>
...
...
@@ -55,7 +55,7 @@
<a-entity
id=
"player-rig"
networked
wasd-controls
snap-rotation=
"pivotSrc: #head"
>
<a-sphere
scale=
"0.1 0.1 0.1"
></a-sphere>
<a-entity
id=
"head"
camera=
"userHeight: 1.6"
look-controls
networked=
"template:#head-template;showLocalTemplate:false;"
></a-entity>
<a-entity
id=
"head"
camera=
"userHeight: 1.6"
personal-space-bubble
look-controls
networked=
"template:#head-template;showLocalTemplate:false;"
></a-entity>
<a-entity
id=
"nametag"
networked=
"template:#nametag-template;showLocalTemplate:false;"
></a-entity>
...
...
This diff is collapsed.
Click to expand it.
src/systems/personal-space-bubble.js
+
57
−
37
View file @
b1391495
var
posA
=
new
AFRAME
.
THREE
.
Vector3
();
var
posB
=
new
AFRAME
.
THREE
.
Vector3
();
function
distance
(
entityA
,
entityB
)
{
entityA
.
object3D
.
getWorldPosition
(
posA
);
entityB
.
object3D
.
getWorldPosition
(
posB
);
return
posA
.
distanceTo
(
posB
);
}
var
invaderPos
=
new
AFRAME
.
THREE
.
Vector3
();
var
bubblePos
=
new
AFRAME
.
THREE
.
Vector3
();
AFRAME
.
registerSystem
(
"
personal-space-bubble
"
,
{
init
()
{
this
.
myEntitie
s
=
[];
this
.
entiti
es
=
[];
this
.
invader
s
=
[];
this
.
bubbl
es
=
[];
},
register
Entity
(
el
)
{
var
networkedEl
=
NAF
.
utils
.
getNetworkedEntity
(
el
);
var
owner
=
NAF
.
utils
.
getNetworkOwner
(
networkedEl
);
register
Bubble
(
el
)
{
this
.
bubbles
.
push
(
el
);
},
if
(
owner
!==
NAF
.
clientId
)
{
this
.
entities
.
push
(
el
);
}
else
{
this
.
myEntities
.
push
(
el
);
unregisterBubble
(
el
)
{
var
index
=
this
.
bubbles
.
indexOf
(
el
);
if
(
index
!==
-
1
)
{
this
.
bubbles
.
splice
(
index
,
1
);
}
},
un
register
Entity
(
el
)
{
register
Invader
(
el
)
{
var
networkedEl
=
NAF
.
utils
.
getNetworkedEntity
(
el
);
var
owner
=
NAF
.
utils
.
getNetworkOwner
(
networkedEl
);
if
(
owner
!==
NAF
.
clientId
)
{
var
index
=
this
.
entities
.
indexOf
(
el
);
this
.
entities
.
splice
(
index
,
1
);
}
else
{
var
index
=
this
.
myEntities
.
indexOf
(
el
);
this
.
myEntities
.
splice
(
index
,
1
);
this
.
invaders
.
push
(
el
);
}
},
unregisterInvader
(
el
)
{
var
index
=
this
.
invaders
.
indexOf
(
el
);
if
(
index
!==
-
1
)
{
this
.
invaders
.
splice
(
index
,
1
);
}
},
tick
()
{
for
(
var
j
=
0
;
j
<
this
.
entities
.
length
;
j
++
)
{
var
otherEntity
=
this
.
entities
[
j
];
// Update matrix positions once for each space bubble and space invader
for
(
var
i
=
0
;
i
<
this
.
bubbles
.
length
;
i
++
)
{
this
.
bubbles
[
i
].
object3D
.
updateMatrixWorld
(
true
);
}
for
(
var
i
=
0
;
i
<
this
.
invaders
.
length
;
i
++
)
{
this
.
invaders
[
i
].
object3D
.
updateMatrixWorld
(
true
);
}
var
visible
=
true
;
// Loop through all of the space bubbles (usually one)
for
(
var
i
=
0
;
i
<
this
.
bubbles
.
length
;
i
++
)
{
var
bubble
=
this
.
bubbles
[
i
];
for
(
var
i
=
0
;
i
<
this
.
myEntities
.
length
;
i
++
)
{
var
myEntity
=
this
.
myEntities
[
i
];
bubblePos
.
setFromMatrixPosition
(
bubble
.
object3D
.
matrixWorld
);
var
d
=
distance
(
myEntity
,
otherEntity
);
var
radius
=
bubble
.
components
[
"
personal-space-bubble
"
].
data
.
radius
;
var
radiusSquared
=
radius
*
radius
;
if
(
d
<
myEntity
.
components
[
"
personal-space-bubble
"
].
data
.
radius
)
{
visible
=
false
;
break
;
}
}
// Hide the invader if inside the bubble
for
(
var
j
=
0
;
j
<
this
.
invaders
.
length
;
j
++
)
{
var
invader
=
this
.
invaders
[
j
]
;
invaderPos
.
setFromMatrixPosition
(
invader
.
object3D
.
matrixWorld
);
otherEntity
.
object3D
.
visible
=
visible
;
var
distanceSquared
=
bubblePos
.
distanceTo
(
invaderPos
);
invader
.
object3D
.
visible
=
distanceSquared
>
radiusSquared
;
}
}
}
});
AFRAME
.
registerComponent
(
"
personal-space-invader
"
,
{
init
()
{
this
.
el
.
sceneEl
.
systems
[
"
personal-space-bubble
"
].
registerInvader
(
this
.
el
);
},
remove
()
{
this
.
el
.
sceneEl
.
systems
[
"
personal-space-bubble
"
].
unregisterInvader
(
this
.
el
);
}
});
AFRAME
.
registerComponent
(
"
personal-space-bubble
"
,
{
schema
:
{
radius
:
{
type
:
"
number
"
,
default
:
0.8
}
},
init
()
{
this
.
system
.
register
Entity
(
this
.
el
);
this
.
system
.
register
Bubble
(
this
.
el
);
},
remove
()
{
this
.
system
.
unregister
Entity
(
this
.
el
);
this
.
system
.
unregister
Bubble
(
this
.
el
);
}
});
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