@shopware-ag/dive 1.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Shopware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+
2
+ # About
3
+ DIVE is a spatial framework made by and optimized for Shopware. It can be used directly integrated in a Shopware frontend such as Storefront or in any other frontend you want to use it in, it is not tied to Shopware.
4
+
5
+ DIVE supplies your frontend application with all needed tooling to set up a basic 3D application with event-based controls called "Actions". For further information, see [Getting started](#getting-started).
6
+
7
+ # Installation
8
+
9
+ #### npm:
10
+ ```
11
+ npm install @shopware-ag/dive
12
+ ```
13
+
14
+ #### yarn:
15
+ ```
16
+ yarn add @shopware-ag/dive
17
+ ```
18
+
19
+ #### Setup in Shopware
20
+ Don't forget to include DIVE in your webpack.config.js:
21
+ ```js
22
+ const path = require('path');
23
+
24
+ module.exports = () => {
25
+ return {
26
+ ...
27
+ resolve: {
28
+ extensions: ['.ts', '.tsx', '.js', '.vue'],
29
+ alias: {
30
+ dive: path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
31
+ }
32
+ },
33
+ ...
34
+ module: {
35
+ rules: [
36
+ ...
37
+ {
38
+ test: /\.(js|ts)$/,
39
+ loader: 'swc-loader',
40
+ include: [
41
+ path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive')
42
+ ],
43
+ options: {
44
+ jsc: {
45
+ parser: {
46
+ syntax: 'typescript',
47
+ },
48
+ target: 'es2022',
49
+ },
50
+ },
51
+ },
52
+ ...
53
+ ],
54
+ }
55
+ };
56
+ };
57
+ ```
58
+
59
+ # Getting started
60
+ Import:
61
+ ```ts
62
+ import { DIVE } from '@shopware-ag/dive'; // <-- import DIVE
63
+ ```
64
+
65
+ Instantiate:
66
+ ```ts
67
+ import { DIVE } from '@shopware-ag/dive';
68
+
69
+ const dive = new DIVE(); // <-- instantiate DIVE
70
+ ```
71
+
72
+ DIVE supplies your application with a HTMLCanvasElement that it uses as a render target. After instantiating, you can use the supplied canvas within you frontend code to attach it to your DOM.
73
+
74
+ ```ts
75
+ const dive = new DIVE();
76
+
77
+ const myCanvasWrapper = document.createElement('div'); // <-- create wrapper element
78
+ myCanvasWrapper.appendChild(dive.Canvas); // <-- reference DIVE canvas
79
+ ```
80
+
81
+ To interact with your newly created DIVE instance you have to perform actions via DIVECommunication. For further information, see [Actions](#actions).
82
+ ```ts
83
+ const dive = new DIVE();
84
+
85
+ const myCanvasWrapper = document.createElement('div');
86
+ myCanvasWrapper.appendChild(dive.Canvas);
87
+
88
+ const com = dive.Communication; // <-- reference DIVECommunication
89
+
90
+ com.PerformAction('SET_CAMERA_TRANSFORM', { // <-- perform action on DIVECommunication
91
+ position: { x: 0, y: 2, z: 2 },
92
+ target: { x: 0, y: 0.5, z: 0 },
93
+ });
94
+ ```
95
+
96
+ # Actions
97
+ Actions symbolize the communication between frontend and 3D space. All actions can be performed anywhere, no matter if you are in frontend or 3D.
98
+
99
+ In addition to the impact that specific actions have, every action can be subscribed to.
100
+ ```ts
101
+ const myCanvasWrapper = document.createElement('div');
102
+ const dive = new DIVE();
103
+
104
+ myCanvasWrapper.appendChild(dive.Canvas);
105
+
106
+ const com = dive.Communication;
107
+
108
+ com.Subscribe('SET_CAMERA_TRANSFORM', () => { // <-- add subscription
109
+ // do something
110
+ });
111
+
112
+ com.PerformAction('SET_CAMERA_TRANSFORM', {
113
+ position: { x: 0, y: 2, z: 2 },
114
+ target: { x: 0, y: 0.5, z: 0 },
115
+ });
116
+ ```
117
+
118
+ Subscribing to an action returns a `unsubscribe()`-callback that should be executed when not needed anymore.
119
+ ```ts
120
+ const myCanvasWrapper = document.createElement('div');
121
+ const dive = new DIVE();
122
+
123
+ myCanvasWrapper.appendChild(dive.Canvas);
124
+
125
+ const com = dive.Communication;
126
+
127
+ const unsubscribe = com.Subscribe('SET_CAMERA_TRANSFORM', () => { // <-- save unsubscribe callback
128
+ // do something
129
+ });
130
+
131
+ com.PerformAction('SET_CAMERA_TRANSFORM', {
132
+ position: { x: 0, y: 2, z: 2 },
133
+ target: { x: 0, y: 0.5, z: 0 },
134
+ });
135
+
136
+ unsubscribe(); // <-- execute unsubscribe callback when done
137
+ ```
138
+
139
+ In the following you find a list of all available actions to perform on DIVECommunication class via `com.PerformAction()`.
140
+
141
+ | Action | Description
142
+ | :--- | :---
143
+ | [GET_ALL_SCENE_DATA](./src/com/actions/scene/getallscenedata.ts) | Return all scene data that is currently set
144
+ | [SET_BACKGROUND](./src/com/actions/scene/setbackground.ts) | Set a background color
145
+ | [UPDATE_SCENE](./src/com/actions/scene/updatescene.ts) | Update scene data
146
+ | [GET_CAMERA_TRANSFORM](./src/com/actions/camera/getcameratransform.ts) | Return currenty camera transformation
147
+ | [MOVE_CAMERA](./src/com/actions/camera/movecamera.ts) | Move camera to a specific position or the position of a previously defined POV (with an animation)
148
+ | [RESET_CAMERA](./src/com/actions/camera/resetcamera.ts) | Reset camera to original position after MOVE_CAMERA was performed
149
+ | [SET_CAMERA_LAYER](./src/com/actions/camera/setcameralayer.ts) | Set camera layer to switch between live view and editor view
150
+ | [SET_CAMERA_TRANSFORM](./src/com/actions/camera/setcameratransform.ts) | Set camera transformation (w/o animation, used to initially set up camera)
151
+ | [ZOOM_CAMERA](./src/com/actions/camera/zoomcamera.ts) | Zoom in or out
152
+ | [GENERATE_MEDIA](./src/com/actions/media/generatemedia.ts) | Generate a screenshot with the specified parameters
153
+ | [MODEL_LOADED](./src/com/actions/object/model/modelloaded.ts) | Is performed when a model file is completely loaded
154
+ | [PLACE_ON_FLOOR](./src/com/actions/object/model/placeonfloor.ts) | Set a model onto to the floor
155
+ | [ADD_OBJECT](./src/com/actions/object/addobject.ts) | Add an object to the scene
156
+ | [UPDATE_OBJECT](./src/com/actions/object/updateobject.ts) | Update an existing object
157
+ | [DELETE_OBJECT](./src/com/actions/object/deleteobject.ts) | Delete an existing object
158
+ | [GET_ALL_OBJECTS](./src/com/actions/object/getallobjects.ts) | Return a map of all objects
159
+ | [GET_OBJECTS](./src/com/actions/object/getobjects.ts) | Return a map of all objects (with the opportunity to filter for ids)
160
+ | [SELECT_OBJECT](./src/com/actions/object/selectobject.ts) | Select an existing object in the scene
161
+ | [SET_GIZMO_MODE](./src/com/actions/toolbox/select/setgizmomode.ts) | Set gizmo mode