Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a3538ec6
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,发现更多精彩内容 >>
未验证
提交
a3538ec6
编写于
6月 16, 2018
作者:
M
Mr.doob
提交者:
GitHub
6月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14200 from Mugen87/dev11
UVDebug: Process BufferGeometry without conversion
上级
d1decbc8
e843cdf3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
52 deletion
+118
-52
examples/js/utils/UVsDebug.js
examples/js/utils/UVsDebug.js
+104
-38
examples/misc_uv_tests.html
examples/misc_uv_tests.html
+14
-14
未找到文件。
examples/js/utils/UVsDebug.js
浏览文件 @
a3538ec6
/*
/*
* @author zz85 / http://github.com/zz85
* @author WestLangley / http://github.com/WestLangley
* @author Mugen87 / https://github.com/Mugen87
*
* tool for "unwrapping" and debugging three.js
* geometries UV mapping
* tool for "unwrapping" and debugging three.js geometries UV mapping
*
* Sample usage:
* document.body.appendChild( THREE.UVsDebug( new THREE.SphereGeometry( 10, 10, 10, 10 ) );
* document.body.appendChild( THREE.UVsDebug( new THREE.Sphere
Buffer
Geometry( 10, 10, 10, 10 ) );
*
*/
THREE
.
UVsDebug
=
function
(
geometry
,
size
)
{
// handles wrapping of uv.x > 1 only
var
abc
=
'
abc
'
;
THREE
.
UVsDebug
=
function
(
geometry
,
size
)
{
var
uv
,
u
,
ax
,
ay
;
var
i
,
il
,
j
,
jl
;
var
vnum
;
// handles wrapping of uv.x > 1 only
var
abc
=
'
abc
'
;
var
a
=
new
THREE
.
Vector2
();
var
b
=
new
THREE
.
Vector2
();
var
geo
=
(
geometry
instanceof
THREE
.
BufferGeometry
)
?
new
THREE
.
Geometry
().
fromBufferGeometry
(
geometry
)
:
geometry
;
var
uvs
=
[
new
THREE
.
Vector2
(),
new
THREE
.
Vector2
(),
new
THREE
.
Vector2
()
];
var
faces
=
geo
.
faces
;
var
uvs
=
geo
.
faceVertexUvs
[
0
];
var
face
=
[];
var
canvas
=
document
.
createElement
(
'
canvas
'
);
var
width
=
size
||
1024
;
// power of 2 required for wrapping
var
width
=
size
||
1024
;
// power of 2 required for wrapping
var
height
=
size
||
1024
;
canvas
.
width
=
width
;
canvas
.
height
=
height
;
...
...
@@ -44,30 +42,97 @@ THREE.UVsDebug = function( geometry, size ) {
ctx
.
fillStyle
=
'
rgba( 255, 255, 255, 1.0 )
'
;
ctx
.
fillRect
(
0
,
0
,
width
,
height
);
for
(
i
=
0
,
il
=
uvs
.
length
;
i
<
il
;
i
++
)
{
if
(
geometry
.
isGeometry
)
{
var
faces
=
geometry
.
faces
;
var
uvSet
=
geometry
.
faceVertexUvs
[
0
];
for
(
var
i
=
0
,
il
=
uvSet
.
length
;
i
<
il
;
i
++
)
{
uv
=
uvs
[
i
];
var
face
=
faces
[
i
];
var
uv
=
uvSet
[
i
];
face
[
0
]
=
face
.
a
;
face
[
1
]
=
face
.
b
;
face
[
2
]
=
face
.
c
;
uvs
[
0
].
copy
(
uv
[
0
]
);
uvs
[
1
].
copy
(
uv
[
1
]
);
uvs
[
2
].
copy
(
uv
[
2
]
);
processFace
(
face
,
uvs
,
i
);
}
}
else
{
var
index
=
geometry
.
index
;
var
uvAttribute
=
geometry
.
attributes
.
uv
;
if
(
index
)
{
// indexed geometry
for
(
var
i
=
0
,
il
=
index
.
count
;
i
<
il
;
i
+=
3
)
{
face
[
0
]
=
index
.
getX
(
i
);
face
[
1
]
=
index
.
getX
(
i
+
1
);
face
[
2
]
=
index
.
getX
(
i
+
2
);
uvs
[
0
].
fromBufferAttribute
(
uvAttribute
,
face
[
0
]
);
uvs
[
1
].
fromBufferAttribute
(
uvAttribute
,
face
[
1
]
);
uvs
[
2
].
fromBufferAttribute
(
uvAttribute
,
face
[
2
]
);
processFace
(
face
,
uvs
,
i
);
}
// draw lines
}
else
{
// non-indexed geometry
for
(
var
i
=
0
,
il
=
uvAttribute
.
count
;
i
<
il
;
i
+=
3
)
{
face
[
0
]
=
i
;
face
[
1
]
=
i
+
1
;
face
[
2
]
=
i
+
2
;
uvs
[
0
].
fromBufferAttribute
(
uvAttribute
,
face
[
0
]
);
uvs
[
1
].
fromBufferAttribute
(
uvAttribute
,
face
[
1
]
);
uvs
[
2
].
fromBufferAttribute
(
uvAttribute
,
face
[
2
]
);
processFace
(
face
,
uvs
,
i
);
}
}
}
return
canvas
;
function
processFace
(
face
,
uvs
,
index
)
{
// draw contour of face
ctx
.
beginPath
();
a
.
set
(
0
,
0
);
for
(
j
=
0
,
jl
=
uv
.
length
;
j
<
jl
;
j
++
)
{
for
(
var
j
=
0
,
jl
=
uvs
.
length
;
j
<
jl
;
j
++
)
{
u
=
uv
[
j
];
var
uv
=
uvs
[
j
];
a
.
x
+=
u
.
x
;
a
.
y
+=
u
.
y
;
a
.
x
+=
u
v
.
x
;
a
.
y
+=
u
v
.
y
;
if
(
j
==
0
)
{
if
(
j
==
=
0
)
{
ctx
.
moveTo
(
u
.
x
*
width
,
(
1
-
u
.
y
)
*
height
);
ctx
.
moveTo
(
u
v
.
x
*
width
,
(
1
-
uv
.
y
)
*
height
);
}
else
{
ctx
.
lineTo
(
u
.
x
*
width
,
(
1
-
u
.
y
)
*
height
);
ctx
.
lineTo
(
u
v
.
x
*
width
,
(
1
-
uv
.
y
)
*
height
);
}
...
...
@@ -76,33 +141,37 @@ THREE.UVsDebug = function( geometry, size ) {
ctx
.
closePath
();
ctx
.
stroke
();
a
.
divideScalar
(
jl
);
// calculate center of face
a
.
divideScalar
(
uvs
.
length
);
// label the face number
ctx
.
font
=
"
12pt Arial bold
"
;
ctx
.
font
=
'
12pt Arial bold
'
;
ctx
.
fillStyle
=
'
rgba( 0, 0, 0, 1.0 )
'
;
ctx
.
fillText
(
i
,
a
.
x
*
width
,
(
1
-
a
.
y
)
*
height
);
ctx
.
fillText
(
i
ndex
,
a
.
x
*
width
,
(
1
-
a
.
y
)
*
height
);
if
(
a
.
x
>
0.95
)
{
// wrap x // 0.95 is arbitrary
ctx
.
fillText
(
i
,
(
a
.
x
%
1
)
*
width
,
(
1
-
a
.
y
)
*
height
);
ctx
.
fillText
(
i
ndex
,
(
a
.
x
%
1
)
*
width
,
(
1
-
a
.
y
)
*
height
);
}
ctx
.
font
=
"
8pt Arial bold
"
;
//
ctx
.
font
=
'
8pt Arial bold
'
;
ctx
.
fillStyle
=
'
rgba( 0, 0, 0, 1.0 )
'
;
// label uv edge orders
for
(
j
=
0
,
jl
=
uv
.
length
;
j
<
jl
;
j
++
)
{
for
(
j
=
0
,
jl
=
uv
s
.
length
;
j
<
jl
;
j
++
)
{
u
=
uv
[
j
];
b
.
addVectors
(
a
,
u
).
divideScalar
(
2
);
var
uv
=
uvs
[
j
];
b
.
addVectors
(
a
,
u
v
).
divideScalar
(
2
);
v
num
=
faces
[
i
][
abc
[
j
]
];
v
ar
vnum
=
face
[
j
];
ctx
.
fillText
(
abc
[
j
]
+
vnum
,
b
.
x
*
width
,
(
1
-
b
.
y
)
*
height
);
if
(
b
.
x
>
0.95
)
{
...
...
@@ -117,7 +186,4 @@ THREE.UVsDebug = function( geometry, size ) {
}
return
canvas
;
};
examples/misc_uv_tests.html
浏览文件 @
a3538ec6
...
...
@@ -30,33 +30,33 @@
}
test
(
'
new THREE.PlaneGeometry( 100, 100, 4, 4 )
'
,
new
THREE
.
PlaneGeometry
(
100
,
100
,
4
,
4
))
;
var
points
=
[]
;
test
(
'
new THREE.PlaneBufferGeometry( 100, 100, 4, 4 )
'
,
new
THREE
.
PlaneBufferGeometry
(
100
,
100
,
4
,
4
));
for
(
var
i
=
0
;
i
<
10
;
i
++
)
{
test
(
'
new THREE.SphereGeometry( 75, 12, 6 )
'
,
new
THREE
.
SphereGeometry
(
75
,
12
,
6
)
);
points
.
push
(
new
THREE
.
Vector2
(
Math
.
sin
(
i
*
0.2
)
*
15
+
50
,
(
i
-
5
)
*
2
)
);
test
(
'
new THREE.IcosahedronGeometry( 30, 1 )
'
,
new
THREE
.
IcosahedronGeometry
(
30
,
1
));
}
test
(
'
new THREE.OctahedronGeometry( 30, 2 )
'
,
new
THREE
.
OctahedronGeometry
(
30
,
2
));
//
test
(
'
new THREE.
CylinderGeometry( 25, 75, 100, 10, 5 )
'
,
new
THREE
.
CylinderGeometry
(
25
,
75
,
100
,
10
,
5
));
test
(
'
new THREE.
PlaneBufferGeometry( 100, 100, 4, 4 )
'
,
new
THREE
.
PlaneBufferGeometry
(
100
,
100
,
4
,
4
));
test
(
'
new THREE.
BoxGeometry( 100, 100, 100, 4, 4, 4 )
'
,
new
THREE
.
BoxGeometry
(
100
,
100
,
100
,
4
,
4
,
4
));
test
(
'
new THREE.
SphereBufferGeometry( 75, 12, 6 )
'
,
new
THREE
.
SphereBufferGeometry
(
75
,
12
,
6
));
var
points
=
[]
;
test
(
'
new THREE.IcosahedronBufferGeometry( 30, 1 )
'
,
new
THREE
.
IcosahedronBufferGeometry
(
30
,
1
))
;
for
(
var
i
=
0
;
i
<
10
;
i
++
)
{
test
(
'
new THREE.OctahedronBufferGeometry( 30, 2 )
'
,
new
THREE
.
OctahedronBufferGeometry
(
30
,
2
));
points
.
push
(
new
THREE
.
Vector2
(
Math
.
sin
(
i
*
0.2
)
*
15
+
50
,
(
i
-
5
)
*
2
)
);
test
(
'
new THREE.CylinderBufferGeometry( 25, 75, 100, 10, 5 )
'
,
new
THREE
.
CylinderBufferGeometry
(
25
,
75
,
100
,
10
,
5
)
);
}
test
(
'
new THREE.BoxBufferGeometry( 100, 100, 100, 4, 4, 4 )
'
,
new
THREE
.
BoxBufferGeometry
(
100
,
100
,
100
,
4
,
4
,
4
));
test
(
'
new THREE.Lathe
Geometry( points, 8 )
'
,
new
THREE
.
Lathe
Geometry
(
points
,
8
));
test
(
'
new THREE.Lathe
BufferGeometry( points, 8 )
'
,
new
THREE
.
LatheBuffer
Geometry
(
points
,
8
));
test
(
'
new THREE.Torus
Geometry( 50, 20, 8, 8 )
'
,
new
THREE
.
Torus
Geometry
(
50
,
20
,
8
,
8
));
test
(
'
new THREE.Torus
BufferGeometry( 50, 20, 8, 8 )
'
,
new
THREE
.
TorusBuffer
Geometry
(
50
,
20
,
8
,
8
));
test
(
'
new THREE.TorusKnot
Geometry( 50, 10, 12, 6 )
'
,
new
THREE
.
TorusKnot
Geometry
(
50
,
10
,
12
,
6
));
test
(
'
new THREE.TorusKnot
BufferGeometry( 50, 10, 12, 6 )
'
,
new
THREE
.
TorusKnotBuffer
Geometry
(
50
,
10
,
12
,
6
));
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录