Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
c6639997
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,发现更多精彩内容 >>
提交
c6639997
编写于
7月 17, 2018
作者:
0
06wj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sprite raycast demo
上级
020b8874
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
178 addition
and
0 deletion
+178
-0
examples/files.js
examples/files.js
+1
-0
examples/webgl_raycast_sprite.html
examples/webgl_raycast_sprite.html
+177
-0
未找到文件。
examples/files.js
浏览文件 @
c6639997
...
@@ -242,6 +242,7 @@ var files = {
...
@@ -242,6 +242,7 @@ var files = {
"
webgl_postprocessing_taa
"
,
"
webgl_postprocessing_taa
"
,
"
webgl_postprocessing_unreal_bloom
"
,
"
webgl_postprocessing_unreal_bloom
"
,
"
webgl_raycast_texture
"
,
"
webgl_raycast_texture
"
,
"
webgl_raycast_sprite
"
,
"
webgl_read_float_buffer
"
,
"
webgl_read_float_buffer
"
,
"
webgl_refraction
"
,
"
webgl_refraction
"
,
"
webgl_rtt
"
,
"
webgl_rtt
"
,
...
...
examples/webgl_raycast_sprite.html
0 → 100644
浏览文件 @
c6639997
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - raycast - sprite
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
margin
:
0px
;
background-color
:
#fff
;
overflow
:
hidden
;
}
#info
{
position
:
absolute
;
z-index
:
1
;
width
:
100%
;
text-align
:
center
;
}
</style>
</head>
<body>
<div
id=
"info"
><a
href=
"http://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
- webgl raycast sprite
<br></div>
<script
src=
"../build/three.js"
></script>
<script
src=
"./js/controls/OrbitControls.js"
></script>
<script>
var
renderer
;
var
scene
;
var
spriteGroup
;
var
camera
;
var
controls
;
init
();
function
init
()
{
initRender
();
initScene
();
initCamera
();
addSprite
();
render
();
window
.
addEventListener
(
"
mousemove
"
,
onDocumentMouseMove
,
false
);
}
function
render
()
{
renderer
.
render
(
scene
,
camera
);
requestAnimationFrame
(
render
);
}
function
initRender
()
{
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
document
.
body
.
appendChild
(
renderer
.
domElement
);
renderer
.
setClearColor
(
0xFFFFFF
,
1.0
);
}
function
initScene
()
{
scene
=
new
THREE
.
Scene
();
spriteGroup
=
new
THREE
.
Object3D
();
scene
.
add
(
spriteGroup
);
}
function
initCamera
()
{
camera
=
new
THREE
.
PerspectiveCamera
(
50
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
1000
);
camera
.
position
.
y
=
15
;
camera
.
position
.
z
=
15
;
camera
.
position
.
x
=
15
;
camera
.
lookAt
(
{
x
:
0
,
y
:
0
,
z
:
0
}
);
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
);
controls
.
target
=
new
THREE
.
Vector3
(
0
,
0
,
0
);
controls
.
enableRotate
=
true
;
}
function
addSprite
()
{
var
sprite
;
sprite
=
makeSprite
(
'
#69f
'
,
spriteGroup
);
sprite
.
position
.
set
(
6
,
5
,
5
);
sprite
.
scale
.
set
(
2
,
5
,
1
);
sprite
=
makeSprite
(
'
#69f
'
,
spriteGroup
);
sprite
.
position
.
set
(
8
,
-
2
,
2
);
sprite
.
center
.
set
(
0.5
,
0
);
sprite
.
scale
.
set
(
1
,
-
5
,
1
);
sprite
.
material
.
rotation
=
Math
.
PI
/
3
*
4
;
var
g
=
new
THREE
.
Object3D
();
spriteGroup
.
add
(
g
);
g
.
scale
.
set
(
1
,
2
,
1
);
g
.
position
.
set
(
-
5
,
0
,
0
);
g
.
rotation
.
set
(
Math
.
PI
/
2
,
0
,
0
);
sprite
=
makeSprite
(
'
#69f
'
,
g
);
sprite
.
position
.
set
(
0
,
2
,
5
);
sprite
.
scale
.
set
(
10
,
2
,
3
);
sprite
.
center
.
set
(
-
0.1
,
0
);
sprite
.
material
.
rotation
=
Math
.
PI
/
3
;
}
function
makeSprite
(
color
,
parent
)
{
var
sprite
=
new
THREE
.
Sprite
(
new
THREE
.
SpriteMaterial
(
{
color
:
color
}
)
);
parent
.
add
(
sprite
);
return
sprite
;
}
var
selectedObject
=
null
;
function
onDocumentMouseMove
(
event
)
{
event
.
preventDefault
();
if
(
selectedObject
)
{
selectedObject
.
material
.
color
.
set
(
'
#69f
'
);
selectedObject
=
null
;
}
var
intersects
=
getIntersects
(
event
.
layerX
,
event
.
layerY
);
if
(
intersects
.
length
>
0
)
{
var
res
=
intersects
.
filter
(
function
(
res
)
{
return
res
&&
res
.
object
;
}
)[
0
];
if
(
res
&&
res
.
object
)
{
selectedObject
=
res
.
object
;
selectedObject
.
material
.
color
.
set
(
'
#f00
'
);
}
}
}
var
raycaster
=
new
THREE
.
Raycaster
();
var
mouseVector
=
new
THREE
.
Vector3
();
function
getIntersects
(
x
,
y
)
{
mouseVector
.
set
(
(
x
/
window
.
innerWidth
)
*
2
-
1
,
-
(
y
/
window
.
innerHeight
)
*
2
+
1
,
0.5
);
raycaster
.
setFromCamera
(
mouseVector
,
camera
);
var
intersects
=
raycaster
.
intersectObjects
(
[
spriteGroup
],
true
);
return
intersects
;
}
</script>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录