@voxel-pixel/entity 0.0.1-beta.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.
@@ -0,0 +1,6 @@
1
+ import { Entity } from "@voxel-pixel/core";
2
+ declare class BaseEntity extends Entity {
3
+ uuid: any;
4
+ constructor(options?: Entity.ConstructorOptions);
5
+ }
6
+ export { BaseEntity };
package/BaseEntity.js ADDED
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { Entity } from "@voxel-pixel/core";
8
+ import { generateUUID } from "@voxel-pixel/utils";
9
+ class BaseEntity extends Entity {
10
+ constructor(options) {
11
+ super(options);
12
+ __publicField(this, "uuid", generateUUID());
13
+ }
14
+ }
15
+ export {
16
+ BaseEntity
17
+ };
@@ -0,0 +1,6 @@
1
+ import { Container, EllipseGraphics } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity";
3
+ declare class Circle extends SingleEntity {
4
+ constructor(container: Container, options: EllipseGraphics.ConstructorOptions);
5
+ }
6
+ export { Circle };
@@ -0,0 +1,14 @@
1
+ import { CallbackProperty } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity.js";
3
+ class Circle extends SingleEntity {
4
+ constructor(container, options) {
5
+ super(container);
6
+ this.instance = container.viewer.entities.add({
7
+ position: new CallbackProperty(() => this.getPosition(), false),
8
+ ellipse: options
9
+ });
10
+ }
11
+ }
12
+ export {
13
+ Circle
14
+ };
package/Entity.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Container, HeadingPitchRange, Entity as CesiumEntity, type PropertyBag } from "@voxel-pixel/core";
2
+ declare abstract class Entity {
3
+ uuid: any;
4
+ protected container: Container;
5
+ instance?: CesiumEntity;
6
+ constructor(container: Container);
7
+ setProperties(properties: PropertyBag): void;
8
+ lookAtMe(offset?: HeadingPitchRange): void;
9
+ setVisible(visible: boolean): void;
10
+ destroy(): void;
11
+ }
12
+ export { Entity };
package/Entity.js ADDED
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { generateUUID } from "@voxel-pixel/utils";
8
+ class Entity {
9
+ constructor(container) {
10
+ __publicField(this, "uuid", generateUUID());
11
+ __publicField(this, "container");
12
+ __publicField(this, "instance");
13
+ this.container = container;
14
+ }
15
+ setProperties(properties) {
16
+ if (this.instance)
17
+ this.instance.properties = properties;
18
+ }
19
+ lookAtMe(offset) {
20
+ if (this.instance)
21
+ this.container.viewer.zoomTo(this.instance, offset);
22
+ }
23
+ setVisible(visible) {
24
+ if (this.instance)
25
+ this.instance.show = visible;
26
+ }
27
+ destroy() {
28
+ if (this.instance)
29
+ this.container.viewer.entities.remove(this.instance);
30
+ this.instance = void 0;
31
+ }
32
+ }
33
+ export {
34
+ Entity
35
+ };
@@ -0,0 +1,36 @@
1
+ import { Container, HeadingPitchRange } from "@voxel-pixel/core";
2
+ import { Entity } from "../Entity";
3
+ import { BaseEntity } from "../BaseEntity";
4
+ import { SingleEntity } from "../SingleEntity";
5
+ declare class Group {
6
+ protected container: Container;
7
+ constructor(container: Container);
8
+ /**
9
+ * 添加子集
10
+ * @param child
11
+ */
12
+ children: (Entity | BaseEntity | SingleEntity)[];
13
+ addChild(child: Entity | BaseEntity | SingleEntity): string;
14
+ /**
15
+ * 观看某个子集
16
+ * @param uuid
17
+ */
18
+ lookAtChild(uuid: string, offset?: HeadingPitchRange, height?: number): void;
19
+ /**
20
+ * 设置某个子集的显示状态
21
+ * @param uuid
22
+ */
23
+ setChildVisible(uuid: string, visible: boolean): void;
24
+ /**
25
+ * 设置显示状态
26
+ * @param visible 为true显示,false隐藏
27
+ */
28
+ setVisible(visible: boolean): void;
29
+ destroy(): void;
30
+ /**
31
+ * 销毁某个子集
32
+ * @param uuid
33
+ */
34
+ destroyChild(uuid: string): void;
35
+ }
36
+ export { Group };
package/Group/index.js ADDED
@@ -0,0 +1,98 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { Entity } from "../Entity.js";
8
+ import { BaseEntity } from "../BaseEntity.js";
9
+ import { SingleEntity } from "../SingleEntity.js";
10
+ class Group {
11
+ constructor(container) {
12
+ __publicField(this, "container");
13
+ /**
14
+ * 添加子集
15
+ * @param child
16
+ */
17
+ __publicField(this, "children", []);
18
+ this.container = container;
19
+ }
20
+ addChild(child) {
21
+ this.children.push(child);
22
+ return child.uuid;
23
+ }
24
+ /**
25
+ * 观看某个子集
26
+ * @param uuid
27
+ */
28
+ lookAtChild(uuid, offset, height) {
29
+ const child = this.children.find((item) => item.uuid === uuid);
30
+ if (child) {
31
+ if (child instanceof BaseEntity) {
32
+ this.container.viewer.zoomTo(child, offset);
33
+ } else if (child instanceof SingleEntity) {
34
+ child.lookAtMe(offset, height);
35
+ } else if (child instanceof Entity) {
36
+ child.lookAtMe(offset);
37
+ }
38
+ }
39
+ }
40
+ /**
41
+ * 设置某个子集的显示状态
42
+ * @param uuid
43
+ */
44
+ setChildVisible(uuid, visible) {
45
+ const child = this.children.find((item) => item.uuid === uuid);
46
+ if (child) {
47
+ if (child instanceof BaseEntity) {
48
+ child.show = visible;
49
+ } else if (child instanceof Entity) {
50
+ child.setVisible(visible);
51
+ }
52
+ }
53
+ }
54
+ /**
55
+ * 设置显示状态
56
+ * @param visible 为true显示,false隐藏
57
+ */
58
+ setVisible(visible) {
59
+ this.children.forEach((item) => {
60
+ if (item instanceof BaseEntity) {
61
+ item.show = visible;
62
+ } else if (item instanceof Entity) {
63
+ item.setVisible(visible);
64
+ }
65
+ });
66
+ }
67
+ //销毁
68
+ destroy() {
69
+ for (let i = this.children.length - 1; i >= 0; i--) {
70
+ const entity = this.children[i];
71
+ if (entity instanceof BaseEntity) {
72
+ this.container.viewer.entities.remove(entity);
73
+ } else if (entity instanceof Entity) {
74
+ entity.destroy();
75
+ }
76
+ }
77
+ this.children = [];
78
+ }
79
+ /**
80
+ * 销毁某个子集
81
+ * @param uuid
82
+ */
83
+ destroyChild(uuid) {
84
+ const idx = this.children.findIndex((item) => item.uuid === uuid);
85
+ if (idx !== -1) {
86
+ const child = this.children[idx];
87
+ if (child instanceof BaseEntity) {
88
+ this.container.viewer.entities.remove(child);
89
+ } else if (child instanceof Entity) {
90
+ child.destroy();
91
+ }
92
+ }
93
+ this.children.splice(idx, 1);
94
+ }
95
+ }
96
+ export {
97
+ Group
98
+ };
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2025-PRESENT voxel-pixel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ import { Container, PolylineGraphics, Cartesian3 } from "@voxel-pixel/core";
2
+ import { Entity } from "../Entity";
3
+ declare class Line extends Entity {
4
+ positions: Cartesian3[];
5
+ constructor(container: Container, options: PolylineGraphics.ConstructorOptions);
6
+ }
7
+ export { Line };
package/Line/index.js ADDED
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { CallbackProperty } from "@voxel-pixel/core";
8
+ import { Entity } from "../Entity.js";
9
+ class Line extends Entity {
10
+ constructor(container, options) {
11
+ super(container);
12
+ __publicField(this, "positions", []);
13
+ this.instance = container.viewer.entities.add({
14
+ polyline: {
15
+ ...options,
16
+ positions: new CallbackProperty(() => this.positions, false)
17
+ }
18
+ });
19
+ }
20
+ }
21
+ export {
22
+ Line
23
+ };
@@ -0,0 +1,6 @@
1
+ import { Container, PointGraphics } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity";
3
+ declare class Point extends SingleEntity {
4
+ constructor(container: Container, options: PointGraphics.ConstructorOptions);
5
+ }
6
+ export { Point };
package/Point/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { CallbackProperty } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity.js";
3
+ class Point extends SingleEntity {
4
+ constructor(container, options) {
5
+ super(container);
6
+ this.instance = container.viewer.entities.add({
7
+ position: new CallbackProperty(() => this.getPosition(), false),
8
+ point: options
9
+ });
10
+ }
11
+ }
12
+ export {
13
+ Point
14
+ };
@@ -0,0 +1,10 @@
1
+ import { Container, PolygonGraphics, PolylineGraphics, Cartesian3 } from "@voxel-pixel/core";
2
+ import { Entity } from "../Entity";
3
+ interface IPolygonOptions extends PolygonGraphics.ConstructorOptions {
4
+ lineOption: PolylineGraphics.ConstructorOptions;
5
+ }
6
+ declare class Polgyon extends Entity {
7
+ positions: Cartesian3[];
8
+ constructor(container: Container, options: IPolygonOptions);
9
+ }
10
+ export { Polgyon };
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { CallbackProperty, PolygonHierarchy } from "@voxel-pixel/core";
8
+ import { Entity } from "../Entity.js";
9
+ class Polgyon extends Entity {
10
+ constructor(container, options) {
11
+ super(container);
12
+ __publicField(this, "positions", []);
13
+ const params = {
14
+ polygon: {
15
+ ...options,
16
+ hierarchy: new CallbackProperty(() => new PolygonHierarchy(this.positions), false)
17
+ }
18
+ };
19
+ if (options.lineOption) {
20
+ params.polyline = {
21
+ ...options.lineOption,
22
+ positions: new CallbackProperty(() => this.positions, false)
23
+ };
24
+ }
25
+ this.instance = container.viewer.entities.add(params);
26
+ }
27
+ }
28
+ export {
29
+ Polgyon
30
+ };
@@ -0,0 +1,9 @@
1
+ import { Container, Cartesian3, HeadingPitchRange } from "@voxel-pixel/core";
2
+ import { Entity } from "./Entity";
3
+ declare abstract class SingleEntity extends Entity {
4
+ position: Cartesian3;
5
+ constructor(container: Container);
6
+ lookAtMe(offset?: HeadingPitchRange, height?: number): void;
7
+ protected getPosition(): any;
8
+ }
9
+ export { SingleEntity };
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { Cartesian3, Cartographic, sampleTerrainMostDetailed } from "@voxel-pixel/core";
8
+ import { Entity } from "./Entity.js";
9
+ class SingleEntity extends Entity {
10
+ constructor(container) {
11
+ super(container);
12
+ __publicField(this, "position");
13
+ this.position = new Cartesian3();
14
+ }
15
+ lookAtMe(offset, height) {
16
+ if (!this.instance)
17
+ return;
18
+ if (this.container.mountedTerrain) {
19
+ const cartographic = Cartographic.fromCartesian(this.position);
20
+ sampleTerrainMostDetailed(
21
+ this.container.viewer.scene.terrainProvider,
22
+ [cartographic]
23
+ ).then(([terrainPoint]) => {
24
+ const terrainHeight = Math.max(terrainPoint.height || 0, 0);
25
+ cartographic.height = terrainHeight + (height || 0);
26
+ this.container.viewer.camera.setView({
27
+ destination: Cartographic.toCartesian(cartographic),
28
+ orientation: offset || {
29
+ heading: Math.PI / 2,
30
+ pitch: -Math.PI / 2,
31
+ roll: 0
32
+ }
33
+ });
34
+ });
35
+ } else {
36
+ const cartographic = Cartographic.fromCartesian(this.position);
37
+ cartographic.height = height || 500;
38
+ this.container.viewer.camera.setView({
39
+ destination: Cartographic.toCartesian(cartographic),
40
+ orientation: offset || {
41
+ heading: Math.PI / 2,
42
+ pitch: -Math.PI / 2,
43
+ roll: 0
44
+ }
45
+ });
46
+ }
47
+ }
48
+ getPosition() {
49
+ return Cartesian3.clone(this.position);
50
+ }
51
+ }
52
+ export {
53
+ SingleEntity
54
+ };
@@ -0,0 +1,6 @@
1
+ import { Container, BillboardGraphics } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity";
3
+ declare class Sprite extends SingleEntity {
4
+ constructor(container: Container, options: BillboardGraphics.ConstructorOptions);
5
+ }
6
+ export { Sprite };
@@ -0,0 +1,14 @@
1
+ import { CallbackProperty } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity.js";
3
+ class Sprite extends SingleEntity {
4
+ constructor(container, options) {
5
+ super(container);
6
+ this.instance = container.viewer.entities.add({
7
+ position: new CallbackProperty(() => this.getPosition(), false),
8
+ billboard: options
9
+ });
10
+ }
11
+ }
12
+ export {
13
+ Sprite
14
+ };
@@ -0,0 +1,6 @@
1
+ import { Container, LabelGraphics } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity";
3
+ declare class Text extends SingleEntity {
4
+ constructor(container: Container, options: LabelGraphics.ConstructorOptions);
5
+ }
6
+ export { Text };
package/Text/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { CallbackProperty } from "@voxel-pixel/core";
2
+ import { SingleEntity } from "../SingleEntity.js";
3
+ class Text extends SingleEntity {
4
+ constructor(container, options) {
5
+ super(container);
6
+ this.instance = container.viewer.entities.add({
7
+ position: new CallbackProperty(() => this.getPosition(), false),
8
+ label: options
9
+ });
10
+ }
11
+ }
12
+ export {
13
+ Text
14
+ };
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./BaseEntity";
2
+ export * from "./Point";
3
+ export * from "./Line";
4
+ export * from "./Polygon";
5
+ export * from "./Circle";
6
+ export * from "./Sprite";
7
+ export * from "./Text";
8
+ export * from "./Group";
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { BaseEntity } from "./BaseEntity.js";
2
+ import { Point } from "./Point/index.js";
3
+ import { Line } from "./Line/index.js";
4
+ import { Polgyon } from "./Polygon/index.js";
5
+ import { Circle } from "./Circle/index.js";
6
+ import { Sprite } from "./Sprite/index.js";
7
+ import { Text } from "./Text/index.js";
8
+ import { Group } from "./Group/index.js";
9
+ export {
10
+ BaseEntity,
11
+ Circle,
12
+ Group,
13
+ Line,
14
+ Point,
15
+ Polgyon,
16
+ Sprite,
17
+ Text
18
+ };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@voxel-pixel/entity",
3
+ "version": "0.0.1-beta.0",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "description": "实体",
7
+ "author": "poggi",
8
+ "license": "MIT",
9
+ "typings": "./index.d.ts",
10
+ "peerDependencies": {
11
+ "@voxel-pixel/core": "0.0.1-beta.0",
12
+ "@voxel-pixel/utils": "0.0.1-beta.0"
13
+ },
14
+ "publishConfig": {
15
+ "registry": "https://registry.npmjs.org/"
16
+ }
17
+ }