Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
skyuning
ThreeJS 范例演示
提交
60053bee
T
ThreeJS 范例演示
项目概览
skyuning
/
ThreeJS 范例演示
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
ThreeJS 范例演示
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
60053bee
编写于
10月 18, 2023
作者:
S
skyun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Wed Oct 18 22:53:00 CST 2023 inscode
上级
f414f2e2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
26 deletion
+56
-26
src/threejs-tools.js
src/threejs-tools.js
+36
-0
src/views/basic.vue
src/views/basic.vue
+20
-26
未找到文件。
src/threejs-tools.js
0 → 100644
浏览文件 @
60053bee
import
{
ref
,
onMounted
}
from
'
vue
'
import
*
as
THREE
from
'
three
'
import
{
OrbitControls
}
from
'
three/addons/controls/OrbitControls.js
'
;
export
class
ThreejsDefault
{
constructor
(
container
)
{
// init scene camera
this
.
scene
=
new
THREE
.
Scene
()
this
.
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
0.1
,
1000
)
this
.
camera
.
position
.
z
=
5
// init renderer
this
.
renderer
=
new
THREE
.
WebGLRenderer
()
this
.
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
)
// init controls
this
.
controls
=
new
OrbitControls
(
this
.
camera
,
this
.
renderer
.
domElement
);
this
.
animateFuncs
=
[]
const
animate
=
()
=>
{
requestAnimationFrame
(
animate
)
this
.
animateFuncs
.
forEach
(
animFunc
=>
animFunc
())
this
.
renderer
.
render
(
this
.
scene
,
this
.
camera
)
}
onMounted
(()
=>
{
container
.
value
.
appendChild
(
this
.
renderer
.
domElement
)
animate
()
})
}
onAnimate
(
animFunc
)
{
this
.
animateFuncs
.
push
(
animFunc
)
}
}
src/views/basic.vue
浏览文件 @
60053bee
...
...
@@ -4,41 +4,35 @@
<
script
setup
>
import
{
ref
,
onMounted
}
from
'
vue
'
import
*
as
TT
from
'
../threejs-tools
'
import
*
as
THREE
from
'
three
'
import
{
OrbitControls
}
from
'
three/addons/controls/OrbitControls.js
'
;
// init scene camera
const
scene
=
new
THREE
.
Scene
()
const
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
0.1
,
1000
)
camera
.
position
.
z
=
5
// init renderer
const
container
=
ref
(
null
)
const
renderer
=
new
THREE
.
WebGLRenderer
()
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
)
const
animate
=
()
=>
{
requestAnimationFrame
(
animate
)
const
td
=
new
TT
.
ThreejsDefault
(
container
)
// add mesh
const
geometry
=
new
THREE
.
BoxGeometry
(
1
,
1
,
1
)
const
material
=
new
THREE
.
MeshPhongMaterial
({
color
:
0x00ff00
})
const
cube
=
new
THREE
.
Mesh
(
geometry
,
material
)
td
.
scene
.
add
(
cube
)
td
.
onAnimate
(()
=>
{
cube
.
rotation
.
x
+=
0.01
cube
.
rotation
.
y
+=
0.01
renderer
.
render
(
scene
,
camera
)
}
onMounted
(()
=>
{
container
.
value
.
appendChild
(
renderer
.
domElement
)
animate
()
})
// init controls
const
controls
=
new
OrbitControls
(
camera
,
renderer
.
domElement
);
const
geometry2
=
new
THREE
.
BoxGeometry
(
1
,
1
,
1
)
const
material2
=
new
THREE
.
MeshPhongMaterial
({
color
:
0x00ff00
})
const
cube2
=
new
THREE
.
Mesh
(
geometry2
,
material2
)
cube2
.
position
.
y
+=
2
td
.
scene
.
add
(
cube2
)
td
.
onAnimate
(()
=>
{
cube2
.
rotation
.
x
+=
0.01
cube2
.
rotation
.
y
+=
0.01
})
// init lights
const
light
=
new
THREE
.
AmbientLight
(
0xffffff
);
// soft white light
scene
.
add
(
light
);
// add light
td
.
scene
.
add
(
new
THREE
.
AmbientLight
(
0xffffff
));
// user code
const
geometry
=
new
THREE
.
BoxGeometry
(
1
,
1
,
1
)
const
material
=
new
THREE
.
MeshPhongMaterial
({
color
:
0x00ff00
})
const
cube
=
new
THREE
.
Mesh
(
geometry
,
material
)
scene
.
add
(
cube
)
</
script
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录