vislite 0.8.0 → 1.0.0-next.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.
Files changed (203) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +18 -2
  3. package/LICENSE +20 -20
  4. package/README.md +2 -36
  5. package/lib/Buffer/index.umd.js +2 -2
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +9 -24
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +2 -2
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +2 -2
  12. package/lib/Eoap/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/SVG/index.umd.js +19 -35
  20. package/lib/SVG/index.umd.min.js +3 -3
  21. package/lib/Shader/index.umd.js +3 -82
  22. package/lib/Shader/index.umd.min.js +3 -3
  23. package/lib/Texture/index.umd.js +2 -2
  24. package/lib/Texture/index.umd.min.js +2 -2
  25. package/lib/TreeLayout/index.umd.js +2 -2
  26. package/lib/TreeLayout/index.umd.min.js +2 -2
  27. package/lib/animation/index.umd.js +2 -2
  28. package/lib/animation/index.umd.min.js +2 -2
  29. package/lib/getLoopColors/index.umd.js +2 -2
  30. package/lib/getLoopColors/index.umd.min.js +2 -2
  31. package/lib/getWebGLContext/index.umd.js +2 -2
  32. package/lib/getWebGLContext/index.umd.min.js +2 -2
  33. package/lib/index.umd.js +104 -975
  34. package/lib/index.umd.min.js +3 -3
  35. package/lib/move/index.umd.js +2 -2
  36. package/lib/move/index.umd.min.js +2 -2
  37. package/lib/rotate/index.umd.js +2 -2
  38. package/lib/rotate/index.umd.min.js +2 -2
  39. package/lib/ruler/index.umd.js +2 -2
  40. package/lib/ruler/index.umd.min.js +2 -2
  41. package/lib/scale/index.umd.js +2 -2
  42. package/lib/scale/index.umd.min.js +2 -2
  43. package/lib/throttle/index.umd.js +2 -2
  44. package/lib/throttle/index.umd.min.js +2 -2
  45. package/miniprogram/ui-canvas/index.js +100 -107
  46. package/miniprogram/ui-canvas/index.json +4 -4
  47. package/miniprogram/ui-canvas/index.wxml +4 -4
  48. package/miniprogram/ui-canvas/index.wxss +5 -5
  49. package/package/Buffer/index.ts +2 -2
  50. package/package/Canvas/index.ts +2 -2
  51. package/package/Cardinal/index.ts +2 -2
  52. package/package/Eoap/index.ts +2 -2
  53. package/package/Hermite/index.ts +2 -2
  54. package/package/Matrix4/index.ts +2 -2
  55. package/package/Mercator/index.ts +2 -2
  56. package/package/SVG/index.ts +2 -2
  57. package/package/Shader/index.ts +2 -39
  58. package/package/Texture/index.ts +2 -2
  59. package/package/TreeLayout/index.ts +2 -2
  60. package/package/animation/index.ts +2 -2
  61. package/package/getLoopColors/index.ts +2 -2
  62. package/package/index.ts +65 -76
  63. package/package/move/index.ts +2 -2
  64. package/package/rotate/index.ts +2 -2
  65. package/package/ruler/index.ts +2 -2
  66. package/package/scale/index.ts +2 -2
  67. package/package/throttle/index.ts +2 -2
  68. package/package.json +1 -1
  69. package/src/Eoap.ts +66 -66
  70. package/src/Matrix4/index.ts +84 -84
  71. package/src/Matrix4/move.ts +12 -12
  72. package/src/Matrix4/rotate.ts +15 -15
  73. package/src/Matrix4/scale.ts +11 -11
  74. package/src/Matrix4/transform.ts +64 -64
  75. package/src/Mercator.ts +27 -27
  76. package/src/SVG.ts +24 -24
  77. package/src/animation.ts +98 -98
  78. package/src/common/assemble.ts +22 -22
  79. package/src/common/canvas/arc.ts +51 -51
  80. package/src/common/canvas/config.ts +158 -158
  81. package/src/common/canvas/gradient.ts +24 -29
  82. package/src/common/canvas/index.ts +1 -12
  83. package/src/common/canvas/texts.ts +18 -18
  84. package/src/common/mergeOption.ts +6 -6
  85. package/src/common/setStyle.ts +5 -5
  86. package/src/common/svg/config.ts +190 -190
  87. package/src/common/svg/gradient.ts +53 -63
  88. package/src/common/svg/index.ts +347 -356
  89. package/src/common/svg/tool.ts +44 -44
  90. package/src/common/tree/index.ts +25 -25
  91. package/src/common/tree/toInnerTree.ts +59 -59
  92. package/src/common/tree/toPlainTree.ts +132 -132
  93. package/src/common/webgl/buffer.ts +79 -79
  94. package/src/common/webgl/getWebGLContext.ts +1 -1
  95. package/src/common/webgl/shader.ts +75 -75
  96. package/src/common/webgl/texture.ts +97 -97
  97. package/src/getLoopColors.ts +42 -42
  98. package/src/interpolation/Cardinal.ts +110 -110
  99. package/src/interpolation/Hermite.ts +65 -65
  100. package/src/layout/TreeLayout.ts +188 -188
  101. package/src/move.ts +7 -7
  102. package/src/rotate.ts +7 -7
  103. package/src/ruler.ts +209 -209
  104. package/src/scale.ts +6 -6
  105. package/src/throttle.ts +52 -52
  106. package/types/Buffer.d.ts +23 -23
  107. package/types/CanvasConfig.d.ts +106 -106
  108. package/types/CanvasOption.d.ts +8 -8
  109. package/types/CanvasOpts.d.ts +9 -9
  110. package/types/Cardinal.d.ts +13 -13
  111. package/types/Gradient.d.ts +14 -14
  112. package/types/Hermite.d.ts +18 -18
  113. package/types/Map.d.ts +9 -9
  114. package/types/Matrix4.d.ts +47 -47
  115. package/types/SVG.d.ts +238 -238
  116. package/types/SVGConfig.d.ts +79 -79
  117. package/types/Shader.d.ts +16 -23
  118. package/types/Texture.d.ts +16 -16
  119. package/types/Tree.d.ts +69 -69
  120. package/types/TreeConfig.d.ts +36 -36
  121. package/types/TreeLayout.d.ts +54 -54
  122. package/types/TreeOption.d.ts +48 -48
  123. package/types/animation.d.ts +9 -6
  124. package/types/getLoopColors.d.ts +5 -2
  125. package/types/getWebGLContext.d.ts +3 -0
  126. package/types/index.d.ts +146 -176
  127. package/types/move.d.ts +5 -2
  128. package/types/painterConfig.d.ts +2 -2
  129. package/types/rotate.d.ts +5 -2
  130. package/types/ruler.d.ts +10 -7
  131. package/types/scale.d.ts +5 -2
  132. package/types/throttle.d.ts +7 -4
  133. package/types/throttleOption.d.ts +21 -21
  134. package/uni-app/ui-canvas.vue +4 -11
  135. package/lib/Geometry/index.umd.d.ts +0 -3
  136. package/lib/Geometry/index.umd.js +0 -353
  137. package/lib/Geometry/index.umd.min.d.ts +0 -3
  138. package/lib/Geometry/index.umd.min.js +0 -11
  139. package/lib/OralCanvas/index.es.d.ts +0 -3
  140. package/lib/OralCanvas/index.es.js +0 -693
  141. package/lib/OralCanvas/index.es.min.d.ts +0 -3
  142. package/lib/OralCanvas/index.es.min.js +0 -11
  143. package/lib/OralWebGL/index.es.d.ts +0 -3
  144. package/lib/OralWebGL/index.es.js +0 -639
  145. package/lib/OralWebGL/index.es.min.d.ts +0 -3
  146. package/lib/OralWebGL/index.es.min.js +0 -11
  147. package/lib/WebGL/index.umd.d.ts +0 -3
  148. package/lib/WebGL/index.umd.js +0 -712
  149. package/lib/WebGL/index.umd.min.d.ts +0 -3
  150. package/lib/WebGL/index.umd.min.js +0 -11
  151. package/lib/formatColor/index.umd.d.ts +0 -3
  152. package/lib/formatColor/index.umd.js +0 -59
  153. package/lib/formatColor/index.umd.min.d.ts +0 -3
  154. package/lib/formatColor/index.umd.min.js +0 -11
  155. package/lib/resizeObserver/index.umd.d.ts +0 -3
  156. package/lib/resizeObserver/index.umd.js +0 -49
  157. package/lib/resizeObserver/index.umd.min.d.ts +0 -3
  158. package/lib/resizeObserver/index.umd.min.js +0 -11
  159. package/lib/viewHandler/index.umd.d.ts +0 -3
  160. package/lib/viewHandler/index.umd.js +0 -139
  161. package/lib/viewHandler/index.umd.min.d.ts +0 -3
  162. package/lib/viewHandler/index.umd.min.js +0 -11
  163. package/package/Geometry/index.ts +0 -3
  164. package/package/OralCanvas/index.ts +0 -3
  165. package/package/OralWebGL/index.ts +0 -3
  166. package/package/WebGL/index.ts +0 -3
  167. package/package/formatColor/index.ts +0 -3
  168. package/package/resizeObserver/index.ts +0 -3
  169. package/package/viewHandler/index.ts +0 -3
  170. package/src/Geometry.ts +0 -211
  171. package/src/WebGL.ts +0 -67
  172. package/src/common/geometry/prism-horizontal.ts +0 -50
  173. package/src/common/geometry/prism-vertical.ts +0 -55
  174. package/src/common/geometry/sphere-fragment.ts +0 -40
  175. package/src/common/geometry/tool/circle.ts +0 -18
  176. package/src/common/geometry/tool/rotateLine.ts +0 -49
  177. package/src/common/geometry/tool/triangles.ts +0 -24
  178. package/src/common/webgl/doDraw.ts +0 -109
  179. package/src/common/webgl/getColorFactory.ts +0 -27
  180. package/src/common/webgl/getShader.ts +0 -49
  181. package/src/common/webgl/getTexture.ts +0 -12
  182. package/src/common/webgl/index.ts +0 -228
  183. package/src/formatColor.ts +0 -45
  184. package/src/resizeObserver.ts +0 -38
  185. package/src/shader/fsColor.c +0 -8
  186. package/src/shader/fsColors.c +0 -8
  187. package/src/shader/fsCube.c +0 -9
  188. package/src/shader/fsImage.c +0 -9
  189. package/src/shader/vsColor.c +0 -18
  190. package/src/shader/vsColors.c +0 -14
  191. package/src/shader/vsCube.c +0 -14
  192. package/src/shader/vsImage.c +0 -14
  193. package/src/viewHandler.ts +0 -161
  194. package/types/Geometry.d.ts +0 -133
  195. package/types/GeometryOption.d.ts +0 -12
  196. package/types/GeometryResult.d.ts +0 -19
  197. package/types/Object3D.d.ts +0 -115
  198. package/types/Scene3D.d.ts +0 -7
  199. package/types/WebGL.d.ts +0 -39
  200. package/types/WebGLOption.d.ts +0 -15
  201. package/types/formatColor.d.ts +0 -3
  202. package/types/resizeObserver.d.ts +0 -3
  203. package/types/viewHandler.d.ts +0 -14
