vislite 0.2.0 → 0.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +27 -1
- package/LICENSE +20 -20
- package/README.md +53 -53
- package/lib/Canvas/index.umd.js +87 -14
- package/lib/Canvas/index.umd.min.js +3 -3
- package/lib/Cardinal/index.umd.js +16 -5
- package/lib/Cardinal/index.umd.min.js +3 -3
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +87 -14
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +17 -6
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +78 -62
- package/lib/SVG/index.umd.min.js +3 -3
- package/lib/WebGL/index.umd.js +15 -6
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +2 -2
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/index.umd.js +190 -81
- package/lib/index.umd.min.js +3 -3
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +2 -2
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Canvas/index.ts +1 -1
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/OralCanvas/index.ts +1 -1
- package/package/OralWebGL/index.ts +1 -1
- package/package/SVG/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package.json +4 -4
- package/src/Matrix4/index.ts +76 -76
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/animation.ts +99 -99
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +142 -61
- package/src/common/canvas/gradient.ts +29 -0
- package/src/common/canvas/index.ts +122 -82
- package/src/common/canvas/painter.ts +12 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +173 -128
- package/src/common/svg/index.ts +315 -266
- package/src/common/svg/tool.ts +43 -43
- package/src/common/webgl/doDraw.ts +13 -3
- package/src/common/webgl/getShader.ts +6 -0
- package/src/common/webgl/index.ts +4 -0
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +109 -91
- package/src/interpolation/Hermite.ts +65 -65
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +99 -99
- package/types/Canvas.d.ts +282 -221
- package/types/CanvasConfig.d.ts +3 -3
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +15 -0
- package/types/Hermite.d.ts +18 -18
- package/types/Matrix4.d.ts +42 -42
- package/types/Object3D.d.ts +7 -0
- package/types/SVG.d.ts +210 -210
- package/types/animation.d.ts +6 -6
- package/types/getLoopColors.d.ts +2 -2
- package/types/rotate.d.ts +2 -2
- package/types/ruler.d.ts +2 -2
- package/uni-app/ui-canvas.vue +22 -46
package/lib/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Wed Jun 28 2023 22:51:53 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -67,9 +67,20 @@
|
|
|
67
67
|
if (points[flag][0] <= points[flag - 1][0])
|
|
68
68
|
throw new Error('The point position should be increamented!');
|
|
69
69
|
this.__HS.x[flag] = points[flag][0];
|
|
70
|
-
|
|
71
|
-
(points[flag + 1][1]
|
|
72
|
-
|
|
70
|
+
if (flag < points.length - 1) {
|
|
71
|
+
if ((points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
|
|
72
|
+
(points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
|
|
73
|
+
points[flag + 1][1] == points[flag][1] ||
|
|
74
|
+
points[flag - 1][1] == points[flag][1]) {
|
|
75
|
+
temp = 0;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
|
|
83
|
+
}
|
|
73
84
|
this.__HS.h[flag - 1] = new Hermite((1 - this.__t) * 0.5).setP(points[flag - 1][0], points[flag - 1][1], points[flag][0], points[flag][1], slope, temp);
|
|
74
85
|
slope = temp;
|
|
75
86
|
}
|
|
@@ -511,22 +522,22 @@
|
|
|
511
522
|
}
|
|
512
523
|
|
|
513
524
|
var initText$1 = function (el, config, x, y, deg) {
|
|
514
|
-
if (el.nodeName.toLowerCase() !==
|
|
515
|
-
throw new Error(
|
|
525
|
+
if (el.nodeName.toLowerCase() !== "text")
|
|
526
|
+
throw new Error("Need a <text> !");
|
|
516
527
|
setAttribute(el, "dy", {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
528
|
+
top: config["fontSize"] * 0.5,
|
|
529
|
+
middle: 0,
|
|
530
|
+
bottom: -config["fontSize"] * 0.5,
|
|
520
531
|
}[config.textBaseline]);
|
|
521
532
|
setStyle(el, {
|
|
522
533
|
"text-anchor": {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
534
|
+
left: "start",
|
|
535
|
+
right: "end",
|
|
536
|
+
center: "middle",
|
|
526
537
|
}[config.textAlign],
|
|
527
538
|
"dominant-baseline": "central",
|
|
528
|
-
"font-size": config[
|
|
529
|
-
"font-family": config[
|
|
539
|
+
"font-size": config["fontSize"] + "px",
|
|
540
|
+
"font-family": config["fontFamily"],
|
|
530
541
|
});
|
|
531
542
|
setAttribute(el, "x", x);
|
|
532
543
|
setAttribute(el, "y", y);
|
|
@@ -536,20 +547,20 @@
|
|
|
536
547
|
}
|
|
537
548
|
};
|
|
538
549
|
var initCircle$1 = function (el, cx, cy, r) {
|
|
539
|
-
if (el.nodeName.toLowerCase() !==
|
|
540
|
-
throw new Error(
|
|
541
|
-
setAttribute(el,
|
|
542
|
-
setAttribute(el,
|
|
543
|
-
setAttribute(el,
|
|
550
|
+
if (el.nodeName.toLowerCase() !== "circle")
|
|
551
|
+
throw new Error("Need a <circle> !");
|
|
552
|
+
setAttribute(el, "cx", cx);
|
|
553
|
+
setAttribute(el, "cy", cy);
|
|
554
|
+
setAttribute(el, "r", r);
|
|
544
555
|
};
|
|
545
556
|
var initPath = function (el, path) {
|
|
546
|
-
if (el.nodeName.toLowerCase() !==
|
|
547
|
-
throw new Error(
|
|
548
|
-
setAttribute(el,
|
|
557
|
+
if (el.nodeName.toLowerCase() !== "path")
|
|
558
|
+
throw new Error("Need a <path> !");
|
|
559
|
+
setAttribute(el, "d", path);
|
|
549
560
|
};
|
|
550
561
|
var initRect$1 = function (el, x, y, width, height) {
|
|
551
|
-
if (el.nodeName.toLowerCase() !==
|
|
552
|
-
throw new Error(
|
|
562
|
+
if (el.nodeName.toLowerCase() !== "rect")
|
|
563
|
+
throw new Error("Need a <rect> !");
|
|
553
564
|
if (height < 0) {
|
|
554
565
|
height *= -1;
|
|
555
566
|
y -= height;
|
|
@@ -558,14 +569,16 @@
|
|
|
558
569
|
width *= -1;
|
|
559
570
|
x -= width;
|
|
560
571
|
}
|
|
561
|
-
setAttribute(el,
|
|
562
|
-
setAttribute(el,
|
|
563
|
-
setAttribute(el,
|
|
564
|
-
setAttribute(el,
|
|
572
|
+
setAttribute(el, "x", x);
|
|
573
|
+
setAttribute(el, "y", y);
|
|
574
|
+
setAttribute(el, "width", width);
|
|
575
|
+
setAttribute(el, "height", height);
|
|
565
576
|
};
|
|
566
577
|
var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
567
|
-
if (el.nodeName.toLowerCase() !==
|
|
568
|
-
throw new Error(
|
|
578
|
+
if (el.nodeName.toLowerCase() !== "path")
|
|
579
|
+
throw new Error("Need a <path> !");
|
|
580
|
+
beginDeg = (beginDeg / 180) * Math.PI;
|
|
581
|
+
deg = (deg / 180) * Math.PI;
|
|
569
582
|
beginDeg = beginDeg % (Math.PI * 2);
|
|
570
583
|
if (r1 > r2) {
|
|
571
584
|
var temp = r1;
|
|
@@ -579,27 +592,28 @@
|
|
|
579
592
|
deg = deg % (Math.PI * 2);
|
|
580
593
|
}
|
|
581
594
|
arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
|
|
582
|
-
var f =
|
|
595
|
+
var f = endA - beginA > Math.PI ? 1 : 0, d = "M" + begInnerX + " " + begInnerY;
|
|
583
596
|
if (r < 0)
|
|
584
597
|
r = -r;
|
|
585
598
|
d +=
|
|
586
599
|
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
|
|
587
|
-
if (config
|
|
600
|
+
if (config.arcEndCap == "round")
|
|
588
601
|
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
|
|
589
|
-
else if (config
|
|
602
|
+
else if (config.arcEndCap == "-round")
|
|
590
603
|
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
|
|
591
604
|
else
|
|
592
605
|
d += "L" + endOuterX + " " + endOuterY;
|
|
593
|
-
d +=
|
|
594
|
-
|
|
606
|
+
d +=
|
|
607
|
+
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
|
|
608
|
+
if (config.arcStartCap == "round")
|
|
595
609
|
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
|
|
596
|
-
else if (config
|
|
610
|
+
else if (config.arcStartCap == "-round")
|
|
597
611
|
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
|
|
598
612
|
else
|
|
599
613
|
d += "L" + begInnerX + " " + begInnerY;
|
|
600
|
-
if (config
|
|
614
|
+
if (config.arcStartCap == "butt")
|
|
601
615
|
d += "Z";
|
|
602
|
-
setAttribute(el,
|
|
616
|
+
setAttribute(el, "d", d);
|
|
603
617
|
});
|
|
604
618
|
};
|
|
605
619
|
|
|
@@ -607,29 +621,29 @@
|
|
|
607
621
|
"font-size": "fontSize",
|
|
608
622
|
"font-family": "fontFamily",
|
|
609
623
|
"arc-start-cap": "arcStartCap",
|
|
610
|
-
"arc-end-cap": "arcEndCap"
|
|
624
|
+
"arc-end-cap": "arcEndCap",
|
|
611
625
|
};
|
|
612
626
|
var SVG$1 = (function () {
|
|
613
627
|
function SVG(svg) {
|
|
614
628
|
this.name = "SVG";
|
|
615
629
|
this.__config = {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
630
|
+
fillStyle: "#000",
|
|
631
|
+
strokeStyle: "#000",
|
|
632
|
+
lineWidth: 1,
|
|
633
|
+
textAlign: "left",
|
|
634
|
+
textBaseline: "middle",
|
|
621
635
|
"font-size": 16,
|
|
622
636
|
"font-family": "sans-serif",
|
|
623
637
|
"arc-start-cap": "butt",
|
|
624
638
|
"arc-end-cap": "butt",
|
|
625
|
-
|
|
639
|
+
lineDash: [],
|
|
626
640
|
};
|
|
627
641
|
this.__path = "";
|
|
628
642
|
this.__currentPosition = [];
|
|
629
643
|
this.__svg = svg;
|
|
630
644
|
}
|
|
631
645
|
SVG.prototype.config = function (params) {
|
|
632
|
-
if (typeof params !==
|
|
646
|
+
if (typeof params !== "object") {
|
|
633
647
|
return this.__config[oldAttrName$1[params] || params];
|
|
634
648
|
}
|
|
635
649
|
else {
|
|
@@ -649,7 +663,7 @@
|
|
|
649
663
|
};
|
|
650
664
|
SVG.prototype.appendEl = function (el, context) {
|
|
651
665
|
context = context || this.__svg;
|
|
652
|
-
if (typeof el ==
|
|
666
|
+
if (typeof el == "string")
|
|
653
667
|
el = toNode(el);
|
|
654
668
|
context.appendChild(el);
|
|
655
669
|
this.__useEl = el;
|
|
@@ -657,14 +671,15 @@
|
|
|
657
671
|
};
|
|
658
672
|
SVG.prototype.appendBoard = function (el, context) {
|
|
659
673
|
var _el = el;
|
|
660
|
-
if (typeof el ==
|
|
661
|
-
_el =
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
674
|
+
if (typeof el == "string")
|
|
675
|
+
_el =
|
|
676
|
+
{
|
|
677
|
+
text: "text",
|
|
678
|
+
path: "path",
|
|
679
|
+
arc: "path",
|
|
680
|
+
circle: "circle",
|
|
681
|
+
rect: "rect",
|
|
682
|
+
}[el] || "";
|
|
668
683
|
if (_el == "")
|
|
669
684
|
throw new Error("Unsupported drawing method:" + el);
|
|
670
685
|
return this.appendEl(_el, context);
|
|
@@ -681,7 +696,7 @@
|
|
|
681
696
|
SVG.prototype.attr = function (params) {
|
|
682
697
|
if (!this.__useEl)
|
|
683
698
|
throw new Error("Currently, no node can be modified or viewed.");
|
|
684
|
-
if (typeof params !==
|
|
699
|
+
if (typeof params !== "object") {
|
|
685
700
|
return getAttribute(this.__useEl, params);
|
|
686
701
|
}
|
|
687
702
|
else {
|
|
@@ -792,17 +807,28 @@
|
|
|
792
807
|
return this;
|
|
793
808
|
};
|
|
794
809
|
SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
|
|
795
|
-
var begPosition = rotate$1(x, y, beginDeg, x + r, y);
|
|
796
|
-
var endPosition = rotate$1(x, y, beginDeg + deg, x + r, y);
|
|
797
|
-
|
|
798
|
-
deg = deg / Math.PI * 180;
|
|
799
|
-
if (this.__path == '') {
|
|
810
|
+
var begPosition = rotate$1(x, y, (beginDeg / 180) * Math.PI, x + r, y);
|
|
811
|
+
var endPosition = rotate$1(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
|
|
812
|
+
if (this.__path == "") {
|
|
800
813
|
this.__path += "M" + begPosition[0] + "," + begPosition[1];
|
|
801
814
|
}
|
|
802
|
-
else if (begPosition[0] != this.__currentPosition[0] ||
|
|
815
|
+
else if (begPosition[0] != this.__currentPosition[0] ||
|
|
816
|
+
begPosition[1] != this.__currentPosition[1]) {
|
|
803
817
|
this.__path += "L" + begPosition[0] + "," + begPosition[1];
|
|
804
818
|
}
|
|
805
|
-
this.__path +=
|
|
819
|
+
this.__path +=
|
|
820
|
+
"A" +
|
|
821
|
+
r +
|
|
822
|
+
"," +
|
|
823
|
+
r +
|
|
824
|
+
" 0 " +
|
|
825
|
+
(deg > 180 || deg < -180 ? 1 : 0) +
|
|
826
|
+
"," +
|
|
827
|
+
(deg > 0 ? 1 : 0) +
|
|
828
|
+
" " +
|
|
829
|
+
endPosition[0] +
|
|
830
|
+
"," +
|
|
831
|
+
endPosition[1];
|
|
806
832
|
return this;
|
|
807
833
|
};
|
|
808
834
|
SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
@@ -810,7 +836,8 @@
|
|
|
810
836
|
return this;
|
|
811
837
|
};
|
|
812
838
|
SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
813
|
-
this.__path +=
|
|
839
|
+
this.__path +=
|
|
840
|
+
"C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
|
|
814
841
|
return this;
|
|
815
842
|
};
|
|
816
843
|
return SVG;
|
|
@@ -837,7 +864,14 @@
|
|
|
837
864
|
painter.beginPath();
|
|
838
865
|
painter.translate(x, y);
|
|
839
866
|
painter.rotate(deg);
|
|
840
|
-
painter.font =
|
|
867
|
+
painter.font =
|
|
868
|
+
config.fontStyle +
|
|
869
|
+
" " +
|
|
870
|
+
config.fontWeight +
|
|
871
|
+
" " +
|
|
872
|
+
config.fontSize +
|
|
873
|
+
"px " +
|
|
874
|
+
config.fontFamily;
|
|
841
875
|
return painter;
|
|
842
876
|
};
|
|
843
877
|
var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
@@ -859,17 +893,21 @@
|
|
|
859
893
|
painter.beginPath();
|
|
860
894
|
painter.moveTo(begInnerX, begInnerY);
|
|
861
895
|
painter.arc(cx, cy, r1, beginA, endA, false);
|
|
862
|
-
if (config.arcEndCap
|
|
863
|
-
painter.lineTo(endOuterX, endOuterY);
|
|
864
|
-
else
|
|
896
|
+
if (config.arcEndCap == "round")
|
|
865
897
|
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
painter.lineTo(begInnerX, begInnerY);
|
|
898
|
+
else if (config.arcEndCap == "-round")
|
|
899
|
+
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
|
|
869
900
|
else
|
|
901
|
+
painter.lineTo(endOuterX, endOuterY);
|
|
902
|
+
painter.arc(cx, cy, r2, endA, beginA, true);
|
|
903
|
+
if (config.arcStartCap == "round")
|
|
870
904
|
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
|
|
905
|
+
else if (config.arcStartCap == "-round")
|
|
906
|
+
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
|
|
907
|
+
else
|
|
908
|
+
painter.lineTo(begInnerX, begInnerY);
|
|
871
909
|
});
|
|
872
|
-
if (config.arcStartCap ==
|
|
910
|
+
if (config.arcStartCap == "butt")
|
|
873
911
|
painter.closePath();
|
|
874
912
|
return painter;
|
|
875
913
|
};
|
|
@@ -942,6 +980,9 @@
|
|
|
942
980
|
this.painter.setLineDash(value);
|
|
943
981
|
}
|
|
944
982
|
else if (key in this.__specialConfig) {
|
|
983
|
+
if (key == 'fontSize') {
|
|
984
|
+
value = Math.round(value);
|
|
985
|
+
}
|
|
945
986
|
this.__specialConfig[key] = value;
|
|
946
987
|
}
|
|
947
988
|
else if (key in this.__initConfig) {
|
|
@@ -1085,6 +1126,12 @@
|
|
|
1085
1126
|
this.painter.restore();
|
|
1086
1127
|
return this;
|
|
1087
1128
|
};
|
|
1129
|
+
Painter.prototype.clip = function () {
|
|
1130
|
+
if (this.__region)
|
|
1131
|
+
this.__region.clip();
|
|
1132
|
+
this.painter.clip();
|
|
1133
|
+
return this;
|
|
1134
|
+
};
|
|
1088
1135
|
Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
1089
1136
|
if (this.__region)
|
|
1090
1137
|
this.__region.quadraticCurveTo(cpx, cpy, x, y);
|
|
@@ -1184,19 +1231,46 @@
|
|
|
1184
1231
|
};
|
|
1185
1232
|
}
|
|
1186
1233
|
|
|
1234
|
+
var linearGradient = function (painter, x0, y0, x1, y1) {
|
|
1235
|
+
var gradient = painter.createLinearGradient(x0, y0, x1, y1);
|
|
1236
|
+
var enhanceGradient = {
|
|
1237
|
+
"value": function () {
|
|
1238
|
+
return gradient;
|
|
1239
|
+
},
|
|
1240
|
+
"setColor": function (stop, color) {
|
|
1241
|
+
gradient.addColorStop(stop, color);
|
|
1242
|
+
return enhanceGradient;
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
return enhanceGradient;
|
|
1246
|
+
};
|
|
1247
|
+
var radialGradient = function (painter, cx, cy, r) {
|
|
1248
|
+
var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
1249
|
+
var enhanceGradient = {
|
|
1250
|
+
"value": function () {
|
|
1251
|
+
return gradient;
|
|
1252
|
+
},
|
|
1253
|
+
"setColor": function (stop, color) {
|
|
1254
|
+
gradient.addColorStop(stop, color);
|
|
1255
|
+
return enhanceGradient;
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
return enhanceGradient;
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1187
1261
|
var oldAttrName = {
|
|
1188
1262
|
"font-size": "fontSize",
|
|
1189
1263
|
"font-family": "fontFamily",
|
|
1190
1264
|
"font-weight": "fontWeight",
|
|
1191
1265
|
"font-style": "fontStyle",
|
|
1192
1266
|
"arc-start-cap": "arcStartCap",
|
|
1193
|
-
"arc-end-cap": "arcEndCap"
|
|
1267
|
+
"arc-end-cap": "arcEndCap",
|
|
1194
1268
|
};
|
|
1195
1269
|
var Canvas$1 = (function (_super) {
|
|
1196
1270
|
__extends(Canvas, _super);
|
|
1197
1271
|
function Canvas(ViewCanvas, RegionCanvas) {
|
|
1198
1272
|
var _this = _super.call(this, ViewCanvas, {}, new Painter(RegionCanvas, {
|
|
1199
|
-
willReadFrequently: true
|
|
1273
|
+
willReadFrequently: true,
|
|
1200
1274
|
})) || this;
|
|
1201
1275
|
_this.name = "Canvas";
|
|
1202
1276
|
_this.__regionList = {};
|
|
@@ -1215,7 +1289,8 @@
|
|
|
1215
1289
|
if (regionName) {
|
|
1216
1290
|
if (this.__regionList[regionName] == undefined) {
|
|
1217
1291
|
var tempColor = this.__regionAssemble();
|
|
1218
|
-
this.__regionList[regionName] =
|
|
1292
|
+
this.__regionList[regionName] =
|
|
1293
|
+
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
|
|
1219
1294
|
}
|
|
1220
1295
|
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
1221
1296
|
this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
|
|
@@ -1233,7 +1308,14 @@
|
|
|
1233
1308
|
var currentRGBA = imgData.data;
|
|
1234
1309
|
var doit = function () {
|
|
1235
1310
|
for (var key in _this.__regionList) {
|
|
1236
|
-
if ("rgb(" +
|
|
1311
|
+
if ("rgb(" +
|
|
1312
|
+
currentRGBA[0] +
|
|
1313
|
+
"," +
|
|
1314
|
+
currentRGBA[1] +
|
|
1315
|
+
"," +
|
|
1316
|
+
currentRGBA[2] +
|
|
1317
|
+
")" ==
|
|
1318
|
+
_this.__regionList[key]) {
|
|
1237
1319
|
resolve(key);
|
|
1238
1320
|
break;
|
|
1239
1321
|
}
|
|
@@ -1255,6 +1337,24 @@
|
|
|
1255
1337
|
if (isRegion === void 0) { isRegion = false; }
|
|
1256
1338
|
return isRegion ? this.__region.painter : this.painter;
|
|
1257
1339
|
};
|
|
1340
|
+
Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
|
|
1341
|
+
return linearGradient(this.painter, x0, y0, x1, y1);
|
|
1342
|
+
};
|
|
1343
|
+
Canvas.prototype.createRadialGradient = function (cx, cy, r) {
|
|
1344
|
+
return radialGradient(this.painter, cx, cy, r);
|
|
1345
|
+
};
|
|
1346
|
+
Canvas.prototype.getColor = function (x, y) {
|
|
1347
|
+
var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
|
|
1348
|
+
return ("rgba(" +
|
|
1349
|
+
currentRGBA[0] +
|
|
1350
|
+
"," +
|
|
1351
|
+
currentRGBA[1] +
|
|
1352
|
+
"," +
|
|
1353
|
+
currentRGBA[2] +
|
|
1354
|
+
"," +
|
|
1355
|
+
currentRGBA[3] +
|
|
1356
|
+
")");
|
|
1357
|
+
};
|
|
1258
1358
|
return Canvas;
|
|
1259
1359
|
}(Painter));
|
|
1260
1360
|
|
|
@@ -1477,11 +1577,12 @@
|
|
|
1477
1577
|
(mesh.geometry.attributes.normal ? "1" : "0") +
|
|
1478
1578
|
(mesh.material.image ? "1" : "0") +
|
|
1479
1579
|
(mesh.material.color ? "1" : "0") +
|
|
1580
|
+
(mesh.material.colors ? "1" : "0") +
|
|
1480
1581
|
(mesh.material.cube ? "1" : "0");
|
|
1481
1582
|
if (shaders[uniqueName])
|
|
1482
1583
|
return shaders[uniqueName].use();
|
|
1483
|
-
var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
|
|
1484
|
-
var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n }\n ");
|
|
1584
|
+
var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n ").concat(mesh.material.colors ? 'attribute vec4 a_color;varying vec4 v_color;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n ").concat(mesh.material.colors ? 'v_color=a_color;' : '', "\n }\n ");
|
|
1585
|
+
var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n ").concat(mesh.material.colors ? 'varying vec4 v_color;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n ").concat(mesh.material.colors ? 'gl_FragColor=v_color;' : '', "\n }\n ");
|
|
1485
1586
|
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
1486
1587
|
shaders[uniqueName] = shader;
|
|
1487
1588
|
return shader;
|
|
@@ -1491,18 +1592,23 @@
|
|
|
1491
1592
|
var shader = getShader(type, painter, mesh);
|
|
1492
1593
|
new BufferObject(painter).use()
|
|
1493
1594
|
.write(mesh.geometry.attributes.position.array)
|
|
1494
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize,
|
|
1595
|
+
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
1495
1596
|
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
1496
1597
|
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
1497
1598
|
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
1498
1599
|
if (mesh.geometry.attributes.normal) {
|
|
1499
1600
|
new BufferObject(painter).use()
|
|
1500
1601
|
.write(mesh.geometry.attributes.normal.array)
|
|
1501
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize,
|
|
1602
|
+
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
1502
1603
|
}
|
|
1503
1604
|
if ("color" in mesh.material) {
|
|
1504
1605
|
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
|
|
1505
1606
|
}
|
|
1607
|
+
if ("colors" in mesh.material) {
|
|
1608
|
+
new BufferObject(painter).use()
|
|
1609
|
+
.write(mesh.material.colors.array)
|
|
1610
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0);
|
|
1611
|
+
}
|
|
1506
1612
|
else if ("cube" in mesh.material) {
|
|
1507
1613
|
var size = mesh.material.cube.right.image.value.width;
|
|
1508
1614
|
getTexture(type, painter, 'cube').useCube([
|
|
@@ -1645,6 +1751,9 @@
|
|
|
1645
1751
|
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
1646
1752
|
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
1647
1753
|
}
|
|
1754
|
+
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
1755
|
+
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
1756
|
+
}
|
|
1648
1757
|
}
|
|
1649
1758
|
this.__scene.children.push(object3D);
|
|
1650
1759
|
this.draw(object3D);
|