@jack120/test 0.2.0 → 0.2.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.
- package/dist/index.d.ts +1140 -0
- package/package.json +4 -1
- package/.gitmodules +0 -3
- package/.prettierrc +0 -6
- package/.vscode/c_cpp_properties.json +0 -14
- package/.vscode/launch.json +0 -24
- package/.vscode/settings.json +0 -8
- package/CMakeLists.txt +0 -52
- package/adamas-config.json +0 -5
- package/external/CMakeLists.txt +0 -1
- package/external/Unity-NodeJS-RPC/CMakeLists.txt +0 -13
- package/external/Unity-NodeJS-RPC/README.md +0 -1
- package/external/Unity-NodeJS-RPC/RpcClient.cpp +0 -265
- package/external/Unity-NodeJS-RPC/include/RpcClient.h +0 -118
- package/external/Unity-NodeJS-RPC/main.cpp +0 -76
- package/external/Unity-NodeJS-RPC/nlohmann/json.hpp +0 -25526
- package/external/Unity-NodeJS-RPC/server/Program.cs +0 -52
- package/external/Unity-NodeJS-RPC/server/json.cs +0 -66
- package/external/Unity-NodeJS-RPC/server/rpc.cs +0 -369
- package/external/Unity-NodeJS-RPC/server/sample1.csproj +0 -10
- package/external/Unity-NodeJS-RPC/server/sample1.sln +0 -24
- package/external/Unity-NodeJS-RPC/server/unity/RpcUnity.cs.txt +0 -60
- package/index.ts +0 -36
- package/library/adamas-types.d.ts +0 -70
- package/library/debug.ts +0 -7
- package/library/device.ts +0 -279
- package/library/entity.ts +0 -35
- package/library/index.ts +0 -19
- package/library/interaction/interaction.ts +0 -281
- package/library/networking/state-sync.ts +0 -62
- package/library/physics/collider.ts +0 -252
- package/library/physics/rigidbody.ts +0 -119
- package/library/render/camera.ts +0 -172
- package/library/render/light.ts +0 -169
- package/library/render/material.ts +0 -258
- package/library/render/mesh.ts +0 -208
- package/library/render/primitives.ts +0 -76
- package/library/render/renderable.ts +0 -137
- package/library/render/renderer.ts +0 -124
- package/library/render/scene.ts +0 -89
- package/library/render/texture.ts +0 -247
- package/library/render/transform.ts +0 -259
- package/library/rpc.ts +0 -81
- package/library/utilities/base64.ts +0 -63
- package/loader-template.ts +0 -419
- package/native.cc +0 -111
- package/project.adamas.json +0 -457
- package/rusk.glb +0 -0
- package/samples/device-sample.ts +0 -30
- package/samples/interaction-sample.ts +0 -134
- package/samples/physics-sample.ts +0 -39
- package/samples/rendering-sample.ts +0 -88
- package/samples/spawn-cube.ts +0 -422
- package/samples/state-sync-sample.ts +0 -25
- package/tsconfig.json +0 -20
- /package/{library → dist}/native-bindings-osx.node +0 -0
- /package/{library → dist}/native-bindings-win.node +0 -0
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { RpcClient } from "../rpc";
|
|
2
|
-
import { Entity } from "../entity";
|
|
3
|
-
import { vec4 } from "gl-matrix";
|
|
4
|
-
|
|
5
|
-
export type MaterialHandle = number;
|
|
6
|
-
|
|
7
|
-
export enum ShaderType {
|
|
8
|
-
URP_LIT = "Universal Render Pipeline/Lit",
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum ShaderProperties {
|
|
12
|
-
/** 2D Texture */
|
|
13
|
-
BaseMap = "_BaseMap",
|
|
14
|
-
/** vec4 [0.0, 1.0] */
|
|
15
|
-
BaseColor = "_BaseColor",
|
|
16
|
-
|
|
17
|
-
/** float [0.0, 1.0] */
|
|
18
|
-
Cutoff = "_Cutoff",
|
|
19
|
-
|
|
20
|
-
/** float [0.0, 1.0] */
|
|
21
|
-
Smoothness = "_Smoothness",
|
|
22
|
-
/** float */
|
|
23
|
-
SmoothnessTextureChannel = "_SmoothnessTextureChannel",
|
|
24
|
-
|
|
25
|
-
/** float [0.0, 1.0] */
|
|
26
|
-
Metallic = "_Metallic",
|
|
27
|
-
/** 2D Texture */
|
|
28
|
-
MetallicGlossMap = "_MetallicGlossMap",
|
|
29
|
-
|
|
30
|
-
/** vec3 [0.0, 1.0] */
|
|
31
|
-
SpecColor = "_SpecColor",
|
|
32
|
-
/** 2D Texture */
|
|
33
|
-
SpecGlossMap = "_SpecGlossMap",
|
|
34
|
-
|
|
35
|
-
/** float */
|
|
36
|
-
SpecularHighlights = "_SpecularHighlights",
|
|
37
|
-
/** float */
|
|
38
|
-
EnvironmentReflections = "_EnvironmentReflections",
|
|
39
|
-
|
|
40
|
-
/** float */
|
|
41
|
-
BumpScale = "_BumpScale",
|
|
42
|
-
/** 2D Texture */
|
|
43
|
-
BumpMap = "_BumpMap",
|
|
44
|
-
|
|
45
|
-
/** float [0.005, 0.08] */
|
|
46
|
-
Parallax = "_Parallax",
|
|
47
|
-
/** 2D Texture */
|
|
48
|
-
ParallaxMap = "_ParallaxMap",
|
|
49
|
-
|
|
50
|
-
/** float [0.0, 1.0] */
|
|
51
|
-
OcclusionStrength = "_OcclusionStrength",
|
|
52
|
-
/** 2D Texture */
|
|
53
|
-
OcclusionMap = "_OcclusionMap",
|
|
54
|
-
|
|
55
|
-
/** vec3 [0.0, 1.0] */
|
|
56
|
-
EmissionColor = "_EmissionColor",
|
|
57
|
-
/** 2D Texture */
|
|
58
|
-
EmissionMap = "_EmissionMap",
|
|
59
|
-
|
|
60
|
-
/** 2D Texture */
|
|
61
|
-
DetailMask = "_DetailMask",
|
|
62
|
-
/** float [0.0, 2.0] */
|
|
63
|
-
DetailAlbedoMapScale = "_DetailAlbedoMapScale",
|
|
64
|
-
/** 2D Texture */
|
|
65
|
-
DetailAlbedoMap = "_DetailAlbedoMap",
|
|
66
|
-
/** float [0.0, 2.0] */
|
|
67
|
-
DetailNormalMapScale = "_DetailNormalMapScale",
|
|
68
|
-
/** 2D Texture */
|
|
69
|
-
DetailNormalMap = "_DetailNormalMap",
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class MaterialManager {
|
|
73
|
-
/**
|
|
74
|
-
* Create a new material with the specified shader
|
|
75
|
-
* @param shader The name of the shader to use
|
|
76
|
-
* @returns The material handle
|
|
77
|
-
*/
|
|
78
|
-
static Create(shader: ShaderType): MaterialHandle;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Create a new material and attach it to a renderable component
|
|
82
|
-
* @param shader The name of the shader to use
|
|
83
|
-
* @param entity The entity with the renderable component
|
|
84
|
-
* @param submeshIndex The submesh index to attach to (default: 0)
|
|
85
|
-
* @returns The material handle
|
|
86
|
-
*/
|
|
87
|
-
static Create(
|
|
88
|
-
shader: ShaderType,
|
|
89
|
-
entity: Entity,
|
|
90
|
-
submeshIndex?: number,
|
|
91
|
-
): MaterialHandle;
|
|
92
|
-
|
|
93
|
-
static Create(
|
|
94
|
-
shader: ShaderType = ShaderType.URP_LIT,
|
|
95
|
-
entity?: Entity,
|
|
96
|
-
submeshIndex: number = 0,
|
|
97
|
-
): MaterialHandle {
|
|
98
|
-
const matHandle = Number(
|
|
99
|
-
RpcClient.Call("Material_Create", {
|
|
100
|
-
shaderName: shader,
|
|
101
|
-
clientId: RpcClient.GetClientId(),
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
if (entity !== undefined) {
|
|
106
|
-
RpcClient.Call("Renderable_SetMaterial", {
|
|
107
|
-
entityHandle: entity,
|
|
108
|
-
materialHandle: matHandle,
|
|
109
|
-
index: submeshIndex,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return matHandle;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Destroy a material
|
|
118
|
-
* @param handle The material handle to destroy
|
|
119
|
-
* @returns boolean indicating success
|
|
120
|
-
*/
|
|
121
|
-
static Destroy(handle: MaterialHandle): boolean {
|
|
122
|
-
return Boolean(
|
|
123
|
-
RpcClient.Call("Material_Destroy", { materialHandle: handle }),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Create a material instance
|
|
129
|
-
* @param handle The material handle to create an instance from
|
|
130
|
-
* @returns The material instance handle
|
|
131
|
-
*/
|
|
132
|
-
static CreateInstance(handle: MaterialHandle): MaterialHandle {
|
|
133
|
-
return Number(
|
|
134
|
-
RpcClient.Call("Material_CreateInstance", {
|
|
135
|
-
materialHandle: handle,
|
|
136
|
-
clientId: RpcClient.GetClientId(),
|
|
137
|
-
}),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Set a float property on the material
|
|
143
|
-
* @param handle The material handle
|
|
144
|
-
* @param prop The property name
|
|
145
|
-
* @param value The float value
|
|
146
|
-
* @returns boolean indicating success
|
|
147
|
-
*/
|
|
148
|
-
static SetFloat(
|
|
149
|
-
handle: MaterialHandle,
|
|
150
|
-
prop: ShaderProperties,
|
|
151
|
-
value: number,
|
|
152
|
-
): boolean {
|
|
153
|
-
return Boolean(
|
|
154
|
-
RpcClient.Call("Material_SetFloat", {
|
|
155
|
-
materialHandle: handle,
|
|
156
|
-
propertyName: prop,
|
|
157
|
-
value,
|
|
158
|
-
}),
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Set a vector property on the material
|
|
164
|
-
* @param handle The material handle
|
|
165
|
-
* @param prop The property name
|
|
166
|
-
* @param value vec4 value
|
|
167
|
-
* @returns boolean indicating success
|
|
168
|
-
*/
|
|
169
|
-
static SetVector(
|
|
170
|
-
handle: MaterialHandle,
|
|
171
|
-
prop: ShaderProperties,
|
|
172
|
-
value: vec4,
|
|
173
|
-
): boolean {
|
|
174
|
-
return Boolean(
|
|
175
|
-
RpcClient.Call("Material_SetVector", {
|
|
176
|
-
materialHandle: handle,
|
|
177
|
-
propertyName: prop,
|
|
178
|
-
x: value[0],
|
|
179
|
-
y: value[1],
|
|
180
|
-
z: value[2],
|
|
181
|
-
w: value[3],
|
|
182
|
-
}),
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Set a color property on the material
|
|
188
|
-
* @param handle The material handle
|
|
189
|
-
* @param prop The property name
|
|
190
|
-
* @param rgba vec4 color [0.0, 1.0]
|
|
191
|
-
* @returns boolean indicating success
|
|
192
|
-
*/
|
|
193
|
-
static SetColor(
|
|
194
|
-
handle: MaterialHandle,
|
|
195
|
-
prop: ShaderProperties,
|
|
196
|
-
rgba: vec4,
|
|
197
|
-
): boolean {
|
|
198
|
-
return Boolean(
|
|
199
|
-
RpcClient.Call("Material_SetColor", {
|
|
200
|
-
materialHandle: handle,
|
|
201
|
-
propertyName: prop,
|
|
202
|
-
r: rgba[0],
|
|
203
|
-
g: rgba[1],
|
|
204
|
-
b: rgba[2],
|
|
205
|
-
a: rgba[3],
|
|
206
|
-
}),
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Set a texture property on the material
|
|
212
|
-
* @param handle The material handle
|
|
213
|
-
* @param prop The property name
|
|
214
|
-
* @param tex The texture handle
|
|
215
|
-
* @returns boolean indicating success
|
|
216
|
-
*/
|
|
217
|
-
static SetTexture(
|
|
218
|
-
handle: MaterialHandle,
|
|
219
|
-
prop: ShaderProperties,
|
|
220
|
-
tex: number,
|
|
221
|
-
): boolean {
|
|
222
|
-
return Boolean(
|
|
223
|
-
RpcClient.Call("Material_SetTexture", {
|
|
224
|
-
materialHandle: handle,
|
|
225
|
-
propertyName: prop,
|
|
226
|
-
textureHandle: tex,
|
|
227
|
-
}),
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Get a float property from the material
|
|
233
|
-
* @param handle The material handle
|
|
234
|
-
* @param prop The property name
|
|
235
|
-
* @returns The float value
|
|
236
|
-
*/
|
|
237
|
-
static GetFloat(handle: MaterialHandle, prop: ShaderProperties): number {
|
|
238
|
-
return Number(
|
|
239
|
-
RpcClient.Call("Material_GetFloat", {
|
|
240
|
-
materialHandle: handle,
|
|
241
|
-
propertyName: prop,
|
|
242
|
-
}),
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Get a color property from the material
|
|
248
|
-
* @param handle The material handle
|
|
249
|
-
* @param prop The property name
|
|
250
|
-
* @returns The color as a string
|
|
251
|
-
*/
|
|
252
|
-
static GetColor(handle: MaterialHandle, prop: ShaderProperties): string {
|
|
253
|
-
return RpcClient.Call("Material_GetColor", {
|
|
254
|
-
materialHandle: handle,
|
|
255
|
-
propertyName: prop,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
package/library/render/mesh.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { RpcClient } from "../rpc";
|
|
2
|
-
import { Entity } from "../entity";
|
|
3
|
-
import { vec2, vec3 } from "gl-matrix";
|
|
4
|
-
import { base64Encode } from "../utilities/base64";
|
|
5
|
-
|
|
6
|
-
export type MeshHandle = number;
|
|
7
|
-
|
|
8
|
-
// NOTE: the following are not supported compared to legacy code:
|
|
9
|
-
// - Filament's VertexBufferBuilder / IndexBufferBuilder (Unity meshes are atomic)
|
|
10
|
-
// - Filament's Attribute, Normalized, AdvancedSkinning on a raw VB/IB
|
|
11
|
-
|
|
12
|
-
// We don't expose VertexBuffer/IndexBuffer builders in Unity; instead use Mesh RPCs directly
|
|
13
|
-
export class MeshManager {
|
|
14
|
-
/**
|
|
15
|
-
* Create a new mesh
|
|
16
|
-
* @returns The mesh handle
|
|
17
|
-
*/
|
|
18
|
-
static Create(): MeshHandle;
|
|
19
|
-
/**
|
|
20
|
-
* Create a new mesh and attach it to a renderable component
|
|
21
|
-
* @param entity The entity with the renderable component
|
|
22
|
-
* @returns The mesh handle
|
|
23
|
-
*/
|
|
24
|
-
static Create(entity: Entity): MeshHandle;
|
|
25
|
-
static Create(entity?: Entity): MeshHandle {
|
|
26
|
-
const meshHandle = Number(
|
|
27
|
-
RpcClient.Call("Mesh_Create", {
|
|
28
|
-
clientId: RpcClient.GetClientId(),
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (entity !== undefined) {
|
|
33
|
-
RpcClient.Call("Renderable_SetMesh", {
|
|
34
|
-
entityHandle: entity,
|
|
35
|
-
meshHandle: meshHandle,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return meshHandle;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Destroy a mesh
|
|
44
|
-
* @param handle The mesh handle to destroy
|
|
45
|
-
* @returns boolean indicating success
|
|
46
|
-
*/
|
|
47
|
-
static Destroy(handle: MeshHandle): boolean {
|
|
48
|
-
return Boolean(RpcClient.Call("Mesh_Destroy", { meshHandle: handle }));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Set the vertices for the mesh
|
|
53
|
-
* @param handle The mesh handle
|
|
54
|
-
* @param vertices Array of vertex positions
|
|
55
|
-
* @returns boolean indicating success
|
|
56
|
-
*/
|
|
57
|
-
static SetVertices(handle: MeshHandle, vertices: vec3[]): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Set the vertices for the mesh
|
|
60
|
-
* @param handle The mesh handle
|
|
61
|
-
* @param base64Vertices Array of vertex positions encoded as a base64 string
|
|
62
|
-
* @returns boolean indicating success
|
|
63
|
-
*/
|
|
64
|
-
static SetVertices(handle: MeshHandle, base64Vertices: string): boolean;
|
|
65
|
-
static SetVertices(
|
|
66
|
-
handle: MeshHandle,
|
|
67
|
-
verticesOrBase64: vec3[] | string,
|
|
68
|
-
): boolean {
|
|
69
|
-
let base64Vertices;
|
|
70
|
-
|
|
71
|
-
if (typeof verticesOrBase64 === "string") {
|
|
72
|
-
base64Vertices = verticesOrBase64;
|
|
73
|
-
} else {
|
|
74
|
-
const buffer = new Float32Array(verticesOrBase64.length * 3);
|
|
75
|
-
for (let i = 0; i < verticesOrBase64.length; i++) {
|
|
76
|
-
const n = verticesOrBase64[i];
|
|
77
|
-
buffer[i * 3] = n[0];
|
|
78
|
-
buffer[i * 3 + 1] = n[1];
|
|
79
|
-
buffer[i * 3 + 2] = n[2];
|
|
80
|
-
}
|
|
81
|
-
base64Vertices = base64Encode(buffer.buffer);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return Boolean(
|
|
85
|
-
RpcClient.Call("Mesh_SetVertices", {
|
|
86
|
-
meshHandle: handle,
|
|
87
|
-
base64Vertices,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Set the triangles (indices) for the mesh
|
|
94
|
-
* @param handle The mesh handle
|
|
95
|
-
* @param indices Array of triangle indices
|
|
96
|
-
* @returns boolean indicating success
|
|
97
|
-
*/
|
|
98
|
-
static SetTriangles(handle: MeshHandle, indices: vec3[]): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Set the triangles (indices) for the mesh
|
|
101
|
-
* @param handle The mesh handle
|
|
102
|
-
* @param base64Indices Array of triangle indices encoeded as a base64 string
|
|
103
|
-
* @returns boolean indicating success
|
|
104
|
-
*/
|
|
105
|
-
static SetTriangles(handle: MeshHandle, base64Indices: string): boolean;
|
|
106
|
-
static SetTriangles(
|
|
107
|
-
handle: MeshHandle,
|
|
108
|
-
indicesOrBase64: vec3[] | string,
|
|
109
|
-
): boolean {
|
|
110
|
-
let base64Triangles: string;
|
|
111
|
-
|
|
112
|
-
if (typeof indicesOrBase64 === "string") {
|
|
113
|
-
base64Triangles = indicesOrBase64;
|
|
114
|
-
} else {
|
|
115
|
-
const buffer = new Float32Array(indicesOrBase64.length * 3);
|
|
116
|
-
for (let i = 0; i < indicesOrBase64.length; i++) {
|
|
117
|
-
const n = indicesOrBase64[i];
|
|
118
|
-
buffer[i * 3] = n[0];
|
|
119
|
-
buffer[i * 3 + 1] = n[1];
|
|
120
|
-
buffer[i * 3 + 2] = n[2];
|
|
121
|
-
}
|
|
122
|
-
base64Triangles = base64Encode(buffer.buffer);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return Boolean(
|
|
126
|
-
RpcClient.Call("Mesh_SetTriangles", {
|
|
127
|
-
meshHandle: handle,
|
|
128
|
-
base64Triangles,
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
static SetUVs(handle: MeshHandle, uvs: vec2[]): boolean;
|
|
134
|
-
static SetUVs(handle: MeshHandle, base64Uvs: string): boolean;
|
|
135
|
-
static SetUVs(handle: MeshHandle, uvsOrBase64: vec2[] | string): boolean {
|
|
136
|
-
let base64Uvs: string;
|
|
137
|
-
|
|
138
|
-
if (typeof uvsOrBase64 === "string") {
|
|
139
|
-
base64Uvs = uvsOrBase64;
|
|
140
|
-
} else {
|
|
141
|
-
const buffer = new Float32Array(uvsOrBase64.length * 2);
|
|
142
|
-
for (let i = 0; i < uvsOrBase64.length; i++) {
|
|
143
|
-
const n = uvsOrBase64[i];
|
|
144
|
-
buffer[i * 2] = n[0];
|
|
145
|
-
buffer[i * 2 + 1] = n[1];
|
|
146
|
-
}
|
|
147
|
-
base64Uvs = base64Encode(buffer.buffer);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return Boolean(
|
|
151
|
-
RpcClient.Call("Mesh_SetUVs", {
|
|
152
|
-
meshHandle: handle,
|
|
153
|
-
base64Uvs,
|
|
154
|
-
}),
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
static SetNormals(handle: MeshHandle, normals: vec3[]): boolean;
|
|
159
|
-
static SetNormals(handle: MeshHandle, base64Normals: string): boolean;
|
|
160
|
-
static SetNormals(
|
|
161
|
-
handle: MeshHandle,
|
|
162
|
-
normalsOrBase64: vec3[] | string,
|
|
163
|
-
): boolean {
|
|
164
|
-
let base64Normals: string;
|
|
165
|
-
|
|
166
|
-
if (typeof normalsOrBase64 === "string") {
|
|
167
|
-
base64Normals = normalsOrBase64;
|
|
168
|
-
} else {
|
|
169
|
-
const buffer = new Float32Array(normalsOrBase64.length * 3);
|
|
170
|
-
for (let i = 0; i < normalsOrBase64.length; i++) {
|
|
171
|
-
const n = normalsOrBase64[i];
|
|
172
|
-
buffer[i * 3] = n[0];
|
|
173
|
-
buffer[i * 3 + 1] = n[1];
|
|
174
|
-
buffer[i * 3 + 2] = n[2];
|
|
175
|
-
}
|
|
176
|
-
base64Normals = base64Encode(buffer.buffer);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return Boolean(
|
|
180
|
-
RpcClient.Call("Mesh_SetNormals", {
|
|
181
|
-
meshHandle: handle,
|
|
182
|
-
base64Normals,
|
|
183
|
-
}),
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Recalculate normals for the mesh
|
|
189
|
-
* @param handle The mesh handle
|
|
190
|
-
* @returns boolean indicating success
|
|
191
|
-
*/
|
|
192
|
-
static RecalcNormals(handle: MeshHandle): boolean {
|
|
193
|
-
return Boolean(
|
|
194
|
-
RpcClient.Call("Mesh_RecalculateNormals", { meshHandle: handle }),
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Recalculate bounds for the mesh
|
|
200
|
-
* @param handle The mesh handle
|
|
201
|
-
* @returns boolean indicating success
|
|
202
|
-
*/
|
|
203
|
-
static RecalcBounds(handle: MeshHandle): boolean {
|
|
204
|
-
return Boolean(
|
|
205
|
-
RpcClient.Call("Mesh_RecalculateBounds", { meshHandle: handle }),
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { MeshManager } from "../render/mesh";
|
|
2
|
-
|
|
3
|
-
export function NewCubeMesh(): number {
|
|
4
|
-
// 8 vertices for a unit cube
|
|
5
|
-
const cubeVertices = [
|
|
6
|
-
[-0.5, -0.5, -0.5], // 0: left-bottom-back
|
|
7
|
-
[0.5, -0.5, -0.5], // 1: right-bottom-back
|
|
8
|
-
[0.5, 0.5, -0.5], // 2: right-top-back
|
|
9
|
-
[-0.5, 0.5, -0.5], // 3: left-top-back
|
|
10
|
-
[-0.5, -0.5, 0.5], // 4: left-bottom-front
|
|
11
|
-
[0.5, -0.5, 0.5], // 5: right-bottom-front
|
|
12
|
-
[0.5, 0.5, 0.5], // 6: right-top-front
|
|
13
|
-
[-0.5, 0.5, 0.5], // 7: left-top-front
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
// 12 triangles = 36 indices for cube faces
|
|
17
|
-
const cubeIndices = [
|
|
18
|
-
// back face
|
|
19
|
-
[0, 2, 1],
|
|
20
|
-
[0, 3, 2],
|
|
21
|
-
// front face
|
|
22
|
-
[4, 5, 6],
|
|
23
|
-
[4, 6, 7],
|
|
24
|
-
// bottom face
|
|
25
|
-
[0, 1, 5],
|
|
26
|
-
[0, 5, 4],
|
|
27
|
-
// top face
|
|
28
|
-
[3, 7, 6],
|
|
29
|
-
[3, 6, 2],
|
|
30
|
-
// left face
|
|
31
|
-
[0, 4, 7],
|
|
32
|
-
[0, 7, 3],
|
|
33
|
-
// right face
|
|
34
|
-
[1, 2, 6],
|
|
35
|
-
[1, 6, 5],
|
|
36
|
-
];
|
|
37
|
-
// Create mesh and attach to renderable
|
|
38
|
-
const meshHandle = MeshManager.Create();
|
|
39
|
-
MeshManager.SetVertices(meshHandle, cubeVertices);
|
|
40
|
-
MeshManager.SetTriangles(meshHandle, cubeIndices);
|
|
41
|
-
MeshManager.RecalcNormals(meshHandle);
|
|
42
|
-
MeshManager.RecalcBounds(meshHandle);
|
|
43
|
-
|
|
44
|
-
return meshHandle;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function NewQuadMesh(): number {
|
|
48
|
-
// Define 4 vertices of the quad in the X-Y plane, Z = 0
|
|
49
|
-
const quadVertices = [
|
|
50
|
-
[-0.5, -0.5, 0.0], // 0: bottom-left
|
|
51
|
-
[0.5, -0.5, 0.0], // 1: bottom-right
|
|
52
|
-
[0.5, 0.5, 0.0], // 2: top-right
|
|
53
|
-
[-0.5, 0.5, 0.0], // 3: top-left
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
// Y-flipped UVs: (0,0) is top-left instead of bottom-left
|
|
57
|
-
const quadUVs = [
|
|
58
|
-
[0.0, 1.0], // 0: bottom-left
|
|
59
|
-
[1.0, 1.0], // 1: bottom-right
|
|
60
|
-
[1.0, 0.0], // 2: top-right
|
|
61
|
-
[0.0, 0.0], // 3: top-left
|
|
62
|
-
];
|
|
63
|
-
const quadIndices = [
|
|
64
|
-
[0, 2, 1],
|
|
65
|
-
[0, 3, 2],
|
|
66
|
-
];
|
|
67
|
-
// Create mesh and set geometry
|
|
68
|
-
const meshHandle = MeshManager.Create();
|
|
69
|
-
MeshManager.SetVertices(meshHandle, quadVertices);
|
|
70
|
-
MeshManager.SetUVs(meshHandle, quadUVs);
|
|
71
|
-
MeshManager.SetTriangles(meshHandle, quadIndices);
|
|
72
|
-
MeshManager.RecalcNormals(meshHandle);
|
|
73
|
-
MeshManager.RecalcBounds(meshHandle);
|
|
74
|
-
|
|
75
|
-
return meshHandle;
|
|
76
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { RpcClient } from "../rpc";
|
|
2
|
-
import { Entity } from "../entity";
|
|
3
|
-
|
|
4
|
-
// NOTE: the following are not supported compared to legacy code:
|
|
5
|
-
// - Filament's RenderableBuilder.Geometry(index,type,vertices,indices,offset,count)
|
|
6
|
-
// - RenderableBuilder.Material(index,materialInstance)
|
|
7
|
-
// - BoundingBox(...), SetBlendOrderAt
|
|
8
|
-
|
|
9
|
-
export class RenderableManager {
|
|
10
|
-
/**
|
|
11
|
-
* Create a renderable component and attach it to the specified entity
|
|
12
|
-
* @param entity The entity to attach the renderable component to
|
|
13
|
-
* @returns boolean indicating success
|
|
14
|
-
*/
|
|
15
|
-
static Create(entity: Entity): boolean {
|
|
16
|
-
return Boolean(
|
|
17
|
-
RpcClient.Call("Renderable_Create", { entityHandle: entity }),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Destroy the Renderable component on this entity.
|
|
23
|
-
* @param entityHandle The entity to remove the renderable component from
|
|
24
|
-
* @returns boolean indicating success
|
|
25
|
-
*/
|
|
26
|
-
static Destroy(entityHandle: Entity): boolean {
|
|
27
|
-
return Boolean(RpcClient.Call("Renderable_Destroy", { entityHandle }));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns whether this entity currently has a Renderable.
|
|
32
|
-
* @param entityHandle The entity to check
|
|
33
|
-
* @returns boolean indicating if renderable component exists
|
|
34
|
-
*/
|
|
35
|
-
static HasComponent(entityHandle: Entity): boolean {
|
|
36
|
-
return Boolean(RpcClient.Call("Renderable_HasComponent", { entityHandle }));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Set the mesh for the renderable component
|
|
41
|
-
* @param entityHandle The entity with the renderable component
|
|
42
|
-
* @param meshHandle The mesh handle to attach
|
|
43
|
-
* @returns boolean indicating success
|
|
44
|
-
*/
|
|
45
|
-
static SetMesh(entityHandle: Entity, meshHandle: number): boolean {
|
|
46
|
-
if (RenderableManager.HasComponent(entityHandle)) {
|
|
47
|
-
return Boolean(
|
|
48
|
-
RpcClient.Call("Renderable_SetMesh", {
|
|
49
|
-
entityHandle,
|
|
50
|
-
meshHandle,
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
53
|
-
} else return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Set the material for the renderable component
|
|
58
|
-
* @param entityHandle The entity with the renderable component
|
|
59
|
-
* @param materialHandle The material handle to attach
|
|
60
|
-
* @param index The submesh index (default: 0)
|
|
61
|
-
* @returns boolean indicating success
|
|
62
|
-
*/
|
|
63
|
-
static SetMaterial(
|
|
64
|
-
entityHandle: Entity,
|
|
65
|
-
materialHandle: number,
|
|
66
|
-
index: number = 0,
|
|
67
|
-
): boolean {
|
|
68
|
-
return Boolean(
|
|
69
|
-
RpcClient.Call("Renderable_SetMaterial", {
|
|
70
|
-
entityHandle,
|
|
71
|
-
materialHandle,
|
|
72
|
-
index,
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Set the layer mask on this Renderable (bitmask of visible layers).
|
|
79
|
-
* @param entityHandle The entity with the renderable component
|
|
80
|
-
* @param layerMask The layer mask
|
|
81
|
-
* @returns boolean indicating success
|
|
82
|
-
*/
|
|
83
|
-
static SetLayerMask(entityHandle: Entity, layerMask: number): boolean {
|
|
84
|
-
return Boolean(
|
|
85
|
-
RpcClient.Call("Renderable_SetLayerMask", {
|
|
86
|
-
entityHandle,
|
|
87
|
-
layerMask,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Enable or disable receiving shadows on this Renderable.
|
|
94
|
-
* @param entityHandle The entity with the renderable component
|
|
95
|
-
* @param receive Whether to receive shadows
|
|
96
|
-
* @returns boolean indicating success
|
|
97
|
-
*/
|
|
98
|
-
static SetReceiveShadows(entityHandle: Entity, receive: boolean): boolean {
|
|
99
|
-
return Boolean(
|
|
100
|
-
RpcClient.Call("Renderable_SetReceiveShadows", {
|
|
101
|
-
entityHandle,
|
|
102
|
-
receive,
|
|
103
|
-
}),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Control shadow‐casting mode.
|
|
109
|
-
* 0 = Off, 1 = On, 2 = TwoSided, 3 = ShadowsOnly
|
|
110
|
-
* @param entityHandle The entity with the renderable component
|
|
111
|
-
* @param shadowMode The shadow casting mode
|
|
112
|
-
* @returns boolean indicating success
|
|
113
|
-
*/
|
|
114
|
-
static SetCastShadows(entityHandle: Entity, shadowMode: number): boolean {
|
|
115
|
-
return Boolean(
|
|
116
|
-
RpcClient.Call("Renderable_SetCastShadows", {
|
|
117
|
-
entityHandle,
|
|
118
|
-
shadowMode,
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Enable or disable frustum‐culling on this Renderable.
|
|
125
|
-
* @param entityHandle The entity with the renderable component
|
|
126
|
-
* @param enabled Whether to enable culling
|
|
127
|
-
* @returns boolean indicating success
|
|
128
|
-
*/
|
|
129
|
-
static SetCulling(entityHandle: Entity, enabled: boolean): boolean {
|
|
130
|
-
return Boolean(
|
|
131
|
-
RpcClient.Call("Renderable_SetCulling", {
|
|
132
|
-
entityHandle,
|
|
133
|
-
enabled,
|
|
134
|
-
}),
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|