Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
60187832
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
60187832
编写于
11月 26, 2019
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples: Removed webvr_vive_* examples and related files.
上级
a8c3ea3a
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
1 addition
and
65193 deletion
+1
-65193
examples/files.js
examples/files.js
+1
-3
examples/js/vr/PaintViveController.js
examples/js/vr/PaintViveController.js
+0
-184
examples/js/vr/ViveController.js
examples/js/vr/ViveController.js
+0
-128
examples/js/vr/deprecated/DaydreamController.js
examples/js/vr/deprecated/DaydreamController.js
+0
-118
examples/js/vr/deprecated/GearVRController.js
examples/js/vr/deprecated/GearVRController.js
+0
-132
examples/jsm/vr/PaintViveController.d.ts
examples/jsm/vr/PaintViveController.d.ts
+0
-14
examples/jsm/vr/PaintViveController.js
examples/jsm/vr/PaintViveController.js
+0
-200
examples/jsm/vr/ViveController.d.ts
examples/jsm/vr/ViveController.d.ts
+0
-15
examples/jsm/vr/ViveController.js
examples/jsm/vr/ViveController.js
+0
-135
examples/jsm/vr/deprecated/DaydreamController.d.ts
examples/jsm/vr/deprecated/DaydreamController.d.ts
+0
-13
examples/jsm/vr/deprecated/DaydreamController.js
examples/jsm/vr/deprecated/DaydreamController.js
+0
-125
examples/jsm/vr/deprecated/GearVRController.d.ts
examples/jsm/vr/deprecated/GearVRController.d.ts
+0
-13
examples/jsm/vr/deprecated/GearVRController.js
examples/jsm/vr/deprecated/GearVRController.js
+0
-139
examples/models/obj/vive-controller/onepointfive_spec.png
examples/models/obj/vive-controller/onepointfive_spec.png
+0
-0
examples/models/obj/vive-controller/onepointfive_texture.png
examples/models/obj/vive-controller/onepointfive_texture.png
+0
-0
examples/models/obj/vive-controller/vr_controller_vive_1_5.obj
...les/models/obj/vive-controller/vr_controller_vive_1_5.obj
+0
-63248
examples/webvr_vive_paint.html
examples/webvr_vive_paint.html
+0
-419
examples/webvr_vive_sculpt.html
examples/webvr_vive_sculpt.html
+0
-305
utils/modularize.js
utils/modularize.js
+0
-2
未找到文件。
examples/files.js
浏览文件 @
60187832
...
...
@@ -334,9 +334,7 @@ var files = {
"
webvr_rollercoaster
"
,
"
webvr_sandbox
"
,
"
webvr_sculpt
"
,
"
webvr_video
"
,
"
webvr_vive_paint
"
,
"
webvr_vive_sculpt
"
"
webvr_video
"
],
"
physics
"
:
[
"
webgl_physics_cloth
"
,
...
...
examples/js/vr/PaintViveController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author mrdoob / http://mrdoob.com
*/
THREE
.
PaintViveController
=
function
(
id
)
{
THREE
.
ViveController
.
call
(
this
,
id
);
var
PI2
=
Math
.
PI
*
2
;
var
MODES
=
{
COLOR
:
0
,
SIZE
:
1
};
var
mode
=
MODES
.
COLOR
;
var
color
=
new
THREE
.
Color
(
1
,
1
,
1
);
var
size
=
1.0
;
//
function
generateHueTexture
()
{
var
canvas
=
document
.
createElement
(
'
canvas
'
);
canvas
.
width
=
256
;
canvas
.
height
=
256
;
var
context
=
canvas
.
getContext
(
'
2d
'
);
var
imageData
=
context
.
getImageData
(
0
,
0
,
256
,
256
);
var
data
=
imageData
.
data
;
var
swatchColor
=
new
THREE
.
Color
();
for
(
var
i
=
0
,
j
=
0
;
i
<
data
.
length
;
i
+=
4
,
j
++
)
{
var
x
=
(
(
j
%
256
)
/
256
)
-
0.5
;
var
y
=
(
Math
.
floor
(
j
/
256
)
/
256
)
-
0.5
;
swatchColor
.
setHSL
(
Math
.
atan2
(
y
,
x
)
/
PI2
,
1
,
(
0.5
-
Math
.
sqrt
(
x
*
x
+
y
*
y
)
)
*
2.0
);
data
[
i
+
0
]
=
swatchColor
.
r
*
256
;
data
[
i
+
1
]
=
swatchColor
.
g
*
256
;
data
[
i
+
2
]
=
swatchColor
.
b
*
256
;
data
[
i
+
3
]
=
256
;
}
context
.
putImageData
(
imageData
,
0
,
0
);
return
new
THREE
.
CanvasTexture
(
canvas
);
}
// COLOR UI
var
geometry
=
new
THREE
.
CircleBufferGeometry
(
1
,
32
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
map
:
generateHueTexture
()
}
);
var
colorUI
=
new
THREE
.
Mesh
(
geometry
,
material
);
colorUI
.
position
.
set
(
0
,
0.005
,
0.0495
);
colorUI
.
rotation
.
x
=
-
1.45
;
colorUI
.
scale
.
setScalar
(
0.02
);
this
.
add
(
colorUI
);
var
geometry
=
new
THREE
.
IcosahedronBufferGeometry
(
0.1
,
2
);
var
material
=
new
THREE
.
MeshBasicMaterial
();
material
.
color
=
color
;
var
ball
=
new
THREE
.
Mesh
(
geometry
,
material
);
colorUI
.
add
(
ball
);
// SIZE UI
var
sizeUI
=
new
THREE
.
Group
();
sizeUI
.
position
.
set
(
0
,
0.005
,
0.0495
);
sizeUI
.
rotation
.
x
=
-
1.45
;
sizeUI
.
scale
.
setScalar
(
0.02
);
this
.
add
(
sizeUI
);
var
triangleShape
=
new
THREE
.
Shape
();
triangleShape
.
moveTo
(
0
,
-
1
);
triangleShape
.
lineTo
(
1
,
1
);
triangleShape
.
lineTo
(
-
1
,
1
);
var
geometry
=
new
THREE
.
ShapeBufferGeometry
(
triangleShape
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
color
:
0x222222
,
wireframe
:
true
}
);
var
sizeUIOutline
=
new
THREE
.
Mesh
(
geometry
,
material
);
sizeUIOutline
.
position
.
z
=
0.001
;
resizeTriangleGeometry
(
sizeUIOutline
.
geometry
,
1.0
);
sizeUI
.
add
(
sizeUIOutline
);
var
geometry
=
new
THREE
.
ShapeBufferGeometry
(
triangleShape
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
side
:
THREE
.
DoubleSide
}
);
material
.
color
=
color
;
var
sizeUIFill
=
new
THREE
.
Mesh
(
geometry
,
material
);
sizeUIFill
.
position
.
z
=
0.0011
;
resizeTriangleGeometry
(
sizeUIFill
.
geometry
,
0.5
);
sizeUI
.
add
(
sizeUIFill
);
sizeUI
.
visible
=
false
;
function
onAxisChanged
(
event
)
{
if
(
this
.
getButtonState
(
'
thumbpad
'
)
===
false
)
return
;
var
x
=
event
.
axes
[
0
]
/
2.0
;
var
y
=
-
event
.
axes
[
1
]
/
2.0
;
if
(
mode
===
MODES
.
COLOR
)
{
color
.
setHSL
(
Math
.
atan2
(
y
,
x
)
/
PI2
,
1
,
(
0.5
-
Math
.
sqrt
(
x
*
x
+
y
*
y
)
)
*
2.0
);
ball
.
position
.
set
(
event
.
axes
[
0
],
event
.
axes
[
1
],
0
);
}
if
(
mode
===
MODES
.
SIZE
)
{
var
ratio
=
0.5
-
y
;
size
=
ratio
*
2
;
resizeTriangleGeometry
(
sizeUIFill
.
geometry
,
ratio
);
}
}
function
resizeTriangleGeometry
(
geometry
,
ratio
)
{
var
x
=
0
,
y
=
0
;
var
fullWidth
=
0.75
,
fullHeight
=
1.5
;
var
angle
=
Math
.
atan
(
(
fullWidth
/
2
)
/
fullHeight
);
var
bottomY
=
y
-
fullHeight
/
2
;
var
height
=
fullHeight
*
ratio
;
var
width
=
(
Math
.
tan
(
angle
)
*
height
)
*
2
;
var
position
=
geometry
.
attributes
.
position
;
position
.
setXYZ
(
0
,
x
,
bottomY
,
0
);
position
.
setXYZ
(
1
,
x
+
width
/
2
,
bottomY
+
height
,
0
);
position
.
setXYZ
(
2
,
x
-
width
/
2
,
bottomY
+
height
,
0
);
position
.
needsUpdate
=
true
;
}
function
onGripsDown
()
{
if
(
mode
===
MODES
.
COLOR
)
{
mode
=
MODES
.
SIZE
;
colorUI
.
visible
=
false
;
sizeUI
.
visible
=
true
;
return
;
}
if
(
mode
===
MODES
.
SIZE
)
{
mode
=
MODES
.
COLOR
;
colorUI
.
visible
=
true
;
sizeUI
.
visible
=
false
;
return
;
}
}
this
.
getColor
=
function
()
{
return
color
;
};
this
.
getSize
=
function
()
{
return
size
;
};
this
.
addEventListener
(
'
axischanged
'
,
onAxisChanged
);
this
.
addEventListener
(
'
gripsdown
'
,
onGripsDown
);
};
THREE
.
PaintViveController
.
prototype
=
Object
.
create
(
THREE
.
ViveController
.
prototype
);
THREE
.
PaintViveController
.
prototype
.
constructor
=
THREE
.
PaintViveController
;
examples/js/vr/ViveController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author mrdoob / http://mrdoob.com
* @author stewdio / http://stewd.io
*/
THREE
.
ViveController
=
function
(
id
)
{
THREE
.
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
thumbpadIsPressed
=
false
;
var
triggerIsPressed
=
false
;
var
gripsArePressed
=
false
;
var
menuIsPressed
=
false
;
function
findGamepad
(
id
)
{
// Iterate across gamepads as Vive Controllers may not be
// in position 0 and 1.
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
,
j
=
0
;
i
<
gamepads
.
length
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
OpenVR Gamepad
'
||
gamepad
.
id
.
startsWith
(
'
Oculus Touch
'
)
||
gamepad
.
id
.
startsWith
(
'
Spatial Controller
'
)
)
)
{
if
(
j
===
id
)
return
gamepad
;
j
++
;
}
}
}
this
.
matrixAutoUpdate
=
false
;
this
.
standingMatrix
=
new
THREE
.
Matrix4
();
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getButtonState
=
function
(
button
)
{
if
(
button
===
'
thumbpad
'
)
return
thumbpadIsPressed
;
if
(
button
===
'
trigger
'
)
return
triggerIsPressed
;
if
(
button
===
'
grips
'
)
return
gripsArePressed
;
if
(
button
===
'
menu
'
)
return
menuIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
(
id
);
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
if
(
gamepad
.
pose
===
null
)
return
;
// No user action yet
// Position and orientation.
var
pose
=
gamepad
.
pose
;
if
(
pose
.
position
!==
null
)
scope
.
position
.
fromArray
(
pose
.
position
);
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
matrix
.
compose
(
scope
.
position
,
scope
.
quaternion
,
scope
.
scale
);
scope
.
matrix
.
premultiply
(
scope
.
standingMatrix
);
scope
.
matrixWorldNeedsUpdate
=
true
;
scope
.
visible
=
true
;
// Thumbpad and Buttons.
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
// X axis: -1 = Left, +1 = Right.
axes
[
1
]
=
gamepad
.
axes
[
1
];
// Y axis: -1 = Bottom, +1 = Top.
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
if
(
thumbpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
thumbpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
thumbpadIsPressed
?
'
thumbpaddown
'
:
'
thumbpadup
'
,
axes
:
axes
}
);
}
if
(
triggerIsPressed
!==
gamepad
.
buttons
[
1
].
pressed
)
{
triggerIsPressed
=
gamepad
.
buttons
[
1
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
triggerIsPressed
?
'
triggerdown
'
:
'
triggerup
'
}
);
}
if
(
gripsArePressed
!==
gamepad
.
buttons
[
2
].
pressed
)
{
gripsArePressed
=
gamepad
.
buttons
[
2
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
gripsArePressed
?
'
gripsdown
'
:
'
gripsup
'
}
);
}
if
(
menuIsPressed
!==
gamepad
.
buttons
[
3
].
pressed
)
{
menuIsPressed
=
gamepad
.
buttons
[
3
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
menuIsPressed
?
'
menudown
'
:
'
menuup
'
}
);
}
}
else
{
scope
.
visible
=
false
;
}
};
};
THREE
.
ViveController
.
prototype
=
Object
.
create
(
THREE
.
Object3D
.
prototype
);
THREE
.
ViveController
.
prototype
.
constructor
=
THREE
.
ViveController
;
examples/js/vr/deprecated/DaydreamController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author Mugen87 / https://github.com/Mugen87
*/
THREE
.
DaydreamController
=
function
()
{
THREE
.
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
touchpadIsPressed
=
false
;
var
angularVelocity
=
new
THREE
.
Vector3
();
this
.
matrixAutoUpdate
=
false
;
function
findGamepad
()
{
// iterate across gamepads as the Daydream Controller may not be
// in position 0
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
Daydream Controller
'
)
)
{
return
gamepad
;
}
}
}
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getTouchpadState
=
function
()
{
return
touchpadIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
();
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
var
pose
=
gamepad
.
pose
;
if
(
pose
===
null
)
return
;
// no user action yet
// orientation
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
updateMatrix
();
scope
.
visible
=
true
;
// angular velocity
if
(
pose
.
angularVelocity
!==
null
&&
!
angularVelocity
.
equals
(
pose
.
angularVelocity
)
)
{
angularVelocity
.
fromArray
(
pose
.
angularVelocity
);
scope
.
dispatchEvent
(
{
type
:
'
angularvelocitychanged
'
,
angularVelocity
:
angularVelocity
}
);
}
// axes (touchpad)
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
axes
[
1
]
=
gamepad
.
axes
[
1
];
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
// button (touchpad)
if
(
touchpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
touchpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
touchpadIsPressed
?
'
touchpaddown
'
:
'
touchpadup
'
}
);
}
// app button not available, reserved for use by the browser
}
else
{
scope
.
visible
=
false
;
}
};
// DEPRECATED
this
.
getTouchPadState
=
function
()
{
console
.
warn
(
'
THREE.DaydreamController: getTouchPadState() is now getTouchpadState()
'
);
return
touchpadIsPressed
;
};
};
THREE
.
DaydreamController
.
prototype
=
Object
.
create
(
THREE
.
Object3D
.
prototype
);
THREE
.
DaydreamController
.
prototype
.
constructor
=
THREE
.
DaydreamController
;
examples/js/vr/deprecated/GearVRController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author servinlp
*/
THREE
.
GearVRController
=
function
()
{
THREE
.
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
touchpadIsPressed
=
false
;
var
triggerIsPressed
=
false
;
var
angularVelocity
=
new
THREE
.
Vector3
();
this
.
matrixAutoUpdate
=
true
;
function
findGamepad
()
{
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
Gear VR Controller
'
||
gamepad
.
id
===
'
Oculus Go Controller
'
)
)
{
return
gamepad
;
}
}
}
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getTouchpadState
=
function
()
{
return
touchpadIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
();
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
var
pose
=
gamepad
.
pose
;
if
(
pose
===
null
)
return
;
// no user action yet
// orientation
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
updateMatrix
();
scope
.
visible
=
true
;
// angular velocity
if
(
pose
.
angularVelocity
!==
null
&&
!
angularVelocity
.
equals
(
pose
.
angularVelocity
)
)
{
angularVelocity
.
fromArray
(
pose
.
angularVelocity
);
scope
.
dispatchEvent
(
{
type
:
'
angularvelocitychanged
'
,
angularVelocity
:
angularVelocity
}
);
}
// axes (touchpad)
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
axes
[
1
]
=
gamepad
.
axes
[
1
];
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
// button (touchpad)
if
(
touchpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
touchpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
touchpadIsPressed
?
'
touchpaddown
'
:
'
touchpadup
'
,
axes
:
axes
}
);
}
// trigger
if
(
triggerIsPressed
!==
gamepad
.
buttons
[
1
].
pressed
)
{
triggerIsPressed
=
gamepad
.
buttons
[
1
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
triggerIsPressed
?
'
triggerdown
'
:
'
triggerup
'
}
);
}
// app button not available, reserved for use by the browser
}
else
{
scope
.
visible
=
false
;
}
};
// DEPRECATED
this
.
getTouchPadState
=
function
()
{
console
.
warn
(
'
THREE.GearVRController: getTouchPadState() is now getTouchpadState()
'
);
return
touchpadIsPressed
;
};
this
.
setHand
=
function
()
{
console
.
warn
(
'
THREE.GearVRController: setHand() has been removed.
'
);
};
};
THREE
.
GearVRController
.
prototype
=
Object
.
create
(
THREE
.
Object3D
.
prototype
);
THREE
.
GearVRController
.
prototype
.
constructor
=
THREE
.
GearVRController
;
examples/jsm/vr/PaintViveController.d.ts
已删除
100644 → 0
浏览文件 @
a8c3ea3a
import
{
Color
}
from
'
../../../src/Three
'
;
import
{
ViveController
}
from
'
./ViveController
'
;
export
class
PaintViveController
extends
ViveController
{
constructor
(
id
:
number
);
getColor
():
Color
;
getSize
():
number
;
}
examples/jsm/vr/PaintViveController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author mrdoob / http://mrdoob.com
*/
import
{
CanvasTexture
,
CircleBufferGeometry
,
Color
,
DoubleSide
,
Group
,
IcosahedronBufferGeometry
,
Mesh
,
MeshBasicMaterial
,
Shape
,
ShapeBufferGeometry
}
from
"
../../../build/three.module.js
"
;
import
{
ViveController
}
from
"
../vr/ViveController.js
"
;
var
PaintViveController
=
function
(
id
)
{
ViveController
.
call
(
this
,
id
);
var
PI2
=
Math
.
PI
*
2
;
var
MODES
=
{
COLOR
:
0
,
SIZE
:
1
};
var
mode
=
MODES
.
COLOR
;
var
color
=
new
Color
(
1
,
1
,
1
);
var
size
=
1.0
;
//
function
generateHueTexture
()
{
var
canvas
=
document
.
createElement
(
'
canvas
'
);
canvas
.
width
=
256
;
canvas
.
height
=
256
;
var
context
=
canvas
.
getContext
(
'
2d
'
);
var
imageData
=
context
.
getImageData
(
0
,
0
,
256
,
256
);
var
data
=
imageData
.
data
;
var
swatchColor
=
new
Color
();
for
(
var
i
=
0
,
j
=
0
;
i
<
data
.
length
;
i
+=
4
,
j
++
)
{
var
x
=
(
(
j
%
256
)
/
256
)
-
0.5
;
var
y
=
(
Math
.
floor
(
j
/
256
)
/
256
)
-
0.5
;
swatchColor
.
setHSL
(
Math
.
atan2
(
y
,
x
)
/
PI2
,
1
,
(
0.5
-
Math
.
sqrt
(
x
*
x
+
y
*
y
)
)
*
2.0
);
data
[
i
+
0
]
=
swatchColor
.
r
*
256
;
data
[
i
+
1
]
=
swatchColor
.
g
*
256
;
data
[
i
+
2
]
=
swatchColor
.
b
*
256
;
data
[
i
+
3
]
=
256
;
}
context
.
putImageData
(
imageData
,
0
,
0
);
return
new
CanvasTexture
(
canvas
);
}
// COLOR UI
var
geometry
=
new
CircleBufferGeometry
(
1
,
32
);
var
material
=
new
MeshBasicMaterial
(
{
map
:
generateHueTexture
()
}
);
var
colorUI
=
new
Mesh
(
geometry
,
material
);
colorUI
.
position
.
set
(
0
,
0.005
,
0.0495
);
colorUI
.
rotation
.
x
=
-
1.45
;
colorUI
.
scale
.
setScalar
(
0.02
);
this
.
add
(
colorUI
);
var
geometry
=
new
IcosahedronBufferGeometry
(
0.1
,
2
);
var
material
=
new
MeshBasicMaterial
();
material
.
color
=
color
;
var
ball
=
new
Mesh
(
geometry
,
material
);
colorUI
.
add
(
ball
);
// SIZE UI
var
sizeUI
=
new
Group
();
sizeUI
.
position
.
set
(
0
,
0.005
,
0.0495
);
sizeUI
.
rotation
.
x
=
-
1.45
;
sizeUI
.
scale
.
setScalar
(
0.02
);
this
.
add
(
sizeUI
);
var
triangleShape
=
new
Shape
();
triangleShape
.
moveTo
(
0
,
-
1
);
triangleShape
.
lineTo
(
1
,
1
);
triangleShape
.
lineTo
(
-
1
,
1
);
var
geometry
=
new
ShapeBufferGeometry
(
triangleShape
);
var
material
=
new
MeshBasicMaterial
(
{
color
:
0x222222
,
wireframe
:
true
}
);
var
sizeUIOutline
=
new
Mesh
(
geometry
,
material
);
sizeUIOutline
.
position
.
z
=
0.001
;
resizeTriangleGeometry
(
sizeUIOutline
.
geometry
,
1.0
);
sizeUI
.
add
(
sizeUIOutline
);
var
geometry
=
new
ShapeBufferGeometry
(
triangleShape
);
var
material
=
new
MeshBasicMaterial
(
{
side
:
DoubleSide
}
);
material
.
color
=
color
;
var
sizeUIFill
=
new
Mesh
(
geometry
,
material
);
sizeUIFill
.
position
.
z
=
0.0011
;
resizeTriangleGeometry
(
sizeUIFill
.
geometry
,
0.5
);
sizeUI
.
add
(
sizeUIFill
);
sizeUI
.
visible
=
false
;
function
onAxisChanged
(
event
)
{
if
(
this
.
getButtonState
(
'
thumbpad
'
)
===
false
)
return
;
var
x
=
event
.
axes
[
0
]
/
2.0
;
var
y
=
-
event
.
axes
[
1
]
/
2.0
;
if
(
mode
===
MODES
.
COLOR
)
{
color
.
setHSL
(
Math
.
atan2
(
y
,
x
)
/
PI2
,
1
,
(
0.5
-
Math
.
sqrt
(
x
*
x
+
y
*
y
)
)
*
2.0
);
ball
.
position
.
set
(
event
.
axes
[
0
],
event
.
axes
[
1
],
0
);
}
if
(
mode
===
MODES
.
SIZE
)
{
var
ratio
=
0.5
-
y
;
size
=
ratio
*
2
;
resizeTriangleGeometry
(
sizeUIFill
.
geometry
,
ratio
);
}
}
function
resizeTriangleGeometry
(
geometry
,
ratio
)
{
var
x
=
0
,
y
=
0
;
var
fullWidth
=
0.75
,
fullHeight
=
1.5
;
var
angle
=
Math
.
atan
(
(
fullWidth
/
2
)
/
fullHeight
);
var
bottomY
=
y
-
fullHeight
/
2
;
var
height
=
fullHeight
*
ratio
;
var
width
=
(
Math
.
tan
(
angle
)
*
height
)
*
2
;
var
position
=
geometry
.
attributes
.
position
;
position
.
setXYZ
(
0
,
x
,
bottomY
,
0
);
position
.
setXYZ
(
1
,
x
+
width
/
2
,
bottomY
+
height
,
0
);
position
.
setXYZ
(
2
,
x
-
width
/
2
,
bottomY
+
height
,
0
);
position
.
needsUpdate
=
true
;
}
function
onGripsDown
()
{
if
(
mode
===
MODES
.
COLOR
)
{
mode
=
MODES
.
SIZE
;
colorUI
.
visible
=
false
;
sizeUI
.
visible
=
true
;
return
;
}
if
(
mode
===
MODES
.
SIZE
)
{
mode
=
MODES
.
COLOR
;
colorUI
.
visible
=
true
;
sizeUI
.
visible
=
false
;
return
;
}
}
this
.
getColor
=
function
()
{
return
color
;
};
this
.
getSize
=
function
()
{
return
size
;
};
this
.
addEventListener
(
'
axischanged
'
,
onAxisChanged
);
this
.
addEventListener
(
'
gripsdown
'
,
onGripsDown
);
};
PaintViveController
.
prototype
=
Object
.
create
(
ViveController
.
prototype
);
PaintViveController
.
prototype
.
constructor
=
PaintViveController
;
export
{
PaintViveController
};
examples/jsm/vr/ViveController.d.ts
已删除
100644 → 0
浏览文件 @
a8c3ea3a
import
{
Matrix4
,
Object3D
}
from
'
../../../src/Three
'
;
export
class
ViveController
extends
Object3D
{
constructor
(
id
:
number
);
standingMatrix
:
Matrix4
;
getButtonState
(
button
:
string
):
boolean
;
getGamepad
():
object
;
update
():
void
;
}
examples/jsm/vr/ViveController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author mrdoob / http://mrdoob.com
* @author stewdio / http://stewd.io
*/
import
{
Matrix4
,
Object3D
}
from
"
../../../build/three.module.js
"
;
var
ViveController
=
function
(
id
)
{
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
thumbpadIsPressed
=
false
;
var
triggerIsPressed
=
false
;
var
gripsArePressed
=
false
;
var
menuIsPressed
=
false
;
function
findGamepad
(
id
)
{
// Iterate across gamepads as Vive Controllers may not be
// in position 0 and 1.
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
,
j
=
0
;
i
<
gamepads
.
length
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
OpenVR Gamepad
'
||
gamepad
.
id
.
startsWith
(
'
Oculus Touch
'
)
||
gamepad
.
id
.
startsWith
(
'
Spatial Controller
'
)
)
)
{
if
(
j
===
id
)
return
gamepad
;
j
++
;
}
}
}
this
.
matrixAutoUpdate
=
false
;
this
.
standingMatrix
=
new
Matrix4
();
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getButtonState
=
function
(
button
)
{
if
(
button
===
'
thumbpad
'
)
return
thumbpadIsPressed
;
if
(
button
===
'
trigger
'
)
return
triggerIsPressed
;
if
(
button
===
'
grips
'
)
return
gripsArePressed
;
if
(
button
===
'
menu
'
)
return
menuIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
(
id
);
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
if
(
gamepad
.
pose
===
null
)
return
;
// No user action yet
// Position and orientation.
var
pose
=
gamepad
.
pose
;
if
(
pose
.
position
!==
null
)
scope
.
position
.
fromArray
(
pose
.
position
);
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
matrix
.
compose
(
scope
.
position
,
scope
.
quaternion
,
scope
.
scale
);
scope
.
matrix
.
premultiply
(
scope
.
standingMatrix
);
scope
.
matrixWorldNeedsUpdate
=
true
;
scope
.
visible
=
true
;
// Thumbpad and Buttons.
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
// X axis: -1 = Left, +1 = Right.
axes
[
1
]
=
gamepad
.
axes
[
1
];
// Y axis: -1 = Bottom, +1 = Top.
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
if
(
thumbpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
thumbpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
thumbpadIsPressed
?
'
thumbpaddown
'
:
'
thumbpadup
'
,
axes
:
axes
}
);
}
if
(
triggerIsPressed
!==
gamepad
.
buttons
[
1
].
pressed
)
{
triggerIsPressed
=
gamepad
.
buttons
[
1
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
triggerIsPressed
?
'
triggerdown
'
:
'
triggerup
'
}
);
}
if
(
gripsArePressed
!==
gamepad
.
buttons
[
2
].
pressed
)
{
gripsArePressed
=
gamepad
.
buttons
[
2
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
gripsArePressed
?
'
gripsdown
'
:
'
gripsup
'
}
);
}
if
(
menuIsPressed
!==
gamepad
.
buttons
[
3
].
pressed
)
{
menuIsPressed
=
gamepad
.
buttons
[
3
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
menuIsPressed
?
'
menudown
'
:
'
menuup
'
}
);
}
}
else
{
scope
.
visible
=
false
;
}
};
};
ViveController
.
prototype
=
Object
.
create
(
Object3D
.
prototype
);
ViveController
.
prototype
.
constructor
=
ViveController
;
export
{
ViveController
};
examples/jsm/vr/deprecated/DaydreamController.d.ts
已删除
100644 → 0
浏览文件 @
a8c3ea3a
import
{
Object3D
}
from
'
../../../../src/Three
'
;
export
class
DaydreamController
extends
Object3D
{
constructor
(
id
:
number
);
getTouchpadState
():
boolean
;
getGamepad
():
object
;
update
():
void
;
}
examples/jsm/vr/deprecated/DaydreamController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author Mugen87 / https://github.com/Mugen87
*/
import
{
Object3D
,
Vector3
}
from
"
../../../../build/three.module.js
"
;
var
DaydreamController
=
function
()
{
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
touchpadIsPressed
=
false
;
var
angularVelocity
=
new
Vector3
();
this
.
matrixAutoUpdate
=
false
;
function
findGamepad
()
{
// iterate across gamepads as the Daydream Controller may not be
// in position 0
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
Daydream Controller
'
)
)
{
return
gamepad
;
}
}
}
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getTouchpadState
=
function
()
{
return
touchpadIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
();
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
var
pose
=
gamepad
.
pose
;
if
(
pose
===
null
)
return
;
// no user action yet
// orientation
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
updateMatrix
();
scope
.
visible
=
true
;
// angular velocity
if
(
pose
.
angularVelocity
!==
null
&&
!
angularVelocity
.
equals
(
pose
.
angularVelocity
)
)
{
angularVelocity
.
fromArray
(
pose
.
angularVelocity
);
scope
.
dispatchEvent
(
{
type
:
'
angularvelocitychanged
'
,
angularVelocity
:
angularVelocity
}
);
}
// axes (touchpad)
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
axes
[
1
]
=
gamepad
.
axes
[
1
];
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
// button (touchpad)
if
(
touchpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
touchpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
touchpadIsPressed
?
'
touchpaddown
'
:
'
touchpadup
'
}
);
}
// app button not available, reserved for use by the browser
}
else
{
scope
.
visible
=
false
;
}
};
// DEPRECATED
this
.
getTouchPadState
=
function
()
{
console
.
warn
(
'
THREE.DaydreamController: getTouchPadState() is now getTouchpadState()
'
);
return
touchpadIsPressed
;
};
};
DaydreamController
.
prototype
=
Object
.
create
(
Object3D
.
prototype
);
DaydreamController
.
prototype
.
constructor
=
DaydreamController
;
export
{
DaydreamController
};
examples/jsm/vr/deprecated/GearVRController.d.ts
已删除
100644 → 0
浏览文件 @
a8c3ea3a
import
{
Object3D
}
from
'
../../../../src/Three
'
;
export
class
GearVRController
extends
Object3D
{
constructor
(
id
:
number
);
getTouchpadState
():
boolean
;
getGamepad
():
object
;
update
():
void
;
}
examples/jsm/vr/deprecated/GearVRController.js
已删除
100644 → 0
浏览文件 @
a8c3ea3a
/**
* @author servinlp
*/
import
{
Object3D
,
Vector3
}
from
"
../../../../build/three.module.js
"
;
var
GearVRController
=
function
()
{
Object3D
.
call
(
this
);
var
scope
=
this
;
var
gamepad
;
var
axes
=
[
0
,
0
];
var
touchpadIsPressed
=
false
;
var
triggerIsPressed
=
false
;
var
angularVelocity
=
new
Vector3
();
this
.
matrixAutoUpdate
=
true
;
function
findGamepad
()
{
var
gamepads
=
navigator
.
getGamepads
&&
navigator
.
getGamepads
();
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
var
gamepad
=
gamepads
[
i
];
if
(
gamepad
&&
(
gamepad
.
id
===
'
Gear VR Controller
'
||
gamepad
.
id
===
'
Oculus Go Controller
'
)
)
{
return
gamepad
;
}
}
}
this
.
getGamepad
=
function
()
{
return
gamepad
;
};
this
.
getTouchpadState
=
function
()
{
return
touchpadIsPressed
;
};
this
.
update
=
function
()
{
gamepad
=
findGamepad
();
if
(
gamepad
!==
undefined
&&
gamepad
.
pose
!==
undefined
)
{
var
pose
=
gamepad
.
pose
;
if
(
pose
===
null
)
return
;
// no user action yet
// orientation
if
(
pose
.
orientation
!==
null
)
scope
.
quaternion
.
fromArray
(
pose
.
orientation
);
scope
.
updateMatrix
();
scope
.
visible
=
true
;
// angular velocity
if
(
pose
.
angularVelocity
!==
null
&&
!
angularVelocity
.
equals
(
pose
.
angularVelocity
)
)
{
angularVelocity
.
fromArray
(
pose
.
angularVelocity
);
scope
.
dispatchEvent
(
{
type
:
'
angularvelocitychanged
'
,
angularVelocity
:
angularVelocity
}
);
}
// axes (touchpad)
if
(
axes
[
0
]
!==
gamepad
.
axes
[
0
]
||
axes
[
1
]
!==
gamepad
.
axes
[
1
]
)
{
axes
[
0
]
=
gamepad
.
axes
[
0
];
axes
[
1
]
=
gamepad
.
axes
[
1
];
scope
.
dispatchEvent
(
{
type
:
'
axischanged
'
,
axes
:
axes
}
);
}
// button (touchpad)
if
(
touchpadIsPressed
!==
gamepad
.
buttons
[
0
].
pressed
)
{
touchpadIsPressed
=
gamepad
.
buttons
[
0
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
touchpadIsPressed
?
'
touchpaddown
'
:
'
touchpadup
'
,
axes
:
axes
}
);
}
// trigger
if
(
triggerIsPressed
!==
gamepad
.
buttons
[
1
].
pressed
)
{
triggerIsPressed
=
gamepad
.
buttons
[
1
].
pressed
;
scope
.
dispatchEvent
(
{
type
:
triggerIsPressed
?
'
triggerdown
'
:
'
triggerup
'
}
);
}
// app button not available, reserved for use by the browser
}
else
{
scope
.
visible
=
false
;
}
};
// DEPRECATED
this
.
getTouchPadState
=
function
()
{
console
.
warn
(
'
THREE.GearVRController: getTouchPadState() is now getTouchpadState()
'
);
return
touchpadIsPressed
;
};
this
.
setHand
=
function
()
{
console
.
warn
(
'
THREE.GearVRController: setHand() has been removed.
'
);
};
};
GearVRController
.
prototype
=
Object
.
create
(
Object3D
.
prototype
);
GearVRController
.
prototype
.
constructor
=
GearVRController
;
export
{
GearVRController
};
examples/models/obj/vive-controller/onepointfive_spec.png
已删除
100644 → 0
浏览文件 @
a8c3ea3a
788.0 KB
examples/models/obj/vive-controller/onepointfive_texture.png
已删除
100644 → 0
浏览文件 @
a8c3ea3a
557.9 KB
examples/models/obj/vive-controller/vr_controller_vive_1_5.obj
已删除
100644 → 0
浏览文件 @
a8c3ea3a
此差异已折叠。
点击以展开。
examples/webvr_vive_paint.html
已删除
100644 → 0
浏览文件 @
a8c3ea3a
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webvr - htc vive - paint
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, user-scalable=no"
>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"main.css"
>
<!-- WebXR Device API (For Chrome M76+), expires 12/04/2019 -->
<meta
http-equiv=
"origin-trial"
content=
"Aq9LklhCLNUveuCr7QTpGpqwCPG817cYHdVyQuJPOZYk47iRB390lUKa5edVmgS1pZSl8HPspElEC/91Fz55dwIAAABTeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZU03NiIsImV4cGlyeSI6MTU3NTQxNzU5OX0="
>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
webgl - htc vive - paint
</div>
<script
src=
"js/vr/HelioWebXRPolyfill.js"
></script>
<script
type=
"module"
>
import
*
as
THREE
from
'
../build/three.module.js
'
;
import
{
OBJLoader
}
from
'
./jsm/loaders/OBJLoader.js
'
;
import
{
PaintViveController
}
from
'
./jsm/vr/PaintViveController.js
'
;
import
{
WEBVR
}
from
'
./jsm/vr/WebVR.js
'
;
var
container
;
var
camera
,
scene
,
renderer
;
var
controller1
,
controller2
;
var
line
;
var
shapes
=
{};
var
up
=
new
THREE
.
Vector3
(
0
,
1
,
0
);
var
vector1
=
new
THREE
.
Vector3
();
var
vector2
=
new
THREE
.
Vector3
();
var
vector3
=
new
THREE
.
Vector3
();
var
vector4
=
new
THREE
.
Vector3
();
init
();
initGeometry
();
animate
();
function
init
()
{
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
scene
=
new
THREE
.
Scene
();
scene
.
background
=
new
THREE
.
Color
(
0x222222
);
camera
=
new
THREE
.
PerspectiveCamera
(
50
,
window
.
innerWidth
/
window
.
innerHeight
,
0.01
,
50
);
camera
.
position
.
set
(
0
,
1.6
,
3
);
var
geometry
=
new
THREE
.
BoxBufferGeometry
(
0.5
,
0.8
,
0.5
);
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x444444
,
roughness
:
1.0
,
metalness
:
0.0
}
);
var
table
=
new
THREE
.
Mesh
(
geometry
,
material
);
table
.
position
.
y
=
0.35
;
table
.
position
.
z
=
0.85
;
table
.
castShadow
=
true
;
table
.
receiveShadow
=
true
;
scene
.
add
(
table
);
/*
var table = new THREE.Mesh( geometry, material );
table.position.y = 0.35;
table.position.z = -0.85;
table.castShadow = true;
table.receiveShadow = true;
scene.add( table );
*/
var
geometry
=
new
THREE
.
PlaneBufferGeometry
(
4
,
4
);
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x222222
,
roughness
:
1.0
,
metalness
:
0.0
}
);
var
floor
=
new
THREE
.
Mesh
(
geometry
,
material
);
floor
.
rotation
.
x
=
-
Math
.
PI
/
2
;
floor
.
receiveShadow
=
true
;
scene
.
add
(
floor
);
scene
.
add
(
new
THREE
.
GridHelper
(
20
,
40
,
0x111111
,
0x111111
)
);
scene
.
add
(
new
THREE
.
HemisphereLight
(
0x888877
,
0x777788
)
);
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
);
light
.
position
.
set
(
0
,
6
,
0
);
light
.
castShadow
=
true
;
light
.
shadow
.
camera
.
top
=
2
;
light
.
shadow
.
camera
.
bottom
=
-
2
;
light
.
shadow
.
camera
.
right
=
2
;
light
.
shadow
.
camera
.
left
=
-
2
;
light
.
shadow
.
mapSize
.
set
(
4096
,
4096
);
scene
.
add
(
light
);
// scene.add( new DirectionalLightHelper( light ) );
// scene.add( new CameraHelper( light.shadow.camera ) );
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
renderer
.
shadowMap
.
enabled
=
true
;
renderer
.
vr
.
enabled
=
true
;
container
.
appendChild
(
renderer
.
domElement
);
document
.
body
.
appendChild
(
WEBVR
.
createButton
(
renderer
)
);
// controllers
controller1
=
new
PaintViveController
(
0
);
controller1
.
standingMatrix
=
renderer
.
vr
.
getStandingMatrix
();
controller1
.
userData
.
points
=
[
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
()
];
controller1
.
userData
.
matrices
=
[
new
THREE
.
Matrix4
(),
new
THREE
.
Matrix4
()
];
scene
.
add
(
controller1
);
controller2
=
new
PaintViveController
(
1
);
controller2
.
standingMatrix
=
renderer
.
vr
.
getStandingMatrix
();
controller2
.
userData
.
points
=
[
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
()
];
controller2
.
userData
.
matrices
=
[
new
THREE
.
Matrix4
(),
new
THREE
.
Matrix4
()
];
scene
.
add
(
controller2
);
var
loader
=
new
OBJLoader
();
loader
.
setPath
(
'
models/obj/vive-controller/
'
);
loader
.
load
(
'
vr_controller_vive_1_5.obj
'
,
function
(
object
)
{
var
loader
=
new
THREE
.
TextureLoader
();
loader
.
setPath
(
'
models/obj/vive-controller/
'
);
var
controller
=
object
.
children
[
0
];
controller
.
material
.
map
=
loader
.
load
(
'
onepointfive_texture.png
'
);
controller
.
material
.
specularMap
=
loader
.
load
(
'
onepointfive_spec.png
'
);
controller
.
castShadow
=
true
;
controller
.
receiveShadow
=
true
;
// var pivot = new Group();
// var pivot = new THREE.Mesh( new THREE.BoxBufferGeometry( 0.01, 0.01, 0.01 ) );
var
pivot
=
new
THREE
.
Mesh
(
new
THREE
.
IcosahedronBufferGeometry
(
0.01
,
2
)
);
pivot
.
name
=
'
pivot
'
;
pivot
.
position
.
y
=
-
0.016
;
pivot
.
position
.
z
=
-
0.043
;
pivot
.
rotation
.
x
=
Math
.
PI
/
5.5
;
controller
.
add
(
pivot
);
controller1
.
add
(
controller
.
clone
()
);
pivot
.
material
=
pivot
.
material
.
clone
();
controller2
.
add
(
controller
.
clone
()
);
}
);
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
initGeometry
()
{
var
geometry
=
new
THREE
.
BufferGeometry
();
var
positions
=
new
THREE
.
BufferAttribute
(
new
Float32Array
(
1000000
*
3
),
3
);
positions
.
usage
=
THREE
.
DynamicDrawUsage
;
geometry
.
setAttribute
(
'
position
'
,
positions
);
var
normals
=
new
THREE
.
BufferAttribute
(
new
Float32Array
(
1000000
*
3
),
3
);
normals
.
usage
=
THREE
.
DynamicDrawUsage
;
geometry
.
setAttribute
(
'
normal
'
,
normals
);
var
colors
=
new
THREE
.
BufferAttribute
(
new
Float32Array
(
1000000
*
3
),
3
);
colors
.
usage
=
THREE
.
DynamicDrawUsage
;
geometry
.
setAttribute
(
'
color
'
,
colors
);
geometry
.
drawRange
.
count
=
0
;
//
/*
var path = "textures/cube/SwedishRoyalCastle/";
var format = '.jpg';
var urls = [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
];
var reflectionCube = new CubeTextureLoader().load( urls );
*/
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
roughness
:
0.9
,
metalness
:
0.0
,
// envMap: reflectionCube,
vertexColors
:
THREE
.
VertexColors
,
side
:
THREE
.
DoubleSide
}
);
line
=
new
THREE
.
Mesh
(
geometry
,
material
);
line
.
frustumCulled
=
false
;
line
.
castShadow
=
true
;
line
.
receiveShadow
=
true
;
scene
.
add
(
line
);
// Shapes
shapes
[
'
tube
'
]
=
getTubeShapes
(
1.0
);
}
function
getTubeShapes
(
size
)
{
var
PI2
=
Math
.
PI
*
2
;
var
sides
=
10
;
var
array
=
[];
var
radius
=
0.01
*
size
;
for
(
var
i
=
0
;
i
<
sides
;
i
++
)
{
var
angle
=
(
i
/
sides
)
*
PI2
;
array
.
push
(
new
THREE
.
Vector3
(
Math
.
sin
(
angle
)
*
radius
,
Math
.
cos
(
angle
)
*
radius
,
0
)
);
}
return
array
;
}
function
stroke
(
controller
,
point1
,
point2
,
matrix1
,
matrix2
)
{
var
color
=
controller
.
getColor
();
var
shapes
=
getTubeShapes
(
controller
.
getSize
()
);
var
geometry
=
line
.
geometry
;
var
attributes
=
geometry
.
attributes
;
var
count
=
geometry
.
drawRange
.
count
;
var
positions
=
attributes
.
position
.
array
;
var
normals
=
attributes
.
normal
.
array
;
var
colors
=
attributes
.
color
.
array
;
for
(
var
j
=
0
,
jl
=
shapes
.
length
;
j
<
jl
;
j
++
)
{
var
vertex1
=
shapes
[
j
];
var
vertex2
=
shapes
[
(
j
+
1
)
%
jl
];
// positions
vector1
.
copy
(
vertex1
);
vector1
.
applyMatrix4
(
matrix2
);
vector1
.
add
(
point2
);
vector2
.
copy
(
vertex2
);
vector2
.
applyMatrix4
(
matrix2
);
vector2
.
add
(
point2
);
vector3
.
copy
(
vertex2
);
vector3
.
applyMatrix4
(
matrix1
);
vector3
.
add
(
point1
);
vector4
.
copy
(
vertex1
);
vector4
.
applyMatrix4
(
matrix1
);
vector4
.
add
(
point1
);
vector1
.
toArray
(
positions
,
(
count
+
0
)
*
3
);
vector2
.
toArray
(
positions
,
(
count
+
1
)
*
3
);
vector4
.
toArray
(
positions
,
(
count
+
2
)
*
3
);
vector2
.
toArray
(
positions
,
(
count
+
3
)
*
3
);
vector3
.
toArray
(
positions
,
(
count
+
4
)
*
3
);
vector4
.
toArray
(
positions
,
(
count
+
5
)
*
3
);
// normals
vector1
.
copy
(
vertex1
);
vector1
.
applyMatrix4
(
matrix2
);
vector1
.
normalize
();
vector2
.
copy
(
vertex2
);
vector2
.
applyMatrix4
(
matrix2
);
vector2
.
normalize
();
vector3
.
copy
(
vertex2
);
vector3
.
applyMatrix4
(
matrix1
);
vector3
.
normalize
();
vector4
.
copy
(
vertex1
);
vector4
.
applyMatrix4
(
matrix1
);
vector4
.
normalize
();
vector1
.
toArray
(
normals
,
(
count
+
0
)
*
3
);
vector2
.
toArray
(
normals
,
(
count
+
1
)
*
3
);
vector4
.
toArray
(
normals
,
(
count
+
2
)
*
3
);
vector2
.
toArray
(
normals
,
(
count
+
3
)
*
3
);
vector3
.
toArray
(
normals
,
(
count
+
4
)
*
3
);
vector4
.
toArray
(
normals
,
(
count
+
5
)
*
3
);
// colors
color
.
toArray
(
colors
,
(
count
+
0
)
*
3
);
color
.
toArray
(
colors
,
(
count
+
1
)
*
3
);
color
.
toArray
(
colors
,
(
count
+
2
)
*
3
);
color
.
toArray
(
colors
,
(
count
+
3
)
*
3
);
color
.
toArray
(
colors
,
(
count
+
4
)
*
3
);
color
.
toArray
(
colors
,
(
count
+
5
)
*
3
);
count
+=
6
;
}
geometry
.
drawRange
.
count
=
count
;
}
function
updateGeometry
(
start
,
end
)
{
if
(
start
===
end
)
return
;
var
offset
=
start
*
3
;
var
count
=
(
end
-
start
)
*
3
;
var
geometry
=
line
.
geometry
;
var
attributes
=
geometry
.
attributes
;
attributes
.
position
.
updateRange
.
offset
=
offset
;
attributes
.
position
.
updateRange
.
count
=
count
;
attributes
.
position
.
needsUpdate
=
true
;
attributes
.
normal
.
updateRange
.
offset
=
offset
;
attributes
.
normal
.
updateRange
.
count
=
count
;
attributes
.
normal
.
needsUpdate
=
true
;
attributes
.
color
.
updateRange
.
offset
=
offset
;
attributes
.
color
.
updateRange
.
count
=
count
;
attributes
.
color
.
needsUpdate
=
true
;
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
//
function
handleController
(
controller
)
{
controller
.
update
();
var
pivot
=
controller
.
getObjectByName
(
'
pivot
'
);
if
(
pivot
)
{
pivot
.
material
.
color
.
copy
(
controller
.
getColor
()
);
pivot
.
scale
.
setScalar
(
controller
.
getSize
()
);
var
matrix
=
pivot
.
matrixWorld
;
var
point1
=
controller
.
userData
.
points
[
0
];
var
point2
=
controller
.
userData
.
points
[
1
];
var
matrix1
=
controller
.
userData
.
matrices
[
0
];
var
matrix2
=
controller
.
userData
.
matrices
[
1
];
point1
.
setFromMatrixPosition
(
matrix
);
matrix1
.
lookAt
(
point2
,
point1
,
up
);
if
(
controller
.
getButtonState
(
'
trigger
'
)
)
{
stroke
(
controller
,
point1
,
point2
,
matrix1
,
matrix2
);
}
point2
.
copy
(
point1
);
matrix2
.
copy
(
matrix1
);
}
}
function
animate
()
{
renderer
.
setAnimationLoop
(
render
);
}
function
render
()
{
var
count
=
line
.
geometry
.
drawRange
.
count
;
handleController
(
controller1
);
handleController
(
controller2
);
updateGeometry
(
count
,
line
.
geometry
.
drawRange
.
count
);
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
examples/webvr_vive_sculpt.html
已删除
100644 → 0
浏览文件 @
a8c3ea3a
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webvr - htc vive - sculpt
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, user-scalable=no"
>
<link
type=
"text/css"
rel=
"stylesheet"
href=
"main.css"
>
<!-- WebXR Device API (For Chrome M76+), expires 12/04/2019 -->
<meta
http-equiv=
"origin-trial"
content=
"Aq9LklhCLNUveuCr7QTpGpqwCPG817cYHdVyQuJPOZYk47iRB390lUKa5edVmgS1pZSl8HPspElEC/91Fz55dwIAAABTeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZU03NiIsImV4cGlyeSI6MTU3NTQxNzU5OX0="
>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
webgl - htc vive - sculpt
</div>
<script
src=
"js/vr/HelioWebXRPolyfill.js"
></script>
<script
type=
"module"
>
import
*
as
THREE
from
'
../build/three.module.js
'
;
import
{
OBJLoader
}
from
'
./jsm/loaders/OBJLoader.js
'
;
import
{
MarchingCubes
}
from
'
./jsm/objects/MarchingCubes.js
'
;
import
{
ViveController
}
from
'
./jsm/vr/ViveController.js
'
;
import
{
WEBVR
}
from
'
./jsm/vr/WebVR.js
'
;
var
container
;
var
camera
,
scene
,
renderer
;
var
controller1
,
controller2
;
var
blob
;
var
points
=
[];
init
();
initBlob
();
animate
();
function
init
()
{
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
scene
=
new
THREE
.
Scene
();
scene
.
background
=
new
THREE
.
Color
(
0x222222
);
camera
=
new
THREE
.
PerspectiveCamera
(
50
,
window
.
innerWidth
/
window
.
innerHeight
,
0.01
,
50
);
camera
.
position
.
set
(
0
,
1.6
,
3
);
var
geometry
=
new
THREE
.
BoxBufferGeometry
(
0.5
,
0.8
,
0.5
);
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x444444
,
roughness
:
1.0
,
metalness
:
0.0
}
);
var
table
=
new
THREE
.
Mesh
(
geometry
,
material
);
table
.
position
.
y
=
0.35
;
table
.
position
.
z
=
0.85
;
table
.
castShadow
=
true
;
table
.
receiveShadow
=
true
;
scene
.
add
(
table
);
var
geometry
=
new
THREE
.
PlaneBufferGeometry
(
4
,
4
);
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x222222
,
roughness
:
1.0
,
metalness
:
0.0
}
);
var
floor
=
new
THREE
.
Mesh
(
geometry
,
material
);
floor
.
rotation
.
x
=
-
Math
.
PI
/
2
;
floor
.
receiveShadow
=
true
;
scene
.
add
(
floor
);
scene
.
add
(
new
THREE
.
GridHelper
(
20
,
40
,
0x111111
,
0x111111
)
);
scene
.
add
(
new
THREE
.
HemisphereLight
(
0x888877
,
0x777788
)
);
var
light
=
new
THREE
.
DirectionalLight
(
0xffffff
);
light
.
position
.
set
(
0
,
6
,
0
);
light
.
castShadow
=
true
;
light
.
shadow
.
camera
.
top
=
2
;
light
.
shadow
.
camera
.
bottom
=
-
2
;
light
.
shadow
.
camera
.
right
=
2
;
light
.
shadow
.
camera
.
left
=
-
2
;
light
.
shadow
.
mapSize
.
set
(
4096
,
4096
);
scene
.
add
(
light
);
// scene.add( new DirectionalLightHelper( light ) );
// scene.add( new CameraHelper( light.shadow.camera ) );
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
renderer
.
shadowMap
.
enabled
=
true
;
renderer
.
vr
.
enabled
=
true
;
container
.
appendChild
(
renderer
.
domElement
);
document
.
body
.
appendChild
(
WEBVR
.
createButton
(
renderer
)
);
// controllers
controller1
=
new
ViveController
(
0
);
controller1
.
standingMatrix
=
renderer
.
vr
.
getStandingMatrix
();
scene
.
add
(
controller1
);
controller2
=
new
ViveController
(
1
);
controller2
.
standingMatrix
=
renderer
.
vr
.
getStandingMatrix
();
scene
.
add
(
controller2
);
var
loader
=
new
OBJLoader
();
loader
.
setPath
(
'
models/obj/vive-controller/
'
);
loader
.
load
(
'
vr_controller_vive_1_5.obj
'
,
function
(
object
)
{
var
loader
=
new
THREE
.
TextureLoader
();
loader
.
setPath
(
'
models/obj/vive-controller/
'
);
var
controller
=
object
.
children
[
0
];
controller
.
material
.
map
=
loader
.
load
(
'
onepointfive_texture.png
'
);
controller
.
material
.
specularMap
=
loader
.
load
(
'
onepointfive_spec.png
'
);
controller
.
castShadow
=
true
;
controller
.
receiveShadow
=
true
;
// var pivot = new THREE.Mesh( new THREE.BoxBufferGeometry( 0.01, 0.01, 0.01 ) );
var
pivot
=
new
THREE
.
Mesh
(
new
THREE
.
IcosahedronBufferGeometry
(
0.002
,
2
),
blob
.
material
);
pivot
.
name
=
'
pivot
'
;
pivot
.
position
.
y
=
-
0.016
;
pivot
.
position
.
z
=
-
0.043
;
pivot
.
rotation
.
x
=
Math
.
PI
/
5.5
;
controller
.
add
(
pivot
);
var
range
=
new
THREE
.
Mesh
(
new
THREE
.
IcosahedronBufferGeometry
(
0.03
,
3
),
new
THREE
.
MeshBasicMaterial
(
{
opacity
:
0.25
,
transparent
:
true
}
)
);
pivot
.
add
(
range
);
controller1
.
add
(
controller
.
clone
()
);
controller2
.
add
(
controller
.
clone
()
);
}
);
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
initBlob
()
{
/*
var path = "textures/cube/SwedishRoyalCastle/";
var format = '.jpg';
var urls = [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
];
var reflectionCube = new CubeTextureLoader().load( urls );
*/
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0xffffff
,
// envMap: reflectionCube,
roughness
:
0.9
,
metalness
:
0.0
}
);
blob
=
new
MarchingCubes
(
64
,
material
);
blob
.
position
.
y
=
1
;
scene
.
add
(
blob
);
initPoints
();
}
function
initPoints
()
{
points
=
[
{
position
:
new
THREE
.
Vector3
(),
strength
:
-
0.08
,
subtract
:
10
},
{
position
:
new
THREE
.
Vector3
(),
strength
:
0.04
,
subtract
:
10
}
];
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
//
function
animate
()
{
renderer
.
setAnimationLoop
(
render
);
}
function
transformPoint
(
vector
)
{
vector
.
x
=
(
vector
.
x
+
1.0
)
/
2.0
;
vector
.
y
=
(
vector
.
y
/
2.0
);
vector
.
z
=
(
vector
.
z
+
1.0
)
/
2.0
;
}
function
handleController
(
controller
,
id
)
{
controller
.
update
();
var
pivot
=
controller
.
getObjectByName
(
'
pivot
'
);
if
(
pivot
)
{
var
matrix
=
pivot
.
matrixWorld
;
points
[
id
].
position
.
setFromMatrixPosition
(
matrix
);
transformPoint
(
points
[
id
].
position
);
if
(
controller
.
getButtonState
(
'
thumbpad
'
)
)
{
blob
.
material
.
color
.
setHex
(
Math
.
random
()
*
0xffffff
);
}
if
(
controller
.
getButtonState
(
'
trigger
'
)
)
{
var
strength
=
points
[
id
].
strength
/
2
;
var
vector
=
new
THREE
.
Vector3
().
setFromMatrixPosition
(
matrix
);
transformPoint
(
vector
);
points
.
push
(
{
position
:
vector
,
strength
:
strength
,
subtract
:
10
}
);
}
if
(
id
===
0
&&
controller
.
getButtonState
(
'
grips
'
)
)
{
if
(
points
.
length
>
2
)
{
points
.
shift
();
points
.
shift
();
updateBlob
();
var
geometry
=
blob
.
generateBufferGeometry
();
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
blob
.
material
.
clone
()
);
mesh
.
position
.
y
=
1
;
mesh
.
castShadow
=
true
;
mesh
.
receiveShadow
=
true
;
scene
.
add
(
mesh
);
initPoints
();
}
}
if
(
id
===
1
&&
controller
.
getButtonState
(
'
grips
'
)
)
{
points
[
id
].
strength
=
(
Math
.
sin
(
performance
.
now
()
/
1000
)
+
1.5
)
/
20.0
;
}
}
}
function
updateBlob
()
{
blob
.
reset
();
for
(
var
i
=
0
;
i
<
points
.
length
;
i
++
)
{
var
point
=
points
[
i
];
var
position
=
point
.
position
;
blob
.
addBall
(
position
.
x
,
position
.
y
,
position
.
z
,
point
.
strength
,
point
.
subtract
);
}
}
function
render
()
{
handleController
(
controller1
,
0
);
handleController
(
controller2
,
1
);
updateBlob
();
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
utils/modularize.js
浏览文件 @
60187832
...
...
@@ -243,8 +243,6 @@ var files = [
{
path
:
'
vr/deprecated/DaydreamController.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
vr/deprecated/GearVRController.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
vr/PaintViveController.js
'
,
dependencies
:
[
{
name
:
'
ViveController
'
,
path
:
'
vr/ViveController.js
'
}
],
ignoreList
:
[]
},
{
path
:
'
vr/ViveController.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
vr/WebVR.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
{
path
:
'
WebGL.js
'
,
dependencies
:
[],
ignoreList
:
[]
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录