Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
a09b189d
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,发现更多精彩内容 >>
提交
a09b189d
编写于
12月 22, 2016
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved ShapePath out of Path.
上级
cc10ea3d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
290 addition
and
265 deletion
+290
-265
src/Three.js
src/Three.js
+2
-1
src/extras/core/Font.js
src/extras/core/Font.js
+1
-1
src/extras/core/Path.js
src/extras/core/Path.js
+6
-263
src/extras/core/ShapePath.js
src/extras/core/ShapePath.js
+281
-0
未找到文件。
src/Three.js
浏览文件 @
a09b189d
...
...
@@ -145,7 +145,8 @@ export { CubicBezierCurve } from './extras/curves/CubicBezierCurve.js';
export
{
QuadraticBezierCurve
}
from
'
./extras/curves/QuadraticBezierCurve.js
'
;
export
{
LineCurve
}
from
'
./extras/curves/LineCurve.js
'
;
export
{
Shape
}
from
'
./extras/core/Shape.js
'
;
export
{
ShapePath
,
Path
}
from
'
./extras/core/Path.js
'
;
export
{
Path
}
from
'
./extras/core/Path.js
'
;
export
{
ShapePath
}
from
'
./extras/core/ShapePath.js
'
;
export
{
Font
}
from
'
./extras/core/Font.js
'
;
export
{
CurvePath
}
from
'
./extras/core/CurvePath.js
'
;
export
{
Curve
}
from
'
./extras/core/Curve.js
'
;
...
...
src/extras/core/Font.js
浏览文件 @
a09b189d
import
{
ShapeUtils
}
from
'
../ShapeUtils
'
;
import
{
ShapePath
}
from
'
./Path
'
;
import
{
ShapePath
}
from
'
./
Shape
Path
'
;
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
...
...
src/extras/core/Path.js
浏览文件 @
a09b189d
import
{
PathPrototype
}
from
'
./PathPrototype
'
;
import
{
Shape
}
from
'
./Shape
'
;
import
{
ShapeUtils
}
from
'
../ShapeUtils
'
;
import
{
Vector2
}
from
'
../../math/Vector2
'
;
import
{
CurvePath
}
from
'
./CurvePath
'
;
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
* Creates free form 2d path using series of points, lines or curves.
*
**/
import
{
PathPrototype
}
from
'
./PathPrototype
'
;
import
{
Vector2
}
from
'
../../math/Vector2
'
;
import
{
CurvePath
}
from
'
./CurvePath
'
;
function
Path
(
points
)
{
CurvePath
.
call
(
this
);
...
...
@@ -26,259 +24,4 @@ function Path( points ) {
Path
.
prototype
=
PathPrototype
;
PathPrototype
.
constructor
=
Path
;
// minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
function
ShapePath
()
{
this
.
subPaths
=
[];
this
.
currentPath
=
null
;
}
ShapePath
.
prototype
=
{
moveTo
:
function
(
x
,
y
)
{
this
.
currentPath
=
new
Path
();
this
.
subPaths
.
push
(
this
.
currentPath
);
this
.
currentPath
.
moveTo
(
x
,
y
);
},
lineTo
:
function
(
x
,
y
)
{
this
.
currentPath
.
lineTo
(
x
,
y
);
},
quadraticCurveTo
:
function
(
aCPx
,
aCPy
,
aX
,
aY
)
{
this
.
currentPath
.
quadraticCurveTo
(
aCPx
,
aCPy
,
aX
,
aY
);
},
bezierCurveTo
:
function
(
aCP1x
,
aCP1y
,
aCP2x
,
aCP2y
,
aX
,
aY
)
{
this
.
currentPath
.
bezierCurveTo
(
aCP1x
,
aCP1y
,
aCP2x
,
aCP2y
,
aX
,
aY
);
},
splineThru
:
function
(
pts
)
{
this
.
currentPath
.
splineThru
(
pts
);
},
toShapes
:
function
(
isCCW
,
noHoles
)
{
function
toShapesNoHoles
(
inSubpaths
)
{
var
shapes
=
[];
for
(
var
i
=
0
,
l
=
inSubpaths
.
length
;
i
<
l
;
i
++
)
{
var
tmpPath
=
inSubpaths
[
i
];
var
tmpShape
=
new
Shape
();
tmpShape
.
curves
=
tmpPath
.
curves
;
shapes
.
push
(
tmpShape
);
}
return
shapes
;
}
function
isPointInsidePolygon
(
inPt
,
inPolygon
)
{
var
polyLen
=
inPolygon
.
length
;
// inPt on polygon contour => immediate success or
// toggling of inside/outside at every single! intersection point of an edge
// with the horizontal line through inPt, left of inPt
// not counting lowerY endpoints of edges and whole edges on that line
var
inside
=
false
;
for
(
var
p
=
polyLen
-
1
,
q
=
0
;
q
<
polyLen
;
p
=
q
++
)
{
var
edgeLowPt
=
inPolygon
[
p
];
var
edgeHighPt
=
inPolygon
[
q
];
var
edgeDx
=
edgeHighPt
.
x
-
edgeLowPt
.
x
;
var
edgeDy
=
edgeHighPt
.
y
-
edgeLowPt
.
y
;
if
(
Math
.
abs
(
edgeDy
)
>
Number
.
EPSILON
)
{
// not parallel
if
(
edgeDy
<
0
)
{
edgeLowPt
=
inPolygon
[
q
];
edgeDx
=
-
edgeDx
;
edgeHighPt
=
inPolygon
[
p
];
edgeDy
=
-
edgeDy
;
}
if
(
(
inPt
.
y
<
edgeLowPt
.
y
)
||
(
inPt
.
y
>
edgeHighPt
.
y
)
)
continue
;
if
(
inPt
.
y
===
edgeLowPt
.
y
)
{
if
(
inPt
.
x
===
edgeLowPt
.
x
)
return
true
;
// inPt is on contour ?
// continue; // no intersection or edgeLowPt => doesn't count !!!
}
else
{
var
perpEdge
=
edgeDy
*
(
inPt
.
x
-
edgeLowPt
.
x
)
-
edgeDx
*
(
inPt
.
y
-
edgeLowPt
.
y
);
if
(
perpEdge
===
0
)
return
true
;
// inPt is on contour ?
if
(
perpEdge
<
0
)
continue
;
inside
=
!
inside
;
// true intersection left of inPt
}
}
else
{
// parallel or collinear
if
(
inPt
.
y
!==
edgeLowPt
.
y
)
continue
;
// parallel
// edge lies on the same horizontal line as inPt
if
(
(
(
edgeHighPt
.
x
<=
inPt
.
x
)
&&
(
inPt
.
x
<=
edgeLowPt
.
x
)
)
||
(
(
edgeLowPt
.
x
<=
inPt
.
x
)
&&
(
inPt
.
x
<=
edgeHighPt
.
x
)
)
)
return
true
;
// inPt: Point on contour !
// continue;
}
}
return
inside
;
}
var
isClockWise
=
ShapeUtils
.
isClockWise
;
var
subPaths
=
this
.
subPaths
;
if
(
subPaths
.
length
===
0
)
return
[];
if
(
noHoles
===
true
)
return
toShapesNoHoles
(
subPaths
);
var
solid
,
tmpPath
,
tmpShape
,
shapes
=
[];
if
(
subPaths
.
length
===
1
)
{
tmpPath
=
subPaths
[
0
];
tmpShape
=
new
Shape
();
tmpShape
.
curves
=
tmpPath
.
curves
;
shapes
.
push
(
tmpShape
);
return
shapes
;
}
var
holesFirst
=
!
isClockWise
(
subPaths
[
0
].
getPoints
()
);
holesFirst
=
isCCW
?
!
holesFirst
:
holesFirst
;
// console.log("Holes first", holesFirst);
var
betterShapeHoles
=
[];
var
newShapes
=
[];
var
newShapeHoles
=
[];
var
mainIdx
=
0
;
var
tmpPoints
;
newShapes
[
mainIdx
]
=
undefined
;
newShapeHoles
[
mainIdx
]
=
[];
for
(
var
i
=
0
,
l
=
subPaths
.
length
;
i
<
l
;
i
++
)
{
tmpPath
=
subPaths
[
i
];
tmpPoints
=
tmpPath
.
getPoints
();
solid
=
isClockWise
(
tmpPoints
);
solid
=
isCCW
?
!
solid
:
solid
;
if
(
solid
)
{
if
(
(
!
holesFirst
)
&&
(
newShapes
[
mainIdx
]
)
)
mainIdx
++
;
newShapes
[
mainIdx
]
=
{
s
:
new
Shape
(),
p
:
tmpPoints
};
newShapes
[
mainIdx
].
s
.
curves
=
tmpPath
.
curves
;
if
(
holesFirst
)
mainIdx
++
;
newShapeHoles
[
mainIdx
]
=
[];
//console.log('cw', i);
}
else
{
newShapeHoles
[
mainIdx
].
push
(
{
h
:
tmpPath
,
p
:
tmpPoints
[
0
]
}
);
//console.log('ccw', i);
}
}
// only Holes? -> probably all Shapes with wrong orientation
if
(
!
newShapes
[
0
]
)
return
toShapesNoHoles
(
subPaths
);
if
(
newShapes
.
length
>
1
)
{
var
ambiguous
=
false
;
var
toChange
=
[];
for
(
var
sIdx
=
0
,
sLen
=
newShapes
.
length
;
sIdx
<
sLen
;
sIdx
++
)
{
betterShapeHoles
[
sIdx
]
=
[];
}
for
(
var
sIdx
=
0
,
sLen
=
newShapes
.
length
;
sIdx
<
sLen
;
sIdx
++
)
{
var
sho
=
newShapeHoles
[
sIdx
];
for
(
var
hIdx
=
0
;
hIdx
<
sho
.
length
;
hIdx
++
)
{
var
ho
=
sho
[
hIdx
];
var
hole_unassigned
=
true
;
for
(
var
s2Idx
=
0
;
s2Idx
<
newShapes
.
length
;
s2Idx
++
)
{
if
(
isPointInsidePolygon
(
ho
.
p
,
newShapes
[
s2Idx
].
p
)
)
{
if
(
sIdx
!==
s2Idx
)
toChange
.
push
(
{
froms
:
sIdx
,
tos
:
s2Idx
,
hole
:
hIdx
}
);
if
(
hole_unassigned
)
{
hole_unassigned
=
false
;
betterShapeHoles
[
s2Idx
].
push
(
ho
);
}
else
{
ambiguous
=
true
;
}
}
}
if
(
hole_unassigned
)
{
betterShapeHoles
[
sIdx
].
push
(
ho
);
}
}
}
// console.log("ambiguous: ", ambiguous);
if
(
toChange
.
length
>
0
)
{
// console.log("to change: ", toChange);
if
(
!
ambiguous
)
newShapeHoles
=
betterShapeHoles
;
}
}
var
tmpHoles
;
for
(
var
i
=
0
,
il
=
newShapes
.
length
;
i
<
il
;
i
++
)
{
tmpShape
=
newShapes
[
i
].
s
;
shapes
.
push
(
tmpShape
);
tmpHoles
=
newShapeHoles
[
i
];
for
(
var
j
=
0
,
jl
=
tmpHoles
.
length
;
j
<
jl
;
j
++
)
{
tmpShape
.
holes
.
push
(
tmpHoles
[
j
].
h
);
}
}
//console.log("shape", shapes);
return
shapes
;
}
}
export
{
ShapePath
,
Path
};
export
{
Path
};
src/extras/core/ShapePath.js
0 → 100644
浏览文件 @
a09b189d
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
* minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
**/
import
{
Path
}
from
'
./Path
'
;
import
{
Shape
}
from
'
./Shape
'
;
import
{
ShapeUtils
}
from
'
../ShapeUtils
'
;
function
ShapePath
()
{
this
.
subPaths
=
[];
this
.
currentPath
=
null
;
}
ShapePath
.
prototype
=
{
moveTo
:
function
(
x
,
y
)
{
this
.
currentPath
=
new
Path
();
this
.
subPaths
.
push
(
this
.
currentPath
);
this
.
currentPath
.
moveTo
(
x
,
y
);
},
lineTo
:
function
(
x
,
y
)
{
this
.
currentPath
.
lineTo
(
x
,
y
);
},
quadraticCurveTo
:
function
(
aCPx
,
aCPy
,
aX
,
aY
)
{
this
.
currentPath
.
quadraticCurveTo
(
aCPx
,
aCPy
,
aX
,
aY
);
},
bezierCurveTo
:
function
(
aCP1x
,
aCP1y
,
aCP2x
,
aCP2y
,
aX
,
aY
)
{
this
.
currentPath
.
bezierCurveTo
(
aCP1x
,
aCP1y
,
aCP2x
,
aCP2y
,
aX
,
aY
);
},
splineThru
:
function
(
pts
)
{
this
.
currentPath
.
splineThru
(
pts
);
},
toShapes
:
function
(
isCCW
,
noHoles
)
{
function
toShapesNoHoles
(
inSubpaths
)
{
var
shapes
=
[];
for
(
var
i
=
0
,
l
=
inSubpaths
.
length
;
i
<
l
;
i
++
)
{
var
tmpPath
=
inSubpaths
[
i
];
var
tmpShape
=
new
Shape
();
tmpShape
.
curves
=
tmpPath
.
curves
;
shapes
.
push
(
tmpShape
);
}
return
shapes
;
}
function
isPointInsidePolygon
(
inPt
,
inPolygon
)
{
var
polyLen
=
inPolygon
.
length
;
// inPt on polygon contour => immediate success or
// toggling of inside/outside at every single! intersection point of an edge
// with the horizontal line through inPt, left of inPt
// not counting lowerY endpoints of edges and whole edges on that line
var
inside
=
false
;
for
(
var
p
=
polyLen
-
1
,
q
=
0
;
q
<
polyLen
;
p
=
q
++
)
{
var
edgeLowPt
=
inPolygon
[
p
];
var
edgeHighPt
=
inPolygon
[
q
];
var
edgeDx
=
edgeHighPt
.
x
-
edgeLowPt
.
x
;
var
edgeDy
=
edgeHighPt
.
y
-
edgeLowPt
.
y
;
if
(
Math
.
abs
(
edgeDy
)
>
Number
.
EPSILON
)
{
// not parallel
if
(
edgeDy
<
0
)
{
edgeLowPt
=
inPolygon
[
q
];
edgeDx
=
-
edgeDx
;
edgeHighPt
=
inPolygon
[
p
];
edgeDy
=
-
edgeDy
;
}
if
(
(
inPt
.
y
<
edgeLowPt
.
y
)
||
(
inPt
.
y
>
edgeHighPt
.
y
)
)
continue
;
if
(
inPt
.
y
===
edgeLowPt
.
y
)
{
if
(
inPt
.
x
===
edgeLowPt
.
x
)
return
true
;
// inPt is on contour ?
// continue; // no intersection or edgeLowPt => doesn't count !!!
}
else
{
var
perpEdge
=
edgeDy
*
(
inPt
.
x
-
edgeLowPt
.
x
)
-
edgeDx
*
(
inPt
.
y
-
edgeLowPt
.
y
);
if
(
perpEdge
===
0
)
return
true
;
// inPt is on contour ?
if
(
perpEdge
<
0
)
continue
;
inside
=
!
inside
;
// true intersection left of inPt
}
}
else
{
// parallel or collinear
if
(
inPt
.
y
!==
edgeLowPt
.
y
)
continue
;
// parallel
// edge lies on the same horizontal line as inPt
if
(
(
(
edgeHighPt
.
x
<=
inPt
.
x
)
&&
(
inPt
.
x
<=
edgeLowPt
.
x
)
)
||
(
(
edgeLowPt
.
x
<=
inPt
.
x
)
&&
(
inPt
.
x
<=
edgeHighPt
.
x
)
)
)
return
true
;
// inPt: Point on contour !
// continue;
}
}
return
inside
;
}
var
isClockWise
=
ShapeUtils
.
isClockWise
;
var
subPaths
=
this
.
subPaths
;
if
(
subPaths
.
length
===
0
)
return
[];
if
(
noHoles
===
true
)
return
toShapesNoHoles
(
subPaths
);
var
solid
,
tmpPath
,
tmpShape
,
shapes
=
[];
if
(
subPaths
.
length
===
1
)
{
tmpPath
=
subPaths
[
0
];
tmpShape
=
new
Shape
();
tmpShape
.
curves
=
tmpPath
.
curves
;
shapes
.
push
(
tmpShape
);
return
shapes
;
}
var
holesFirst
=
!
isClockWise
(
subPaths
[
0
].
getPoints
()
);
holesFirst
=
isCCW
?
!
holesFirst
:
holesFirst
;
// console.log("Holes first", holesFirst);
var
betterShapeHoles
=
[];
var
newShapes
=
[];
var
newShapeHoles
=
[];
var
mainIdx
=
0
;
var
tmpPoints
;
newShapes
[
mainIdx
]
=
undefined
;
newShapeHoles
[
mainIdx
]
=
[];
for
(
var
i
=
0
,
l
=
subPaths
.
length
;
i
<
l
;
i
++
)
{
tmpPath
=
subPaths
[
i
];
tmpPoints
=
tmpPath
.
getPoints
();
solid
=
isClockWise
(
tmpPoints
);
solid
=
isCCW
?
!
solid
:
solid
;
if
(
solid
)
{
if
(
(
!
holesFirst
)
&&
(
newShapes
[
mainIdx
]
)
)
mainIdx
++
;
newShapes
[
mainIdx
]
=
{
s
:
new
Shape
(),
p
:
tmpPoints
};
newShapes
[
mainIdx
].
s
.
curves
=
tmpPath
.
curves
;
if
(
holesFirst
)
mainIdx
++
;
newShapeHoles
[
mainIdx
]
=
[];
//console.log('cw', i);
}
else
{
newShapeHoles
[
mainIdx
].
push
(
{
h
:
tmpPath
,
p
:
tmpPoints
[
0
]
}
);
//console.log('ccw', i);
}
}
// only Holes? -> probably all Shapes with wrong orientation
if
(
!
newShapes
[
0
]
)
return
toShapesNoHoles
(
subPaths
);
if
(
newShapes
.
length
>
1
)
{
var
ambiguous
=
false
;
var
toChange
=
[];
for
(
var
sIdx
=
0
,
sLen
=
newShapes
.
length
;
sIdx
<
sLen
;
sIdx
++
)
{
betterShapeHoles
[
sIdx
]
=
[];
}
for
(
var
sIdx
=
0
,
sLen
=
newShapes
.
length
;
sIdx
<
sLen
;
sIdx
++
)
{
var
sho
=
newShapeHoles
[
sIdx
];
for
(
var
hIdx
=
0
;
hIdx
<
sho
.
length
;
hIdx
++
)
{
var
ho
=
sho
[
hIdx
];
var
hole_unassigned
=
true
;
for
(
var
s2Idx
=
0
;
s2Idx
<
newShapes
.
length
;
s2Idx
++
)
{
if
(
isPointInsidePolygon
(
ho
.
p
,
newShapes
[
s2Idx
].
p
)
)
{
if
(
sIdx
!==
s2Idx
)
toChange
.
push
(
{
froms
:
sIdx
,
tos
:
s2Idx
,
hole
:
hIdx
}
);
if
(
hole_unassigned
)
{
hole_unassigned
=
false
;
betterShapeHoles
[
s2Idx
].
push
(
ho
);
}
else
{
ambiguous
=
true
;
}
}
}
if
(
hole_unassigned
)
{
betterShapeHoles
[
sIdx
].
push
(
ho
);
}
}
}
// console.log("ambiguous: ", ambiguous);
if
(
toChange
.
length
>
0
)
{
// console.log("to change: ", toChange);
if
(
!
ambiguous
)
newShapeHoles
=
betterShapeHoles
;
}
}
var
tmpHoles
;
for
(
var
i
=
0
,
il
=
newShapes
.
length
;
i
<
il
;
i
++
)
{
tmpShape
=
newShapes
[
i
].
s
;
shapes
.
push
(
tmpShape
);
tmpHoles
=
newShapeHoles
[
i
];
for
(
var
j
=
0
,
jl
=
tmpHoles
.
length
;
j
<
jl
;
j
++
)
{
tmpShape
.
holes
.
push
(
tmpHoles
[
j
].
h
);
}
}
//console.log("shape", shapes);
return
shapes
;
}
};
export
{
ShapePath
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录