@webspatial/core-sdk 1.0.4 → 1.0.5
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 +2 -0
- package/README.md +112 -81
- package/dist/iife/index.d.ts +683 -561
- package/dist/iife/index.global.js +3 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +683 -561
- package/dist/index.js +2175 -1291
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/JSBCommand.ts +631 -0
- package/src/Spatial.ts +68 -0
- package/src/SpatialObject.ts +46 -0
- package/src/SpatialScene.ts +75 -0
- package/src/SpatialSession.ts +187 -0
- package/src/SpatialWebEvent.ts +23 -0
- package/src/SpatialWebEventCreator.ts +12 -0
- package/src/Spatialized2DElement.ts +51 -0
- package/src/SpatializedDynamic3DElement.ts +30 -0
- package/src/SpatializedElement.ts +331 -0
- package/src/SpatializedElementCreator.ts +45 -0
- package/src/SpatializedStatic3DElement.ts +111 -0
- package/src/WebMsgCommand.ts +88 -0
- package/src/index.ts +23 -1
- package/src/platform-adapter/CommandResultUtils.ts +22 -0
- package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
- package/src/platform-adapter/index.ts +21 -0
- package/src/platform-adapter/interface.ts +36 -0
- package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
- package/src/reality/component/ModelComponent.ts +11 -0
- package/src/reality/component/SpatialComponent.ts +17 -0
- package/src/reality/component/index.ts +2 -0
- package/src/reality/entity/SpatialEntity.ts +255 -0
- package/src/reality/entity/SpatialModelEntity.ts +15 -0
- package/src/reality/entity/index.ts +2 -0
- package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
- package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
- package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
- package/src/reality/geometry/SpatialGeometry.ts +12 -0
- package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
- package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
- package/src/reality/geometry/index.ts +6 -0
- package/src/reality/index.ts +5 -0
- package/src/reality/material/SpatialMaterial.ts +14 -0
- package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
- package/src/reality/material/index.ts +2 -0
- package/src/reality/realityCreator.ts +94 -0
- package/src/reality/resource/SpatialModelAsset.ts +11 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/scene-polyfill.test.ts +376 -0
- package/src/scene-polyfill.ts +359 -0
- package/src/spatial-window-polyfill.ts +182 -0
- package/src/ssr-polyfill.ts +3 -0
- package/src/types/global.d.ts +33 -1
- package/src/types/internal.ts +13 -0
- package/src/types/types.ts +380 -0
- package/src/utils.ts +61 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +8 -0
- package/src/core/Spatial.ts +0 -50
- package/src/core/SpatialEntity.ts +0 -147
- package/src/core/SpatialHelper.ts +0 -230
- package/src/core/SpatialObject.ts +0 -26
- package/src/core/SpatialSession.ts +0 -457
- package/src/core/SpatialTransform.ts +0 -26
- package/src/core/SpatialWindowContainer.ts +0 -59
- package/src/core/component/EventSpatialComponent.ts +0 -32
- package/src/core/component/SpatialComponent.ts +0 -26
- package/src/core/component/SpatialInputComponent.ts +0 -24
- package/src/core/component/SpatialModel3DComponent.ts +0 -223
- package/src/core/component/SpatialModelComponent.ts +0 -39
- package/src/core/component/SpatialViewComponent.ts +0 -32
- package/src/core/component/SpatialWindowComponent.ts +0 -177
- package/src/core/component/index.ts +0 -14
- package/src/core/index.ts +0 -10
- package/src/core/private/WebSpatial.ts +0 -383
- package/src/core/private/remote-command/RemoteCommand.ts +0 -15
- package/src/core/private/remote-command/index.ts +0 -1
- package/src/core/resource/SpatialMeshResource.ts +0 -6
- package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
- package/src/core/resource/index.ts +0 -2
- package/src/core/types.ts +0 -32
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,115 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
> This library is still in development. APIs may change as we enable additional platforms/features
|
|
1
|
+
# WebSpatial Core SDK
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This library is still in development. APIs may change as we enable additional platforms/features.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
## Overview
|
|
7
7
|
|
|
8
|
-
The core-sdk library is responsible for interacting with the target
|
|
8
|
+
WebSpatial Core SDK is a framework-agnostic pure JavaScript API that enables the WebSpatial App Shell to natively spatialize 2D HTML content and render 3D content. The core-sdk library is responsible for interacting with the target platform's native APIs to expose spatial behaviors not commonly found on the web.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
To run a WebSpatial website you currently need to package it within a native app.
|
|
12
|
-
|
|
13
|
-
See docs on our [github](https://github.com/webspatial/webspatial-sd) for more information.
|
|
10
|
+
## Installation
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
```bash
|
|
13
|
+
npm install @webspatial/core-sdk
|
|
14
|
+
```
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
## Getting Started
|
|
17
|
+
|
|
18
|
+
To run a WebSpatial website, you currently need to package it within a native app. See documentation on our [GitHub repository](https://github.com/webspatial/webspatial-sdk) for more information.
|
|
19
|
+
|
|
20
|
+
### Hello World Example
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import { Spatial } from '@webspatial/core-sdk'
|
|
24
|
+
|
|
25
|
+
const main = async () => {
|
|
26
|
+
// Initialize the Spatial environment
|
|
27
|
+
const spatial = new Spatial()
|
|
28
|
+
|
|
29
|
+
if (spatial.isSupported()) {
|
|
30
|
+
const session = spatial.requestSession()
|
|
31
|
+
if (session) {
|
|
32
|
+
console.log("Session supported and created")
|
|
33
|
+
|
|
34
|
+
// Now you can create spatial elements
|
|
35
|
+
// Example: Create a 2D element
|
|
36
|
+
const element2D = await session.createSpatialized2DElement()
|
|
37
|
+
|
|
38
|
+
// Example: Create a 3D static element (for models)
|
|
39
|
+
const static3DElement = await session.createSpatializedStatic3DElement()
|
|
40
|
+
|
|
41
|
+
// Example: Create a 3D dynamic element (for custom geometry)
|
|
42
|
+
const dynamic3DElement = await session.createSpatializedDynamic3DElement()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
19
46
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var versionInfo = "clientVersion:" + spatial.getClientVersion() + "\nnativeVersion:" + spatial.getNativeVersion() + "\nisSupported:" + spatial.isSupported()
|
|
47
|
+
main()
|
|
48
|
+
```
|
|
23
49
|
|
|
24
|
-
|
|
25
|
-
if (sh) {
|
|
26
|
-
// Create a new window container
|
|
27
|
-
var container = await sh.session.createWindowContainer({ style: 'Volumetric' })
|
|
50
|
+
## Core Concepts
|
|
28
51
|
|
|
29
|
-
|
|
30
|
-
var rootEntity = await sh.session.createEntity()
|
|
31
|
-
await rootEntity.setCoordinateSpace("Root")
|
|
32
|
-
rootEntity.setComponent(await sh.session.createViewComponent())
|
|
52
|
+
### Initialization
|
|
33
53
|
|
|
34
|
-
|
|
35
|
-
var box = await sh.shape.createShapeEntity("box")
|
|
36
|
-
await box.setParent(rootEntity)
|
|
54
|
+
Create a new `Spatial` object which is the root entry point to the API. This object should be available in standard browsers as well as WebSpatial environments. It can check client and native versions of the library and detect if WebSpatial is available in your setup.
|
|
37
55
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
```javascript
|
|
57
|
+
const spatial = new Spatial()
|
|
58
|
+
if (spatial.isSupported()) {
|
|
59
|
+
const session = spatial.requestSession()
|
|
60
|
+
if (session) {
|
|
61
|
+
console.log("Session supported and created")
|
|
62
|
+
}
|
|
41
63
|
}
|
|
42
|
-
main()
|
|
43
64
|
```
|
|
44
65
|
|
|
45
|
-
|
|
66
|
+
### Async/Await/Promises
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
Due to the architecture of WebSpatial, the client library communicates with native code over a JS Bridge provided by the platform. Because of this, function calls may not be completed immediately. To accommodate this, the majority of WebSpatial API uses [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to track completion. It is recommended you create an async main function to allow you to use the await syntax for app setup.
|
|
48
69
|
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var session = spatial.requestSession()
|
|
53
|
-
if(session){
|
|
54
|
-
console.log("session supported and created")
|
|
55
|
-
}
|
|
70
|
+
```javascript
|
|
71
|
+
const main = async () => {
|
|
72
|
+
// Your code goes here
|
|
56
73
|
}
|
|
74
|
+
main()
|
|
57
75
|
```
|
|
58
76
|
|
|
59
|
-
|
|
77
|
+
## Key Components
|
|
60
78
|
|
|
61
|
-
|
|
79
|
+
### SpatialSession
|
|
62
80
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
main()'
|
|
81
|
+
The `SpatialSession` class is used to establish a connection to the spatial renderer of the system. All spatial resources must be created through this session.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
const session = spatial.requestSession()
|
|
68
85
|
```
|
|
69
86
|
|
|
70
|
-
|
|
87
|
+
Key methods include:
|
|
88
|
+
- `getSpatialScene()`: Returns the current spatial scene
|
|
89
|
+
- `createSpatialized2DElement()`: Creates a 2D element in spatial environment
|
|
90
|
+
- `createSpatializedStatic3DElement()`: Creates a static 3D element for models
|
|
91
|
+
- `createSpatializedDynamic3DElement()`: Creates a dynamic 3D element for custom geometry
|
|
71
92
|
|
|
72
|
-
|
|
93
|
+
### SpatializedElement
|
|
73
94
|
|
|
74
|
-
|
|
75
|
-
var windowContainer = await session.createWindowContainer({ style: 'Volumetric' })
|
|
76
|
-
```
|
|
95
|
+
The base class for all spatial elements. It provides common functionality for:
|
|
77
96
|
|
|
78
|
-
|
|
97
|
+
- Updating element properties
|
|
98
|
+
- Handling spatial transforms
|
|
99
|
+
- Processing spatial events (tap, drag, rotate, magnify)
|
|
79
100
|
|
|
80
|
-
|
|
101
|
+
### Element Types
|
|
81
102
|
|
|
82
|
-
|
|
103
|
+
#### Spatialized2DElement
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// Create component
|
|
89
|
-
await entity.setComponent(
|
|
90
|
-
await session.createViewComponent({ windowContainer: windowContainer }),
|
|
91
|
-
)
|
|
92
|
-
await entity.setCoordinateSpace('Root')
|
|
93
|
-
|
|
94
|
-
// Set root entity on the window container.
|
|
95
|
-
// Note the entity much have:
|
|
96
|
-
// - Root coordinate space
|
|
97
|
-
// - have a ViewComponent for Volumetric windowContainer
|
|
98
|
-
// - have a WindowComponent for Plain windowContainer
|
|
99
|
-
await windowContainer.setRootEntity(entity)
|
|
100
|
-
```
|
|
105
|
+
Represents HTML content in a spatial environment with properties like:
|
|
106
|
+
- Corner radius
|
|
107
|
+
- Background material type
|
|
108
|
+
- Scroll behavior
|
|
101
109
|
|
|
102
|
-
|
|
110
|
+
#### SpatializedStatic3DElement
|
|
103
111
|
|
|
104
|
-
|
|
112
|
+
Represents static 3D models loaded from URLs.
|
|
105
113
|
|
|
106
|
-
|
|
114
|
+
#### SpatializedDynamic3DElement
|
|
107
115
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'https://www.npmjs.com/package/@webspatial/core-sdk',
|
|
112
|
-
{ resolution: { width: 600, height: 100 } },
|
|
113
|
-
)
|
|
114
|
-
```
|
|
116
|
+
Represents dynamic 3D content with custom geometry and materials.
|
|
117
|
+
|
|
118
|
+
## Spatial Geometry and Materials
|
|
115
119
|
|
|
120
|
+
The SDK provides various geometry types:
|
|
121
|
+
- `SpatialBoxGeometry`
|
|
122
|
+
- `SpatialPlaneGeometry`
|
|
123
|
+
- `SpatialSphereGeometry`
|
|
124
|
+
- `SpatialConeGeometry`
|
|
125
|
+
- `SpatialCylinderGeometry`
|
|
126
|
+
|
|
127
|
+
And material options including:
|
|
128
|
+
- Background material types: 'none', 'translucent', 'thick', 'regular', 'thin', 'transparent'
|
|
129
|
+
- Custom unlit materials
|
|
130
|
+
|
|
131
|
+
## Event Handling
|
|
132
|
+
|
|
133
|
+
The SDK supports various spatial events:
|
|
134
|
+
- Tap events
|
|
135
|
+
- Drag events (start, drag, end)
|
|
136
|
+
- Rotate events (start, rotate, end)
|
|
137
|
+
- Magnify events (start, magnify, end)
|
|
138
|
+
|
|
139
|
+
## Advanced Usage
|
|
140
|
+
|
|
141
|
+
For more advanced usage and detailed API documentation, please refer to the [official documentation](https://github.com/webspatial/webspatial-sdk).
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
See the LICENSE file in the repository root for more information.
|
|
146
|
+
|