blockymodel-web 0.1.0 → 0.1.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 (2) hide show
  1. package/README.md +277 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # blockymodel-web
2
+
3
+ Web-based 3D editor for BlockyModel format (.blockymodel) built with [Three.js](https://threejs.org/).
4
+
5
+ ![License](https://img.shields.io/npm/l/blockymodel-web)
6
+ ![npm](https://img.shields.io/npm/v/blockymodel-web)
7
+
8
+ ## Features
9
+
10
+ - **3D Viewport** - Interactive scene with orbit controls
11
+ - **Selection** - Click to select objects with visual highlighting
12
+ - **Transform Gizmos** - Move, rotate, and scale with keyboard shortcuts (G/R/S)
13
+ - **Property Panel** - Edit position, rotation, scale, and shape properties
14
+ - **Hierarchy Panel** - Tree view with add/delete/duplicate via context menu
15
+ - **UV Editor** - Per-face texture offset, mirror, and rotation
16
+ - **Undo/Redo** - Full history with Ctrl+Z / Ctrl+Y
17
+ - **Save/Export** - Download as .blockymodel JSON
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install blockymodel-web three
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### As a Library
28
+
29
+ ```typescript
30
+ import {
31
+ Editor,
32
+ ViewerController,
33
+ BlockyModelLoader,
34
+ PropertyPanel,
35
+ HierarchyPanel
36
+ } from 'blockymodel-web';
37
+
38
+ // Create container
39
+ const container = document.getElementById('viewport');
40
+
41
+ // Initialize viewer
42
+ const viewer = new ViewerController(container);
43
+
44
+ // Load a model
45
+ const loader = new BlockyModelLoader();
46
+ const model = await loader.loadAsync('/path/to/model.blockymodel');
47
+ viewer.scene.add(model);
48
+
49
+ // Enable editing
50
+ const editor = new Editor(
51
+ viewer.scene,
52
+ viewer.camera,
53
+ viewer.renderer,
54
+ viewer.controls
55
+ );
56
+
57
+ // Add UI panels
58
+ const hierarchy = new HierarchyPanel(
59
+ document.getElementById('hierarchy'),
60
+ editor
61
+ );
62
+
63
+ const properties = new PropertyPanel(
64
+ document.getElementById('properties'),
65
+ editor
66
+ );
67
+ ```
68
+
69
+ ### Standalone App
70
+
71
+ ```bash
72
+ git clone https://github.com/ZacxDev/blockymodel-web.git
73
+ cd blockymodel-web
74
+ npm install
75
+ npm run dev
76
+ ```
77
+
78
+ Open http://localhost:3000 and load a .blockymodel file.
79
+
80
+ ## Keyboard Shortcuts
81
+
82
+ | Key | Action |
83
+ |-----|--------|
84
+ | G | Translate mode |
85
+ | R | Rotate mode |
86
+ | S | Scale mode |
87
+ | Delete | Remove selected node |
88
+ | Ctrl+Z | Undo |
89
+ | Ctrl+Y | Redo |
90
+
91
+ ## API Reference
92
+
93
+ ### Editor
94
+
95
+ Central state manager that coordinates all editing components.
96
+
97
+ ```typescript
98
+ const editor = new Editor(scene, camera, renderer, orbitControls);
99
+
100
+ // Events
101
+ editor.on('selectionChanged', (object) => { });
102
+ editor.on('objectChanged', (object) => { });
103
+ editor.on('historyChanged', () => { });
104
+
105
+ // Methods
106
+ editor.select(object); // Select an object
107
+ editor.deselect(); // Clear selection
108
+ editor.getSelected(); // Get selected object
109
+ editor.execute(command); // Execute a command (adds to history)
110
+ editor.undo(); // Undo last command
111
+ editor.redo(); // Redo last undone command
112
+ ```
113
+
114
+ ### Commands
115
+
116
+ All state changes go through commands for undo/redo support.
117
+
118
+ ```typescript
119
+ import {
120
+ SetPositionCommand,
121
+ SetRotationCommand,
122
+ SetScaleCommand,
123
+ SetPropertyCommand,
124
+ AddNodeCommand,
125
+ RemoveNodeCommand
126
+ } from 'blockymodel-web';
127
+
128
+ // Move an object
129
+ editor.execute(new SetPositionCommand(
130
+ object,
131
+ new THREE.Vector3(10, 0, 0), // new position
132
+ object.position.clone() // old position
133
+ ));
134
+
135
+ // Change a property
136
+ editor.execute(new SetPropertyCommand(
137
+ object,
138
+ 'userData.customProp', // supports nested paths
139
+ 'newValue',
140
+ 'oldValue'
141
+ ));
142
+
143
+ // Add a child node
144
+ const child = new THREE.Mesh(geometry, material);
145
+ editor.execute(new AddNodeCommand(parent, child));
146
+ ```
147
+
148
+ ### Serializer
149
+
150
+ Export the scene back to BlockyModel format.
151
+
152
+ ```typescript
153
+ import { Serializer } from 'blockymodel-web';
154
+
155
+ const serializer = new Serializer();
156
+
157
+ // Get as object
158
+ const model = serializer.serialize(scene);
159
+
160
+ // Get as JSON string
161
+ const json = serializer.toJSON(scene);
162
+
163
+ // Download file
164
+ const blob = new Blob([json], { type: 'application/json' });
165
+ const url = URL.createObjectURL(blob);
166
+ const a = document.createElement('a');
167
+ a.href = url;
168
+ a.download = 'model.blockymodel';
169
+ a.click();
170
+ ```
171
+
172
+ ### BlockyModelLoader
173
+
174
+ Load .blockymodel files into Three.js.
175
+
176
+ ```typescript
177
+ import { BlockyModelLoader, applyTextureToModel } from 'blockymodel-web';
178
+
179
+ const loader = new BlockyModelLoader();
180
+
181
+ // Async/await
182
+ const model = await loader.loadAsync('/model.blockymodel');
183
+ scene.add(model);
184
+
185
+ // With texture
186
+ const texture = new THREE.TextureLoader().load('/texture.png');
187
+ applyTextureToModel(model, texture);
188
+ ```
189
+
190
+ ## BlockyModel Format
191
+
192
+ ```typescript
193
+ interface BlockyModel {
194
+ format?: "character" | "prop";
195
+ lod?: "auto" | string;
196
+ nodes: BlockyNode[];
197
+ }
198
+
199
+ interface BlockyNode {
200
+ id: string;
201
+ name: string;
202
+ position?: { x: number; y: number; z: number };
203
+ orientation?: { w: number; x: number; y: number; z: number };
204
+ shape: {
205
+ type: "box" | "quad" | "none";
206
+ offset: { x: number; y: number; z: number };
207
+ stretch: { x: number; y: number; z: number };
208
+ settings: {
209
+ size?: { x: number; y: number; z: number };
210
+ };
211
+ textureLayout: {
212
+ front?: FaceUV;
213
+ back?: FaceUV;
214
+ left?: FaceUV;
215
+ right?: FaceUV;
216
+ top?: FaceUV;
217
+ bottom?: FaceUV;
218
+ };
219
+ visible: boolean;
220
+ doubleSided: boolean;
221
+ shadingMode: "standard" | "flat" | "fullbright" | "reflective";
222
+ };
223
+ children: BlockyNode[];
224
+ }
225
+ ```
226
+
227
+ ## Development
228
+
229
+ ```bash
230
+ # Install dependencies
231
+ npm install
232
+
233
+ # Start dev server
234
+ npm run dev
235
+
236
+ # Run tests
237
+ npm run test:run
238
+
239
+ # Run tests with coverage
240
+ npm run test:coverage
241
+
242
+ # Type check
243
+ npm run typecheck
244
+
245
+ # Build for production
246
+ npm run build
247
+
248
+ # Build library for npm
249
+ npm run build:lib
250
+ ```
251
+
252
+ ## Project Structure
253
+
254
+ ```
255
+ src/
256
+ ├── editor/
257
+ │ ├── Editor.ts # Central state manager
258
+ │ ├── SelectionManager.ts # Raycasting + selection
259
+ │ ├── TransformManager.ts # Transform gizmos
260
+ │ ├── History.ts # Undo/redo stack
261
+ │ ├── Serializer.ts # Export to JSON
262
+ │ └── commands/ # Command pattern implementations
263
+ ├── ui/
264
+ │ ├── PropertyPanel.ts # Transform/shape editing
265
+ │ ├── HierarchyPanel.ts # Tree view + context menu
266
+ │ └── UVEditor.ts # Per-face UV controls
267
+ ├── loaders/
268
+ │ └── BlockyModelLoader.ts
269
+ ├── viewer/
270
+ │ └── ViewerController.ts
271
+ └── types/
272
+ └── blockymodel.ts # TypeScript interfaces
273
+ ```
274
+
275
+ ## License
276
+
277
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockymodel-web",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Web-based 3D editor for BlockyModel format with transform gizmos, hierarchy panel, property editing, and undo/redo",
5
5
  "type": "module",
6
6
  "main": "./dist/blockymodel-web.umd.cjs",