Skip to content

Commit 1ed134e

Browse files
committed
feat(reconciler): add grid layout
1 parent 1414d92 commit 1ed134e

13 files changed

Lines changed: 936 additions & 840 deletions

File tree

CONTRIBUTING.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,18 @@ Do you have a great idea or a request for a new feature? Please use [Discussions
4848
```bash
4949
npx create-reactylon-app playground
5050
```
51-
3. Go into _tsconfig.json_ and add to the **compilerOptions** attribute:
52-
53-
```json
54-
"paths": {
55-
"*": [
56-
"node_modules/*"
57-
]
58-
},
59-
```
60-
4. Go into _webpack.config.ts_ and add to **resolve** attribute:
51+
3. Go into _webpack.config.ts_ and add to **resolve** attribute:
6152
6253
```ts
6354
modules: [path.resolve(__dirname, 'node_modules'), 'node_modules']
6455
```
65-
5. Move on move _playground_ folder and symlink the Reactylon package by executing the command:
56+
4. Move on _playground_ folder and symlink the Reactylon package by executing the command:
6657
6758
```bash
6859
cd playground && npm link reactylon
6960
```
70-
6. Start the live server by executing the command:
61+
<a id='linking'></a>
62+
5. Start the live server by executing the command:
7163
7264
```bash
7365
npm start
@@ -91,6 +83,9 @@ Do you have a great idea or a request for a new feature? Please use [Discussions
9183
9284
(*) If you make changes to _packages/common_ or _packages/generator_, run `npm run build` in the respective directory.
9385
86+
## Troubleshooting
87+
After [linking](#linking), if you are experiencing TypeScript errors on Reactylon JSX elements (e.g., ```Property 'box' does not exist on type 'JSX.IntrinsicElements'.ts(2339)```), it means that your `@types/react` version is mismatched with Reactylon's `@types/react` version. For module augmentation to work properly, both must use the same version of the library. To fix this, make sure you have the same `@types/react` version installed in both your playground project and Reactylon.
88+
9489
## Development Guidelines
9590

9691
### Git Hooks

package-lock.json

Lines changed: 354 additions & 795 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/generator/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ type JsxElementsInfo = {
4040
constructorArguments: Record<string, Array<string>>;
4141
};
4242

43+
// special elements for Grid layout (these elements are not in BabylonJS)
44+
function createJsxGridElements(jsxElements: JsxElementsInfo) {
45+
const importStatement = `import type { RowProps, ColumnProps } from '../types/props';`;
46+
const rowDeclarationStatement = `row: React.DetailedHTMLProps<RowProps, any>;`;
47+
const columnDeclarationStatement = `column: React.DetailedHTMLProps<ColumnProps, any>;`;
48+
49+
jsxElements.imports.push(importStatement);
50+
jsxElements.declarations.push(rowDeclarationStatement, columnDeclarationStatement);
51+
}
52+
4353
async function createJsxBabylonElements(index: string, babylonPackage: BabylonPackages): Promise<JsxElementsInfo> {
4454
const jsxElements: JsxElementsInfo = {
4555
imports: [],
@@ -119,6 +129,10 @@ ${props}
119129
}
120130
});
121131
//console.log('Total classes in error: ', classesInError);
132+
133+
if (babylonPackage === BabylonPackages.GUI) {
134+
createJsxGridElements(jsxElements);
135+
}
122136
return jsxElements;
123137
}
124138

@@ -142,8 +156,8 @@ const packages = {
142156
const jsxElements = await createJsxBabylonElements(index, babylonPackage);
143157
const declarationsContent = `
144158
//@ts-nocheck
145-
import { type BabylonProps, type ExcludeReadonlyAndPrivate } from '../types/types';
146-
import { type MeshProps, type GuiProps, type Clonable, type WebXRCameraProps, type TextureProps, type MaterialProps, type CameraProps } from '../types/props';
159+
import type { BabylonProps, ExcludeReadonlyAndPrivate } from '../types/types';
160+
import type { MeshProps, GuiProps, Clonable, WebXRCameraProps, TextureProps, MaterialProps, CameraProps } from '../types/props';
147161
${jsxElements.imports.join('\n')}
148162
149163
export interface JSXElements {

packages/library/setup-jest.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { jest } from '@jest/globals';
22
import * as BabylonCore from '@babylonjs/core';
3+
import * as BabylonGui from '@babylonjs/gui';
34
import { BabylonPackages, lowercaseFirstLetter } from '@dvmstudios/reactylon-common'
45
import { register } from './src/core/inventory';
56

@@ -10,18 +11,61 @@ jest.mock('react-dom/server', () => {
1011
};
1112
});
1213

14+
// Mock HTMLCanvasElement and its getContext method
15+
HTMLCanvasElement.prototype.getContext = jest.fn(() => {
16+
return {
17+
fillRect: jest.fn(),
18+
clearRect: jest.fn(),
19+
getImageData: jest.fn(),
20+
putImageData: jest.fn(),
21+
createImageData: jest.fn(),
22+
setTransform: jest.fn(),
23+
drawImage: jest.fn(),
24+
save: jest.fn(),
25+
fillText: jest.fn(),
26+
restore: jest.fn(),
27+
beginPath: jest.fn(),
28+
moveTo: jest.fn(),
29+
lineTo: jest.fn(),
30+
closePath: jest.fn(),
31+
stroke: jest.fn(),
32+
translate: jest.fn(),
33+
scale: jest.fn(),
34+
rotate: jest.fn(),
35+
arc: jest.fn(),
36+
fill: jest.fn(),
37+
measureText: jest.fn(() => ({ width: 0 })),
38+
transform: jest.fn(),
39+
rect: jest.fn(),
40+
clip: jest.fn(),
41+
}
42+
});
43+
1344
// Suppress warning React component capital letter (Babylon.js elements are JSXIntrinsicElements)
1445
const originalError = console.error.bind(console.error);
1546

1647
beforeAll(() => {
1748
// Populate inventory with all Babylon.js core elements
1849
const coreElements = Object.entries(BabylonCore).reduce((obj, [key, value]) => {
19-
const type = key.replace('Create', ''); // MeshBuilder case
20-
obj[lowercaseFirstLetter(type)] = [value, BabylonPackages.CORE];
50+
const type = lowercaseFirstLetter(key.replace('Create', '')); // MeshBuilder case
51+
if (!obj[type]) {
52+
obj[type] = [value, BabylonPackages.CORE];
53+
}
54+
return obj;
55+
}, {});
56+
57+
// Populate inventory with all Babylon.js GUI elements
58+
const guiElements = Object.entries(BabylonGui).reduce((obj, [key, value]) => {
59+
const type = lowercaseFirstLetter(key);
60+
if (!obj[type]) {
61+
obj[type] = [value, BabylonPackages.GUI];
62+
}
2163
return obj;
2264
}, {});
2365

2466
register(coreElements);
67+
register(guiElements);
68+
2569
console.error = (msg, ...rest) => !msg.toString().includes('If you meant to render a React component, start its name with an uppercase letter.') && originalError(msg, ...rest);
2670
});
2771

packages/library/src/_generated/babylon.core.constructors.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ const ConstructorsMap: Record<string, Array<string>> = {
8080
baseParticleSystem: ["name"],
8181
baseSixDofDragBehavior: [],
8282
baseTexture: ["sceneOrEngine","internalTexture"],
83+
basicPositionUpdateBlock: ["name"],
84+
basicSpriteUpdateBlock: ["name"],
8385
bezierCurveEase: ["x1","y1","x2","y2"],
8486
biPlanarBlock: ["name"],
8587
binaryFileAssetTask: ["name","url"],
@@ -115,6 +117,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
115117
boundingSphere: ["min","max","worldMatrix"],
116118
boxBlock: ["name"],
117119
boxParticleEmitter: [],
120+
boxShapeBlock: ["name"],
118121
buffer: ["engine","data","updatable","stride","postponeInternalCreation","instanced","useBytes","divisor","label"],
119122
cSG: [],
120123
cSG2: ["manifold","numProp","vertexStructure"],
@@ -202,6 +205,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
202205
lines: ["name","options","scene"],
203206
mainAudioBusAsync: ["name","options","engine"],
204207
microphoneSoundSourceAsync: ["name","options","engine"],
208+
createParticleBlock: ["name"],
205209
pickingRay: ["scene","x","y","world","camera","cameraViewSpace"],
206210
pickingRayInCameraSpace: ["scene","x","y","camera"],
207211
pickingRayInCameraSpaceToRef: ["scene","x","y","result","camera"],
@@ -250,9 +254,11 @@ const ConstructorsMap: Record<string, Array<string>> = {
250254
customBlock: ["name"],
251255
customParticleEmitter: [],
252256
customProceduralTexture: ["name","texturePath","size","scene","fallbackTexture","generateMipMaps","skipJson"],
257+
customShapeBlock: ["name"],
253258
cylinderBlock: ["name"],
254259
cylinderDirectedParticleEmitter: ["radius","height","radiusRange","direction1","direction2"],
255260
cylinderParticleEmitter: ["radius","height","radiusRange","directionRandomizer"],
261+
cylinderShapeBlock: ["name"],
256262
dataBuffer: [],
257263
dataReader: ["buffer"],
258264
database: ["urlToScene","callbackManifestChecked","disableManifestCheck"],
@@ -344,12 +350,14 @@ const ConstructorsMap: Record<string, Array<string>> = {
344350
flowGraphAcosBlock: ["config"],
345351
flowGraphAcoshBlock: ["config"],
346352
flowGraphAddBlock: ["config"],
353+
flowGraphAngleBetweenBlock: ["config"],
347354
flowGraphArrayIndexBlock: ["config"],
348355
flowGraphAsinBlock: ["config"],
349356
flowGraphAsinhBlock: ["config"],
350357
flowGraphAtan2Block: ["config"],
351358
flowGraphAtanBlock: ["config"],
352359
flowGraphAtanhBlock: ["config"],
360+
flowGraphAxisAngleFromQuaternionBlock: ["config"],
353361
flowGraphBezierCurveEasingBlock: ["config"],
354362
flowGraphBitwiseAndBlock: ["config"],
355363
flowGraphBitwiseLeftShiftBlock: ["config"],
@@ -373,6 +381,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
373381
flowGraphCombineVector3Block: ["config"],
374382
flowGraphCombineVector4Block: ["config"],
375383
flowGraphConditionalDataBlock: ["config"],
384+
flowGraphConjugateBlock: ["config"],
376385
flowGraphConnection: ["name","_connectionType","_ownerBlock"],
377386
flowGraphConsoleLogBlock: ["config"],
378387
flowGraphConstantBlock: ["config"],
@@ -457,6 +466,8 @@ const ConstructorsMap: Record<string, Array<string>> = {
457466
flowGraphPointerOutEventBlock: ["config"],
458467
flowGraphPointerOverEventBlock: ["config"],
459468
flowGraphPowerBlock: ["config"],
469+
flowGraphQuaternionFromAxisAngleBlock: ["config"],
470+
flowGraphQuaternionFromDirectionsBlock: ["config"],
460471
flowGraphRadToDegBlock: ["config"],
461472
flowGraphRandomBlock: ["config"],
462473
flowGraphReceiveCustomEventBlock: ["config"],
@@ -516,10 +527,11 @@ const ConstructorsMap: Record<string, Array<string>> = {
516527
frameGraphBlackAndWhiteTask: ["name","frameGraph","thinPostProcess"],
517528
frameGraphBloomTask: ["name","frameGraph","weight","kernel","threshold","hdr","bloomScale"],
518529
frameGraphBlurTask: ["name","frameGraph","thinPostProcess"],
519-
frameGraphCascadedShadowGeneratorTask: [],
530+
frameGraphCascadedShadowGeneratorTask: ["name","frameGraph","scene"],
520531
frameGraphChromaticAberrationTask: ["name","frameGraph","thinPostProcess"],
521532
frameGraphCircleOfConfusionTask: ["name","frameGraph","thinPostProcess"],
522533
frameGraphClearTextureTask: ["name","frameGraph"],
534+
frameGraphContext: ["_engine","_textureManager","_scene"],
523535
frameGraphCopyToTextureTask: ["name","frameGraph"],
524536
frameGraphCullObjectsTask: ["name","frameGraph","scene"],
525537
frameGraphCullPass: ["name","parentTask","context","engine"],
@@ -539,11 +551,11 @@ const ConstructorsMap: Record<string, Array<string>> = {
539551
frameGraphPassCubeTask: ["name","frameGraph","thinPostProcess"],
540552
frameGraphPassTask: ["name","frameGraph","thinPostProcess"],
541553
frameGraphPostProcessTask: ["name","frameGraph","postProcess"],
542-
frameGraphRenderContext: ["_engine","_textureManager","_scene"],
554+
frameGraphRenderContext: ["engine","textureManager","scene"],
543555
frameGraphRenderPass: ["name","parentTask","context","engine"],
544556
frameGraphRenderTarget: ["name","textureManager","renderTargets","renderTargetDepth"],
545557
frameGraphSSRRenderingPipelineTask: ["name","frameGraph","textureType"],
546-
frameGraphShadowGeneratorTask: ["name","frameGraph","scene"],
558+
frameGraphShadowGeneratorTask: ["name","frameGraph","_scene"],
547559
frameGraphTAAObjectRendererTask: ["name","frameGraph","scene","options"],
548560
frameGraphTask: ["name","frameGraph"],
549561
frameGraphTextureManager: ["engine","_debugTextures","_scene"],
@@ -611,6 +623,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
611623
geometryTextureFetchBlock: ["name"],
612624
geometryTransformBlock: ["name"],
613625
geometryTrigonometryBlock: ["name"],
626+
getAngleBetweenQuaternions: ["q1","q2"],
614627
getClass: ["fqdn"],
615628
getClassName: ["obj"],
616629
getDOMTextContent: ["element"],
@@ -631,6 +644,8 @@ const ConstructorsMap: Record<string, Array<string>> = {
631644
getMimeType: [],
632645
getParser: ["name"],
633646
getPointsCount: ["allPoints"],
647+
getQuaternionFromDirections: ["a","b"],
648+
getQuaternionFromDirectionsToRef: ["a","b","result"],
634649
getRegisteredSceneLoaderPluginMetadata: [],
635650
getSignalInConnectionByUniqueId: ["blocks","uniqueId"],
636651
getTGAHeader: ["data"],
@@ -817,6 +832,10 @@ const ConstructorsMap: Record<string, Array<string>> = {
817832
nodeMaterialDefines: [],
818833
nodeMaterialTeleportInBlock: ["name"],
819834
nodeMaterialTeleportOutBlock: ["name"],
835+
nodeParticleBlock: ["name"],
836+
nodeParticleBuildState: [],
837+
nodeParticleConnectionPoint: ["name","ownerBlock","direction"],
838+
nodeParticleSystemSet: ["name"],
820839
nodeRenderGraph: ["name","scene","options"],
821840
nodeRenderGraphAnaglyphPostProcessBlock: ["name","frameGraph","scene"],
822841
nodeRenderGraphBlackAndWhitePostProcessBlock: ["name","frameGraph","scene"],
@@ -910,10 +929,25 @@ const ConstructorsMap: Record<string, Array<string>> = {
910929
parseValue: ["dataView","offset","type","size"],
911930
particle: ["particleSystem"],
912931
particleBlendMultiplyBlock: ["name"],
932+
particleConditionBlock: ["name"],
933+
particleConverterBlock: ["name"],
934+
particleDebugBlock: ["name"],
935+
particleElbowBlock: ["name"],
936+
particleGradientBlock: ["name"],
937+
particleGradientValueBlock: ["name"],
938+
particleInputBlock: ["name","type"],
939+
particleLerpBlock: ["name"],
940+
particleMathBlock: ["name"],
913941
particleRampGradientBlock: ["name"],
942+
particleRandomBlock: ["name"],
914943
particleSystem: [],
915944
particleSystemSet: [],
945+
particleTeleportInBlock: ["name"],
946+
particleTeleportOutBlock: ["name"],
916947
particleTextureBlock: ["name"],
948+
particleTextureSourceBlock: ["name"],
949+
particleTriggerBlock: ["name"],
950+
particleTrigonometryBlock: ["name"],
917951
passCubePostProcess: ["name","options","camera","samplingMode","engine","reusable","textureType","blockCompilation"],
918952
passPostProcess: ["name","options","camera","samplingMode","engine","reusable","textureType","blockCompilation"],
919953
path2: ["x","y"],
@@ -960,6 +994,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
960994
pointLight: ["name","position","scene"],
961995
pointListBlock: ["name"],
962996
pointParticleEmitter: [],
997+
pointShapeBlock: ["name"],
963998
pointerDragBehavior: ["options"],
964999
pointerInfo: ["type","event","pickInfo","inputManager"],
9651000
pointerInfoBase: ["type","event"],
@@ -1025,12 +1060,14 @@ const ConstructorsMap: Record<string, Array<string>> = {
10251060
randomBlock: ["name"],
10261061
randomGUID: [],
10271062
randomNumberBlock: ["name"],
1063+
randomRangeBlock: ["name"],
10281064
rawCubeTexture: ["scene","data","size","format","type","generateMipMaps","invertY","samplingMode","compression"],
10291065
rawTexture: ["data","width","height","format","sceneOrEngine","generateMipMaps","invertY","samplingMode","type","creationFlags","useSRGBBuffer","waitDataToBeReady"],
10301066
rawTexture2DArray: ["data","width","height","depth","format","scene","generateMipMaps","invertY","samplingMode","textureType","creationFlags"],
10311067
rawTexture3D: ["data","width","height","depth","format","scene","generateMipMaps","invertY","samplingMode","textureType","creationFlags"],
10321068
ray: ["origin","direction","length","epsilon"],
10331069
rayHelper: ["ray"],
1070+
readExrDataAsync: ["data"],
10341071
readFile: [],
10351072
readFileError: ["message","file"],
10361073
recastJSCrowd: ["plugin","maxAgents","maxAgentRadius","scene"],
@@ -1107,6 +1144,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
11071144
setToDefaultSFE: ["nodeMaterial"],
11081145
setUVsBlock: ["name"],
11091146
setValueAction: ["triggerOptions","target","propertyPath","value","condition"],
1147+
setupSpriteSheetBlock: ["name"],
11101148
shaderCodeInliner: ["sourceCode","numMaxIterations"],
11111149
shaderMaterial: ["name","scene","shaderPath","options","storeEffectOnSubMeshes"],
11121150
shadowDepthWrapper: ["baseMaterial","scene","options"],
@@ -1128,6 +1166,8 @@ const ConstructorsMap: Record<string, Array<string>> = {
11281166
sliderConstraint: ["pivotA","pivotB","axisA","axisB","scene"],
11291167
smartArray: ["capacity"],
11301168
smartArrayNoDuplicate: [],
1169+
smartFilterFragmentOutputBlock: ["name"],
1170+
smartFilterTextureBlock: ["name"],
11311171
smoothStepBlock: ["name"],
11321172
snapshotRenderingHelper: ["scene","options"],
11331173
solidParticle: ["particleIndex","particleId","positionIndex","indiceIndex","model","shapeId","idxInShape","sps","modelBoundingInfo","materialIndex"],
@@ -1139,6 +1179,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
11391179
sphereBlock: ["name"],
11401180
sphereDirectedParticleEmitter: ["radius","direction1","direction2"],
11411181
sphereParticleEmitter: ["radius","radiusRange","directionRandomizer"],
1182+
sphereShapeBlock: ["name"],
11421183
spherical: ["radius","theta","phi"],
11431184
sphericalHarmonics: [],
11441185
sphericalPolynomial: [],
@@ -1185,6 +1226,7 @@ const ConstructorsMap: Record<string, Array<string>> = {
11851226
subtractBlock: ["name"],
11861227
surfaceMagnetismBehavior: [],
11871228
switchBooleanAction: ["triggerOptions","target","propertyPath","condition"],
1229+
systemBlock: ["name"],
11881230
tAARenderingPipeline: ["name","scene","cameras","textureType"],
11891231
tBNBlock: ["name"],
11901232
targetCamera: ["name","position","scene","setActiveOnSceneIfNoneActive"],
@@ -1246,10 +1288,17 @@ const ConstructorsMap: Record<string, Array<string>> = {
12461288
universalCamera: ["name","position","scene"],
12471289
unregisterAllMaterialPlugins: [],
12481290
unregisterMaterialPlugin: ["pluginName"],
1291+
updateAngleBlock: ["name"],
1292+
updateColorBlock: ["name"],
1293+
updateDirectionBlock: ["name"],
1294+
updateFlowMapBlock: ["name"],
1295+
updatePositionBlock: ["name"],
1296+
updateScaleBlock: ["name"],
1297+
updateSpriteCellIndexBlock: ["name"],
12491298
uploadContent: ["texture","data"],
12501299
uploadEnvLevelsAsync: ["texture","data","info"],
12511300
uploadEnvSpherical: ["texture","info"],
1252-
uploadIrradianceLevelsAsync: ["mainTexture","imageData","size","imageType"],
1301+
uploadIrradianceLevelsAsync: ["mainTexture","imageData","size","imageType","dominantDirection"],
12531302
uploadRadianceLevelsAsync: ["texture","imageData","imageType"],
12541303
utilityLayerRenderer: ["originalScene","handleEvents","manualRender"],
12551304
vRCameraMetrics: [],

0 commit comments

Comments
 (0)