Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OrigamiSimulator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amanda Ghassaei
OrigamiSimulator
Commits
427a4f4f
Commit
427a4f4f
authored
May 11, 2017
by
amandaghassaei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vive
parent
a0d94af3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
13 deletions
+135
-13
dependencies/ViveController.js
dependencies/ViveController.js
+1
-1
js/3dUI.js
js/3dUI.js
+0
-1
js/ViveInterface.js
js/ViveInterface.js
+124
-5
js/model.js
js/model.js
+2
-2
js/node.js
js/node.js
+8
-4
No files found.
dependencies/ViveController.js
View file @
427a4f4f
...
@@ -60,7 +60,7 @@ THREE.ViveController = function ( id ) {
...
@@ -60,7 +60,7 @@ THREE.ViveController = function ( id ) {
this
.
update
=
function
()
{
this
.
update
=
function
()
{
gamepad
=
findGamepad
(
id
);
gamepad
=
findGamepad
(
id
);
//not working in chrome https://github.com/mrdoob/three.js/issues/9723
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
if
(
gamepad
.
pose
===
null
)
return
;
// No user action yet
if
(
gamepad
.
pose
===
null
)
return
;
// No user action yet
...
...
js/3dUI.js
View file @
427a4f4f
...
@@ -123,7 +123,6 @@ function init3DUI(globals) {
...
@@ -123,7 +123,6 @@ function init3DUI(globals) {
function
hideHighlighters
(){
function
hideHighlighters
(){
highlighter1
.
getObject3D
().
visible
=
false
;
highlighter1
.
getObject3D
().
visible
=
false
;
// highlighter2.getObject3D().visible = false;
}
}
// globals.threeView.sceneAdd(raycasterPlane);
// globals.threeView.sceneAdd(raycasterPlane);
...
...
js/ViveInterface.js
View file @
427a4f4f
...
@@ -15,7 +15,10 @@ function initViveInterface(globals){
...
@@ -15,7 +15,10 @@ function initViveInterface(globals){
$status
.
html
(
"
No device connected.
"
);
$status
.
html
(
"
No device connected.
"
);
$
(
"
#VRoptions
"
).
show
();
$
(
"
#VRoptions
"
).
show
();
var
mesh
=
new
THREE
.
Mesh
(
new
THREE
.
CubeGeometry
(
0.01
,
0.01
,
0.01
),
new
THREE
.
MeshLambertMaterial
({
color
:
0xff0000
}));
var
geo
=
new
THREE
.
CylinderGeometry
(
0
,
0.05
,
0.25
,
4
);
geo
.
applyMatrix
(
new
THREE
.
Matrix4
().
makeRotationX
(
-
Math
.
PI
/
2
));
var
mesh
=
new
THREE
.
Mesh
(
geo
,
new
THREE
.
MeshLambertMaterial
({
color
:
0x444444
}));
mesh
.
position
.
set
(
0
,
0
,
0.125
);
mesh
.
visible
=
false
;
mesh
.
visible
=
false
;
var
controls
=
new
THREE
.
VRControls
(
globals
.
threeView
.
camera
);
var
controls
=
new
THREE
.
VRControls
(
globals
.
threeView
.
camera
);
...
@@ -33,37 +36,153 @@ function initViveInterface(globals){
...
@@ -33,37 +36,153 @@ function initViveInterface(globals){
controller1
.
add
(
mesh
.
clone
());
controller1
.
add
(
mesh
.
clone
());
controller2
.
add
(
mesh
.
clone
());
controller2
.
add
(
mesh
.
clone
());
var
controllers
=
[
controller1
,
controller2
];
var
controllerStates
=
[
false
,
false
];
//vis
var
highlighters
=
[
new
Node
(
new
THREE
.
Vector3
()),
new
Node
(
new
THREE
.
Vector3
())];
_
.
each
(
highlighters
,
function
(
highlighter
){
highlighter
.
setTransparentVR
();
globals
.
threeView
.
scene
.
add
(
highlighter
.
getObject3D
());
});
var
nodes
=
[
null
,
null
];
var
draggingEvent
=
[
false
,
false
];
var
releaseEvent
=
[
false
,
false
];
var
effect
=
new
THREE
.
VREffect
(
globals
.
threeView
.
renderer
);
var
effect
=
new
THREE
.
VREffect
(
globals
.
threeView
.
renderer
);
connect
();
connect
();
var
yOffset
=
1.6
;
var
scale
=
0.5
;
function
connect
(){
function
connect
(){
WEBVR
.
getVRDisplay
(
function
(
display
)
{
WEBVR
.
getVRDisplay
(
function
(
display
)
{
if
(
!
display
)
return
;
if
(
!
display
)
return
;
$status
.
html
(
"
VR device detected.
"
);
$status
.
html
(
"
VR device detected.
"
);
var
button
=
WEBVR
.
getButton
(
display
,
globals
.
threeView
.
renderer
.
domElement
);
var
button
=
WEBVR
.
getButton
(
display
,
globals
.
threeView
.
renderer
.
domElement
);
console
.
log
(
button
);
$
(
"
#VRoptions
"
).
html
(
button
);
$
(
"
#VRoptions
"
).
html
(
button
);
var
callback
=
button
.
onclick
;
var
callback
=
button
.
onclick
;
button
.
onclick
=
function
()
{
button
.
onclick
=
function
()
{
globals
.
vrEnabled
=
!
display
.
isPresenting
;
globals
.
vrEnabled
=
!
display
.
isPresenting
;
var
y
=
0
;
var
y
=
0
;
if
(
globals
.
vrEnabled
)
y
=
1
;
if
(
globals
.
vrEnabled
)
y
=
yOffset
;
globals
.
threeView
.
modelWrapper
.
scale
.
set
(
scale
,
scale
,
scale
);
globals
.
threeView
.
modelWrapper
.
position
.
set
(
0
,
y
,
0
);
globals
.
threeView
.
modelWrapper
.
position
.
set
(
0
,
y
,
0
);
// var scale = 0.01;
_
.
each
(
controller1
.
children
,
function
(
child
){
// globals.threeView.modelWrapper.scale.set(scale, scale, scale);
child
.
visible
=
true
;
});
_
.
each
(
controller2
.
children
,
function
(
child
){
child
.
visible
=
true
;
});
setControllerEvents
();
if
(
callback
)
callback
();
if
(
callback
)
callback
();
};
};
}
);
}
);
}
}
function
setControllerEvents
(){
controller1
.
addEventListener
(
'
triggerdown
'
,
function
()
{
controllerStates
[
0
]
=
true
;
draggingEvent
[
0
]
=
true
;
});
controller2
.
addEventListener
(
'
triggerdown
'
,
function
()
{
controllerStates
[
1
]
=
true
;
draggingEvent
[
1
]
=
true
;
});
controller1
.
addEventListener
(
'
triggerup
'
,
function
()
{
controllerStates
[
0
]
=
false
;
releaseEvent
[
0
]
=
true
;
});
controller2
.
addEventListener
(
'
triggerup
'
,
function
()
{
controllerStates
[
1
]
=
false
;
releaseEvent
[
1
]
=
true
;
});
}
function
render
(){
function
render
(){
controller1
.
update
();
controller1
.
update
();
controller2
.
update
();
controller2
.
update
();
checkForIntersections
();
controls
.
update
();
controls
.
update
();
effect
.
render
(
globals
.
threeView
.
scene
,
globals
.
threeView
.
camera
);
effect
.
render
(
globals
.
threeView
.
scene
,
globals
.
threeView
.
camera
);
}
}
function
checkForIntersections
(){
for
(
var
i
=
0
;
i
<
2
;
i
++
){
var
object3D
=
highlighters
[
i
].
object3D
;
var
controller
=
controllers
[
i
];
object3D
.
visible
=
false
;
var
position
=
controller
.
position
.
clone
();
position
.
applyMatrix4
(
controller
.
standingMatrix
);
if
(
controllerStates
[
i
]
&&
nodes
[
i
]){
//drag node
if
(
draggingEvent
[
i
])
{
nodes
[
i
].
setFixed
(
true
);
globals
.
fixedHasChanged
=
true
;
draggingEvent
[
i
]
=
false
;
}
position
.
y
-=
yOffset
;
position
.
multiplyScalar
(
1
/
scale
);
nodes
[
i
].
moveManually
(
position
);
globals
.
nodePositionHasChanged
=
true
;
continue
;
}
if
(
releaseEvent
[
i
]){
if
(
nodes
[
i
])
nodes
[
i
].
setFixed
(
false
);
globals
.
fixedHasChanged
=
true
;
}
draggingEvent
[
i
]
=
false
;
releaseEvent
[
i
]
=
false
;
var
direction
=
new
THREE
.
Vector3
(
0
,
0
,
-
1
);
direction
.
applyQuaternion
(
controller
.
quaternion
);
position
.
add
(
direction
.
clone
().
multiplyScalar
(
-
0.05
));
var
cast
=
new
THREE
.
Raycaster
(
position
,
direction
,
-
0.1
,
10
);
var
intersects
=
cast
.
intersectObjects
(
globals
.
model
.
getMesh
(),
false
);
if
(
intersects
.
length
>
0
){
var
intersection
=
intersects
[
0
];
var
face
=
intersection
.
face
;
var
point
=
intersection
.
point
;
if
(
point
.
clone
().
sub
(
position
).
length
()
>
0.2
)
{
nodes
[
i
]
=
null
;
continue
;
}
var
verticesArray
=
globals
.
model
.
getVertices
();
var
vertices
=
[];
vertices
.
push
(
verticesArray
[
face
.
a
]);
vertices
.
push
(
verticesArray
[
face
.
b
]);
vertices
.
push
(
verticesArray
[
face
.
c
]);
var
dist
=
transformToGlobalCoords
(
vertices
[
0
].
clone
()).
sub
(
point
).
lengthSq
();
var
nodeIndex
=
face
.
a
;
for
(
var
j
=
1
;
j
<
3
;
j
++
){
var
_dist
=
(
transformToGlobalCoords
(
vertices
[
j
].
clone
()).
sub
(
point
)).
lengthSq
();
if
(
_dist
<
dist
){
dist
=
_dist
;
if
(
j
==
1
)
nodeIndex
=
face
.
b
;
else
nodeIndex
=
face
.
c
;
}
}
var
nodesArray
=
globals
.
model
.
getNodes
();
nodes
[
i
]
=
nodesArray
[
nodeIndex
];
object3D
.
position
.
copy
(
transformToGlobalCoords
(
nodes
[
i
].
getPosition
().
clone
()));
object3D
.
visible
=
true
;
}
else
nodes
[
i
]
=
null
;
}
}
function
transformToGlobalCoords
(
position
){
position
.
multiplyScalar
(
scale
);
position
.
y
+=
yOffset
;
return
position
;
}
return
{
return
{
effect
:
effect
,
effect
:
effect
,
render
:
render
render
:
render
...
...
js/model.js
View file @
427a4f4f
...
@@ -173,8 +173,8 @@ function initModel(globals){
...
@@ -173,8 +173,8 @@ function initModel(globals){
geometry
.
attributes
.
position
.
needsUpdate
=
true
;
geometry
.
attributes
.
position
.
needsUpdate
=
true
;
if
(
globals
.
colorMode
==
"
axialStrain
"
)
geometry
.
attributes
.
color
.
needsUpdate
=
true
;
if
(
globals
.
colorMode
==
"
axialStrain
"
)
geometry
.
attributes
.
color
.
needsUpdate
=
true
;
else
geometry
.
computeVertexNormals
();
else
geometry
.
computeVertexNormals
();
// if (globals.userInteractionEnabled) geometry.computeBoundingSphere
();
if
(
globals
.
userInteractionEnabled
||
globals
.
vrEnabled
)
geometry
.
computeBoundingBox
();
// geometry.computeBoundingBox();
// geometry.computeBoundingSphere();
// geometry.computeBoundingSphere();
}
}
...
...
js/node.js
View file @
427a4f4f
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
var
nodeMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x000000
,
side
:
THREE
.
DoubleSide
});
var
nodeMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x000000
,
side
:
THREE
.
DoubleSide
});
var
nodeMaterialFixed
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x000000
,
side
:
THREE
.
DoubleSide
});
var
nodeMaterialFixed
=
new
THREE
.
MeshBasicMaterial
({
color
:
0x000000
,
side
:
THREE
.
DoubleSide
});
var
nodeMaterialHighlight
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xffffff
,
side
:
THREE
.
DoubleSide
});
var
nodeMaterialHighlight
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xffffff
,
side
:
THREE
.
DoubleSide
});
var
transparentMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xffffff
,
side
:
THREE
.
DoubleSide
,
opacity
:
0.5
,
transparent
:
true
});
var
transparentMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xffffff
,
opacity
:
0.5
,
transparent
:
true
});
var
transparentVRMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xeeeeee
,
opacity
:
0.8
,
transparent
:
true
});
var
nodeGeo
=
new
THREE
.
SphereGeometry
(
0.04
,
20
);
var
nodeGeo
=
new
THREE
.
SphereGeometry
(
0.04
,
20
);
nodeGeo
.
rotateX
(
Math
.
PI
/
2
);
var
nodeFixedGeo
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
nodeFixedGeo
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
nodeFixedGeo
.
applyMatrix
(
new
THREE
.
Matrix4
().
makeTranslation
(
0
,
0.25
,
0
)
);
function
Node
(
position
,
index
){
function
Node
(
position
,
index
){
...
@@ -149,6 +148,11 @@ Node.prototype.setTransparent = function(){
...
@@ -149,6 +148,11 @@ Node.prototype.setTransparent = function(){
this
.
object3D
.
material
=
transparentMaterial
;
this
.
object3D
.
material
=
transparentMaterial
;
};
};
Node
.
prototype
.
setTransparentVR
=
function
(){
this
.
object3D
.
material
=
transparentVRMaterial
;
this
.
object3D
.
scale
.
set
(
0.2
,
0.2
,
0.2
);
};
Node
.
prototype
.
hide
=
function
(){
Node
.
prototype
.
hide
=
function
(){
this
.
object3D
.
visible
=
false
;
this
.
object3D
.
visible
=
false
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment