Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
ca7a680b
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
ca7a680b
编写于
8月 21, 2014
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Editor: Added basic scripting support.
上级
49ab64c8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
82 addition
and
3 deletion
+82
-3
editor/js/Menubar.File.js
editor/js/Menubar.File.js
+1
-1
editor/js/Player.js
editor/js/Player.js
+34
-1
editor/js/Sidebar.Script.js
editor/js/Sidebar.Script.js
+30
-0
src/core/Object3D.js
src/core/Object3D.js
+3
-0
src/core/Script.js
src/core/Script.js
+13
-1
src/loaders/ObjectLoader.js
src/loaders/ObjectLoader.js
+1
-0
未找到文件。
editor/js/Menubar.File.js
浏览文件 @
ca7a680b
...
...
@@ -211,7 +211,7 @@ Menubar.File = function ( editor ) {
var
preview
=
new
Player
(
editor
.
scene
.
toJSON
()
);
preview
.
setSize
(
800
,
600
);
preview
.
update
();
preview
.
play
();
var
popup
=
window
.
open
(
''
,
'
preview
'
,
'
width=800,height=600
'
);
popup
.
document
.
body
.
style
.
margin
=
0
;
...
...
editor/js/Player.js
浏览文件 @
ca7a680b
...
...
@@ -5,8 +5,27 @@ var Player = function ( json ) {
camera
.
lookAt
(
new
THREE
.
Vector3
()
);
var
scene
=
new
THREE
.
ObjectLoader
().
parse
(
json
);
var
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
//
var
scriptObjects
=
[];
scene
.
traverse
(
function
(
child
)
{
if
(
child
.
script
!==
undefined
)
{
child
.
script
.
compiled
=
new
Function
(
'
object
'
,
child
.
script
.
source
);
scriptObjects
.
push
(
child
);
}
}
);
//
var
setSize
=
function
(
width
,
height
)
{
camera
.
aspect
=
width
/
height
;
...
...
@@ -16,8 +35,22 @@ var Player = function ( json ) {
};
var
play
=
function
()
{
requestAnimationFrame
(
play
);
update
();
};
var
update
=
function
()
{
for
(
var
i
=
0
;
i
<
scriptObjects
.
length
;
i
++
)
{
var
object
=
scriptObjects
[
i
];
object
.
script
.
compiled
(
object
);
}
renderer
.
render
(
scene
,
camera
);
};
...
...
@@ -25,7 +58,7 @@ var Player = function ( json ) {
return
{
dom
:
renderer
.
domElement
,
setSize
:
setSize
,
update
:
update
play
:
play
}
};
\ No newline at end of file
editor/js/Sidebar.Script.js
浏览文件 @
ca7a680b
...
...
@@ -17,12 +17,42 @@ Sidebar.Script = function ( editor ) {
var
scriptsRow
=
new
UI
.
Panel
();
container
.
add
(
scriptsRow
);
// source
var
scriptSourceRow
=
new
UI
.
Panel
();
var
scriptSource
=
new
UI
.
TextArea
().
setWidth
(
'
240px
'
).
setHeight
(
'
180px
'
).
setColor
(
'
#444
'
).
setFontSize
(
'
12px
'
);
scriptSource
.
onChange
(
function
()
{
var
object
=
editor
.
selected
;
object
.
script
=
new
THREE
.
Script
(
scriptSource
.
getValue
()
);
editor
.
signals
.
objectChanged
.
dispatch
(
object
);
}
);
scriptSourceRow
.
add
(
scriptSource
);
container
.
add
(
scriptSourceRow
);
//
signals
.
objectSelected
.
add
(
function
(
object
)
{
if
(
object
!==
null
)
{
container
.
setDisplay
(
'
block
'
);
if
(
object
.
script
!==
undefined
)
{
scriptSource
.
setValue
(
object
.
script
.
source
);
}
else
{
scriptSource
.
setValue
(
''
);
}
}
else
{
container
.
setDisplay
(
'
none
'
);
...
...
src/core/Object3D.js
浏览文件 @
ca7a680b
...
...
@@ -577,6 +577,7 @@ THREE.Object3D.prototype = {
if
(
object
.
name
!==
''
)
data
.
name
=
object
.
name
;
if
(
JSON
.
stringify
(
object
.
userData
)
!==
'
{}
'
)
data
.
userData
=
object
.
userData
;
if
(
object
.
script
!==
undefined
)
data
.
script
=
object
.
script
.
source
;
if
(
object
.
visible
!==
true
)
data
.
visible
=
object
.
visible
;
if
(
object
instanceof
THREE
.
PerspectiveCamera
)
{
...
...
@@ -690,6 +691,8 @@ THREE.Object3D.prototype = {
object
.
userData
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
userData
)
);
if
(
this
.
script
!==
undefined
)
object
.
script
=
this
.
script
.
clone
();
if
(
recursive
===
true
)
{
for
(
var
i
=
0
;
i
<
this
.
children
.
length
;
i
++
)
{
...
...
src/core/Script.js
浏览文件 @
ca7a680b
...
...
@@ -7,4 +7,16 @@ THREE.Script = function ( source ) {
this
.
uuid
=
THREE
.
Math
.
generateUUID
();
this
.
source
=
source
;
};
\ No newline at end of file
};
THREE
.
Script
.
prototype
=
{
constructor
:
THREE
.
Script
,
clone
:
function
()
{
return
new
THREE
.
Script
(
this
.
source
);
}
}
\ No newline at end of file
src/loaders/ObjectLoader.js
浏览文件 @
ca7a680b
...
...
@@ -332,6 +332,7 @@ THREE.ObjectLoader.prototype = {
if
(
data
.
visible
!==
undefined
)
object
.
visible
=
data
.
visible
;
if
(
data
.
userData
!==
undefined
)
object
.
userData
=
data
.
userData
;
if
(
data
.
script
!==
undefined
)
object
.
script
=
new
THREE
.
Script
(
data
.
script
);
if
(
data
.
children
!==
undefined
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录