@objectifthunes/three-book 0.5.6 → 0.5.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/demo-kit/dist/index.d.ts +1144 -0
- package/demo-kit/dist/index.js +331 -0
- package/package.json +10 -4
|
@@ -0,0 +1,1144 @@
|
|
|
1
|
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
|
|
4
|
+
export declare function addCheckbox(container: HTMLElement, label: string, value: boolean, onChange: (v: boolean) => void): HTMLInputElement;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* DOM control builders for the demo panel.
|
|
8
|
+
* All styling via CSS classes from @objectifthunes/three-book/demo.css.
|
|
9
|
+
*/
|
|
10
|
+
export declare function addCollapseToggle(container: HTMLElement, label: string, initiallyOpen: boolean): {
|
|
11
|
+
header: HTMLElement;
|
|
12
|
+
body: HTMLElement;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export declare function addColor(container: HTMLElement, label: string, value: string, onChange: (v: string) => void): HTMLInputElement;
|
|
16
|
+
|
|
17
|
+
export declare function addSectionTitle(container: HTMLElement, text: string): HTMLElement;
|
|
18
|
+
|
|
19
|
+
export declare function addSelect(container: HTMLElement, label: string, value: string, options: Array<{
|
|
20
|
+
value: string;
|
|
21
|
+
label: string;
|
|
22
|
+
}>, onChange: (v: string) => void): HTMLSelectElement;
|
|
23
|
+
|
|
24
|
+
export declare function addSlider(container: HTMLElement, label: string, min: number, max: number, step: number, value: number, onChange: (v: number) => void): HTMLInputElement;
|
|
25
|
+
|
|
26
|
+
declare class AnimationCurve {
|
|
27
|
+
keys: Keyframe_2[];
|
|
28
|
+
constructor(keys?: Keyframe_2[]);
|
|
29
|
+
/**
|
|
30
|
+
* Evaluate the curve at parameter `t`.
|
|
31
|
+
* Linear interpolation between keyframes (Unity default is cubic,
|
|
32
|
+
* but the exact tangent data is not available here).
|
|
33
|
+
*/
|
|
34
|
+
evaluate(t: number): number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Defines the direction for auto page turning.
|
|
39
|
+
*/
|
|
40
|
+
declare enum AutoTurnDirection {
|
|
41
|
+
/** Indicates the next page direction. */
|
|
42
|
+
Next = 0,
|
|
43
|
+
/** Indicates the previous page direction. */
|
|
44
|
+
Back = 1
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare enum AutoTurnMode {
|
|
48
|
+
/** This mode simulates swiping the paper surface to turn it. */
|
|
49
|
+
Surface = 0,
|
|
50
|
+
/** This mode simulates holding the paper edge and turning it. */
|
|
51
|
+
Edge = 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Represents an individual setting for auto page turning.
|
|
56
|
+
*
|
|
57
|
+
* C# struct — emulated with clone().
|
|
58
|
+
*/
|
|
59
|
+
declare class AutoTurnSetting {
|
|
60
|
+
private m_Mode;
|
|
61
|
+
private m_Constant;
|
|
62
|
+
private m_ConstantMin;
|
|
63
|
+
private m_ConstantMax;
|
|
64
|
+
private m_Curve;
|
|
65
|
+
private m_CurveMin;
|
|
66
|
+
private m_CurveMax;
|
|
67
|
+
private m_CurveTimeMode;
|
|
68
|
+
get mode(): AutoTurnSettingMode;
|
|
69
|
+
set mode(value: AutoTurnSettingMode);
|
|
70
|
+
get constant(): number;
|
|
71
|
+
set constant(value: number);
|
|
72
|
+
get constantMin(): number;
|
|
73
|
+
set constantMin(value: number);
|
|
74
|
+
get constantMax(): number;
|
|
75
|
+
set constantMax(value: number);
|
|
76
|
+
get curve(): AnimationCurve | null;
|
|
77
|
+
set curve(value: AnimationCurve | null);
|
|
78
|
+
get curveMin(): AnimationCurve | null;
|
|
79
|
+
set curveMin(value: AnimationCurve | null);
|
|
80
|
+
get curveMax(): AnimationCurve | null;
|
|
81
|
+
set curveMax(value: AnimationCurve | null);
|
|
82
|
+
get curveTimeMode(): AutoTurnSettingCurveTimeMode;
|
|
83
|
+
set curveTimeMode(value: AutoTurnSettingCurveTimeMode);
|
|
84
|
+
constructor();
|
|
85
|
+
/** A constant value. */
|
|
86
|
+
constructor(constant: number);
|
|
87
|
+
/** A random value generated between two constant values. */
|
|
88
|
+
constructor(constantMin: number, constantMax: number);
|
|
89
|
+
/** A value based on a curve. */
|
|
90
|
+
static fromCurve(curve: AnimationCurve, curveTimeMode: AutoTurnSettingCurveTimeMode): AutoTurnSetting;
|
|
91
|
+
/** A random value generated between two curves. */
|
|
92
|
+
static fromCurveRange(curveMin: AnimationCurve, curveMax: AnimationCurve, curveTimeMode: AutoTurnSettingCurveTimeMode): AutoTurnSetting;
|
|
93
|
+
/* Excluded from this release type: getValue */
|
|
94
|
+
/* Excluded from this release type: clampValues */
|
|
95
|
+
private clampCurve;
|
|
96
|
+
clone(): AutoTurnSetting;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Defines the curve time mode of AutoTurnSetting when AutoTurnSettingMode is
|
|
101
|
+
* Curve or RandomBetweenTwoCurves.
|
|
102
|
+
*/
|
|
103
|
+
declare enum AutoTurnSettingCurveTimeMode {
|
|
104
|
+
/**
|
|
105
|
+
* Evaluates the curve based on the current paper index divided by the
|
|
106
|
+
* total paper count. This gives a time value proportional to the
|
|
107
|
+
* progression through the papers.
|
|
108
|
+
*/
|
|
109
|
+
PaperIndexTime = 0,
|
|
110
|
+
/**
|
|
111
|
+
* Evaluates the curve based on the current turn index divided by the
|
|
112
|
+
* total turn count. This provides a time value proportional to the
|
|
113
|
+
* progression through the turns.
|
|
114
|
+
*/
|
|
115
|
+
TurnIndexTime = 1
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Defines the mode of AutoTurnSetting.
|
|
120
|
+
*/
|
|
121
|
+
declare enum AutoTurnSettingMode {
|
|
122
|
+
/** Specifies a constant value for the auto turn setting. */
|
|
123
|
+
Constant = 0,
|
|
124
|
+
/** Specifies a random value generated between two constant values for the auto turn setting. */
|
|
125
|
+
RandomBetweenTwoConstants = 1,
|
|
126
|
+
/** Specifies a value based on a curve for the auto turn setting. */
|
|
127
|
+
Curve = 2,
|
|
128
|
+
/** Specifies a random value generated between two curves for the auto turn setting. */
|
|
129
|
+
RandomBetweenTwoCurves = 3
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Represents settings for auto page turning.
|
|
134
|
+
*/
|
|
135
|
+
declare class AutoTurnSettings {
|
|
136
|
+
/* Excluded from this release type: kMinTwist */
|
|
137
|
+
/* Excluded from this release type: kMaxTwist */
|
|
138
|
+
/* Excluded from this release type: kMinBend */
|
|
139
|
+
/* Excluded from this release type: kMaxBend */
|
|
140
|
+
/* Excluded from this release type: kMinDuration */
|
|
141
|
+
/* Excluded from this release type: kMaxDuration */
|
|
142
|
+
private m_Mode;
|
|
143
|
+
private m_Twist;
|
|
144
|
+
private m_Bend;
|
|
145
|
+
private m_Duration;
|
|
146
|
+
get mode(): AutoTurnMode;
|
|
147
|
+
set mode(value: AutoTurnMode);
|
|
148
|
+
get twist(): AutoTurnSetting;
|
|
149
|
+
set twist(value: AutoTurnSetting);
|
|
150
|
+
get bend(): AutoTurnSetting;
|
|
151
|
+
set bend(value: AutoTurnSetting);
|
|
152
|
+
get duration(): AutoTurnSetting;
|
|
153
|
+
set duration(value: AutoTurnSetting);
|
|
154
|
+
/* Excluded from this release type: getModeValue */
|
|
155
|
+
/* Excluded from this release type: getBendValue */
|
|
156
|
+
/* Excluded from this release type: getDurationValue */
|
|
157
|
+
/* Excluded from this release type: getTwistValue */
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class Book extends THREE.Group implements IBookOwner {
|
|
161
|
+
private static s_Instances;
|
|
162
|
+
private static s_InstancesArray;
|
|
163
|
+
static get instances(): Book[];
|
|
164
|
+
private m_Content;
|
|
165
|
+
private m_Binding;
|
|
166
|
+
private m_InitialOpenProgress;
|
|
167
|
+
private m_BuildOnAwake;
|
|
168
|
+
private m_CastShadows;
|
|
169
|
+
private m_AlignToGround;
|
|
170
|
+
private m_HideBinder;
|
|
171
|
+
private m_ReduceShadows;
|
|
172
|
+
private m_ReduceSubMeshes;
|
|
173
|
+
private m_ReduceOverdraw;
|
|
174
|
+
private m_CoverPaperSetup;
|
|
175
|
+
private m_PagePaperSetup;
|
|
176
|
+
private m_Root;
|
|
177
|
+
private m_IsBuilt;
|
|
178
|
+
private m_HasCover;
|
|
179
|
+
private m_RendererFactory;
|
|
180
|
+
private m_MeshFactory;
|
|
181
|
+
private m_Bound;
|
|
182
|
+
private m_Papers;
|
|
183
|
+
private m_SelectedPaper;
|
|
184
|
+
private m_Direction;
|
|
185
|
+
private m_AutoTurnQueue;
|
|
186
|
+
private m_AutoTurnTimer;
|
|
187
|
+
private m_AutoTurningEndTime;
|
|
188
|
+
private m_CurrentTime;
|
|
189
|
+
private m_CoverPaperCount;
|
|
190
|
+
private m_PagePaperCount;
|
|
191
|
+
private m_TotalThickness;
|
|
192
|
+
private m_MinPaperWidth;
|
|
193
|
+
private m_MinPaperHeight;
|
|
194
|
+
private m_MinPaperThickness;
|
|
195
|
+
private m_MaxPaperThickness;
|
|
196
|
+
private m_RendererIds;
|
|
197
|
+
private m_WasIdle;
|
|
198
|
+
private m_ContentDirty;
|
|
199
|
+
private m_StructuralDirty;
|
|
200
|
+
private m_AppliedDirection;
|
|
201
|
+
private _frontPapersCache;
|
|
202
|
+
get minPaperWidth(): number;
|
|
203
|
+
get minPaperHeight(): number;
|
|
204
|
+
get minPaperThickness(): number;
|
|
205
|
+
get maxPaperThickness(): number;
|
|
206
|
+
get totalThickness(): number;
|
|
207
|
+
get hasCover(): boolean;
|
|
208
|
+
get castShadowsFlag(): boolean;
|
|
209
|
+
/** Alias matching IBookOwner interface expected by Paper.ts */
|
|
210
|
+
get castShadows(): boolean;
|
|
211
|
+
set castShadows(value: boolean);
|
|
212
|
+
get alignToGround(): boolean;
|
|
213
|
+
set alignToGround(value: boolean);
|
|
214
|
+
get hideBinder(): boolean;
|
|
215
|
+
set hideBinder(value: boolean);
|
|
216
|
+
get reduceShadows(): boolean;
|
|
217
|
+
set reduceShadows(value: boolean);
|
|
218
|
+
get reduceSubMeshes(): boolean;
|
|
219
|
+
set reduceSubMeshes(value: boolean);
|
|
220
|
+
get reduceOverdraw(): boolean;
|
|
221
|
+
set reduceOverdraw(value: boolean);
|
|
222
|
+
get coverPaperSetup(): PaperSetup;
|
|
223
|
+
set coverPaperSetup(value: Partial<PaperSetupInit>);
|
|
224
|
+
get pagePaperSetup(): PaperSetup;
|
|
225
|
+
set pagePaperSetup(value: Partial<PaperSetupInit>);
|
|
226
|
+
get bound(): BookBound | null;
|
|
227
|
+
get papers(): Paper[];
|
|
228
|
+
get rendererIds(): number[];
|
|
229
|
+
get direction(): BookDirection;
|
|
230
|
+
get binding(): BookBinding | null;
|
|
231
|
+
set binding(value: BookBinding | null);
|
|
232
|
+
get content(): BookContent | null;
|
|
233
|
+
set content(value: BookContent | null);
|
|
234
|
+
get initialOpenProgress(): number;
|
|
235
|
+
set initialOpenProgress(value: number);
|
|
236
|
+
get isBuilt(): boolean;
|
|
237
|
+
get paperCount(): number;
|
|
238
|
+
get coverPaperCount(): number;
|
|
239
|
+
get pagePaperCount(): number;
|
|
240
|
+
get isTurning(): boolean;
|
|
241
|
+
get isFalling(): boolean;
|
|
242
|
+
get isIdle(): boolean;
|
|
243
|
+
get isAutoTurning(): boolean;
|
|
244
|
+
get hasPendingAutoTurns(): boolean;
|
|
245
|
+
get autoTurningEndTime(): number;
|
|
246
|
+
/** Current open progress (0-1), read from actual paper positions. */
|
|
247
|
+
get openProgress(): number;
|
|
248
|
+
constructor(options?: BookOptions);
|
|
249
|
+
startTurning(ray: THREE.Ray): boolean;
|
|
250
|
+
updateTurning(ray: THREE.Ray): void;
|
|
251
|
+
stopTurning(): void;
|
|
252
|
+
getActivePaperSideIndices(indices: Set<number>): void;
|
|
253
|
+
/**
|
|
254
|
+
* Sets the book's open progress to a value between 0 (fully closed) and 1 (fully open).
|
|
255
|
+
* This cancels any pending auto turns and immediately moves all papers to match
|
|
256
|
+
* the requested progress.
|
|
257
|
+
*/
|
|
258
|
+
setOpenProgress(openProgress: number): void;
|
|
259
|
+
setOpenProgressByIndex(paperSideIndex: number): void;
|
|
260
|
+
/**
|
|
261
|
+
* Starts auto-turning pages in the given direction.
|
|
262
|
+
* @param direction - Which direction to turn (Next or Back)
|
|
263
|
+
* @param settings - Turn animation settings (twist, bend, duration)
|
|
264
|
+
* @param turnCount - Number of pages to turn
|
|
265
|
+
* @param delayPerTurn - Delay between consecutive turns (number in seconds, or AutoTurnSetting)
|
|
266
|
+
* @returns true if at least one turn was queued
|
|
267
|
+
*/
|
|
268
|
+
startAutoTurning(direction: AutoTurnDirection, settings: AutoTurnSettings, turnCount?: number, delayPerTurn?: number | AutoTurnSetting): boolean;
|
|
269
|
+
cancelPendingAutoTurns(): void;
|
|
270
|
+
private processAutoTurnQueue;
|
|
271
|
+
private getAutoTurnPaper;
|
|
272
|
+
private getMaxAutoTurnCount;
|
|
273
|
+
private canAutoTurn;
|
|
274
|
+
private getAutoTurnPaperIndexTime;
|
|
275
|
+
/**
|
|
276
|
+
* Initialize the book. Call this after adding to scene.
|
|
277
|
+
* Equivalent to Unity's Start/Awake.
|
|
278
|
+
*/
|
|
279
|
+
init(): void;
|
|
280
|
+
/**
|
|
281
|
+
* Call every frame with delta time in seconds.
|
|
282
|
+
* Equivalent to Unity's LateUpdate.
|
|
283
|
+
* @param dt - Delta time in seconds since the last frame
|
|
284
|
+
*/
|
|
285
|
+
update(dt: number): void;
|
|
286
|
+
/**
|
|
287
|
+
* Dispose the book and release all resources.
|
|
288
|
+
* MANDATORY: You must call dispose() when removing a Book to prevent memory leaks.
|
|
289
|
+
* The Book holds a reference in the static `s_Instances` set; without dispose(),
|
|
290
|
+
* it will never be garbage collected.
|
|
291
|
+
*/
|
|
292
|
+
dispose(): void;
|
|
293
|
+
private build;
|
|
294
|
+
/**
|
|
295
|
+
* Clears the built state of the book.
|
|
296
|
+
* NOTE: This does NOT call super.clear() — it has different semantics from
|
|
297
|
+
* THREE.Group.clear(). It resets internal book state (papers, bound, flags)
|
|
298
|
+
* without removing children from the Three.js scene graph.
|
|
299
|
+
*/
|
|
300
|
+
clear(): this;
|
|
301
|
+
private hardClear;
|
|
302
|
+
private createPaperMeshDataPool;
|
|
303
|
+
private getFrontPapers;
|
|
304
|
+
getAverageTime(): number;
|
|
305
|
+
bookRaycast(ray: THREE.Ray): BookRaycastHit | null;
|
|
306
|
+
/**
|
|
307
|
+
* Re-apply all page/cover textures from the current BookContent
|
|
308
|
+
* to existing papers without rebuilding geometry.
|
|
309
|
+
* Returns false if a structural rebuild is needed (page count changed).
|
|
310
|
+
*/
|
|
311
|
+
private refreshContent;
|
|
312
|
+
private getCurrentOpenProgress;
|
|
313
|
+
private updateLivePages;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
declare abstract class BookBinding {
|
|
317
|
+
abstract createBound(book: Book, root: THREE.Object3D, rendererFactory: RendererFactory, meshFactory: MeshFactory): BookBound;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
declare abstract class BookBound {
|
|
321
|
+
protected m_Book: Book;
|
|
322
|
+
protected m_Root: THREE.Object3D;
|
|
323
|
+
/** Discriminant property for runtime type checks (avoids constructor.name). */
|
|
324
|
+
readonly bindingType: string;
|
|
325
|
+
abstract get useSharedMeshDataForLowpoly(): boolean;
|
|
326
|
+
abstract get binderRenderer(): IBinderRenderer;
|
|
327
|
+
constructor(book: Book, root: THREE.Object3D);
|
|
328
|
+
abstract createPaperPattern(quality: number, size: THREE.Vector2, thickness: number, uvMargin: PaperUVMargin, reduceOverdraw: boolean, reduceSubMeshes: boolean): PaperPattern;
|
|
329
|
+
abstract resetPaperPosition(paper: Paper): void;
|
|
330
|
+
abstract updatePaperPosition(paper: Paper): void;
|
|
331
|
+
abstract onLateUpdate(): void;
|
|
332
|
+
/** Release GPU resources. Override in subclasses. */
|
|
333
|
+
dispose(): void;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Content for the book: covers and pages.
|
|
338
|
+
*
|
|
339
|
+
* In Unity, list items can be Sprite, SpritePageContent, or LivePageContent.
|
|
340
|
+
* In Three.js, list items are either THREE.Texture or IPageContent instances.
|
|
341
|
+
*/
|
|
342
|
+
declare class BookContent {
|
|
343
|
+
private m_Direction;
|
|
344
|
+
private m_Covers;
|
|
345
|
+
private m_Pages;
|
|
346
|
+
private m_Book;
|
|
347
|
+
private _cachedCovers;
|
|
348
|
+
private _cachedPages;
|
|
349
|
+
private get coverCount4();
|
|
350
|
+
private get pageCount4();
|
|
351
|
+
get book(): Book | null;
|
|
352
|
+
get covers(): (THREE.Texture | IPageContent | null)[];
|
|
353
|
+
set covers(value: (THREE.Texture | IPageContent | null)[]);
|
|
354
|
+
get pages(): (THREE.Texture | IPageContent | null)[];
|
|
355
|
+
set pages(value: (THREE.Texture | IPageContent | null)[]);
|
|
356
|
+
get isEmpty(): boolean;
|
|
357
|
+
get direction(): BookDirection;
|
|
358
|
+
set direction(value: BookDirection);
|
|
359
|
+
get coverContents(): IPageContent[];
|
|
360
|
+
get pageContents(): IPageContent[];
|
|
361
|
+
private getContents;
|
|
362
|
+
private nextMultipleOf4;
|
|
363
|
+
private getContent;
|
|
364
|
+
init(book: Book): void;
|
|
365
|
+
convertCoverIndexToPaperSideIndex(coverIndex: number): number;
|
|
366
|
+
convertPageIndexToPaperSideIndex(pageIndex: number): number;
|
|
367
|
+
convertPaperSideIndexToCoverIndex(paperSideIndex: number): number;
|
|
368
|
+
convertPaperSideIndexToPageIndex(paperSideIndex: number): number;
|
|
369
|
+
convertPaperSideIndexToOpenProgress(paperSideIndex: number): number;
|
|
370
|
+
isCoverPaperSideIndex(paperSideIndex: number): boolean;
|
|
371
|
+
isPagePaperSideIndex(paperSideIndex: number): boolean;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Ported from BookContent.cs — BookDirection enum.
|
|
376
|
+
*/
|
|
377
|
+
declare enum BookDirection {
|
|
378
|
+
LeftToRight = 0,
|
|
379
|
+
RightToLeft = 1,
|
|
380
|
+
UpToDown = 2,
|
|
381
|
+
DownToUp = 3
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
declare interface BookOptions {
|
|
385
|
+
content?: BookContent;
|
|
386
|
+
binding?: BookBinding;
|
|
387
|
+
initialOpenProgress?: number;
|
|
388
|
+
buildOnAwake?: boolean;
|
|
389
|
+
castShadows?: boolean;
|
|
390
|
+
alignToGround?: boolean;
|
|
391
|
+
hideBinder?: boolean;
|
|
392
|
+
reduceShadows?: boolean;
|
|
393
|
+
reduceSubMeshes?: boolean;
|
|
394
|
+
reduceOverdraw?: boolean;
|
|
395
|
+
coverPaperSetup?: Partial<PaperSetupInit>;
|
|
396
|
+
pagePaperSetup?: Partial<PaperSetupInit>;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Wires pointer events on a DOM element to Book's interactive turning API.
|
|
401
|
+
*
|
|
402
|
+
* Usage:
|
|
403
|
+
* const interaction = new BookPointerInteraction(camera, renderer.domElement);
|
|
404
|
+
* interaction.onTurnStart = (book) => { controls.enabled = false; };
|
|
405
|
+
* interaction.onTurnEnd = (book) => { controls.enabled = true; };
|
|
406
|
+
* // Later: interaction.dispose();
|
|
407
|
+
*/
|
|
408
|
+
declare class BookPointerInteraction {
|
|
409
|
+
/** Set to false to temporarily disable interaction without disposing. */
|
|
410
|
+
enabled: boolean;
|
|
411
|
+
onTurnStart?: (book: Book) => void;
|
|
412
|
+
onTurnEnd?: (book: Book) => void;
|
|
413
|
+
private readonly m_Camera;
|
|
414
|
+
private readonly m_DomElement;
|
|
415
|
+
private readonly m_Raycaster;
|
|
416
|
+
private readonly m_Mouse;
|
|
417
|
+
private m_SelectedBook;
|
|
418
|
+
private m_IsPointerDown;
|
|
419
|
+
constructor(camera: THREE.Camera, domElement: HTMLElement);
|
|
420
|
+
dispose(): void;
|
|
421
|
+
private m_GetRay;
|
|
422
|
+
private m_OnPointerDown;
|
|
423
|
+
private m_OnPointerMove;
|
|
424
|
+
private m_OnPointerUp;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
declare interface BookRaycastHit {
|
|
428
|
+
point: THREE.Vector3;
|
|
429
|
+
textureCoordinate: THREE.Vector2;
|
|
430
|
+
pageContent: IPageContent | null;
|
|
431
|
+
paperIndex: number;
|
|
432
|
+
pageIndex: number;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
declare class BookRenderer implements IPaperRenderer {
|
|
436
|
+
private m_Object3D;
|
|
437
|
+
private m_Mesh;
|
|
438
|
+
private m_Visibility;
|
|
439
|
+
private m_Id;
|
|
440
|
+
private m_PropertyBlocks;
|
|
441
|
+
private m_MaterialTextures;
|
|
442
|
+
get bounds(): THREE.Box3;
|
|
443
|
+
get id(): number;
|
|
444
|
+
get transform(): THREE.Object3D;
|
|
445
|
+
get visibility(): boolean;
|
|
446
|
+
get castShadows(): boolean;
|
|
447
|
+
set castShadows(value: boolean);
|
|
448
|
+
get mesh(): THREE.BufferGeometry | null;
|
|
449
|
+
set mesh(value: THREE.BufferGeometry | null);
|
|
450
|
+
get meshObject(): THREE.Mesh;
|
|
451
|
+
constructor(root: THREE.Object3D, name: string);
|
|
452
|
+
setMaterials(materials: THREE.Material | THREE.Material[]): void;
|
|
453
|
+
setPropertyBlock(properties: PropertyBlock, materialIndex: number): void;
|
|
454
|
+
reset(name: string): void;
|
|
455
|
+
clear(): void;
|
|
456
|
+
destroy(): void;
|
|
457
|
+
setVisibility(visibility: boolean): void;
|
|
458
|
+
private getMaterial;
|
|
459
|
+
private isMapCapable;
|
|
460
|
+
private isColorCapable;
|
|
461
|
+
private getSTKey;
|
|
462
|
+
private applyTextureProperty;
|
|
463
|
+
private clearMaterialTexture;
|
|
464
|
+
private clearManagedTexture;
|
|
465
|
+
private disposeManagedTextures;
|
|
466
|
+
private disposeCurrentMaterials;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export declare function clearImageSlot(slot: ImageSlot): void;
|
|
470
|
+
|
|
471
|
+
export declare function createDefaultTextBlock(canvasW: number, canvasH: number): PageTextBlock;
|
|
472
|
+
|
|
473
|
+
export declare function createDemoInteraction(camera: THREE.PerspectiveCamera, domElement: HTMLElement, controls: OrbitControls, enabled: boolean): BookPointerInteraction;
|
|
474
|
+
|
|
475
|
+
export declare function createDemoPanel(config: DemoPanelConfig): DemoPanel;
|
|
476
|
+
|
|
477
|
+
export declare function createDemoScene(): DemoScene;
|
|
478
|
+
|
|
479
|
+
export declare function createImageSlot(): ImageSlot;
|
|
480
|
+
|
|
481
|
+
export declare function createImageSlotCard(config: ImageSlotCardConfig): HTMLElement;
|
|
482
|
+
|
|
483
|
+
export declare function createPageNavigation(config: PageNavConfig): PageNav;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Creates a `THREE.CanvasTexture` suitable for use as a book page.
|
|
487
|
+
*
|
|
488
|
+
* Wraps `createPageCanvas` in a THREE.CanvasTexture. If you only need the
|
|
489
|
+
* canvas (e.g. for TextOverlayContent.source), use `createPageCanvas` instead
|
|
490
|
+
* to avoid an extra texture allocation.
|
|
491
|
+
*/
|
|
492
|
+
export declare function createPageTexture(color: string, label: string, image: HTMLImageElement | null, fitMode: ImageFitMode, fullBleed: boolean, pageWidth?: number, pageHeight?: number, imageRect?: ImageRect | null): THREE.Texture;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Ported from Book.cs — Cylinder struct (lines ~3805-3902).
|
|
496
|
+
*
|
|
497
|
+
* Rolling-deformation core used to curl paper around a cylindrical axis.
|
|
498
|
+
*
|
|
499
|
+
* C# value-type (struct) semantics are emulated with a clone() method.
|
|
500
|
+
*
|
|
501
|
+
* Unity's `Quaternion.Euler(0, eulerY, z) * Vector3(x, 0, 0)` is replaced
|
|
502
|
+
* with manual trig: first rotate by Z around the Z-axis, then rotate by Y
|
|
503
|
+
* around the Y-axis.
|
|
504
|
+
*/
|
|
505
|
+
declare class Cylinder {
|
|
506
|
+
private m_PositionX;
|
|
507
|
+
private m_PositionZ;
|
|
508
|
+
private m_DirectionX;
|
|
509
|
+
private m_DirectionZ;
|
|
510
|
+
private m_EulerY;
|
|
511
|
+
private m_Radius;
|
|
512
|
+
private readonly _positionOut;
|
|
513
|
+
private readonly _scratchRP1;
|
|
514
|
+
private readonly _scratchRP2;
|
|
515
|
+
private readonly _scratchRollClosest;
|
|
516
|
+
private readonly _scratchRollEuler;
|
|
517
|
+
private readonly _scratchOffsetRoll;
|
|
518
|
+
/** Returns internal vector — do NOT mutate. Copy if you need to store it. */
|
|
519
|
+
get position(): THREE.Vector3;
|
|
520
|
+
set position(value: THREE.Vector3);
|
|
521
|
+
set direction(value: THREE.Vector3);
|
|
522
|
+
set radius(value: number);
|
|
523
|
+
rollPoint(point: THREE.Vector3): THREE.Vector3;
|
|
524
|
+
/**
|
|
525
|
+
* Apply Quaternion.Euler(0, eulerY, z) * Vector3(x, 0, 0) manually.
|
|
526
|
+
*
|
|
527
|
+
* Unity Euler convention (ZXY intrinsic, i.e. applied Z then X then Y):
|
|
528
|
+
* 1. Rotate (x, 0, 0) by Z degrees around Z-axis.
|
|
529
|
+
* 2. Rotate by X degrees around X-axis (X = 0 here, so skip).
|
|
530
|
+
* 3. Rotate by Y degrees around Y-axis.
|
|
531
|
+
*
|
|
532
|
+
* Writes result into `out` and returns it.
|
|
533
|
+
*/
|
|
534
|
+
private eulerRotateVector;
|
|
535
|
+
/**
|
|
536
|
+
* Rolls `point` in place around the cylinder. Mutates and returns `point`.
|
|
537
|
+
* Uses _scratchRollClosest for closest-point calculation and
|
|
538
|
+
* _scratchRollEuler for euler rotation result.
|
|
539
|
+
*/
|
|
540
|
+
private roll;
|
|
541
|
+
/**
|
|
542
|
+
* Computes offset for `point`. Mutates and returns `point`.
|
|
543
|
+
* Offset = roll(point with x=0) with z adjusted.
|
|
544
|
+
* Uses _scratchOffsetRoll to hold a copy for rolling (avoids aliasing
|
|
545
|
+
* with `point` itself when roll() internally reads and writes).
|
|
546
|
+
*/
|
|
547
|
+
private getOffset;
|
|
548
|
+
/**
|
|
549
|
+
* Projects `point` onto the cylinder axis, writing the result into `point`.
|
|
550
|
+
* Returns the mutated `point`.
|
|
551
|
+
*/
|
|
552
|
+
private getClosestPointInto;
|
|
553
|
+
private getSide;
|
|
554
|
+
clone(): Cylinder;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export declare interface DemoPanel {
|
|
558
|
+
root: HTMLElement;
|
|
559
|
+
toggleBtn: HTMLElement;
|
|
560
|
+
statusEl: HTMLElement;
|
|
561
|
+
setStatus(msg: string): void;
|
|
562
|
+
switchTab(key: string): void;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export declare interface DemoPanelConfig {
|
|
566
|
+
title: string;
|
|
567
|
+
subtitle: string;
|
|
568
|
+
tabs: DemoPanelTab[];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export declare interface DemoPanelTab {
|
|
572
|
+
key: string;
|
|
573
|
+
label: string;
|
|
574
|
+
content: HTMLElement;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export declare interface DemoScene {
|
|
578
|
+
scene: THREE.Scene;
|
|
579
|
+
camera: THREE.PerspectiveCamera;
|
|
580
|
+
renderer: THREE.WebGLRenderer;
|
|
581
|
+
controls: OrbitControls;
|
|
582
|
+
ambientLight: THREE.AmbientLight;
|
|
583
|
+
dirLight: THREE.DirectionalLight;
|
|
584
|
+
syncLights(config: DemoSceneConfig): void;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export declare interface DemoSceneConfig {
|
|
588
|
+
ambientIntensity: number;
|
|
589
|
+
sunIntensity: number;
|
|
590
|
+
sunX: number;
|
|
591
|
+
sunY: number;
|
|
592
|
+
sunZ: number;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export declare type DirectionOption = 'left-to-right' | 'right-to-left' | 'up-to-down' | 'down-to-up';
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Draws `image` into a 2D canvas context within the rectangle
|
|
599
|
+
* (x, y, width, height) using the given fit mode.
|
|
600
|
+
*
|
|
601
|
+
* - `'fill'` — stretches to fill exactly, ignoring aspect ratio
|
|
602
|
+
* - `'contain'` — scales uniformly to fit inside, letterboxed
|
|
603
|
+
* - `'cover'` — scales uniformly to fill, cropping the overflow
|
|
604
|
+
*/
|
|
605
|
+
export declare function drawImageWithFit(ctx: CanvasRenderingContext2D, image: HTMLImageElement, x: number, y: number, width: number, height: number, fit: ImageFitMode): void;
|
|
606
|
+
|
|
607
|
+
export declare const FONT_OPTIONS: string[];
|
|
608
|
+
|
|
609
|
+
declare interface IBinderRenderer {
|
|
610
|
+
setVisibility(visible: boolean): void;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
declare interface IBookBound {
|
|
614
|
+
resetPaperPosition(paper: Paper): void;
|
|
615
|
+
updatePaperPosition(paper: Paper): void;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
declare interface IBookOwner {
|
|
619
|
+
readonly bound: IBookBound | null;
|
|
620
|
+
readonly castShadows: boolean;
|
|
621
|
+
readonly reduceShadows: boolean;
|
|
622
|
+
readonly direction: BookDirection;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** How an image is scaled to fit a rectangular area. */
|
|
626
|
+
export declare type ImageFitMode = 'contain' | 'cover' | 'fill';
|
|
627
|
+
|
|
628
|
+
/** Custom image position and size in canvas pixels. */
|
|
629
|
+
export declare interface ImageRect {
|
|
630
|
+
x: number;
|
|
631
|
+
y: number;
|
|
632
|
+
width: number;
|
|
633
|
+
height: number;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export declare interface ImageSlot {
|
|
637
|
+
image: HTMLImageElement | null;
|
|
638
|
+
objectUrl: string | null;
|
|
639
|
+
useImage: boolean;
|
|
640
|
+
fitMode: ImageFitMode;
|
|
641
|
+
fullBleed: boolean;
|
|
642
|
+
imageRect: ImageRect | null;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export declare interface ImageSlotCardConfig {
|
|
646
|
+
label: string;
|
|
647
|
+
slot: ImageSlot;
|
|
648
|
+
bgColor: string;
|
|
649
|
+
showFitControls?: boolean;
|
|
650
|
+
/** Canvas width in pixels for computing imageRect on upload. */
|
|
651
|
+
canvasWidth?: number;
|
|
652
|
+
/** Canvas height in pixels for computing imageRect on upload. */
|
|
653
|
+
canvasHeight?: number;
|
|
654
|
+
onChanged: () => void;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
declare interface IPageContent {
|
|
658
|
+
readonly texture: THREE.Texture | null;
|
|
659
|
+
readonly textureST: THREE.Vector4;
|
|
660
|
+
isPointOverUI(textureCoord: THREE.Vector2): boolean;
|
|
661
|
+
init(bookContent: BookContent): void;
|
|
662
|
+
setActive(active: boolean): void;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
declare interface IPaperRenderer {
|
|
666
|
+
readonly transform: THREE.Object3D;
|
|
667
|
+
mesh: THREE.BufferGeometry | null;
|
|
668
|
+
castShadows: boolean;
|
|
669
|
+
setMaterials(materials: THREE.Material[]): void;
|
|
670
|
+
setPropertyBlock(props: PropertyBlock, materialIndex: number): void;
|
|
671
|
+
readonly bounds: THREE.Box3;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Minimal replacement for Unity's AnimationCurve.
|
|
676
|
+
* Stores an array of { time, value } keyframes and evaluates them
|
|
677
|
+
* with linear interpolation (matches the most common Unity curve
|
|
678
|
+
* usage; tangent / bezier evaluation is omitted since the C# plugin
|
|
679
|
+
* only reads curve values via `Evaluate`).
|
|
680
|
+
*/
|
|
681
|
+
declare interface Keyframe_2 {
|
|
682
|
+
time: number;
|
|
683
|
+
value: number;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/** Resolved image ready to be passed to createPageTexture. */
|
|
687
|
+
export declare interface LoadedImage {
|
|
688
|
+
image: HTMLImageElement;
|
|
689
|
+
/** Object URL created by URL.createObjectURL — revoke when no longer needed. */
|
|
690
|
+
objectUrl: string;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Loads a `File` into an `HTMLImageElement` and returns both the element
|
|
695
|
+
* and the object URL it was decoded from.
|
|
696
|
+
*
|
|
697
|
+
* The caller is responsible for calling `URL.revokeObjectURL(result.objectUrl)`
|
|
698
|
+
* when the image is no longer needed.
|
|
699
|
+
*
|
|
700
|
+
* Returns `null` if `file` is null/undefined or if decoding fails.
|
|
701
|
+
*/
|
|
702
|
+
export declare function loadImage(file: File | null | undefined): Promise<LoadedImage | null>;
|
|
703
|
+
|
|
704
|
+
export declare function loadImageFromFile(slot: ImageSlot, file: File | null): Promise<void>;
|
|
705
|
+
|
|
706
|
+
declare class MeshFactory {
|
|
707
|
+
private m_UsedMeshs;
|
|
708
|
+
private m_FreeMeshs;
|
|
709
|
+
private m_Meshs;
|
|
710
|
+
get(): THREE.BufferGeometry;
|
|
711
|
+
recycle(): void;
|
|
712
|
+
destroy(): void;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
export declare interface PageNav {
|
|
716
|
+
root: HTMLElement;
|
|
717
|
+
update(config: PageNavConfig): void;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export declare interface PageNavConfig {
|
|
721
|
+
pageCount: number;
|
|
722
|
+
currentPage: number;
|
|
723
|
+
spreadPages: Set<number>;
|
|
724
|
+
onPageChange: (index: number) => void;
|
|
725
|
+
onSpreadToggle: (index: number, checked: boolean) => void;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
export declare interface PageTextBlock {
|
|
729
|
+
text: string;
|
|
730
|
+
x: number;
|
|
731
|
+
y: number;
|
|
732
|
+
width: number;
|
|
733
|
+
fontFamily: string;
|
|
734
|
+
fontSize: number;
|
|
735
|
+
fontWeight: 'normal' | 'bold';
|
|
736
|
+
fontStyle: 'normal' | 'italic';
|
|
737
|
+
color: string;
|
|
738
|
+
textAlign: 'left' | 'center' | 'right';
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
declare class Paper {
|
|
742
|
+
private m_Index;
|
|
743
|
+
private m_Transform;
|
|
744
|
+
private m_FrontContent;
|
|
745
|
+
private m_BackContent;
|
|
746
|
+
private m_UseBackContentForSides;
|
|
747
|
+
private m_Book;
|
|
748
|
+
private m_Prev;
|
|
749
|
+
private m_Next;
|
|
750
|
+
private m_NoHole;
|
|
751
|
+
private m_MaterialData;
|
|
752
|
+
private m_Renderer;
|
|
753
|
+
private m_Size;
|
|
754
|
+
private m_Thickness;
|
|
755
|
+
private m_Stiffness;
|
|
756
|
+
private m_Margin;
|
|
757
|
+
private m_IsCover;
|
|
758
|
+
private m_UVMargin;
|
|
759
|
+
private m_MeshData;
|
|
760
|
+
private m_LowpolyMeshData;
|
|
761
|
+
private m_LowpolyHoleMeshData;
|
|
762
|
+
private m_HighpolyMeshDataPool;
|
|
763
|
+
private m_MeshDataType;
|
|
764
|
+
private m_Cylinder;
|
|
765
|
+
private m_IsRolling;
|
|
766
|
+
private m_IsAutoTurning;
|
|
767
|
+
private m_WorldPlane;
|
|
768
|
+
private m_StartHandle;
|
|
769
|
+
private m_CurrentHandle;
|
|
770
|
+
private m_EndHandle;
|
|
771
|
+
private m_PrevHandle;
|
|
772
|
+
private m_HandleOffset;
|
|
773
|
+
private m_HandleVelocity;
|
|
774
|
+
private m_HandleVelocities;
|
|
775
|
+
private m_SubMeshCount;
|
|
776
|
+
private m_MinTurningRadius;
|
|
777
|
+
private m_TurningRadius;
|
|
778
|
+
private m_FallDuration;
|
|
779
|
+
private m_FallTime;
|
|
780
|
+
private m_XTime;
|
|
781
|
+
private m_ZTime;
|
|
782
|
+
private m_IsTurning;
|
|
783
|
+
private m_IsFalling;
|
|
784
|
+
private m_IsFallingLeft;
|
|
785
|
+
private m_isMeshChanged;
|
|
786
|
+
sizeXOffset: number;
|
|
787
|
+
private readonly _ucStartHandle;
|
|
788
|
+
private readonly _ucCurrentHandle;
|
|
789
|
+
private readonly _ucHandleDir;
|
|
790
|
+
private readonly _ucA;
|
|
791
|
+
private readonly _ucB;
|
|
792
|
+
private readonly _ucMid;
|
|
793
|
+
private readonly _ucRollResult;
|
|
794
|
+
private readonly _ucCylDir;
|
|
795
|
+
private readonly _utV1;
|
|
796
|
+
private readonly _utV2;
|
|
797
|
+
private readonly _utV3;
|
|
798
|
+
private readonly _utV4;
|
|
799
|
+
private readonly _chP;
|
|
800
|
+
private readonly _chA;
|
|
801
|
+
private readonly _chC;
|
|
802
|
+
private readonly _chEllipseCenter1;
|
|
803
|
+
private readonly _chEllipseCenter2;
|
|
804
|
+
private readonly _chEllipseSize1;
|
|
805
|
+
private readonly _chEllipseSize2;
|
|
806
|
+
private readonly _chP2;
|
|
807
|
+
private readonly _dirResult;
|
|
808
|
+
private readonly _gdA;
|
|
809
|
+
private readonly _gdB;
|
|
810
|
+
private readonly _rlMatrix;
|
|
811
|
+
private readonly _rlPlane;
|
|
812
|
+
private readonly _rlTarget;
|
|
813
|
+
private readonly _rlNormal;
|
|
814
|
+
private readonly _utTarget;
|
|
815
|
+
private readonly _ufSmoothTime;
|
|
816
|
+
private readonly _umFrontST;
|
|
817
|
+
private readonly _umBackST;
|
|
818
|
+
private readonly _h2uResult;
|
|
819
|
+
get isMeshChanged(): boolean;
|
|
820
|
+
set isMeshChanged(value: boolean);
|
|
821
|
+
get isCover(): boolean;
|
|
822
|
+
get index(): number;
|
|
823
|
+
get transform(): THREE.Object3D;
|
|
824
|
+
get renderer(): IPaperRenderer;
|
|
825
|
+
get meshData(): PaperMeshData;
|
|
826
|
+
get size(): THREE.Vector2;
|
|
827
|
+
set size(value: THREE.Vector2);
|
|
828
|
+
get thickness(): number;
|
|
829
|
+
get margin(): number;
|
|
830
|
+
get zTime(): number;
|
|
831
|
+
get direction(): THREE.Vector3;
|
|
832
|
+
get isTurning(): boolean;
|
|
833
|
+
get isFalling(): boolean;
|
|
834
|
+
get isFlipped(): boolean;
|
|
835
|
+
get isOnRightStack(): boolean;
|
|
836
|
+
get frontContent(): IPageContent;
|
|
837
|
+
get backContent(): IPageContent;
|
|
838
|
+
get currentContent(): IPageContent;
|
|
839
|
+
private get needHole();
|
|
840
|
+
set prev(value: Paper | null);
|
|
841
|
+
set next(value: Paper | null);
|
|
842
|
+
set noHole(value: boolean);
|
|
843
|
+
private get isIdle();
|
|
844
|
+
constructor(isCover: boolean, index: number, book: IBookOwner, renderer: IPaperRenderer);
|
|
845
|
+
setTime(time: number): void;
|
|
846
|
+
setMeshData(lowpolyMeshData: PaperMeshData, lowpolyHoleMeshData: PaperMeshData | null, highpolyMeshDataPool: PaperMeshDataPool): void;
|
|
847
|
+
restState(rightStack: boolean): void;
|
|
848
|
+
restMesh(): void;
|
|
849
|
+
setMaterialData(data: PaperMaterialData): void;
|
|
850
|
+
setPaperSetup(settings: PaperSetup): void;
|
|
851
|
+
setContentData(frontContent: IPageContent, backContent: IPageContent, useBackContentForSides?: boolean): void;
|
|
852
|
+
setMinTurningRadius(min: number): void;
|
|
853
|
+
updateTurningRadius(bend?: number): void;
|
|
854
|
+
startTurning(ray: THREE.Ray): boolean;
|
|
855
|
+
stopTurning(): void;
|
|
856
|
+
/**
|
|
857
|
+
* Called each frame while the user is dragging.
|
|
858
|
+
* `dt` replaces Time.deltaTime.
|
|
859
|
+
*/
|
|
860
|
+
updateTurning(ray: THREE.Ray, dt?: number): void;
|
|
861
|
+
/**
|
|
862
|
+
* Called each frame while the page is falling back into place.
|
|
863
|
+
* `dt` replaces Time.deltaTime.
|
|
864
|
+
*/
|
|
865
|
+
updateFalling(dt?: number): void;
|
|
866
|
+
getTextureCoordinate(ray: THREE.Ray): THREE.Vector2;
|
|
867
|
+
raycast(ray: THREE.Ray): {
|
|
868
|
+
hit: boolean;
|
|
869
|
+
hitInfo: BookRaycastHit;
|
|
870
|
+
};
|
|
871
|
+
private hit2UV;
|
|
872
|
+
/**
|
|
873
|
+
* Internal raycast against the paper plane in local space.
|
|
874
|
+
* Returns the local-space hit point, or null if no hit / out of bounds.
|
|
875
|
+
*/
|
|
876
|
+
raycastLocal(ray: THREE.Ray, noBoundsCheck?: boolean): THREE.Vector3 | null;
|
|
877
|
+
private trySwitchMeshData;
|
|
878
|
+
private switchMeshData;
|
|
879
|
+
updateMaterials(): void;
|
|
880
|
+
updateBaseVertices(): void;
|
|
881
|
+
updateMesh(): void;
|
|
882
|
+
getDirection(z: number): THREE.Vector3;
|
|
883
|
+
updateTime(): void;
|
|
884
|
+
private findTime;
|
|
885
|
+
private clampHandle;
|
|
886
|
+
private updateCylinder;
|
|
887
|
+
private rollPoint;
|
|
888
|
+
startAutoTurning(mode: AutoTurnMode, twist: number, bend: number, duration: number): void;
|
|
889
|
+
get cylinder(): Cylinder;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Rectangle defined by two corner indices (startX/Z, endX/Z) plus flip/left flags.
|
|
894
|
+
* C# struct — emulated with clone().
|
|
895
|
+
*/
|
|
896
|
+
declare class PaperBorder {
|
|
897
|
+
startX: number;
|
|
898
|
+
startZ: number;
|
|
899
|
+
endX: number;
|
|
900
|
+
endZ: number;
|
|
901
|
+
flip: boolean;
|
|
902
|
+
left: boolean;
|
|
903
|
+
constructor(startX: number, startZ: number, endX: number, endZ: number, flip: boolean, left?: boolean);
|
|
904
|
+
clone(): PaperBorder;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
declare class PaperMaterialData {
|
|
908
|
+
private m_Materials1;
|
|
909
|
+
private m_Materials3;
|
|
910
|
+
private m_Color;
|
|
911
|
+
private m_Texture;
|
|
912
|
+
private m_TextureST;
|
|
913
|
+
private _cachedPropertyBlock;
|
|
914
|
+
private _propertyBlockDirty;
|
|
915
|
+
get materials1(): THREE.Material[];
|
|
916
|
+
get materials3(): THREE.Material[];
|
|
917
|
+
get color(): THREE.Color;
|
|
918
|
+
get texture(): THREE.Texture | null;
|
|
919
|
+
get textureST(): THREE.Vector4;
|
|
920
|
+
constructor(paperSetup: PaperSetup);
|
|
921
|
+
/**
|
|
922
|
+
* Mirrors Unity's MaterialPropertyBlock: stores color, texture, and textureST.
|
|
923
|
+
* Paper.ts reads this after calling updatePropertyBlock.
|
|
924
|
+
*
|
|
925
|
+
* Returns a cached object — callers must NOT mutate the returned values.
|
|
926
|
+
*/
|
|
927
|
+
get propertyBlock(): PropertyBlock;
|
|
928
|
+
updatePropertyBlock(texture: THREE.Texture | null, textureST: THREE.Vector4): void;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
declare class PaperMeshData {
|
|
932
|
+
private m_Geometry;
|
|
933
|
+
private m_Pattern;
|
|
934
|
+
private m_BaseVertices;
|
|
935
|
+
private m_Vertices;
|
|
936
|
+
private m_Normals;
|
|
937
|
+
get geometry(): THREE.BufferGeometry;
|
|
938
|
+
get pattern(): PaperPattern;
|
|
939
|
+
get baseVertices(): THREE.Vector3[];
|
|
940
|
+
constructor(geometry: THREE.BufferGeometry, pattern: PaperPattern);
|
|
941
|
+
/**
|
|
942
|
+
* Recalculates base vertex positions from the pattern's X/Z arrays
|
|
943
|
+
* and offset.
|
|
944
|
+
*
|
|
945
|
+
* Ported from lines ~2167-2183.
|
|
946
|
+
*/
|
|
947
|
+
updateBaseVertices(): void;
|
|
948
|
+
/**
|
|
949
|
+
* Recomputes all vertex positions and normals.
|
|
950
|
+
*
|
|
951
|
+
* Algorithm:
|
|
952
|
+
* 1. Clear normals for all base vertices.
|
|
953
|
+
* 2. Interpolate seam positions in X and Z.
|
|
954
|
+
* 3. Accumulate face normals per quad onto each vertex.
|
|
955
|
+
* 4. Normalise by dividing by weight and re-normalising.
|
|
956
|
+
* 5. Interpolate seam normals (with slerp).
|
|
957
|
+
* 6. Offset front/back by +/- halfThickness along normal.
|
|
958
|
+
* 7. Update border vertex positions and normals.
|
|
959
|
+
* 8. Push data into BufferGeometry attributes.
|
|
960
|
+
*
|
|
961
|
+
* Ported from lines ~2185-2255.
|
|
962
|
+
*/
|
|
963
|
+
updateMesh(): void;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
declare class PaperMeshDataPool {
|
|
967
|
+
private m_Stack;
|
|
968
|
+
private m_MeshFactory;
|
|
969
|
+
private m_Pattern;
|
|
970
|
+
private m_SharedData;
|
|
971
|
+
private m_UseSharedData;
|
|
972
|
+
constructor(meshFactory: MeshFactory, pattern: PaperPattern, useSharedData?: boolean);
|
|
973
|
+
get(): PaperMeshData;
|
|
974
|
+
free(mesh: PaperMeshData): void;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Ported from Book.cs — PaperPattern class (lines ~2265-2290).
|
|
979
|
+
*
|
|
980
|
+
* Holds the tessellation layout of a single paper sheet: vertex arrays,
|
|
981
|
+
* seam information, triangle indices, UV coordinates and border definitions.
|
|
982
|
+
*/
|
|
983
|
+
declare class PaperPattern {
|
|
984
|
+
baseXArray: number[];
|
|
985
|
+
baseZArray: number[];
|
|
986
|
+
baseXOffset: number;
|
|
987
|
+
baseVertexCount: number;
|
|
988
|
+
xSeams: PaperSeam[];
|
|
989
|
+
zSeams: PaperSeam[];
|
|
990
|
+
xNoneSeamIndexes: number[];
|
|
991
|
+
borders: PaperBorder[];
|
|
992
|
+
texcoords: THREE.Vector2[];
|
|
993
|
+
weights: number[];
|
|
994
|
+
triangles: number[];
|
|
995
|
+
frontTriangles: number[];
|
|
996
|
+
backTriangles: number[];
|
|
997
|
+
borderTriangles: number[];
|
|
998
|
+
vertexCount: number;
|
|
999
|
+
subMeshCount: number;
|
|
1000
|
+
size: THREE.Vector2;
|
|
1001
|
+
thickness: number;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Describes a seam (extra split) in the paper mesh along one axis.
|
|
1006
|
+
* C# struct — emulated with clone().
|
|
1007
|
+
*/
|
|
1008
|
+
declare class PaperSeam {
|
|
1009
|
+
active: boolean;
|
|
1010
|
+
prevIndex: number;
|
|
1011
|
+
index: number;
|
|
1012
|
+
nextIndex: number;
|
|
1013
|
+
time: number;
|
|
1014
|
+
constructor(prevIndex: number, index: number, nextIndex: number, time: number);
|
|
1015
|
+
clone(): PaperSeam;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Ported from Book.cs — PaperSetup class (lines ~1617-1712).
|
|
1020
|
+
*
|
|
1021
|
+
* Holds the serialised configuration for a single paper sheet: material,
|
|
1022
|
+
* colour, dimensions, stiffness, quality and UV margin.
|
|
1023
|
+
*/
|
|
1024
|
+
declare class PaperSetup {
|
|
1025
|
+
private static readonly kMinSize;
|
|
1026
|
+
private static readonly kMinThickness;
|
|
1027
|
+
private static readonly kMinQuality;
|
|
1028
|
+
private static readonly kMaxQuality;
|
|
1029
|
+
private m_Material;
|
|
1030
|
+
private m_Color;
|
|
1031
|
+
private m_Width;
|
|
1032
|
+
private m_Height;
|
|
1033
|
+
private m_Thickness;
|
|
1034
|
+
private m_Stiffness;
|
|
1035
|
+
private m_Quality;
|
|
1036
|
+
private m_UVMargin;
|
|
1037
|
+
margin: number;
|
|
1038
|
+
bookDirection: BookDirection;
|
|
1039
|
+
constructor(opts?: {
|
|
1040
|
+
color?: THREE.Color;
|
|
1041
|
+
width?: number;
|
|
1042
|
+
height?: number;
|
|
1043
|
+
thickness?: number;
|
|
1044
|
+
stiffness?: number;
|
|
1045
|
+
quality?: number;
|
|
1046
|
+
material?: THREE.Material | null;
|
|
1047
|
+
});
|
|
1048
|
+
get material(): THREE.Material | null;
|
|
1049
|
+
set material(value: THREE.Material | null);
|
|
1050
|
+
get color(): THREE.Color;
|
|
1051
|
+
set color(value: THREE.Color);
|
|
1052
|
+
get width(): number;
|
|
1053
|
+
set width(value: number);
|
|
1054
|
+
get height(): number;
|
|
1055
|
+
set height(value: number);
|
|
1056
|
+
get thickness(): number;
|
|
1057
|
+
set thickness(value: number);
|
|
1058
|
+
get stiffness(): number;
|
|
1059
|
+
set stiffness(value: number);
|
|
1060
|
+
get quality(): number;
|
|
1061
|
+
set quality(value: number);
|
|
1062
|
+
get uvMargin(): PaperUVMargin;
|
|
1063
|
+
set uvMargin(value: PaperUVMargin);
|
|
1064
|
+
get size(): THREE.Vector2;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
declare interface PaperSetupInit {
|
|
1068
|
+
color: THREE.Color;
|
|
1069
|
+
width: number;
|
|
1070
|
+
height: number;
|
|
1071
|
+
thickness: number;
|
|
1072
|
+
stiffness: number;
|
|
1073
|
+
material: THREE.Material | null;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* Ported from Book.cs — PaperUVMargin struct (lines ~1714-1796).
|
|
1078
|
+
*
|
|
1079
|
+
* Defines the blank space around content on each of the four sides.
|
|
1080
|
+
* C# struct — emulated with clone().
|
|
1081
|
+
*/
|
|
1082
|
+
declare class PaperUVMargin {
|
|
1083
|
+
/* Excluded from this release type: kMin */
|
|
1084
|
+
/* Excluded from this release type: kMax */
|
|
1085
|
+
private m_Left;
|
|
1086
|
+
private m_Right;
|
|
1087
|
+
private m_Down;
|
|
1088
|
+
private m_Up;
|
|
1089
|
+
get left(): number;
|
|
1090
|
+
set left(value: number);
|
|
1091
|
+
get right(): number;
|
|
1092
|
+
set right(value: number);
|
|
1093
|
+
get down(): number;
|
|
1094
|
+
set down(value: number);
|
|
1095
|
+
get up(): number;
|
|
1096
|
+
set up(value: number);
|
|
1097
|
+
private clamp;
|
|
1098
|
+
/**
|
|
1099
|
+
* Returns a new PaperUVMargin with margins remapped according to the
|
|
1100
|
+
* book direction.
|
|
1101
|
+
*/
|
|
1102
|
+
transform(direction: BookDirection): PaperUVMargin;
|
|
1103
|
+
/**
|
|
1104
|
+
* Remap a UV coordinate so that (0,0) and (1,1) correspond to the
|
|
1105
|
+
* content area inside the margins.
|
|
1106
|
+
*
|
|
1107
|
+
* Unity's `Mathf.InverseLerp(a, b, v)` = `(v - a) / (b - a)` clamped to [0,1].
|
|
1108
|
+
*/
|
|
1109
|
+
fixUV(uv: THREE.Vector2): THREE.Vector2;
|
|
1110
|
+
private static inverseLerp;
|
|
1111
|
+
clone(): PaperUVMargin;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
declare interface PropertyBlock {
|
|
1115
|
+
color: THREE.Color;
|
|
1116
|
+
map: THREE.Texture | null;
|
|
1117
|
+
textureST: THREE.Vector4;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** Pixels per world unit — used to compute canvas size from page dimensions. */
|
|
1121
|
+
export declare const PX_PER_UNIT = 256;
|
|
1122
|
+
|
|
1123
|
+
declare class RendererFactory {
|
|
1124
|
+
private m_Root;
|
|
1125
|
+
private m_UsedRenderers;
|
|
1126
|
+
private m_FreeRenderers;
|
|
1127
|
+
private m_Renderers;
|
|
1128
|
+
private m_Ids;
|
|
1129
|
+
get ids(): number[];
|
|
1130
|
+
constructor(root: THREE.Object3D);
|
|
1131
|
+
get(name: string): BookRenderer;
|
|
1132
|
+
recycle(): void;
|
|
1133
|
+
destroy(): void;
|
|
1134
|
+
getBounds(): THREE.Box3;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
export declare function resolvePageIndex(currentPage: number, spreadPages: Set<number>, pageCount: number): {
|
|
1138
|
+
effectiveIdx: number;
|
|
1139
|
+
isSpread: boolean;
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
export declare function toBookDirection(direction: DirectionOption): BookDirection;
|
|
1143
|
+
|
|
1144
|
+
export { }
|