This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
forked from petrbroz/svf-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intermediate-format.ts
149 lines (124 loc) · 2.88 KB
/
intermediate-format.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Intermediate 3D format schema
export type NodeID = number;
export type GeometryID = number;
export type MaterialID = number;
export type CameraID = number;
export type LightID = number;
export interface IScene {
getMetadata(): IMetadata;
getNodeCount(): number;
getNode(id: NodeID): Node;
getGeometryCount(): number;
getGeometry(id: GeometryID): Geometry;
getMaterialCount(): number;
getMaterial(id: MaterialID): Material;
getImage(uri: string): Buffer | undefined;
}
export interface IMetadata {
[key: string]: any;
}
export interface IVec2 {
x: number;
y: number;
}
export interface IVec3 {
x: number;
y: number;
z: number;
}
export interface IQuaternion {
x: number;
y: number;
z: number;
w: number;
}
export enum TransformKind {
Matrix,
Decomposed
}
export interface IMatrixTransform {
kind: TransformKind.Matrix;
elements: number[];
}
export interface IDecomposedTransform {
kind: TransformKind.Decomposed;
translation?: IVec3;
rotation?: IQuaternion;
scale?: IVec3;
}
export type Transform = IMatrixTransform | IDecomposedTransform;
export enum NodeKind {
Group,
Object,
Camera,
Light
}
export interface IGroupNode {
kind: NodeKind.Group;
dbid: number;
transform?: Transform;
children: NodeID[];
}
export interface IObjectNode {
kind: NodeKind.Object;
dbid: number;
transform?: Transform;
geometry: GeometryID;
material: MaterialID;
}
export interface ICameraNode {
kind: NodeKind.Camera;
transform?: Transform;
camera: CameraID;
}
export interface ILightNode {
kind: NodeKind.Light;
transform?: Transform;
light: LightID;
}
export type Node = IGroupNode | IObjectNode | ICameraNode | ILightNode;
export enum GeometryKind {
Mesh,
Lines,
Points,
Empty
}
export interface IMeshGeometry {
kind: GeometryKind.Mesh;
getIndices(): Uint16Array;
getVertices(): Float32Array;
getNormals(): Float32Array | undefined;
getColors(): Float32Array | undefined;
getUvChannelCount(): number;
getUvs(channel: number): Float32Array;
}
export interface ILineGeometry {
kind: GeometryKind.Lines;
getIndices(): Uint16Array;
getVertices(): Float32Array;
getColors(): Float32Array | undefined;
}
export interface IPointGeometry {
kind: GeometryKind.Points;
getVertices(): Float32Array;
getColors(): Float32Array | undefined;
}
export interface IEmptyGeometry {
kind: GeometryKind.Empty;
}
export type Geometry = IMeshGeometry | ILineGeometry | IPointGeometry | IEmptyGeometry;
export enum MaterialKind {
Physical
}
export interface IPhysicalMaterial {
kind: MaterialKind.Physical;
diffuse: IVec3;
metallic: number;
roughness: number;
opacity: number;
maps?: {
diffuse?: string;
};
scale?: IVec2;
}
export type Material = IPhysicalMaterial;