Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
56bbbd7b
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,发现更多精彩内容 >>
提交
56bbbd7b
编写于
9月 17, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7183 from elisee/rotation-and-local-snap
TransformControls: Add rotation snapping support
上级
3ee6fbe8
16e956d5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
39 deletion
+106
-39
editor/js/Viewport.js
editor/js/Viewport.js
+1
-1
examples/js/controls/TransformControls.js
examples/js/controls/TransformControls.js
+54
-13
examples/misc_controls_transform.html
examples/misc_controls_transform.html
+51
-25
未找到文件。
editor/js/Viewport.js
浏览文件 @
56bbbd7b
...
...
@@ -283,7 +283,7 @@ var Viewport = function ( editor ) {
signals
.
snapChanged
.
add
(
function
(
dist
)
{
transformControls
.
setSnap
(
dist
);
transformControls
.
set
Translation
Snap
(
dist
);
}
);
...
...
examples/js/controls/TransformControls.js
浏览文件 @
56bbbd7b
...
...
@@ -617,7 +617,8 @@
this
.
object
=
undefined
;
this
.
visible
=
false
;
this
.
snap
=
null
;
this
.
translationSnap
=
null
;
this
.
rotationSnap
=
null
;
this
.
space
=
"
world
"
;
this
.
size
=
1
;
this
.
axis
=
null
;
...
...
@@ -750,9 +751,15 @@
};
this
.
set
Snap
=
function
(
s
nap
)
{
this
.
set
TranslationSnap
=
function
(
translationS
nap
)
{
scope
.
snap
=
snap
;
scope
.
translationSnap
=
translationSnap
;
};
this
.
setRotationSnap
=
function
(
rotationSnap
)
{
scope
.
rotationSnap
=
rotationSnap
;
};
...
...
@@ -930,11 +937,23 @@
}
if
(
scope
.
s
nap
!==
null
)
{
if
(
scope
.
translationS
nap
!==
null
)
{
if
(
scope
.
axis
.
search
(
"
X
"
)
!==
-
1
)
scope
.
object
.
position
.
x
=
Math
.
round
(
scope
.
object
.
position
.
x
/
scope
.
snap
)
*
scope
.
snap
;
if
(
scope
.
axis
.
search
(
"
Y
"
)
!==
-
1
)
scope
.
object
.
position
.
y
=
Math
.
round
(
scope
.
object
.
position
.
y
/
scope
.
snap
)
*
scope
.
snap
;
if
(
scope
.
axis
.
search
(
"
Z
"
)
!==
-
1
)
scope
.
object
.
position
.
z
=
Math
.
round
(
scope
.
object
.
position
.
z
/
scope
.
snap
)
*
scope
.
snap
;
if
(
scope
.
space
===
"
local
"
)
{
scope
.
object
.
position
.
applyMatrix4
(
tempMatrix
.
getInverse
(
worldRotationMatrix
)
);
}
if
(
scope
.
axis
.
search
(
"
X
"
)
!==
-
1
)
scope
.
object
.
position
.
x
=
Math
.
round
(
scope
.
object
.
position
.
x
/
scope
.
translationSnap
)
*
scope
.
translationSnap
;
if
(
scope
.
axis
.
search
(
"
Y
"
)
!==
-
1
)
scope
.
object
.
position
.
y
=
Math
.
round
(
scope
.
object
.
position
.
y
/
scope
.
translationSnap
)
*
scope
.
translationSnap
;
if
(
scope
.
axis
.
search
(
"
Z
"
)
!==
-
1
)
scope
.
object
.
position
.
z
=
Math
.
round
(
scope
.
object
.
position
.
z
/
scope
.
translationSnap
)
*
scope
.
translationSnap
;
if
(
scope
.
space
===
"
local
"
)
{
scope
.
object
.
position
.
applyMatrix4
(
worldRotationMatrix
);
}
}
...
...
@@ -1013,9 +1032,20 @@
offsetRotation
.
set
(
Math
.
atan2
(
tempVector
.
z
,
tempVector
.
y
),
Math
.
atan2
(
tempVector
.
x
,
tempVector
.
z
),
Math
.
atan2
(
tempVector
.
y
,
tempVector
.
x
)
);
quaternionXYZ
.
setFromRotationMatrix
(
oldRotationMatrix
);
quaternionX
.
setFromAxisAngle
(
unitX
,
rotation
.
x
-
offsetRotation
.
x
);
quaternionY
.
setFromAxisAngle
(
unitY
,
rotation
.
y
-
offsetRotation
.
y
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
rotation
.
z
-
offsetRotation
.
z
);
if
(
scope
.
rotationSnap
!==
null
)
{
quaternionX
.
setFromAxisAngle
(
unitX
,
Math
.
round
(
(
rotation
.
x
-
offsetRotation
.
x
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
quaternionY
.
setFromAxisAngle
(
unitY
,
Math
.
round
(
(
rotation
.
y
-
offsetRotation
.
y
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
Math
.
round
(
(
rotation
.
z
-
offsetRotation
.
z
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
}
else
{
quaternionX
.
setFromAxisAngle
(
unitX
,
rotation
.
x
-
offsetRotation
.
x
);
quaternionY
.
setFromAxisAngle
(
unitY
,
rotation
.
y
-
offsetRotation
.
y
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
rotation
.
z
-
offsetRotation
.
z
);
}
if
(
scope
.
axis
===
"
X
"
)
quaternionXYZ
.
multiplyQuaternions
(
quaternionXYZ
,
quaternionX
);
if
(
scope
.
axis
===
"
Y
"
)
quaternionXYZ
.
multiplyQuaternions
(
quaternionXYZ
,
quaternionY
);
...
...
@@ -1030,9 +1060,20 @@
tempQuaternion
.
setFromRotationMatrix
(
tempMatrix
.
getInverse
(
parentRotationMatrix
)
);
quaternionX
.
setFromAxisAngle
(
unitX
,
rotation
.
x
-
offsetRotation
.
x
);
quaternionY
.
setFromAxisAngle
(
unitY
,
rotation
.
y
-
offsetRotation
.
y
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
rotation
.
z
-
offsetRotation
.
z
);
if
(
scope
.
rotationSnap
!==
null
)
{
quaternionX
.
setFromAxisAngle
(
unitX
,
Math
.
round
(
(
rotation
.
x
-
offsetRotation
.
x
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
quaternionY
.
setFromAxisAngle
(
unitY
,
Math
.
round
(
(
rotation
.
y
-
offsetRotation
.
y
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
Math
.
round
(
(
rotation
.
z
-
offsetRotation
.
z
)
/
scope
.
rotationSnap
)
*
scope
.
rotationSnap
);
}
else
{
quaternionX
.
setFromAxisAngle
(
unitX
,
rotation
.
x
-
offsetRotation
.
x
);
quaternionY
.
setFromAxisAngle
(
unitY
,
rotation
.
y
-
offsetRotation
.
y
);
quaternionZ
.
setFromAxisAngle
(
unitZ
,
rotation
.
z
-
offsetRotation
.
z
);
}
quaternionXYZ
.
setFromRotationMatrix
(
worldRotationMatrix
);
if
(
scope
.
axis
===
"
X
"
)
tempQuaternion
.
multiplyQuaternions
(
tempQuaternion
,
quaternionX
);
...
...
examples/misc_controls_transform.html
浏览文件 @
56bbbd7b
...
...
@@ -26,7 +26,7 @@
<div
id=
"info"
>
"W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size
<br
/>
Press "Q" to toggle world/local space
Press "Q" to toggle world/local space
, keep "Ctrl" down to snap to grid
</div>
<script
src=
"../build/three.min.js"
></script>
...
...
@@ -79,30 +79,56 @@
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
window
.
addEventListener
(
'
keydown
'
,
function
(
event
)
{
//console.log(event.which);
switch
(
event
.
keyCode
)
{
case
81
:
// Q
control
.
setSpace
(
control
.
space
==
"
local
"
?
"
world
"
:
"
local
"
);
break
;
case
87
:
// W
control
.
setMode
(
"
translate
"
);
break
;
case
69
:
// E
control
.
setMode
(
"
rotate
"
);
break
;
case
82
:
// R
control
.
setMode
(
"
scale
"
);
break
;
case
187
:
case
107
:
// +,=,num+
control
.
setSize
(
control
.
size
+
0.1
);
break
;
case
189
:
case
109
:
// -,_,num-
control
.
setSize
(
Math
.
max
(
control
.
size
-
0.1
,
0.1
)
);
break
;
}
});
switch
(
event
.
keyCode
)
{
case
81
:
// Q
control
.
setSpace
(
control
.
space
===
"
local
"
?
"
world
"
:
"
local
"
);
break
;
case
17
:
// Ctrl
control
.
setTranslationSnap
(
100
);
control
.
setRotationSnap
(
THREE
.
Math
.
degToRad
(
15
)
);
break
;
case
87
:
// W
control
.
setMode
(
"
translate
"
);
break
;
case
69
:
// E
control
.
setMode
(
"
rotate
"
);
break
;
case
82
:
// R
control
.
setMode
(
"
scale
"
);
break
;
case
187
:
case
107
:
// +, =, num+
control
.
setSize
(
control
.
size
+
0.1
);
break
;
case
189
:
case
109
:
// -, _, num-
control
.
setSize
(
Math
.
max
(
control
.
size
-
0.1
,
0.1
)
);
break
;
}
});
window
.
addEventListener
(
'
keyup
'
,
function
(
event
)
{
switch
(
event
.
keyCode
)
{
case
17
:
// Ctrl
control
.
setTranslationSnap
(
null
);
control
.
setRotationSnap
(
null
);
break
;
}
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录