@antv/g-webgpu 0.5.6 → 0.7.0
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/CHANGELOG.md +0 -14
- package/dist/gwebgpu.js +1 -0
- package/es/Kernel.js +30 -87
- package/es/Kernel.js.map +1 -1
- package/es/World.js +13 -240
- package/es/World.js.map +1 -1
- package/es/index.js +1 -5
- package/es/index.js.map +1 -1
- package/es/utils/canvas.js.map +1 -1
- package/es/utils/typedarray.js +7 -8
- package/es/utils/typedarray.js.map +1 -1
- package/lib/Kernel.js +28 -98
- package/lib/Kernel.js.map +1 -1
- package/lib/World.js +11 -260
- package/lib/World.js.map +1 -1
- package/lib/index.js +0 -34
- package/lib/index.js.map +1 -1
- package/lib/utils/canvas.js +0 -1
- package/lib/utils/canvas.js.map +1 -1
- package/lib/utils/typedarray.js +7 -9
- package/lib/utils/typedarray.js.map +1 -1
- package/package.json +6 -12
- package/es/Kernel.d.ts +0 -21
- package/es/Renderer.d.ts +0 -24
- package/es/Renderer.js +0 -341
- package/es/Renderer.js.map +0 -1
- package/es/Scene.d.ts +0 -11
- package/es/Scene.js +0 -54
- package/es/Scene.js.map +0 -1
- package/es/View.d.ts +0 -20
- package/es/View.js +0 -86
- package/es/View.js.map +0 -1
- package/es/World.d.ts +0 -49
- package/es/camera/Camera.d.ts +0 -252
- package/es/camera/Camera.js +0 -831
- package/es/camera/Camera.js.map +0 -1
- package/es/camera/Landmark.d.ts +0 -28
- package/es/camera/Landmark.js +0 -86
- package/es/camera/Landmark.js.map +0 -1
- package/es/geometry/Box.d.ts +0 -11
- package/es/geometry/Box.js +0 -180
- package/es/geometry/Box.js.map +0 -1
- package/es/geometry/Merged.d.ts +0 -8
- package/es/geometry/Merged.js +0 -91
- package/es/geometry/Merged.js.map +0 -1
- package/es/geometry/Plane.d.ts +0 -10
- package/es/geometry/Plane.js +0 -112
- package/es/geometry/Plane.js.map +0 -1
- package/es/geometry/Sphere.d.ts +0 -9
- package/es/geometry/Sphere.js +0 -121
- package/es/geometry/Sphere.js.map +0 -1
- package/es/geometry/index.d.ts +0 -19
- package/es/geometry/index.js +0 -59
- package/es/geometry/index.js.map +0 -1
- package/es/glsl.d.js +0 -2
- package/es/glsl.d.js.map +0 -1
- package/es/index.d.ts +0 -7
- package/es/material/basic/index.d.ts +0 -10
- package/es/material/basic/index.js +0 -108
- package/es/material/basic/index.js.map +0 -1
- package/es/material/index.d.ts +0 -16
- package/es/material/index.js +0 -60
- package/es/material/index.js.map +0 -1
- package/es/renderable/Renderable.d.ts +0 -41
- package/es/renderable/Renderable.js +0 -169
- package/es/renderable/Renderable.js.map +0 -1
- package/es/renderable/grid/index.d.ts +0 -17
- package/es/renderable/grid/index.js +0 -133
- package/es/renderable/grid/index.js.map +0 -1
- package/es/renderable/line/index.d.ts +0 -23
- package/es/renderable/line/index.js +0 -231
- package/es/renderable/line/index.js.map +0 -1
- package/es/renderable/point/index.d.ts +0 -29
- package/es/renderable/point/index.js +0 -241
- package/es/renderable/point/index.js.map +0 -1
- package/es/texture/Cache.d.ts +0 -6
- package/es/texture/Cache.js +0 -28
- package/es/texture/Cache.js.map +0 -1
- package/es/texture/Texture2D.d.ts +0 -13
- package/es/texture/Texture2D.js +0 -126
- package/es/texture/Texture2D.js.map +0 -1
- package/es/utils/canvas.d.ts +0 -1
- package/es/utils/is-array.d.ts +0 -2
- package/es/utils/is-array.js +0 -5
- package/es/utils/is-array.js.map +0 -1
- package/es/utils/is-number.d.ts +0 -1
- package/es/utils/is-number.js +0 -4
- package/es/utils/is-number.js.map +0 -1
- package/es/utils/is-type.d.ts +0 -2
- package/es/utils/is-type.js +0 -8
- package/es/utils/is-type.js.map +0 -1
- package/es/utils/is-typedarray.d.ts +0 -27
- package/es/utils/is-typedarray.js +0 -99
- package/es/utils/is-typedarray.js.map +0 -1
- package/es/utils/math.d.ts +0 -3
- package/es/utils/math.js +0 -24
- package/es/utils/math.js.map +0 -1
- package/es/utils/picking.d.ts +0 -1
- package/es/utils/picking.js +0 -4
- package/es/utils/picking.js.map +0 -1
- package/es/utils/polyline-normals.d.ts +0 -6
- package/es/utils/polyline-normals.js +0 -129
- package/es/utils/polyline-normals.js.map +0 -1
- package/es/utils/typedarray.d.ts +0 -1
- package/lib/Renderer.js +0 -354
- package/lib/Renderer.js.map +0 -1
- package/lib/Scene.js +0 -64
- package/lib/Scene.js.map +0 -1
- package/lib/View.js +0 -99
- package/lib/View.js.map +0 -1
- package/lib/camera/Camera.js +0 -900
- package/lib/camera/Camera.js.map +0 -1
- package/lib/camera/Landmark.js +0 -95
- package/lib/camera/Landmark.js.map +0 -1
- package/lib/geometry/Box.js +0 -205
- package/lib/geometry/Box.js.map +0 -1
- package/lib/geometry/Merged.js +0 -110
- package/lib/geometry/Merged.js.map +0 -1
- package/lib/geometry/Plane.js +0 -127
- package/lib/geometry/Plane.js.map +0 -1
- package/lib/geometry/Sphere.js +0 -136
- package/lib/geometry/Sphere.js.map +0 -1
- package/lib/geometry/index.js +0 -71
- package/lib/geometry/index.js.map +0 -1
- package/lib/glsl.d.js +0 -2
- package/lib/glsl.d.js.map +0 -1
- package/lib/material/basic/index.js +0 -125
- package/lib/material/basic/index.js.map +0 -1
- package/lib/material/index.js +0 -72
- package/lib/material/index.js.map +0 -1
- package/lib/renderable/Renderable.js +0 -178
- package/lib/renderable/Renderable.js.map +0 -1
- package/lib/renderable/grid/index.js +0 -148
- package/lib/renderable/grid/index.js.map +0 -1
- package/lib/renderable/line/index.js +0 -248
- package/lib/renderable/line/index.js.map +0 -1
- package/lib/renderable/point/index.js +0 -259
- package/lib/renderable/point/index.js.map +0 -1
- package/lib/texture/Cache.js +0 -38
- package/lib/texture/Cache.js.map +0 -1
- package/lib/texture/Texture2D.js +0 -142
- package/lib/texture/Texture2D.js.map +0 -1
- package/lib/utils/is-array.js +0 -17
- package/lib/utils/is-array.js.map +0 -1
- package/lib/utils/is-number.js +0 -11
- package/lib/utils/is-number.js.map +0 -1
- package/lib/utils/is-type.js +0 -15
- package/lib/utils/is-type.js.map +0 -1
- package/lib/utils/is-typedarray.js +0 -109
- package/lib/utils/is-typedarray.js.map +0 -1
- package/lib/utils/math.js +0 -35
- package/lib/utils/math.js.map +0 -1
- package/lib/utils/picking.js +0 -11
- package/lib/utils/picking.js.map +0 -1
- package/lib/utils/polyline-normals.js +0 -137
- package/lib/utils/polyline-normals.js.map +0 -1
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.Renderable = void 0;
|
|
9
|
-
|
|
10
|
-
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
17
|
-
|
|
18
|
-
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
|
|
19
|
-
|
|
20
|
-
var _gWebgpuCore = require("@antv/g-webgpu-core");
|
|
21
|
-
|
|
22
|
-
var _inversify = require("inversify");
|
|
23
|
-
|
|
24
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _class3, _temp;
|
|
25
|
-
|
|
26
|
-
var Renderable = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.MeshComponentManager), _dec3 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.CullableComponentManager), _dec4 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.TransformComponentManager), _dec5 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec6 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.SceneGraphSystem), _dec(_class = (_class2 = (_temp = _class3 = /*#__PURE__*/function () {
|
|
27
|
-
function Renderable() {
|
|
28
|
-
(0, _classCallCheck2.default)(this, Renderable);
|
|
29
|
-
this.attributes = {};
|
|
30
|
-
this.config = void 0;
|
|
31
|
-
(0, _initializerDefineProperty2.default)(this, "mesh", _descriptor, this);
|
|
32
|
-
(0, _initializerDefineProperty2.default)(this, "cullable", _descriptor2, this);
|
|
33
|
-
(0, _initializerDefineProperty2.default)(this, "transform", _descriptor3, this);
|
|
34
|
-
(0, _initializerDefineProperty2.default)(this, "sceneGraphSystem", _descriptor4, this);
|
|
35
|
-
this.meshComponent = void 0;
|
|
36
|
-
this.transformComponent = void 0;
|
|
37
|
-
this.entity = void 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
(0, _createClass2.default)(Renderable, [{
|
|
41
|
-
key: "getEntity",
|
|
42
|
-
value: function getEntity() {
|
|
43
|
-
return this.entity;
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "getTransformComponent",
|
|
47
|
-
value: function getTransformComponent() {
|
|
48
|
-
return this.transformComponent;
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "getMeshComponent",
|
|
52
|
-
value: function getMeshComponent() {
|
|
53
|
-
return this.meshComponent;
|
|
54
|
-
}
|
|
55
|
-
}, {
|
|
56
|
-
key: "setConfig",
|
|
57
|
-
value: function setConfig(config) {
|
|
58
|
-
this.config = config;
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: "setEntity",
|
|
62
|
-
value: function setEntity(entity) {
|
|
63
|
-
this.entity = entity;
|
|
64
|
-
this.cullable.create(entity);
|
|
65
|
-
this.meshComponent = this.mesh.create(entity);
|
|
66
|
-
this.transformComponent = this.transform.create(entity);
|
|
67
|
-
this.onEntityCreated();
|
|
68
|
-
}
|
|
69
|
-
}, {
|
|
70
|
-
key: "setMaterial",
|
|
71
|
-
value: function setMaterial(material) {
|
|
72
|
-
this.meshComponent.material = material;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "setGeometry",
|
|
77
|
-
value: function setGeometry(geometry) {
|
|
78
|
-
this.meshComponent.geometry = geometry;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "setAttributes",
|
|
83
|
-
value: function setAttributes(attributes) {
|
|
84
|
-
var _this = this;
|
|
85
|
-
|
|
86
|
-
Object.keys(attributes).forEach(function (name) {
|
|
87
|
-
if (attributes[name] !== undefined && attributes[name] !== _this.attributes[name]) {
|
|
88
|
-
_this.onAttributeChanged({
|
|
89
|
-
name: name,
|
|
90
|
-
data: attributes[name]
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
_this.attributes[name] = attributes[name];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "setVisible",
|
|
99
|
-
value: function setVisible(visible) {
|
|
100
|
-
var _this2 = this;
|
|
101
|
-
|
|
102
|
-
this.meshComponent.visible = visible;
|
|
103
|
-
this.meshComponent.children.forEach(function (childEntity) {
|
|
104
|
-
var child = _this2.mesh.getComponentByEntity(childEntity);
|
|
105
|
-
|
|
106
|
-
if (child) {
|
|
107
|
-
child.visible = visible;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "isVisible",
|
|
114
|
-
value: function isVisible() {
|
|
115
|
-
return this.meshComponent.visible;
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "attach",
|
|
119
|
-
value: function attach(parentRenderable) {
|
|
120
|
-
this.sceneGraphSystem.attach(this.entity, parentRenderable.entity);
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "detach",
|
|
125
|
-
value: function detach() {
|
|
126
|
-
this.sceneGraphSystem.detach(this.entity);
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
}, {
|
|
130
|
-
key: "detachChildren",
|
|
131
|
-
value: function detachChildren() {
|
|
132
|
-
this.sceneGraphSystem.detachChildren(this.entity);
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
}, {
|
|
136
|
-
key: "onEntityCreated",
|
|
137
|
-
value: function onEntityCreated() {//
|
|
138
|
-
}
|
|
139
|
-
}, {
|
|
140
|
-
key: "onAttributeChanged",
|
|
141
|
-
value: function onAttributeChanged(_ref) {
|
|
142
|
-
var name = _ref.name,
|
|
143
|
-
data = _ref.data;
|
|
144
|
-
|
|
145
|
-
if (this.meshComponent && this.meshComponent.material) {
|
|
146
|
-
this.meshComponent.material.setUniform(this.convertAttributeName2UniformName(name), data);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}, {
|
|
150
|
-
key: "convertAttributeName2UniformName",
|
|
151
|
-
value: function convertAttributeName2UniformName(attributeName) {
|
|
152
|
-
return attributeName;
|
|
153
|
-
}
|
|
154
|
-
}]);
|
|
155
|
-
return Renderable;
|
|
156
|
-
}(), _class3.POINT = 'point', _class3.LINE = 'line', _class3.GRID = 'grid', _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "mesh", [_dec2], {
|
|
157
|
-
configurable: true,
|
|
158
|
-
enumerable: true,
|
|
159
|
-
writable: true,
|
|
160
|
-
initializer: null
|
|
161
|
-
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "cullable", [_dec3], {
|
|
162
|
-
configurable: true,
|
|
163
|
-
enumerable: true,
|
|
164
|
-
writable: true,
|
|
165
|
-
initializer: null
|
|
166
|
-
}), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "transform", [_dec4], {
|
|
167
|
-
configurable: true,
|
|
168
|
-
enumerable: true,
|
|
169
|
-
writable: true,
|
|
170
|
-
initializer: null
|
|
171
|
-
}), _descriptor4 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "sceneGraphSystem", [_dec5, _dec6], {
|
|
172
|
-
configurable: true,
|
|
173
|
-
enumerable: true,
|
|
174
|
-
writable: true,
|
|
175
|
-
initializer: null
|
|
176
|
-
})), _class2)) || _class);
|
|
177
|
-
exports.Renderable = Renderable;
|
|
178
|
-
//# sourceMappingURL=Renderable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/renderable/Renderable.ts"],"names":["Renderable","IDENTIFIER","MeshComponentManager","CullableComponentManager","TransformComponentManager","Systems","SceneGraphSystem","attributes","config","meshComponent","transformComponent","entity","cullable","create","mesh","transform","onEntityCreated","material","geometry","Object","keys","forEach","name","undefined","onAttributeChanged","data","visible","children","childEntity","child","getComponentByEntity","parentRenderable","sceneGraphSystem","attach","detach","detachChildren","setUniform","convertAttributeName2UniformName","attributeName","POINT","LINE","GRID"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AAaA;;;;IAWaA,U,WADZ,4B,UASE,uBAAOC,wBAAWC,oBAAlB,C,UAGA,uBAAOD,wBAAWE,wBAAlB,C,UAGA,uBAAOF,wBAAWG,yBAAlB,C,UAGA,uBAAOH,wBAAWI,OAAlB,C,UACA,sBAAMJ,wBAAWK,gBAAjB,C;;;SAbSC,U,GAAyC,E;SACzCC,M;;;;;SAeFC,a;SACAC,kB;SAEAC,M;;;;;gCAEW;AACjB,aAAO,KAAKA,MAAZ;AACD;;;4CAE8B;AAC7B,aAAO,KAAKD,kBAAZ;AACD;;;uCAEyB;AACxB,aAAO,KAAKD,aAAZ;AACD;;;8BAEgBD,M,EAAW;AAC1B,WAAKA,MAAL,GAAcA,MAAd;AACD;;;8BAEgBG,M,EAAgB;AAC/B,WAAKA,M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D;AACF,OALD;AAMA,aAAO,IAAP;AACD;;;gCAEkB;AACjB,aAAO,KAAKjB,aAAL,CAAmBiB,OAA1B;AACD;;;2BAEaK,gB,EAAiC;AAC7C,WAAKC,gBAAL,CAAsBC,MAAtB,CAA6B,KAAKtB,MAAlC,EAA0CoB,gBAAgB,CAACpB,MAA3D;AACA,aAAO,IAAP;AACD;;;6BAEe;AACd,WAAKqB,gBAAL,CAAsBE,MAAtB,CAA6B,KAAKvB,MAAlC;AACA,aAAO,IAAP;AACD;;;qCAEuB;AACtB,WAAKqB,gBAAL,CAAsBG,cAAtB,CAAqC,KAAKxB,MAA1C;AACA,aAAO,IAAP;AACD;;;sCAE2B,CAC1B;AACD;;;6CAQE;AAAA,UALDW,IAKC,QALDA,IAKC;AAAA,UAJDG,IAIC,QAJDA,IAIC;;AACD,UAAI,KAAKhB,aAAL,IAAsB,KAAKA,aAAL,CAAmBQ,QAA7C,EAAuD;AACrD,aAAKR,aAAL,CAAmBQ,QAAnB,CAA4BmB,UAA5B,CACE,KAAKC,gCAAL,CAAsCf,IAAtC,CADF,EAEEG,IAFF;AAID;AACF;;;qDAE0Ca,a,EAAuB;AAChE,aAAOA,aAAP;AACD;;;aA7HaC,K,GAAQ,O,UACRC,I,GAAO,M,UACPC,I,GAAO,M","sourcesContent":["import {\n BufferData,\n ComponentManager,\n CullableComponent,\n Entity,\n GeometryComponent,\n HierarchyComponent,\n IDENTIFIER,\n MaterialComponent,\n MeshComponent,\n SceneGraphSystem,\n TransformComponent,\n} from '@antv/g-webgpu-core';\nimport { inject, injectable, named } from 'inversify';\n\nexport interface IRenderable<T> {\n setConfig(config: T): void;\n setAttributes(attributes: Record<string, BufferData | undefined>): void;\n setEntity(entity: Entity): void;\n setMaterial(material: MaterialComponent): void;\n setGeometry(geometry: GeometryComponent): void;\n}\n\n@injectable()\nexport class Renderable<T = {}> implements IRenderable<T> {\n public static POINT = 'point';\n public static LINE = 'line';\n public static GRID = 'grid';\n\n protected attributes: Record<string, BufferData> = {};\n protected config: T;\n\n @inject(IDENTIFIER.MeshComponentManager)\n private readonly mesh: ComponentManager<MeshComponent>;\n\n @inject(IDENTIFIER.CullableComponentManager)\n private readonly cullable: ComponentManager<CullableComponent>;\n\n @inject(IDENTIFIER.TransformComponentManager)\n private readonly transform: ComponentManager<TransformComponent>;\n\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.SceneGraphSystem)\n private readonly sceneGraphSystem: SceneGraphSystem;\n\n private meshComponent: MeshComponent;\n private transformComponent: TransformComponent;\n\n private entity: Entity;\n\n public getEntity() {\n return this.entity;\n }\n\n public getTransformComponent() {\n return this.transformComponent;\n }\n\n public getMeshComponent() {\n return this.meshComponent;\n }\n\n public setConfig(config: T) {\n this.config = config;\n }\n\n public setEntity(entity: Entity) {\n this.entity = entity;\n this.cullable.create(entity);\n this.meshComponent = this.mesh.create(entity);\n this.transformComponent = this.transform.create(entity);\n this.onEntityCreated();\n }\n\n public setMaterial(material: MaterialComponent) {\n this.meshComponent.material = material;\n return this;\n }\n\n public setGeometry(geometry: GeometryComponent) {\n this.meshComponent.geometry = geometry;\n return this;\n }\n\n public setAttributes(attributes: Record<string, BufferData | undefined>) {\n Object.keys(attributes).forEach((name) => {\n if (\n attributes[name] !== undefined &&\n attributes[name] !== this.attributes[name]\n ) {\n this.onAttributeChanged({\n name,\n data: attributes[name]!,\n });\n this.attributes[name] = attributes[name]!;\n }\n });\n }\n\n public setVisible(visible: boolean) {\n this.meshComponent.visible = visible;\n this.meshComponent.children.forEach((childEntity) => {\n const child = this.mesh.getComponentByEntity(childEntity);\n if (child) {\n child.visible = visible;\n }\n });\n return this;\n }\n\n public isVisible() {\n return this.meshComponent.visible;\n }\n\n public attach(parentRenderable: Renderable<T>) {\n this.sceneGraphSystem.attach(this.entity, parentRenderable.entity);\n return this;\n }\n\n public detach() {\n this.sceneGraphSystem.detach(this.entity);\n return this;\n }\n\n public detachChildren() {\n this.sceneGraphSystem.detachChildren(this.entity);\n return this;\n }\n\n protected onEntityCreated() {\n //\n }\n\n protected onAttributeChanged({\n name,\n data,\n }: {\n name: string;\n data: BufferData;\n }) {\n if (this.meshComponent && this.meshComponent.material) {\n this.meshComponent.material.setUniform(\n this.convertAttributeName2UniformName(name),\n data,\n );\n }\n }\n\n protected convertAttributeName2UniformName(attributeName: string) {\n return attributeName;\n }\n}\n"],"file":"Renderable.js"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.Grid = void 0;
|
|
9
|
-
|
|
10
|
-
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
-
|
|
22
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
-
|
|
24
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
25
|
-
|
|
26
|
-
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
|
|
27
|
-
|
|
28
|
-
var _gWebgpuCore = require("@antv/g-webgpu-core");
|
|
29
|
-
|
|
30
|
-
var _inversify = require("inversify");
|
|
31
|
-
|
|
32
|
-
var _Renderable2 = require("../Renderable");
|
|
33
|
-
|
|
34
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _temp;
|
|
35
|
-
|
|
36
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
37
|
-
|
|
38
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
|
-
|
|
40
|
-
/* babel-plugin-inline-import './shaders/webgl.grid.frag.glsl' */
|
|
41
|
-
var gridFrag = "// generate grid, borrow from clay.gl viewer\n// @see https://github.com/pissang/clay-viewer/blob/master/src/graphic/ground.glsl\n#extension GL_OES_standard_derivatives : enable\n\nvarying vec3 v_Position;\n// varying vec3 v_Normal;\n\nuniform float u_GridSize : 5;\nuniform float u_GridSize2 : .5;\nuniform vec4 u_GridColor : [0, 0, 0, 1];\nuniform vec4 u_GridColor2 : [0.3, 0.3, 0.3, 1];\nuniform bool u_GridEnabled : true;\n\n// uniform vec3 u_LightDirection;\n// uniform vec3 u_LightColor;\n// uniform vec3 u_Camera;\n\nvoid main() {\n // vec3 n = v_Normal;\n // vec3 l = normalize(u_LightDirection);\n // float NdotL = clamp(dot(n, l), 0.001, 1.0);\n\n gl_FragColor = vec4(1.);\n\n if (u_GridEnabled) {\n float wx = v_Position.x;\n float wz = v_Position.z;\n // float x0 = abs(fract(wx / u_GridSize - 0.5) - 0.5) / fwidth(wx) * u_GridSize / 2.0;\n // float z0 = abs(fract(wz / u_GridSize - 0.5) - 0.5) / fwidth(wz) * u_GridSize / 2.0;\n\n float x1 = abs(fract(wx / u_GridSize2 - 0.5) - 0.5) / fwidth(wx) * u_GridSize2;\n float z1 = abs(fract(wz / u_GridSize2 - 0.5) - 0.5) / fwidth(wz) * u_GridSize2;\n\n // float v0 = 1.0 - clamp(min(x0, z0), 0.0, 1.0);\n float v1 = 1.0 - clamp(min(x1, z1), 0.0, 1.0);\n // if (v0 > 0.1) {\n // gl_FragColor = mix(gl_FragColor, u_GridColor, v0);\n // }\n // else {\n gl_FragColor = mix(gl_FragColor, u_GridColor2, v1);\n // }\n }\n\n // float shadowFactor = calcShadow(u_ShadowMap, v_PositionFromLight, l, n);\n // vec3 diffuseColor = u_LightColor * NdotL * shadowFactor;\n\n // gl_FragColor.rgb *= diffuseColor;\n}";
|
|
42
|
-
|
|
43
|
-
/* babel-plugin-inline-import './shaders/webgl.grid.vert.glsl' */
|
|
44
|
-
var gridVert = "attribute vec3 a_Position;\n\nvarying vec3 v_Position;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelViewMatrix;\n\nvoid main() {\n v_Position = a_Position;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(a_Position, 1.);\n}";
|
|
45
|
-
var Grid = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec3 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.MaterialSystem), _dec4 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec5 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.GeometrySystem), _dec6 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.ShaderModuleService), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function (_Renderable) {
|
|
46
|
-
(0, _inherits2.default)(Grid, _Renderable);
|
|
47
|
-
|
|
48
|
-
var _super = _createSuper(Grid);
|
|
49
|
-
|
|
50
|
-
function Grid() {
|
|
51
|
-
var _this;
|
|
52
|
-
|
|
53
|
-
(0, _classCallCheck2.default)(this, Grid);
|
|
54
|
-
|
|
55
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
56
|
-
args[_key] = arguments[_key];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
60
|
-
(0, _initializerDefineProperty2.default)(_this, "materialSystem", _descriptor, (0, _assertThisInitialized2.default)(_this));
|
|
61
|
-
(0, _initializerDefineProperty2.default)(_this, "geometrySystem", _descriptor2, (0, _assertThisInitialized2.default)(_this));
|
|
62
|
-
(0, _initializerDefineProperty2.default)(_this, "shaderModuleService", _descriptor3, (0, _assertThisInitialized2.default)(_this));
|
|
63
|
-
return _this;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
(0, _createClass2.default)(Grid, [{
|
|
67
|
-
key: "onAttributeChanged",
|
|
68
|
-
value: function onAttributeChanged(_ref) {
|
|
69
|
-
var name = _ref.name,
|
|
70
|
-
data = _ref.data;
|
|
71
|
-
var mesh = this.getMeshComponent();
|
|
72
|
-
|
|
73
|
-
if (mesh && mesh.material) {
|
|
74
|
-
if (name === 'gridColor') {
|
|
75
|
-
mesh.material.setUniform('u_GridColor', data);
|
|
76
|
-
mesh.material.setUniform('u_GridColor2', data);
|
|
77
|
-
} else if (name === 'gridSize') {
|
|
78
|
-
mesh.material.setUniform('u_GridSize', data);
|
|
79
|
-
mesh.material.setUniform('u_GridSize2', data);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "onEntityCreated",
|
|
85
|
-
value: function onEntityCreated() {
|
|
86
|
-
this.shaderModuleService.registerModule('grid', {
|
|
87
|
-
vs: gridVert,
|
|
88
|
-
fs: gridFrag
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
var _this$shaderModuleSer = this.shaderModuleService.getModule('grid'),
|
|
92
|
-
vs = _this$shaderModuleSer.vs,
|
|
93
|
-
fs = _this$shaderModuleSer.fs,
|
|
94
|
-
extractedUniforms = _this$shaderModuleSer.uniforms;
|
|
95
|
-
|
|
96
|
-
var material = this.materialSystem.createShaderMaterial({
|
|
97
|
-
vertexShader: vs,
|
|
98
|
-
fragmentShader: fs
|
|
99
|
-
});
|
|
100
|
-
this.setMaterial(material);
|
|
101
|
-
var geometry = this.geometrySystem.createBufferGeometry({
|
|
102
|
-
vertexCount: 4
|
|
103
|
-
});
|
|
104
|
-
this.setGeometry(geometry);
|
|
105
|
-
material.setCull({
|
|
106
|
-
enable: false,
|
|
107
|
-
face: _gWebgpuCore.gl.BACK
|
|
108
|
-
}).setDepth({
|
|
109
|
-
enable: true,
|
|
110
|
-
func: _gWebgpuCore.gl.LESS
|
|
111
|
-
}); // @ts-ignore
|
|
112
|
-
|
|
113
|
-
material.setUniform(extractedUniforms);
|
|
114
|
-
this.setAttributes({
|
|
115
|
-
gridColor: this.config.gridColor,
|
|
116
|
-
gridSize: this.config.gridSize
|
|
117
|
-
});
|
|
118
|
-
geometry.setIndex([0, 3, 2, 2, 1, 0]);
|
|
119
|
-
geometry.setAttribute('a_Position', Float32Array.from([-4, -1, -4, 4, -1, -4, 4, -1, 4, -4, -1, 4]), {
|
|
120
|
-
arrayStride: 4 * 2,
|
|
121
|
-
stepMode: 'vertex',
|
|
122
|
-
attributes: [{
|
|
123
|
-
shaderLocation: 0,
|
|
124
|
-
offset: 0,
|
|
125
|
-
format: 'float2'
|
|
126
|
-
}]
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}]);
|
|
130
|
-
return Grid;
|
|
131
|
-
}(_Renderable2.Renderable), _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "materialSystem", [_dec2, _dec3], {
|
|
132
|
-
configurable: true,
|
|
133
|
-
enumerable: true,
|
|
134
|
-
writable: true,
|
|
135
|
-
initializer: null
|
|
136
|
-
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "geometrySystem", [_dec4, _dec5], {
|
|
137
|
-
configurable: true,
|
|
138
|
-
enumerable: true,
|
|
139
|
-
writable: true,
|
|
140
|
-
initializer: null
|
|
141
|
-
}), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "shaderModuleService", [_dec6], {
|
|
142
|
-
configurable: true,
|
|
143
|
-
enumerable: true,
|
|
144
|
-
writable: true,
|
|
145
|
-
initializer: null
|
|
146
|
-
})), _class2)) || _class);
|
|
147
|
-
exports.Grid = Grid;
|
|
148
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/renderable/grid/index.ts"],"names":["Grid","IDENTIFIER","Systems","MaterialSystem","GeometrySystem","ShaderModuleService","name","data","mesh","getMeshComponent","material","setUniform","shaderModuleService","registerModule","vs","gridVert","fs","gridFrag","getModule","extractedUniforms","uniforms","materialSystem","createShaderMaterial","vertexShader","fragmentShader","setMaterial","geometry","geometrySystem","createBufferGeometry","vertexCount","setGeometry","setCull","enable","face","gl","BACK","setDepth","func","LESS","setAttributes","gridColor","config","gridSize","setIndex","setAttribute","Float32Array","from","arrayStride","stepMode","attributes","shaderLocation","offset","format","Renderable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AACA;;;;;;;;;;;;;IAUaA,I,WADZ,4B,UAEE,uBAAOC,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWE,cAAjB,C,UAGA,uBAAOF,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWG,cAAjB,C,UAGA,uBAAOH,wBAAWI,mBAAlB,C;;;;;;;;;;;;;;;;;;;;;;;6CASE;AAAA,UALDC,IAKC,QALDA,IAKC;AAAA,UAJDC,IAIC,QAJDA,IAIC;AACD,UAAMC,IAAI,GAAG,KAAKC,gBAAL,EAAb;;AACA,UAAID,IAAI,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;AACRJ,QAAAA,MAAM,EAAE,IADA;AAERK,QAAAA,IAAI,EAAEH,gBAAGI;AAFD,OALZ,EAtB0B,CAgC1B;;AACA5B,MAAAA,QAAQ,CAACC,UAAT,CAAoBQ,iBAApB;AAEA,WAAKoB,aAAL,CAAmB;AACjBC,QAAAA,SAAS,EAAE,KAAKC,MAAL,CAAYD,SADN;AAEjBE,QAAAA,QAAQ,EAAE,KAAKD,MAAL,CAAYC;AAFL,OAAnB;AAKAhB,MAAAA,QAAQ,CAACiB,QAAT,CAAkB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,CAAlB;AAEAjB,MAAAA,QAAQ,CAACkB,YAAT,CACE,YADF,EAEEC,YAAY,CAACC,IAAb,CAAkB,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,EAAS,CAAC,CAAV,EAAa,CAAb,EAAgB,CAAC,CAAjB,EAAoB,CAAC,CAArB,EAAwB,CAAxB,EAA2B,CAAC,CAA5B,EAA+B,CAA/B,EAAkC,CAAC,CAAnC,EAAsC,CAAC,CAAvC,EAA0C,CAA1C,CAAlB,CAFF,EAGE;AACEC,QAAAA,WAAW,EAAE,IAAI,CADnB;AAEEC,QAAAA,QAAQ,EAAE,QAFZ;AAGEC,QAAAA,UAAU,EAAE,CACV;AACEC,UAAAA,cAAc,EAAE,CADlB;AAEEC,UAAAA,MAAM,EAAE,CAFV;AAGEC,UAAAA,MAAM,EAAE;AAHV,SADU;AAHd,OAHF;AAeD;;;EAxFuBC,uB","sourcesContent":["import {\n BufferData,\n GeometrySystem,\n gl,\n IDENTIFIER,\n IShaderModuleService,\n MaterialSystem,\n} from '@antv/g-webgpu-core';\nimport { inject, injectable, named } from 'inversify';\nimport { Renderable } from '../Renderable';\nimport gridFrag from './shaders/webgl.grid.frag.glsl';\nimport gridVert from './shaders/webgl.grid.vert.glsl';\n\ninterface IGridConfig {\n gridColor: number[];\n gridSize: number;\n}\n\n@injectable()\nexport class Grid extends Renderable<Partial<IGridConfig>> {\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.MaterialSystem)\n private readonly materialSystem: MaterialSystem;\n\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.GeometrySystem)\n private readonly geometrySystem: GeometrySystem;\n\n @inject(IDENTIFIER.ShaderModuleService)\n private readonly shaderModuleService: IShaderModuleService;\n\n protected onAttributeChanged({\n name,\n data,\n }: {\n name: string;\n data: BufferData;\n }) {\n const mesh = this.getMeshComponent();\n if (mesh && mesh.material) {\n if (name === 'gridColor') {\n mesh.material.setUniform('u_GridColor', data);\n mesh.material.setUniform('u_GridColor2', data);\n } else if (name === 'gridSize') {\n mesh.material.setUniform('u_GridSize', data);\n mesh.material.setUniform('u_GridSize2', data);\n }\n }\n }\n\n protected onEntityCreated() {\n this.shaderModuleService.registerModule('grid', {\n vs: gridVert,\n fs: gridFrag,\n });\n const {\n vs,\n fs,\n uniforms: extractedUniforms,\n } = this.shaderModuleService.getModule('grid');\n\n const material = this.materialSystem.createShaderMaterial({\n vertexShader: vs!,\n fragmentShader: fs!,\n });\n this.setMaterial(material);\n\n const geometry = this.geometrySystem.createBufferGeometry({\n vertexCount: 4,\n });\n this.setGeometry(geometry);\n\n material\n .setCull({\n enable: false,\n face: gl.BACK,\n })\n .setDepth({\n enable: true,\n func: gl.LESS,\n });\n\n // @ts-ignore\n material.setUniform(extractedUniforms);\n\n this.setAttributes({\n gridColor: this.config.gridColor,\n gridSize: this.config.gridSize,\n });\n\n geometry.setIndex([0, 3, 2, 2, 1, 0]);\n\n geometry.setAttribute(\n 'a_Position',\n Float32Array.from([-4, -1, -4, 4, -1, -4, 4, -1, 4, -4, -1, 4]),\n {\n arrayStride: 4 * 2,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 0,\n offset: 0,\n format: 'float2',\n },\n ],\n },\n );\n }\n}\n"],"file":"index.js"}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.Line = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
27
|
-
|
|
28
|
-
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
|
|
29
|
-
|
|
30
|
-
var _gWebgpuCore = require("@antv/g-webgpu-core");
|
|
31
|
-
|
|
32
|
-
var _inversify = require("inversify");
|
|
33
|
-
|
|
34
|
-
var _polylineNormals = _interopRequireDefault(require("../../utils/polyline-normals"));
|
|
35
|
-
|
|
36
|
-
var _Renderable2 = require("../Renderable");
|
|
37
|
-
|
|
38
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _temp;
|
|
39
|
-
|
|
40
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
43
|
-
|
|
44
|
-
/* babel-plugin-inline-import './shaders/webgl.line.frag.glsl' */
|
|
45
|
-
var lineFrag = "uniform float u_dash_array : 0.02;\nuniform float u_dash_offset : 0;\nuniform float u_dash_ratio : 0;\nuniform float u_thickness : 0.02;\n\nvarying vec4 v_color;\nvarying vec2 v_normal;\nvarying float v_counters;\n\nvoid main() {\n float blur = 1. - smoothstep(0.98, 1., length(v_normal));\n\n gl_FragColor = v_color;\n gl_FragColor.a *= blur * ceil(mod(v_counters + u_dash_offset, u_dash_array) - (u_dash_array * u_dash_ratio));\n}";
|
|
46
|
-
|
|
47
|
-
/* babel-plugin-inline-import './shaders/webgl.line.vert.glsl' */
|
|
48
|
-
var lineVert = "attribute vec2 a_pos;\nattribute vec4 a_color;\nattribute float a_line_miter;\nattribute vec2 a_line_normal;\nattribute float a_counters;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelViewMatrix;\nuniform float u_thickness : 0.02;\nuniform vec2 u_viewport;\n\nvarying vec4 v_color;\nvarying vec2 v_normal;\nvarying float v_counters;\n\nvoid main() {\n v_color = a_color;\n v_counters = a_counters;\n\n vec3 normal = normalize(vec3(a_line_normal, 0.0));\n\n vec4 offset = vec4(normal * u_thickness / 2.0 * a_line_miter, 0.0);\n\n v_normal = vec2(normal * sign(a_line_miter));\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4(a_pos, 0.0, 1.0) + offset;\n}\n";
|
|
49
|
-
var Line = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec3 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.MaterialSystem), _dec4 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.Systems), _dec5 = (0, _inversify.named)(_gWebgpuCore.IDENTIFIER.GeometrySystem), _dec6 = (0, _inversify.inject)(_gWebgpuCore.IDENTIFIER.ShaderModuleService), _dec(_class = (_class2 = (_temp = /*#__PURE__*/function (_Renderable) {
|
|
50
|
-
(0, _inherits2.default)(Line, _Renderable);
|
|
51
|
-
|
|
52
|
-
var _super = _createSuper(Line);
|
|
53
|
-
|
|
54
|
-
function Line() {
|
|
55
|
-
var _this;
|
|
56
|
-
|
|
57
|
-
(0, _classCallCheck2.default)(this, Line);
|
|
58
|
-
|
|
59
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
60
|
-
args[_key] = arguments[_key];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
64
|
-
(0, _initializerDefineProperty2.default)(_this, "materialSystem", _descriptor, (0, _assertThisInitialized2.default)(_this));
|
|
65
|
-
(0, _initializerDefineProperty2.default)(_this, "geometrySystem", _descriptor2, (0, _assertThisInitialized2.default)(_this));
|
|
66
|
-
(0, _initializerDefineProperty2.default)(_this, "shaderModuleService", _descriptor3, (0, _assertThisInitialized2.default)(_this));
|
|
67
|
-
_this.vertexCount = void 0;
|
|
68
|
-
return _this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
(0, _createClass2.default)(Line, [{
|
|
72
|
-
key: "onAttributeChanged",
|
|
73
|
-
value: function onAttributeChanged(_ref) {
|
|
74
|
-
var name = _ref.name,
|
|
75
|
-
data = _ref.data;
|
|
76
|
-
var mesh = this.getMeshComponent();
|
|
77
|
-
|
|
78
|
-
if (mesh && mesh.material) {
|
|
79
|
-
switch (name) {
|
|
80
|
-
case 'dashArray':
|
|
81
|
-
mesh.material.setUniform('u_dash_array', data);
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'dashOffset':
|
|
85
|
-
mesh.material.setUniform('u_dash_offset', data);
|
|
86
|
-
break;
|
|
87
|
-
|
|
88
|
-
case 'dashRatio':
|
|
89
|
-
mesh.material.setUniform('u_dash_ratio', data);
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 'thickness':
|
|
93
|
-
mesh.material.setUniform('u_thickness', data);
|
|
94
|
-
break;
|
|
95
|
-
|
|
96
|
-
case 'color':
|
|
97
|
-
var colors = new Array(this.vertexCount).fill(undefined).map(function () {
|
|
98
|
-
return data;
|
|
99
|
-
}).reduce(function (prev, cur) {
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(cur));
|
|
102
|
-
}, []); // @ts-ignore
|
|
103
|
-
|
|
104
|
-
mesh.geometry.setAttribute('a_color', Float32Array.from(colors), {
|
|
105
|
-
arrayStride: 4 * 4,
|
|
106
|
-
stepMode: 'vertex',
|
|
107
|
-
attributes: [{
|
|
108
|
-
shaderLocation: 1,
|
|
109
|
-
offset: 0,
|
|
110
|
-
format: 'float4'
|
|
111
|
-
}]
|
|
112
|
-
});
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, {
|
|
118
|
-
key: "onEntityCreated",
|
|
119
|
-
value: function onEntityCreated() {
|
|
120
|
-
var _this2 = this;
|
|
121
|
-
|
|
122
|
-
this.shaderModuleService.registerModule('line', {
|
|
123
|
-
vs: lineVert,
|
|
124
|
-
fs: lineFrag
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
var _this$shaderModuleSer = this.shaderModuleService.getModule('line'),
|
|
128
|
-
vs = _this$shaderModuleSer.vs,
|
|
129
|
-
fs = _this$shaderModuleSer.fs,
|
|
130
|
-
extractedUniforms = _this$shaderModuleSer.uniforms;
|
|
131
|
-
|
|
132
|
-
var material = this.materialSystem.createShaderMaterial({
|
|
133
|
-
vertexShader: vs,
|
|
134
|
-
fragmentShader: fs
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
var _getNormals = (0, _polylineNormals.default)(this.config.points, false),
|
|
138
|
-
normals = _getNormals.normals,
|
|
139
|
-
attrIndex = _getNormals.attrIndex,
|
|
140
|
-
attrPos = _getNormals.attrPos,
|
|
141
|
-
attrCounters = _getNormals.attrCounters;
|
|
142
|
-
|
|
143
|
-
var vertexCount = attrPos.length;
|
|
144
|
-
this.vertexCount = vertexCount;
|
|
145
|
-
var geometry = this.geometrySystem.createBufferGeometry({
|
|
146
|
-
vertexCount: vertexCount
|
|
147
|
-
});
|
|
148
|
-
this.setMaterial(material);
|
|
149
|
-
this.setGeometry(geometry);
|
|
150
|
-
material.setCull({
|
|
151
|
-
enable: false,
|
|
152
|
-
face: _gWebgpuCore.gl.BACK
|
|
153
|
-
}) // @ts-ignore
|
|
154
|
-
.setUniform(extractedUniforms);
|
|
155
|
-
this.setAttributes({
|
|
156
|
-
dashArray: this.config.dashArray,
|
|
157
|
-
dashOffset: this.config.dashOffset,
|
|
158
|
-
dashRatio: this.config.dashRatio,
|
|
159
|
-
thickness: this.config.thickness
|
|
160
|
-
});
|
|
161
|
-
var attrNormal = [];
|
|
162
|
-
var attrMiter = [];
|
|
163
|
-
normals.forEach(function (n) {
|
|
164
|
-
var norm = n[0];
|
|
165
|
-
var miter = n[1];
|
|
166
|
-
attrNormal.push([norm[0], norm[1]]); // @ts-ignore
|
|
167
|
-
|
|
168
|
-
attrMiter.push(miter);
|
|
169
|
-
}); // [[0,1,2], [2,1,3]]
|
|
170
|
-
|
|
171
|
-
geometry.setIndex(attrIndex.reduce(function (prev, cur) {
|
|
172
|
-
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(cur));
|
|
173
|
-
}, []));
|
|
174
|
-
geometry.setAttribute('a_pos', Float32Array.from(attrPos.reduce(function (prev, cur) {
|
|
175
|
-
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(cur));
|
|
176
|
-
}, [])), {
|
|
177
|
-
arrayStride: 4 * 2,
|
|
178
|
-
stepMode: 'vertex',
|
|
179
|
-
attributes: [{
|
|
180
|
-
shaderLocation: 0,
|
|
181
|
-
offset: 0,
|
|
182
|
-
format: 'float2'
|
|
183
|
-
}]
|
|
184
|
-
});
|
|
185
|
-
var colors = new Array(vertexCount).fill(undefined).map(function () {
|
|
186
|
-
return (0, _toConsumableArray2.default)(_this2.config.color);
|
|
187
|
-
}).reduce(function (prev, cur) {
|
|
188
|
-
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(cur));
|
|
189
|
-
}, []);
|
|
190
|
-
geometry.setAttribute('a_color', Float32Array.from(colors), {
|
|
191
|
-
arrayStride: 4 * 4,
|
|
192
|
-
stepMode: 'vertex',
|
|
193
|
-
attributes: [{
|
|
194
|
-
shaderLocation: 1,
|
|
195
|
-
offset: 0,
|
|
196
|
-
format: 'float4'
|
|
197
|
-
}]
|
|
198
|
-
});
|
|
199
|
-
geometry.setAttribute('a_line_miter', Float32Array.from(attrMiter), {
|
|
200
|
-
arrayStride: 4 * 1,
|
|
201
|
-
stepMode: 'vertex',
|
|
202
|
-
attributes: [{
|
|
203
|
-
shaderLocation: 2,
|
|
204
|
-
offset: 0,
|
|
205
|
-
format: 'float'
|
|
206
|
-
}]
|
|
207
|
-
});
|
|
208
|
-
geometry.setAttribute('a_line_normal', Float32Array.from(attrNormal.reduce(function (prev, cur) {
|
|
209
|
-
return [].concat((0, _toConsumableArray2.default)(prev), (0, _toConsumableArray2.default)(cur));
|
|
210
|
-
}, [])), {
|
|
211
|
-
arrayStride: 4 * 2,
|
|
212
|
-
stepMode: 'vertex',
|
|
213
|
-
attributes: [{
|
|
214
|
-
shaderLocation: 3,
|
|
215
|
-
offset: 0,
|
|
216
|
-
format: 'float2'
|
|
217
|
-
}]
|
|
218
|
-
});
|
|
219
|
-
geometry.setAttribute('a_counters', Float32Array.from(attrCounters), {
|
|
220
|
-
arrayStride: 4 * 1,
|
|
221
|
-
stepMode: 'vertex',
|
|
222
|
-
attributes: [{
|
|
223
|
-
shaderLocation: 4,
|
|
224
|
-
offset: 0,
|
|
225
|
-
format: 'float'
|
|
226
|
-
}]
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}]);
|
|
230
|
-
return Line;
|
|
231
|
-
}(_Renderable2.Renderable), _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "materialSystem", [_dec2, _dec3], {
|
|
232
|
-
configurable: true,
|
|
233
|
-
enumerable: true,
|
|
234
|
-
writable: true,
|
|
235
|
-
initializer: null
|
|
236
|
-
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "geometrySystem", [_dec4, _dec5], {
|
|
237
|
-
configurable: true,
|
|
238
|
-
enumerable: true,
|
|
239
|
-
writable: true,
|
|
240
|
-
initializer: null
|
|
241
|
-
}), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "shaderModuleService", [_dec6], {
|
|
242
|
-
configurable: true,
|
|
243
|
-
enumerable: true,
|
|
244
|
-
writable: true,
|
|
245
|
-
initializer: null
|
|
246
|
-
})), _class2)) || _class);
|
|
247
|
-
exports.Line = Line;
|
|
248
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/renderable/line/index.ts"],"names":["Line","IDENTIFIER","Systems","MaterialSystem","GeometrySystem","ShaderModuleService","vertexCount","name","data","mesh","getMeshComponent","material","setUniform","colors","Array","fill","undefined","map","reduce","prev","cur","geometry","setAttribute","Float32Array","from","arrayStride","stepMode","attributes","shaderLocation","offset","format","shaderModuleService","registerModule","vs","lineVert","fs","lineFrag","getModule","extractedUniforms","uniforms","materialSystem","createShaderMaterial","vertexShader","fragmentShader","config","points","normals","attrIndex","attrPos","attrCounters","length","geometrySystem","createBufferGeometry","setMaterial","setGeometry","setCull","enable","face","gl","BACK","setAttributes","dashArray","dashOffset","dashRatio","thickness","attrNormal","attrMiter","forEach","n","norm","miter","push","setIndex","color","Renderable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AAEA;;AACA;;;;;;;;;;;;;IAeaA,I,WADZ,4B,UAEE,uBAAOC,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWE,cAAjB,C,UAGA,uBAAOF,wBAAWC,OAAlB,C,UACA,sBAAMD,wBAAWG,cAAjB,C,UAGA,uBAAOH,wBAAWI,mBAAlB,C;;;;;;;;;;;;;;;;;;UAGOC,W;;;;;;6CAQL;AAAA,UALDC,IAKC,QALDA,IAKC;AAAA,UAJDC,IAIC,QAJDA,IAIC;AACD,UAAMC,IAAI,GAAG,KAAKC,gBAAL,EAAb;;AACA,UAAID,IAAI,IAAIA,IAAI,CAACE,QAAjB,EAA2B;AACzB,gBAAQJ,IAAR;AACE,eAAK,WAAL;AACEE,YAAAA,IAAI,CAACE,QAAL,CAAcC,UAAd,CAAyB,cAAzB,EAAyCJ,IAAzC;AACA;;AACF,eAAK,YAAL;AACEC,YAAAA,IAAI,CAACE,QAAL,CAAcC,UAAd,CAAyB,eAAzB,EAA0CJ,IAA1C;AACA;;AACF,eAAK,WAAL;AACEC,YAAAA,IAAI,CAACE,QAAL,CAAcC,UAAd,CAAyB,cAAzB,EAAyCJ,IAAzC;AACA;;AACF,eAAK,WAAL;AACEC,YAAAA,IAAI,CAACE,QAAL,CAAcC,UAAd,CAAyB,aAAzB,EAAwCJ,IAAxC;AACA;;AACF,eAAK,OAAL;AACE,gBAAMK,MAAM,GAAG,IAAIC,KAAJ,CAAU,KA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oE;AAClEzC,QAAAA,WAAW,EAAE,IAAI,CADiD;AAElEC,QAAAA,QAAQ,EAAE,QAFwD;AAGlEC,QAAAA,UAAU,EAAE,CACV;AACEC,UAAAA,cAAc,EAAE,CADlB;AAEEC,UAAAA,MAAM,EAAE,CAFV;AAGEC,UAAAA,MAAM,EAAE;AAHV,SADU;AAHsD,OAApE;AAYAT,MAAAA,QAAQ,CAACC,YAAT,CACE,eADF,EAEEC,YAAY,CAACC,IAAb,CACEyC,UAAU,CAAC/C,MAAX,CAAkB,UAACC,IAAD,EAAOC,GAAP,EAAe;AAC/B,0DAAWD,IAAX,oCAAoBC,GAApB;AACD,OAFD,EAEG,EAFH,CADF,CAFF,EAOE;AACEK,QAAAA,WAAW,EAAE,IAAI,CADnB;AAEEC,QAAAA,QAAQ,EAAE,QAFZ;AAGEC,QAAAA,UAAU,EAAE,CACV;AACEC,UAAAA,cAAc,EAAE,CADlB;AAEEC,UAAAA,MAAM,EAAE,CAFV;AAGEC,UAAAA,MAAM,EAAE;AAHV,SADU;AAHd,OAPF;AAoBAT,MAAAA,QAAQ,CAACC,YAAT,CAAsB,YAAtB,EAAoCC,YAAY,CAACC,IAAb,CAAkByB,YAAlB,CAApC,EAAqE;AACnExB,QAAAA,WAAW,EAAE,IAAI,CADkD;AAEnEC,QAAAA,QAAQ,EAAE,QAFyD;AAGnEC,QAAAA,UAAU,EAAE,CACV;AACEC,UAAAA,cAAc,EAAE,CADlB;AAEEC,UAAAA,MAAM,EAAE,CAFV;AAGEC,UAAAA,MAAM,EAAE;AAHV,SADU;AAHuD,OAArE;AAWD;;;EA5MuB4C,uB","sourcesContent":["import {\n BufferData,\n GeometrySystem,\n gl,\n IDENTIFIER,\n IShaderModuleService,\n MaterialSystem,\n} from '@antv/g-webgpu-core';\nimport { inject, injectable, named } from 'inversify';\nimport { encodePickingColor } from '../../utils/picking';\nimport getNormals from '../../utils/polyline-normals';\nimport { Renderable } from '../Renderable';\nimport lineFrag from './shaders/webgl.line.frag.glsl';\nimport lineVert from './shaders/webgl.line.vert.glsl';\n\ninterface ILineConfig {\n id: number;\n points: number[][];\n thickness: number;\n color: [number, number, number, number]; // sRGB\n dashOffset: number;\n dashArray: number;\n dashRatio: number;\n}\n\n@injectable()\nexport class Line extends Renderable<Partial<ILineConfig>> {\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.MaterialSystem)\n private readonly materialSystem: MaterialSystem;\n\n @inject(IDENTIFIER.Systems)\n @named(IDENTIFIER.GeometrySystem)\n private readonly geometrySystem: GeometrySystem;\n\n @inject(IDENTIFIER.ShaderModuleService)\n private readonly shaderModuleService: IShaderModuleService;\n\n private vertexCount: number;\n\n protected onAttributeChanged({\n name,\n data,\n }: {\n name: string;\n data: BufferData;\n }) {\n const mesh = this.getMeshComponent();\n if (mesh && mesh.material) {\n switch (name) {\n case 'dashArray':\n mesh.material.setUniform('u_dash_array', data);\n break;\n case 'dashOffset':\n mesh.material.setUniform('u_dash_offset', data);\n break;\n case 'dashRatio':\n mesh.material.setUniform('u_dash_ratio', data);\n break;\n case 'thickness':\n mesh.material.setUniform('u_thickness', data);\n break;\n case 'color':\n const colors = new Array(this.vertexCount)\n .fill(undefined)\n .map(() => data)\n .reduce((prev, cur) => {\n // @ts-ignore\n return [...prev, ...cur];\n }, []);\n // @ts-ignore\n mesh.geometry.setAttribute('a_color', Float32Array.from(colors), {\n arrayStride: 4 * 4,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 1,\n offset: 0,\n format: 'float4',\n },\n ],\n });\n break;\n }\n }\n }\n\n protected onEntityCreated() {\n this.shaderModuleService.registerModule('line', {\n vs: lineVert,\n fs: lineFrag,\n });\n const {\n vs,\n fs,\n uniforms: extractedUniforms,\n } = this.shaderModuleService.getModule('line');\n\n const material = this.materialSystem.createShaderMaterial({\n vertexShader: vs!,\n fragmentShader: fs!,\n });\n\n const { normals, attrIndex, attrPos, attrCounters } = getNormals(\n this.config.points!,\n false,\n );\n const vertexCount = attrPos.length;\n this.vertexCount = vertexCount;\n const geometry = this.geometrySystem.createBufferGeometry({\n vertexCount,\n });\n\n this.setMaterial(material);\n this.setGeometry(geometry);\n\n material\n .setCull({\n enable: false,\n face: gl.BACK,\n })\n // @ts-ignore\n .setUniform(extractedUniforms);\n\n this.setAttributes({\n dashArray: this.config.dashArray,\n dashOffset: this.config.dashOffset,\n dashRatio: this.config.dashRatio,\n thickness: this.config.thickness,\n });\n\n const attrNormal: number[][] = [];\n const attrMiter: number[] = [];\n\n normals.forEach((n: number[][]) => {\n const norm = n[0];\n const miter = n[1];\n attrNormal.push([norm[0], norm[1]]);\n // @ts-ignore\n attrMiter.push(miter);\n });\n\n // [[0,1,2], [2,1,3]]\n geometry.setIndex(\n attrIndex.reduce((prev, cur) => {\n return [...prev, ...cur];\n }, []),\n );\n\n geometry.setAttribute(\n 'a_pos',\n Float32Array.from(\n attrPos.reduce((prev, cur) => {\n return [...prev, ...cur];\n }, []),\n ),\n {\n arrayStride: 4 * 2,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 0,\n offset: 0,\n format: 'float2',\n },\n ],\n },\n );\n\n const colors = new Array(vertexCount)\n .fill(undefined)\n .map(() => [...this.config.color!])\n .reduce((prev, cur) => {\n return [...prev, ...cur];\n }, []);\n geometry.setAttribute('a_color', Float32Array.from(colors), {\n arrayStride: 4 * 4,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 1,\n offset: 0,\n format: 'float4',\n },\n ],\n });\n\n geometry.setAttribute('a_line_miter', Float32Array.from(attrMiter), {\n arrayStride: 4 * 1,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 2,\n offset: 0,\n format: 'float',\n },\n ],\n });\n\n geometry.setAttribute(\n 'a_line_normal',\n Float32Array.from(\n attrNormal.reduce((prev, cur) => {\n return [...prev, ...cur];\n }, []),\n ),\n {\n arrayStride: 4 * 2,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 3,\n offset: 0,\n format: 'float2',\n },\n ],\n },\n );\n\n geometry.setAttribute('a_counters', Float32Array.from(attrCounters), {\n arrayStride: 4 * 1,\n stepMode: 'vertex',\n attributes: [\n {\n shaderLocation: 4,\n offset: 0,\n format: 'float',\n },\n ],\n });\n }\n}\n"],"file":"index.js"}
|