package/src/WebGL.ts DELETED
@@ -1,67 +0,0 @@
1
- import type WebGLOptionType from '../types/WebGLOption'
2
- import type WebGLType from '../types/WebGL'
3
-
4
- import OralWebGL from './common/webgl/index'
5
- import mergeOption from './common/mergeOption'
6
-
7
- class WebGL extends OralWebGL implements WebGLType {
8
- constructor(el: HTMLElement | null, option: WebGLOptionType = {}) {
9
- if (!el) {
10
- throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.")
11
- }
12
-
13
- option = mergeOption(option, {
14
- region: true
15
- })
16
-
17
- const width = el.clientWidth, height = el.clientHeight
18
-
19
- let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
20
-
21
- const _el = el as any
22
-
23
- // 如果已经初始化过了
24
- if (_el._vislite_canvas_) {
25
- ViewCanvas = _el._vislite_canvas_[0]
26
- RegionCanvas = _el._vislite_canvas_[1]
27
- }
28
-
29
- // 否则就初始化
30
- else {
31
-
32
- if (option.region) {
33
-
34
- RegionCanvas = document.createElement('canvas')
35
- el.appendChild(RegionCanvas)
36
-
37
- RegionCanvas.style.position = 'absolute'
38
- RegionCanvas.style.zIndex = "-1"
39
- RegionCanvas.style.opacity = "0"
40
-
41
- }
42
-
43
- ViewCanvas = document.createElement('canvas')
44
- el.appendChild(ViewCanvas)
45
-
46
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
47
-
48
- el.setAttribute('vislite', 'WebGL')
49
- }
50
-
51
- // 设置画布大小
52
- for (const canvas of [ViewCanvas, RegionCanvas]) {
53
-
54
- if (canvas) {
55
- canvas.style.width = width + "px"
56
- canvas.setAttribute('width', width + "")
57
-
58
- canvas.style.height = height + "px"
59
- canvas.setAttribute('height', height + "")
60
- }
61
- }
62
-
63
- super(ViewCanvas, RegionCanvas, option.mode)
64
- }
65
- }
66
-
67
- export default WebGL
@@ -1,50 +0,0 @@
1
- import rotate from '../../rotate'
2
-
3
- /**
4
- * 棱柱水平部分
5
- * @param normal 是否需要法向量
6
- * @param x 中心
7
- * @param y
8
- * @param z
9
- * @param radius 半径
10
- * @param num 份数
11
- * @param d 方向(用于 表示是底还是顶,方便计算法向量)
12
- * @param beginDeg 开始弧度,默认0
13
- * @param deg 跨越弧度,默认2pi
14
- * @returns 点数组
15
- */
16
- export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
17
-
18
- let beginX: number, beginZ: number
19
- if (num == 4) {
20
- const temp = radius / 1.414
21
- beginX = x + temp
22
- beginZ = z + temp
23
-
24
- } else {
25
- beginX = x + radius
26
- beginZ = z
27
- }
28
-
29
- let point = [beginX, beginZ]
30
- if (beginDeg != 0) {
31
- point = rotate(x, z, beginDeg, beginX, beginZ)
32
- }
33
-
34
- const points = []
35
- const perDeg = deg / num
36
- for (let i = 0; i < num; i++) {
37
-
38
- points.push(x, y, z)
39
- if (normal) points.push(0, d, 0)
40
-
41
- points.push(point[0], y, point[1])
42
- if (normal) points.push(0, d, 0)
43
-
44
- point = rotate(x, z, perDeg * (i + 1), beginX, beginZ)
45
- points.push(point[0], y, point[1])
46
- if (normal) points.push(0, d, 0)
47
- }
48
-
49
- return points
50
- }
@@ -1,55 +0,0 @@
1
- import rotate from '../../rotate'
2
-
3
- /**
4
- * 棱柱垂直部分
5
- * @param normal 是否需要法向量
6
- * @param x 中心
7
- * @param y
8
- * @param z
9
- * @param radius 半径
10
- * @param height 高
11
- * @param num 份数
12
- * @param beginDeg 开始弧度,默认0
13
- * @param deg 跨越弧度,默认2pi
14
- * @returns 点数组
15
- */
16
- export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
17
- const points = []
18
- let beginPosition: [number, number]
19
-
20
- if (num == 4) {
21
- beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
22
- } else {
23
- beginPosition = [x + radius, z]
24
- }
25
-
26
- if (beginDeg != 0) {
27
- beginPosition = rotate(x, z, beginDeg, ...beginPosition)
28
- }
29
-
30
- const perDeg = deg / num, degHalf = deg / (num * 2)
31
-
32
- let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
33
- for (let i = 0; i < num; i++) {
34
-
35
- endPosition = rotate(x, z, perDeg, ...beginPosition)
36
-
37
- if (normal) {
38
- const halfPosition = rotate(x, z, degHalf, ...beginPosition)
39
- normalPosition = [halfPosition[0], 0, halfPosition[1]]
40
- }
41
-
42
- points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
43
- points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
44
- points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
45
-
46
- points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
47
- points.push(endPosition[0], y, endPosition[1], ...normalPosition)
48
- points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
49
-
50
-
51
- beginPosition = endPosition
52
- }
53
-
54
- return points
55
- }
@@ -1,40 +0,0 @@
1
- import rotate from '../../rotate'
2
-
3
- // 球体中的一瓣子
4
-
5
- export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
6
- const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
7
- let point: [number, number]
8
-
9
- if (normal) points.push(0, radius, 0)
10
-
11
- const copy2 = () => {
12
- points.push(...points.slice(points.length - (normal ? 12 : 6)))
13
- }
14
-
15
- for (let i = 1; i < num * 0.5; i++) {
16
- point = rotate(cx, cy, deg * i, cx, cy + radius)
17
-
18
- if (i > 1) copy2()
19
-
20
- // 第一个点
21
- const point1 = rotate(cx, cz, deg * index, point[0], cz)
22
- points.push(point1[0], point[1], point1[1])
23
-
24
- if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
25
-
26
- if (i > 1) copy2()
27
-
28
- // 下一个点
29
- const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
30
- points.push(point2[0], point[1], point2[1])
31
-
32
- if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
33
- }
34
- copy2()
35
- points.push(cx, cy - radius, cz)
36
-
37
- if (normal) points.push(0, - radius, 0)
38
-
39
- return points
40
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * 计算切割份数
3
- * @param precision 精度
4
- * @param radius 半径
5
- * @param deg 需要跨越的弧度,默认圆(2pi)
6
- * @returns 切割份数
7
- */
8
- export const splitNum = function (precision: number, radius: number, deg: number = Math.PI * 2) {
9
-
10
- // 根据切割弧度得出切割块数目
11
- const num = Math.ceil(deg /
12
-
13
- // 为了满足最小精度而得出的切割弧度
14
- Math.asin(precision / radius) * 2)
15
-
16
- return (isNaN(num) || num < 12) ? 12 : num
17
-
18
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * 物体方向转换
3
- * 由(x,y,z)转换成(x2-x,y2-y,z2-z)
4
- * @param x
5
- * @param y
6
- * @param z
7
- * @param x2
8
- * @param y2
9
- * @param z2
10
- * @returns 点转换函数
11
- */
12
- export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
13
- return (x0: number, y0: number, z0: number, isNormal: boolean) => {
14
- if (x == x2 && z == z2) return [x0, y0, z0]
15
-
16
- let sin: number, cos: number, temp: Array<number>
17
-
18
- // 第一步:归零化
19
- let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
20
- const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
21
-
22
- // 第二步:围绕OZ轴旋转
23
-
24
- const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
25
- cos = _x2 / __d
26
- sin = _z2 / __d
27
-
28
- const _x2N = _z2 * sin + _x2 * cos
29
-
30
- const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
31
- cos = _y2 / d
32
- sin = _x2N / d
33
-
34
- temp = [_y0, _x0]
35
- _y0 = temp[0] * cos - temp[1] * sin
36
- _x0 = temp[0] * sin + temp[1] * cos
37
-
38
- // 第三步:围绕0Y轴旋转
39
- cos = _x2 / __d
40
- sin = _z2 / __d
41
-
42
- temp = [_x0, _z0]
43
- _x0 = temp[0] * cos - temp[1] * sin
44
- _z0 = temp[0] * sin + temp[1] * cos
45
-
46
- // 第四步:去零化(直接返回)
47
- return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
48
- }
49
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * 方向:ab x ac
3
- * @param normal 是否需要法向量
4
- * @param points [a1, b1, c1, a2, b2, c2, ...]
5
- * @returns 完整的点数据
6
- */
7
- export default function (normal: boolean, points: Array<number>) {
8
- if (normal) {
9
- const _points = []
10
- for (let i = 0; i < points.length; i += 9) {
11
- const ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]]
12
- const ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]]
13
- const normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]]
14
- _points.push(
15
- points[i], points[i + 1], points[i + 2], ...normalVector,
16
- points[i + 3], points[i + 4], points[i + 5], ...normalVector,
17
- points[i + 6], points[i + 7], points[i + 8], ...normalVector,
18
- )
19
- }
20
- return _points
21
- } else {
22
- return points
23
- }
24
- }
@@ -1,109 +0,0 @@
1
- import BufferObject from './buffer'
2
-
3
- import getTexture from './getTexture'
4
- import getShader from './getShader'
5
-
6
- interface MeshWorldType {
7
- matrix: number[]
8
- }
9
-
10
- interface GlobalWorldType {
11
- matrix: number[]
12
- proporion: number[]
13
- }
14
-
15
- import { meshType } from '../../../types/Object3D'
16
-
17
- export default function (type: string, painter: WebGLRenderingContext, mesh: meshType, meshWorld: MeshWorldType, globalWorld: GlobalWorldType) {
18
- const shader = getShader(type, painter, mesh)
19
-
20
- // 点数据写入缓冲区
21
- new BufferObject(painter).use()
22
- .write(mesh.geometry.attributes.position.array as Float32Array)
23
- .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0)
24
-
25
- // 写入矩阵
26
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix)
27
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion)
28
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix)
29
-
30
- // 如果有法向量数据
31
- if (mesh.geometry.attributes.normal) {
32
- new BufferObject(painter).use()
33
- .write(mesh.geometry.attributes.normal.array as Float32Array)
34
- .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0)
35
- }
36
-
37
- // 颜色
38
- if ("color" in mesh.material) {
39
-
40
- // 写入颜色
41
- painter.uniform4f(painter.getUniformLocation(shader.program, "u_color")
42
- , mesh.material.color?.r as number
43
- , mesh.material.color?.g as number
44
- , mesh.material.color?.b as number
45
- , mesh.material.color?.alpha as number)
46
- }
47
-
48
- // 多颜色
49
- if ("colors" in mesh.material) {
50
-
51
- // 写入颜色序列
52
- new BufferObject(painter).use()
53
- .write(mesh.material.colors?.array as Float32Array)
54
- .divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors?.itemSize as number, mesh.material.colors?.itemSize as number, 0)
55
-
56
- }
57
-
58
- // 立方纹理
59
- else if ("cube" in mesh.material) {
60
-
61
- const size = (mesh.material.cube?.right?.image.value as any).width
62
-
63
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0)
64
-
65
- getTexture(type, painter, 'cube').useCube([
66
- mesh.material.cube?.right?.image.value,
67
- mesh.material.cube?.left?.image.value,
68
- mesh.material.cube?.top?.image.value,
69
- mesh.material.cube?.bottom?.image.value,
70
- mesh.material.cube?.far?.image.value,
71
- mesh.material.cube?.near?.image.value
72
- ], size, size)
73
-
74
- }
75
-
76
- // 二维纹理
77
- else if ("image" in mesh.material) {
78
-
79
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0)
80
-
81
- new BufferObject(painter).use()
82
- .write(mesh.geometry.attributes.uv?.array as Float32Array)
83
- .divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv?.itemSize as number, 2, 0)
84
-
85
- getTexture(type, painter, '2d').useImage(mesh.material.image?.value)
86
-
87
- }
88
-
89
- // 如果使用了索引
90
- if (mesh.geometry.index) {
91
-
92
- // 索引数据
93
- new BufferObject(painter, true).use()
94
- .write(mesh.geometry.index.array as Uint8Array)
95
-
96
- // 绘制
97
- painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0)
98
-
99
- }
100
-
101
- // 否则
102
- else {
103
-
104
- // 绘制
105
- painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count)
106
-
107
- }
108
-
109
- }
@@ -1,27 +0,0 @@
1
- export default function (painter: WebGLRenderingContext) {
2
- const width = painter.drawingBufferWidth, height = painter.drawingBufferHeight
3
-
4
- const pixels = new Uint8Array(
5
- 4 * width * height
6
- )
7
- painter.readPixels(
8
- 0,
9
- 0,
10
- width,
11
- height,
12
- painter.RGBA,
13
- painter.UNSIGNED_BYTE,
14
- pixels
15
- )
16
-
17
- return function (x: number, y: number): string {
18
- y = height - y
19
-
20
- const pixelR = pixels[4 * (y * width + x)]
21
- const pixelG = pixels[4 * (y * width + x) + 1]
22
- const pixelB = pixels[4 * (y * width + x) + 2]
23
- const pixelA = pixels[4 * (y * width + x) + 3]
24
-
25
- return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")"
26
- }
27
- }
@@ -1,49 +0,0 @@
1
- import type { meshType } from '../../../types/Object3D'
2
-
3
- import ShaderObject from './shader'
4
-
5
- import vsColor from '../../shader/vsColor.c'
6
- import vsColors from '../../shader/vsColors.c'
7
- import vsImage from '../../shader/vsImage.c'
8
- import vsCube from '../../shader/vsCube.c'
9
-
10
- import fsColor from '../../shader/fsColor.c'
11
- import fsColors from '../../shader/fsColors.c'
12
- import fsImage from '../../shader/fsImage.c'
13
- import fsCube from '../../shader/fsCube.c'
14
-
15
- const shaders = {}
16
- export default function (type: string, painter: WebGLRenderingContext, mesh: meshType) {
17
-
18
- const uniqueName = type +
19
- (mesh.material.color ? "1" : "0") +
20
- (mesh.material.colors ? "1" : "0") +
21
- (mesh.material.image ? "1" : "0") +
22
- (mesh.material.cube ? "1" : "0")
23
- if (shaders[uniqueName]) return shaders[uniqueName].use()
24
-
25
- // 顶点着色器
26
- const vertexShader = {
27
- [type + "1000"]: vsColor,
28
- [type + "0100"]: vsColors,
29
- [type + "0010"]: vsImage,
30
- [type + "0001"]: vsCube
31
- }[uniqueName].replace(/uniform +mat4 +u_matrix;/, `
32
- uniform mat4 u_matrix_world;
33
- uniform mat4 u_matrix_mesh;
34
- uniform mat4 u_matrix_proporion;`).replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position")
35
-
36
- // 片段(元)着色器
37
- const fragmentShader = {
38
- [type + "1000"]: fsColor,
39
- [type + "0100"]: fsColors,
40
- [type + "0010"]: fsImage,
41
- [type + "0001"]: fsCube
42
- }[uniqueName]
43
-
44
- // 启用着色器
45
- const shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use()
46
-
47
- shaders[uniqueName] = shader
48
- return shader
49
- }
@@ -1,12 +0,0 @@
1
- import TextureObject from './texture'
2
-
3
- const textures = {}
4
- export default function (type: string, painter: WebGLRenderingContext, kind: string) {
5
- const uniqueName = type + "-" + kind
6
-
7
- if (!textures[uniqueName]) {
8
- textures[uniqueName] = new TextureObject(painter, kind)
9
- }
10
-
11
- return textures[uniqueName]
12
- }