Skip to content

Commit ca70334

Browse files
MiiBondMike Bondsebavanryantrem
authored
OpenPBRMaterial (including loading and exporting glTF) (#16773)
Co-authored-by: Mike Bond <[email protected]> Co-authored-by: sebavan <[email protected]> Co-authored-by: Ryan Tremblay <[email protected]>
1 parent 4e58015 commit ca70334

File tree

159 files changed

+13750
-1664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+13750
-1664
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"acumin",
44
"babylonjs",
55
"desaturated",
6-
"fluentui"
6+
"fluentui",
77
"multilines",
88
"ONEDEF",
99
"Pickable",

packages/dev/buildTools/src/addJSToCompiledFiles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function ProcessSource(sourceCode: string, forceMJS: boolean) {
88
const extension = forceMJS ? ".mjs" : ".js";
99
return (
1010
sourceCode
11+
// replace imports from directories with index.js (mixins are generating them)
12+
.replace(/import\("([./]+)"\)/g, `import("$1/index${extension}")`)
1113
// replace imports and exports with js extensions
1214
.replace(/((import|export).*["'](@babylonjs\/.*\/|\.{1,2}\/)((?!\.scss|\.svg|\.png|\.jpg).)*?)("|');/g, `$1${extension}$5;`)
1315
.replace(/((import|export)\(["']((@babylonjs\/.*\/|\.{1,2}\/)((?!\.scss|\.svg|\.png|\.jpg).)*?))(["'])\)/g, `$1${extension}$6)`)

packages/dev/buildTools/src/generateDeclaration.ts

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,45 +76,56 @@ function GetModuleDeclaration(
7676
line = line.startsWith(" ") ? " //" + line.substring(3) : "// " + line;
7777
}
7878

79+
// replace type imports from directories with index (mixins are generating them)
80+
line = line.replace(/import\("([./]+)"\)/g, `import("$1/index")`);
81+
7982
[
8083
// Declaration
81-
/declare module ['"](.*)['"]/,
84+
/declare module ['"](.*)['"]/g,
8285
// From
83-
/ from ['"](.*)['"]/,
86+
/ from ['"](.*)['"]/g,
8487
// Module augmentation
85-
/ {4}module ['"](.*)['"]/,
86-
/^module ['"](\..*)['"]/,
88+
/ {4}module ['"](.*)['"]/g,
89+
/^module ['"](\..*)['"]/g,
8790
// Inlined Import
88-
/import\(['"](.*)['"]/,
91+
/import\(['"]([^'"]*)['"]/g,
8992
// Side Effect Import
90-
/import ['"](.*)['"]/,
93+
/import ['"](.*)['"]/g,
9194
].forEach((regex) => {
92-
const match = line.match(regex);
93-
if (match) {
94-
if (match[1][0] === ".") {
95-
const newLocation = path.join(sourceDir, match[1]).replace(/\\/g, "/");
96-
line = line.replace(match[1], newLocation);
97-
} else {
98-
let found = false;
99-
Object.keys(mapping).forEach((devPackageName) => {
100-
if (match[1].startsWith(devPackageName)) {
101-
line = line.replace(
102-
match[1],
103-
getPublicPackageName(
104-
mapping[(isValidDevPackageName(devPackageName, true) ? devPackageName : kebabize(config.devPackageName)) as DevPackageName][buildType],
105-
match[1]
106-
) + match[1].substring(devPackageName.length)
107-
);
108-
found = true;
109-
}
110-
});
111-
if (!found) {
112-
// not a dev dependency
113-
// TODO - make a list of external dependencies per package
114-
// for now - we support react
115-
if (match[1] !== "react" /* && !match[1].startsWith("@fluentui")*/) {
116-
// check what the line imports
117-
line = "";
95+
const matches = line.matchAll(regex);
96+
if (matches) {
97+
for (const match of matches) {
98+
const group = match[1];
99+
if (group[0] === ".") {
100+
const newLocation = path.join(sourceDir, group).replace(/\\/g, "/");
101+
// replaceAll only avaialable by modifying the typescript lib
102+
// which we prefered to not change for now
103+
line = (line as any).replace(group, newLocation);
104+
// while (line.indexOf("//") > -1) {}
105+
} else {
106+
let found = false;
107+
Object.keys(mapping).forEach((devPackageName) => {
108+
if (group.startsWith(devPackageName)) {
109+
line = line.replace(
110+
group,
111+
getPublicPackageName(
112+
mapping[(isValidDevPackageName(devPackageName, true) ? devPackageName : kebabize(config.devPackageName)) as DevPackageName][
113+
buildType
114+
],
115+
group
116+
) + group.substring(devPackageName.length)
117+
);
118+
found = true;
119+
}
120+
});
121+
if (!found) {
122+
// not a dev dependency
123+
// TODO - make a list of external dependencies per package
124+
// for now - we support react
125+
if (group !== "react" /* && !group.startsWith("@fluentui")*/) {
126+
// check what the line imports
127+
line = "";
128+
}
118129
}
119130
}
120131
}
@@ -319,8 +330,8 @@ function GetPackageDeclaration(
319330
while (i < lines.length) {
320331
let line = lines[i];
321332

322-
if (/import\("\.(.*)\)./g.test(line) && !/^declare type (.*) import/g.test(line)) {
323-
line = line.replace(/import\((.*)\)./, "");
333+
if (/import\("\.([^)]*)\)./g.test(line) && !/^declare type (.*) import/g.test(line)) {
334+
line = line.replace(/import\(([^)]*)\)./g, "");
324335
}
325336

326337
if (!line.includes("const enum") && !line.includes("=")) {

packages/dev/buildTools/src/packageMapping.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ const packageMapping: {
290290
// },
291291
namespace: {
292292
core: (filePath?: string) => {
293+
filePath = filePath?.replaceAll("\\", "/");
293294
if (
294295
filePath &&
295296
(filePath.includes("/Debug/axesViewer") ||
@@ -304,6 +305,7 @@ const packageMapping: {
304305
gui: "BABYLON.GUI",
305306
materials: "BABYLON",
306307
loaders: (filePath?: string) => {
308+
filePath = filePath?.replaceAll("\\", "/");
307309
if (filePath) {
308310
if (filePath.includes("/glTF/1.0")) {
309311
// was .endsWith
@@ -320,6 +322,7 @@ const packageMapping: {
320322
},
321323
serializers: "BABYLON",
322324
inspector: (filePath?: string) => {
325+
filePath = filePath?.replaceAll("\\", "/");
323326
if (filePath) {
324327
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
325328
// was .endsWith
@@ -331,6 +334,7 @@ const packageMapping: {
331334
return "INSPECTOR";
332335
},
333336
"node-editor": (filePath?: string) => {
337+
filePath = filePath?.replaceAll("\\", "/");
334338
if (filePath) {
335339
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
336340
// was .endsWith
@@ -342,6 +346,7 @@ const packageMapping: {
342346
return "BABYLON.NodeEditor";
343347
},
344348
"node-geometry-editor": (filePath?: string) => {
349+
filePath = filePath?.replaceAll("\\", "/");
345350
if (filePath) {
346351
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
347352
// was .endsWith
@@ -353,6 +358,7 @@ const packageMapping: {
353358
return "BABYLON.NodeGeometryEditor";
354359
},
355360
"node-render-graph-editor": (filePath?: string) => {
361+
filePath = filePath?.replaceAll("\\", "/");
356362
if (filePath) {
357363
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
358364
// was .endsWith
@@ -364,6 +370,7 @@ const packageMapping: {
364370
return "BABYLON.NodeRenderGraphEditor";
365371
},
366372
"node-particle-editor": (filePath?: string) => {
373+
filePath = filePath?.replaceAll("\\", "/");
367374
if (filePath) {
368375
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
369376
// was .endsWith
@@ -375,6 +382,7 @@ const packageMapping: {
375382
return "BABYLON.NodeParticleEditor";
376383
},
377384
"gui-editor": (filePath?: string) => {
385+
filePath = filePath?.replaceAll("\\", "/");
378386
if (filePath) {
379387
if (filePath.includes("shared-ui-components/") || filePath.includes("/sharedUiComponents/")) {
380388
// was .endsWith

0 commit comments

Comments
 (0)