Skip to content

The open alternative to Salesforce, designed for AI.

[Onboarding 9/10] Add 3D background (#26784)

Thomas des Francsdca6b57ff995
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSite.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSite.tsx
new file mode 100644
index 00000000000..1b9fcbfbd20
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSite.tsx
@@ -0,0 +1,88 @@
+import { styled } from '@linaria/react';
+import { useRef } from 'react';
+
+import { currentUserState } from '@/auth/states/currentUserState';
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadedState';
+import { billingState } from '@/client-config/states/billingState';
+import { clientConfigApiStatusState } from '@/client-config/states/clientConfigApiStatusState';
+import { isBookCallOnboardingStepEnabledState } from '@/client-config/states/isBookCallOnboardingStepEnabledState';
+import { OnboardingConstructionSiteCanvasEffect } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteCanvasEffect';
+import { getOnboardingConstructionSiteStage } from '@/onboarding/components/OnboardingConstructionSite/getOnboardingConstructionSiteStage';
+import { getIsBookCallRequired } from '@/onboarding/utils/getIsBookCallRequired';
+import { getIsLastOnboardingStep } from '@/onboarding/utils/getIsLastOnboardingStep';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { themeCssVariables, useThemeColorScheme } from 'twenty-ui/theme';
+import { useMediaQuery } from 'twenty-ui/utilities';
+
+const StyledCanvas = styled.canvas`
+ animation: onboardingConstructionSiteIn 0.8s ease-out both;
+ color: color-mix(
+ in srgb,
+ ${themeCssVariables.border.color.medium} 50%,
+ ${themeCssVariables.border.color.strong} 50%
+ );
+ display: block;
+ height: 100%;
+ width: 100%;
+
+ @keyframes onboardingConstructionSiteIn {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ animation: none;
+ }
+`;
+
+export const OnboardingConstructionSite = () => {
+ const canvasRef = useRef<HTMLCanvasElement>(null);
+ const currentUser = useAtomStateValue(currentUserState);
+ const currentWorkspace = useAtomStateValue(currentWorkspaceState);
+ const billing = useAtomStateValue(billingState);
+ const isClientConfigLoaded = useAtomStateValue(
+ clientConfigApiStatusState,
+ ).isLoadedOnce;
+ const isCurrentUserLoaded = useAtomStateValue(isCurrentUserLoadedState);
+ const isBookCallOnboardingStepEnabled = useAtomStateValue(
+ isBookCallOnboardingStepEnabledState,
+ );
+ const colorScheme = useThemeColorScheme();
+ const prefersReducedMotion = useMediaQuery(
+ '(prefers-reduced-motion: reduce)',
+ );
+
+ if (!isClientConfigLoaded || !isCurrentUserLoaded) {
+ return null;
+ }
+
+ const { stageIndex } = getOnboardingConstructionSiteStage({
+ onboardingStatus: currentUser?.onboardingStatus,
+ isLastOnboardingStep: getIsLastOnboardingStep({
+ currentUser,
+ currentWorkspace,
+ isBillingEnabled: billing?.isBillingEnabled ?? false,
+ isBookCallRequired: getIsBookCallRequired({
+ isBookCallOnboardingStepEnabled,
+ currentUser,
+ }),
+ }),
+ });
+
+ return (
+ <>
+ <StyledCanvas ref={canvasRef} aria-hidden="true" />
+ <OnboardingConstructionSiteCanvasEffect
+ canvasRef={canvasRef}
+ stageIndex={stageIndex}
+ colorScheme={colorScheme}
+ prefersReducedMotion={prefersReducedMotion}
+ />
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteCanvasEffect.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteCanvasEffect.tsx
new file mode 100644
index 00000000000..8a492b6f61c
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteCanvasEffect.tsx
@@ -0,0 +1,95 @@
+import { type RefObject, useEffect, useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import {
+ createOnboardingConstructionSiteRenderer,
+ type OnboardingConstructionSiteColors,
+ type OnboardingConstructionSiteRenderer,
+} from '@/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteRenderer';
+import { ONBOARDING_CONSTRUCTION_SITE_DEFAULT_SETTINGS } from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteDefaultSettings';
+import { ONBOARDING_CONTENT_BLOCK_WIDTH } from '@/onboarding/constants/OnboardingContentBlockWidth';
+
+const readColorChannels = (cssColor: string) => {
+ const probeCanvas = document.createElement('canvas');
+ probeCanvas.width = 1;
+ probeCanvas.height = 1;
+ const probeContext = probeCanvas.getContext('2d');
+ if (!isDefined(probeContext)) {
+ return null;
+ }
+ probeContext.fillStyle = cssColor;
+ probeContext.fillRect(0, 0, 1, 1);
+ const [red, green, blue] = probeContext.getImageData(0, 0, 1, 1).data;
+ return [red / 255, green / 255, blue / 255] as const;
+};
+
+const readCanvasColors = (
+ canvas: HTMLCanvasElement,
+): OnboardingConstructionSiteColors | null => {
+ const dashColor = readColorChannels(getComputedStyle(canvas).color);
+ return isDefined(dashColor) ? { dashColor } : null;
+};
+
+type OnboardingConstructionSiteCanvasEffectProps = {
+ canvasRef: RefObject<HTMLCanvasElement | null>;
+ stageIndex: number;
+ colorScheme: 'light' | 'dark';
+ prefersReducedMotion: boolean;
+};
+
+export const OnboardingConstructionSiteCanvasEffect = ({
+ canvasRef,
+ stageIndex,
+ colorScheme,
+ prefersReducedMotion,
+}: OnboardingConstructionSiteCanvasEffectProps) => {
+ const [renderer, setRenderer] =
+ useState<OnboardingConstructionSiteRenderer | null>(null);
+
+ useEffect(() => {
+ const canvas = canvasRef.current;
+ if (!isDefined(canvas) || typeof WebGL2RenderingContext === 'undefined') {
+ return;
+ }
+
+ const colors = readCanvasColors(canvas);
+ if (!isDefined(colors)) {
+ return;
+ }
+
+ const activeRenderer = createOnboardingConstructionSiteRenderer({
+ canvas,
+ colors,
+ settings: ONBOARDING_CONSTRUCTION_SITE_DEFAULT_SETTINGS,
+ contentColumnWidth: ONBOARDING_CONTENT_BLOCK_WIDTH,
+ prefersReducedMotion,
+ });
+ if (!isDefined(activeRenderer)) {
+ return;
+ }
+
+ const resizeObserver = new ResizeObserver(() => activeRenderer.resize());
+ resizeObserver.observe(canvas);
+ setRenderer(activeRenderer);
+
+ return () => {
+ resizeObserver.disconnect();
+ activeRenderer.destroy();
+ setRenderer(null);
+ };
+ }, [canvasRef, prefersReducedMotion]);
+
+ useEffect(() => {
+ renderer?.setStage({ stageIndex });
+ }, [renderer, stageIndex]);
+
+ useEffect(() => {
+ const canvas = canvasRef.current;
+ const colors = isDefined(canvas) ? readCanvasColors(canvas) : null;
+ if (isDefined(colors)) {
+ renderer?.setColors(colors);
+ }
+ }, [canvasRef, renderer, colorScheme]);
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction.ts
new file mode 100644
index 00000000000..082a0cb7b07
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction.ts
@@ -0,0 +1,4 @@
+export type OnboardingConstructionSiteConstruction = {
+ builtStageIndex: number;
+ growingStageGrowths: number[];
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances.ts
new file mode 100644
index 00000000000..f457986e025
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances.ts
@@ -0,0 +1,15 @@
+export type OnboardingConstructionSiteMeshName =
+ | 'cube'
+ | 'cylinder'
+ | 'cone'
+ | 'mixerDrum';
+
+export type OnboardingConstructionSiteInstanceBatch = {
+ data: Float32Array;
+ count: number;
+};
+
+export type OnboardingConstructionSiteInstances = Record<
+ OnboardingConstructionSiteMeshName,
+ OnboardingConstructionSiteInstanceBatch
+>;
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteSettings.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteSettings.ts
new file mode 100644
index 00000000000..811bdc73aab
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteSettings.ts
@@ -0,0 +1,17 @@
+export type OnboardingConstructionSiteSettings = {
+ dashPitch: number;
+ dashWidth: number;
+ dashScale: number;
+ dashThreshold: number;
+ dashOpacity: number;
+ halftonePower: number;
+ contentColumnOpacity: number;
+ keyLightAngleDegrees: number;
+ keyLightHeight: number;
+ keyLightIntensity: number;
+ fillLightIntensity: number;
+ ambientIntensity: number;
+ environmentIntensity: number;
+ materialRoughness: number;
+ materialMetalness: number;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteStage.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteStage.ts
new file mode 100644
index 00000000000..d81281bdd8e
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteStage.ts
@@ -0,0 +1,3 @@
+export type OnboardingConstructionSiteStage = {
+ stageIndex: number;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/buildOnboardingConstructionSiteScene.test.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/buildOnboardingConstructionSiteScene.test.ts
new file mode 100644
index 00000000000..dc42b36738d
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/buildOnboardingConstructionSiteScene.test.ts
@@ -0,0 +1,258 @@
+import {
+ buildOnboardingConstructionSiteScene,
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+} from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import { type OnboardingConstructionSiteConstruction } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction';
+import { type OnboardingConstructionSiteInstances } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances';
+
+const LAYOUT = {
+ halfWidth: 5.5,
+ halfHeight: 3.44,
+ contentHalfWidth: 2.2,
+ groundY: -3.44,
+};
+
+const createBatch = (capacity: number) => ({
+ data: new Float32Array(
+ capacity * ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+ ),
+ count: 0,
+});
+
+const createInstances = (
+ cubeCapacity = 1024,
+): OnboardingConstructionSiteInstances => ({
+ cube: createBatch(cubeCapacity),
+ cylinder: createBatch(256),
+ cone: createBatch(16),
+ mixerDrum: createBatch(4),
+});
+
+const buildScene = (
+ construction: OnboardingConstructionSiteConstruction,
+ cubeCapacity?: number,
+ craneMotion = 0,
+) => {
+ const instances = createInstances(cubeCapacity);
+ buildOnboardingConstructionSiteScene({
+ instances,
+ layout: LAYOUT,
+ construction,
+ craneMotion,
+ });
+ return instances;
+};
+
+const buildSettledScene = (stageIndex: number, cubeCapacity?: number) =>
+ buildScene(
+ { builtStageIndex: stageIndex, growingStageGrowths: [] },
+ cubeCapacity,
+ );
+
+const getTotalCount = (instances: OnboardingConstructionSiteInstances) =>
+ Object.values(instances).reduce((total, batch) => total + batch.count, 0);
+
+const getInstanceMatrices = (
+ batch: OnboardingConstructionSiteInstances['cube'],
+) =>
+ Array.from({ length: batch.count }, (_, index) => {
+ const offset = index * ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE;
+ return batch.data.slice(
+ offset,
+ offset + ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+ );
+ });
+
+const getSuspendedLoads = ({ cube }: OnboardingConstructionSiteInstances) =>
+ getInstanceMatrices(cube).filter(
+ (instance) => Math.abs(instance[16] - 0.8) < 0.001,
+ );
+
+describe('buildOnboardingConstructionSiteScene', () => {
+ it('should add more of the site with every stage', () => {
+ const counts = [
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ ]
+ .map((stageIndex) => buildSettledScene(stageIndex))
+ .map(getTotalCount);
+
+ expect(counts[0]).toBeGreaterThan(0);
+ counts.slice(1).forEach((count, index) => {
+ expect(count).toBeGreaterThan(counts[index]);
+ });
+ });
+
+ it('should start with only the static site details', () => {
+ const emptySiteCount = getTotalCount(buildSettledScene(-1));
+
+ expect(emptySiteCount).toBeGreaterThan(1);
+ expect(getTotalCount(buildSettledScene(0))).toBeGreaterThan(emptySiteCount);
+ });
+
+ it('should grow a transition in from the ground up', () => {
+ const settledCount = getTotalCount(buildSettledScene(1));
+ const growingCount = getTotalCount(
+ buildScene({ builtStageIndex: 1, growingStageGrowths: [0.2] }),
+ );
+ const nextSettledCount = getTotalCount(buildSettledScene(2));
+
+ expect(growingCount).toBeGreaterThan(settledCount);
+ expect(growingCount).toBeLessThan(nextSettledCount);
+ });
+
+ it('should land on the same site at either end of a transition', () => {
+ const buildTransitionFromThirdToLastStage = (growth: number) =>
+ buildScene({
+ builtStageIndex: 3,
+ growingStageGrowths: [growth, growth],
+ });
+
+ expect(getTotalCount(buildTransitionFromThirdToLastStage(0))).toBe(
+ getTotalCount(buildSettledScene(3)),
+ );
+ expect(getTotalCount(buildTransitionFromThirdToLastStage(1))).toBe(
+ getTotalCount(
+ buildSettledScene(ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX),
+ ),
+ );
+ });
+
+ it('should only top out the tower for the finale', () => {
+ const coneCountBeforeFinale = buildSettledScene(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX - 1,
+ ).cone.count;
+ const coneCountAtFinale = buildSettledScene(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ ).cone.count;
+
+ expect(coneCountAtFinale).toBeGreaterThan(coneCountBeforeFinale);
+ });
+
+ it('should park the mixer facing left from before the first step', () => {
+ const parked = buildSettledScene(0).mixerDrum.data;
+
+ expect(parked[12]).toBeLessThan(LAYOUT.halfWidth);
+ expect(parked[4]).toBeLessThan(0);
+ expect(buildSettledScene(-1).mixerDrum.data).toEqual(parked);
+ });
+
+ it('should turn the mixer around before driving back off the right edge', () => {
+ const turning = buildScene({
+ builtStageIndex: 0,
+ growingStageGrowths: [0.325],
+ }).mixerDrum.data;
+ const turned = buildScene({
+ builtStageIndex: 0,
+ growingStageGrowths: [0.55],
+ }).mixerDrum.data;
+ const exited = buildSettledScene(1).mixerDrum.data;
+
+ expect(turning[4]).toBeCloseTo(0);
+ expect(turning[6]).toBeGreaterThan(0);
+ expect(turned[4]).toBeGreaterThan(0);
+ expect(turned[12]).toBeLessThan(LAYOUT.halfWidth);
+ expect(exited[12]).toBeGreaterThan(LAYOUT.halfWidth);
+ expect(buildSettledScene(2).mixerDrum.data).toEqual(exited);
+ });
+
+ it('should accelerate toward the edge after completing the truck turn', () => {
+ const positions = [0.55, 0.7, 0.85, 1].map(
+ (growth) =>
+ buildScene({ builtStageIndex: 0, growingStageGrowths: [growth] })
+ .mixerDrum.data[12],
+ );
+ const distances = positions
+ .slice(1)
+ .map((position, index) => position - positions[index]);
+ expect(distances[1]).toBeGreaterThan(distances[0]);
+ expect(distances[2]).toBeGreaterThan(distances[1]);
+ });
+
+ it('should lower crane loads vertically over their buildings without swinging', () => {
+ const construction = {
+ builtStageIndex: 2,
+ growingStageGrowths: [0.25],
+ };
+ const raised = getSuspendedLoads(buildScene(construction));
+ const lowered = getSuspendedLoads(buildScene(construction, undefined, 1));
+
+ expect(raised).toHaveLength(2);
+ expect(lowered).toHaveLength(2);
+ lowered.forEach((load, index) => {
+ expect(load.slice(0, 12)).toEqual(raised[index].slice(0, 12));
+ expect(load[12]).toBe(raised[index][12]);
+ expect(load[14]).toBe(raised[index][14]);
+ expect(load[13]).toBeLessThan(raised[index][13]);
+ });
+ });
+
+ it('should release delivered loads and leave the hooks empty between steps', () => {
+ expect(
+ getSuspendedLoads(
+ buildScene({ builtStageIndex: 2, growingStageGrowths: [0.75] }),
+ ),
+ ).toHaveLength(0);
+ expect(getSuspendedLoads(buildSettledScene(3))).toHaveLength(0);
+ });
+
+ it('should land the load on the highest visible round floor during growth', () => {
+ const scene = buildScene(
+ { builtStageIndex: 2, growingStageGrowths: [0.25] },
+ undefined,
+ 1,
+ );
+ const load = getSuspendedLoads(scene)[0];
+ const floorTops = getInstanceMatrices(scene.cylinder)
+ .filter(
+ (instance) =>
+ instance[16] === 1 &&
+ Math.abs(instance[12] - load[12]) < instance[0] / 2,
+ )
+ .map((instance) => instance[13] + instance[5] / 2);
+
+ expect(floorTops.length).toBeGreaterThan(0);
+ expect(load[13] - load[5] / 2).toBeCloseTo(Math.max(...floorTops));
+ });
+
+ it('should fit the renderer instance buffers', () => {
+ const instances = buildSettledScene(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ );
+
+ expect(instances.cube.count).toBeLessThan(1024);
+ expect(instances.cylinder.count).toBeLessThan(256);
+ expect(instances.cone.count).toBeLessThan(16);
+ expect(instances.mixerDrum.count).toBeLessThan(4);
+ });
+
+ it('should never write past the instance buffers', () => {
+ const instances = buildSettledScene(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ 8,
+ );
+
+ expect(instances.cube.count).toBe(8);
+ });
+
+ it('should leave the scene empty when the buildings would reach the content', () => {
+ const instances = createInstances();
+
+ buildOnboardingConstructionSiteScene({
+ instances,
+ layout: { ...LAYOUT, halfWidth: 4 },
+ construction: {
+ builtStageIndex: ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ growingStageGrowths: [],
+ },
+ craneMotion: 0,
+ });
+
+ expect(getTotalCount(instances)).toBe(0);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/createOnboardingConstructionSiteTimeline.test.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/createOnboardingConstructionSiteTimeline.test.ts
new file mode 100644
index 00000000000..84d9e910e7a
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/createOnboardingConstructionSiteTimeline.test.ts
@@ -0,0 +1,187 @@
+import { ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX } from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import {
+ createOnboardingConstructionSiteTimeline,
+ type OnboardingConstructionSiteTimeline,
+} from '@/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteTimeline';
+
+const FRAME_SECONDS = 1 / 60;
+
+const advanceBySeconds = (
+ timeline: OnboardingConstructionSiteTimeline,
+ seconds: number,
+) => {
+ for (let elapsed = 0; elapsed < seconds; elapsed += FRAME_SECONDS) {
+ timeline.advance(FRAME_SECONDS);
+ }
+};
+
+const createSettledTimeline = (stageIndex: number) => {
+ const timeline = createOnboardingConstructionSiteTimeline();
+ timeline.jumpToStageIndex(stageIndex);
+ return timeline;
+};
+
+describe('createOnboardingConstructionSiteTimeline', () => {
+ it('should support a longer linear truck transition without changing building timing', () => {
+ const buildings = createSettledTimeline(0);
+ const truck = createOnboardingConstructionSiteTimeline({
+ transitionSecondsPerStep: 2.2,
+ easing: (ratio) => ratio,
+ });
+ truck.jumpToStageIndex(0);
+ buildings.setTargetStageIndex(1);
+ truck.setTargetStageIndex(1);
+ buildings.advance(1.6);
+ truck.advance(1.6);
+
+ expect(buildings.isTransitioning()).toBe(false);
+ expect(truck.isTransitioning()).toBe(true);
+ expect(truck.getConstruction().growingStageGrowths[0]).toBeCloseTo(
+ 1.6 / 2.2,
+ );
+ truck.advance(0.61);
+ expect(truck.isTransitioning()).toBe(false);
+ expect(truck.getConstruction().builtStageIndex).toBe(1);
+ });
+
+ it('should build the site from empty up to the first step, then rest', () => {
+ const timeline = createOnboardingConstructionSiteTimeline();
+
+ timeline.setTargetStageIndex(2);
+
+ expect(timeline.getConstruction()).toEqual({
+ builtStageIndex: -1,
+ growingStageGrowths: [0, 0, 0],
+ });
+
+ advanceBySeconds(timeline, 10);
+
+ expect(timeline.isTransitioning()).toBe(false);
+ expect(timeline.getConstruction()).toEqual({
+ builtStageIndex: 2,
+ growingStageGrowths: [],
+ });
+ });
+
+ it('should grow a jump over several steps in a single sweep', () => {
+ const timeline = createSettledTimeline(3);
+ const growths: number[] = [];
+
+ timeline.setTargetStageIndex(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ );
+ while (timeline.isTransitioning()) {
+ const { builtStageIndex, growingStageGrowths } =
+ timeline.getConstruction();
+
+ expect(builtStageIndex).toBe(3);
+ expect(growingStageGrowths).toHaveLength(2);
+ expect(growingStageGrowths[1]).toBe(growingStageGrowths[0]);
+ growths.push(growingStageGrowths[0]);
+ timeline.advance(FRAME_SECONDS);
+ }
+
+ growths.slice(1).forEach((growth, index) => {
+ expect(growth).toBeGreaterThanOrEqual(growths[index]);
+ });
+ expect(timeline.getConstruction().builtStageIndex).toBe(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ );
+ });
+
+ it('should settle the motion, light and shimmer as the transition lands', () => {
+ const timeline = createSettledTimeline(3);
+
+ timeline.setTargetStageIndex(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ );
+ advanceBySeconds(timeline, 1);
+
+ expect(timeline.getMotion()).toBeGreaterThan(0);
+ expect(timeline.getFinaleBump()).toBeGreaterThan(0);
+
+ advanceBySeconds(timeline, 10);
+
+ expect(timeline.isTransitioning()).toBe(false);
+ expect(timeline.getMotion()).toBe(0);
+ expect(timeline.getFinaleBump()).toBe(0);
+ });
+
+ it('should keep the light still on steps before the last one', () => {
+ const timeline = createSettledTimeline(2);
+
+ timeline.setTargetStageIndex(3);
+ advanceBySeconds(timeline, 0.8);
+
+ expect(timeline.getFinaleBump()).toBe(0);
+ });
+
+ it('should reverse from what is on screen when going back mid-transition', () => {
+ const timeline = createSettledTimeline(3);
+
+ timeline.setTargetStageIndex(4);
+ advanceBySeconds(timeline, 0.8);
+ const [growthWhenGoingBack] =
+ timeline.getConstruction().growingStageGrowths;
+ timeline.setTargetStageIndex(3);
+ timeline.advance(FRAME_SECONDS);
+ const [growthAfterGoingBack] =
+ timeline.getConstruction().growingStageGrowths;
+
+ expect(growthAfterGoingBack).toBeLessThan(growthWhenGoingBack);
+ expect(growthAfterGoingBack).toBeGreaterThan(growthWhenGoingBack - 0.05);
+
+ advanceBySeconds(timeline, 10);
+
+ expect(timeline.getConstruction()).toEqual({
+ builtStageIndex: 3,
+ growingStageGrowths: [],
+ });
+ });
+
+ it('should fold a step that skips itself into the running transition', () => {
+ const timeline = createSettledTimeline(0);
+
+ timeline.setTargetStageIndex(1);
+ advanceBySeconds(timeline, 0.4);
+ const [firstStepGrowthWhenJoined] =
+ timeline.getConstruction().growingStageGrowths;
+ timeline.setTargetStageIndex(2);
+
+ expect(timeline.getConstruction()).toEqual({
+ builtStageIndex: 0,
+ growingStageGrowths: [firstStepGrowthWhenJoined, 0],
+ });
+
+ while (timeline.isTransitioning()) {
+ const { builtStageIndex, growingStageGrowths } =
+ timeline.getConstruction();
+
+ expect(builtStageIndex).toBe(0);
+ expect(growingStageGrowths[1]).toBeLessThanOrEqual(
+ growingStageGrowths[0],
+ );
+ timeline.advance(FRAME_SECONDS);
+ }
+
+ expect(timeline.getConstruction()).toEqual({
+ builtStageIndex: 2,
+ growingStageGrowths: [],
+ });
+ });
+
+ it('should play a step reached while going back once it lands', () => {
+ const timeline = createSettledTimeline(3);
+
+ timeline.setTargetStageIndex(2);
+ advanceBySeconds(timeline, 0.5);
+ timeline.setTargetStageIndex(1);
+
+ expect(timeline.getConstruction().builtStageIndex).toBe(2);
+
+ advanceBySeconds(timeline, 20);
+
+ expect(timeline.isTransitioning()).toBe(false);
+ expect(timeline.getConstruction().builtStageIndex).toBe(1);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/getOnboardingConstructionSiteStage.test.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/getOnboardingConstructionSiteStage.test.ts
new file mode 100644
index 00000000000..2c7bb0ab091
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/getOnboardingConstructionSiteStage.test.ts
@@ -0,0 +1,65 @@
+import { ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX } from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import { getOnboardingConstructionSiteStage } from '@/onboarding/components/OnboardingConstructionSite/getOnboardingConstructionSiteStage';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+describe('getOnboardingConstructionSiteStage', () => {
+ it('should start the site on the first step', () => {
+ expect(
+ getOnboardingConstructionSiteStage({
+ onboardingStatus: OnboardingStatus.SYNC_EMAIL,
+ isLastOnboardingStep: false,
+ }),
+ ).toEqual({ stageIndex: 0 });
+ });
+
+ it('should move the construction forward with each step', () => {
+ const stageIndexes = [
+ OnboardingStatus.SYNC_EMAIL,
+ OnboardingStatus.APPS_INSTALLATION,
+ OnboardingStatus.PROFILE_CREATION,
+ OnboardingStatus.INVITE_TEAM,
+ OnboardingStatus.BOOK_CALL,
+ ].map(
+ (onboardingStatus) =>
+ getOnboardingConstructionSiteStage({
+ onboardingStatus,
+ isLastOnboardingStep: false,
+ }).stageIndex,
+ );
+
+ expect(stageIndexes).toEqual([0, 1, 2, 3, 4]);
+ });
+
+ it('should keep the site on its first stage before the first step that shows it', () => {
+ expect(
+ getOnboardingConstructionSiteStage({
+ onboardingStatus: OnboardingStatus.WORKSPACE_ACTIVATION,
+ isLastOnboardingStep: false,
+ }),
+ ).toEqual({ stageIndex: 0 });
+ expect(
+ getOnboardingConstructionSiteStage({
+ onboardingStatus: undefined,
+ isLastOnboardingStep: false,
+ }),
+ ).toEqual({ stageIndex: 0 });
+ });
+
+ it('should keep the finale for the last step', () => {
+ expect(
+ getOnboardingConstructionSiteStage({
+ onboardingStatus: OnboardingStatus.PLAN_REQUIRED,
+ isLastOnboardingStep: false,
+ }).stageIndex,
+ ).toBe(ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX - 1);
+ });
+
+ it('should complete the site with the finale on the last step', () => {
+ expect(
+ getOnboardingConstructionSiteStage({
+ onboardingStatus: OnboardingStatus.INVITE_TEAM,
+ isLastOnboardingStep: true,
+ }),
+ ).toEqual({ stageIndex: ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX });
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/onboardingConstructionSiteMatrices.test.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/onboardingConstructionSiteMatrices.test.ts
new file mode 100644
index 00000000000..0845b051e40
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/__tests__/onboardingConstructionSiteMatrices.test.ts
@@ -0,0 +1,61 @@
+import {
+ createLookAtMatrix,
+ createPerspectiveMatrix,
+ multiplyMatrices,
+ writeTransformMatrix,
+} from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices';
+
+const transformPoint = (matrix: Float32Array, point: readonly number[]) => {
+ const [x, y, z] = point;
+ const w = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
+ return [
+ (matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]) / w,
+ (matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]) / w,
+ (matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]) / w,
+ ];
+};
+
+describe('onboardingConstructionSiteMatrices', () => {
+ it('should scale then translate an instance', () => {
+ const matrix = new Float32Array(16);
+ writeTransformMatrix(matrix, 0, [1, 2, 3], [0, 0, 0], [2, 3, 4]);
+
+ expect(transformPoint(matrix, [0.5, 0.5, 0.5])).toEqual([2, 3.5, 5]);
+ });
+
+ it('should turn the unit x axis into the yaw direction', () => {
+ const matrix = new Float32Array(16);
+ writeTransformMatrix(matrix, 0, [0, 0, 0], [0, Math.PI / 2, 0], [1, 1, 1]);
+
+ const [x, y, z] = transformPoint(matrix, [1, 0, 0]);
+ expect(x).toBeCloseTo(0);
+ expect(y).toBeCloseTo(0);
+ expect(z).toBeCloseTo(-1);
+ });
+
+ it('should project the look-at target to the center of the screen', () => {
+ const viewProjection = multiplyMatrices(
+ createPerspectiveMatrix(Math.PI / 4, 1.6, 0.1, 60),
+ createLookAtMatrix([0, 1, 10], [0, 0, 0]),
+ );
+
+ const [x, y, depth] = transformPoint(viewProjection, [0, 0, 0]);
+ expect(x).toBeCloseTo(0);
+ expect(y).toBeCloseTo(0);
+ expect(depth).toBeGreaterThan(-1);
+ expect(depth).toBeLessThan(1);
+ });
+
+ it('should shift the image vertically without tilting the view', () => {
+ const viewProjection = multiplyMatrices(
+ createPerspectiveMatrix(Math.PI / 4, 1.6, 0.1, 60, -0.4),
+ createLookAtMatrix([0, -1, 10], [0, -1, 0]),
+ );
+
+ const [, bottomY] = transformPoint(viewProjection, [0, -2, 0]);
+ const [, topY] = transformPoint(viewProjection, [0, 2, 0]);
+ const [, eyeLevelY] = transformPoint(viewProjection, [3, -1, -5]);
+ expect(eyeLevelY).toBeCloseTo(-0.4);
+ expect(topY - bottomY).toBeCloseTo(4 / (10 * Math.tan(Math.PI / 8)));
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene.ts
new file mode 100644
index 00000000000..86e64d9730d
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene.ts
@@ -0,0 +1,1214 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { type OnboardingConstructionSiteConstruction } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction';
+import {
+ type OnboardingConstructionSiteInstances,
+ type OnboardingConstructionSiteMeshName,
+} from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances';
+import {
+ type OnboardingConstructionSiteVector,
+ writeTransformMatrix,
+} from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices';
+
+export const ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX = 5;
+export const ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE = 17;
+
+const REVEAL_SWEEP = 0.8;
+const WHEEL_RADIUS = 0.12;
+const EDGE_MARGIN = 0.2;
+const CONTENT_GAP = 0.25;
+const SCENE_HEIGHT_TO_HALF_HEIGHT_RATIO = 1.2;
+const MINIMUM_CLUSTER_SCALE = 0.5;
+const MAXIMUM_CLUSTER_SCALE = 1.25;
+const NO_ROTATION: OnboardingConstructionSiteVector = [0, 0, 0];
+
+const ROUND_TOWER_CLUSTER_WIDTH = 3.0;
+const ROUND_TOWER_CLUSTER_HEIGHT = 4.65;
+const BRACED_TOWER_CLUSTER_WIDTH = 3.3;
+const BRACED_TOWER_CLUSTER_HEIGHT = 3.5;
+
+const SLAB_THICKNESS = 0.08;
+
+const ROUND_TOWER_X = 1.85;
+const ROUND_TOWER_Z = -0.45;
+const ROUND_TOWER_FLOOR_HEIGHT = 0.34;
+const ROUND_TOWER_GLASS_RADIUS = 0.6;
+const ROUND_TOWER_SLAB_RADIUS = 0.68;
+const ROUND_TOWER_COLUMN_RADIUS = 0.5;
+const ROUND_TOWER_COLUMN_COUNT = 10;
+const ROUND_TOWER_BUILT_FLOORS_BY_STAGE = [1, 3, 5, 7, 9, 10];
+const ROUND_TOWER_CLAD_FLOORS_BY_STAGE = [0, 1, 3, 5, 7, 10];
+const SMALL_ROUND_TOWER_BUILT_FLOORS_BY_STAGE = [0, 0, 2, 3, 3, 4];
+
+const BRACED_TOWER_X = 1.95;
+const BRACED_TOWER_Z = -0.6;
+const BRACED_TOWER_FLOOR_COUNT = 14;
+const BRACED_TOWER_FLOOR_HEIGHT = 0.3;
+const BRACED_TOWER_WIDTH = 1.1;
+const BRACED_TOWER_BUILT_FLOORS_BY_STAGE = [0, 0, 4, 7, 10, 14];
+
+const MIXER_TRUCK_EXIT_PROGRESS_BY_STAGE = [0, 1, 1, 1, 1, 1];
+const MIXER_TRUCK_TURN_START_PROGRESS = 0.1;
+const MIXER_TRUCK_TURN_END_PROGRESS = 0.55;
+const MIXER_TRUCK_TURN_RADIUS = 0.4;
+
+const EDGE_BUILDING_BAY_COUNT = 4;
+const EDGE_BUILDING_BAY_WIDTH = 0.55;
+const EDGE_BUILDING_FLOOR_HEIGHT = 0.34;
+const EDGE_BUILDING_FRONT_Z = -0.2;
+const EDGE_BUILDING_BACK_Z = -1.0;
+const EDGE_BUILDING_COLUMN_WIDTH = 0.1;
+const EDGE_BUILDING_VISIBLE_WIDTH = 0.8;
+const EDGE_BUILDING_BUILT_FLOORS_BY_STAGE = [0, 0, 4, 5, 7, 11];
+const EDGE_BUILDING_FRAMED_FLOORS_BY_STAGE = [0, 0, 1, 2, 3, 4];
+const LEFT_EDGE_TOWER_VISIBLE_WIDTH = 0.5;
+const LEFT_EDGE_TOWER_BUILT_FLOORS_BY_STAGE = [3, 6, 9, 13, 17, 20];
+const LEFT_EDGE_TOWER_FRAMED_FLOORS_BY_STAGE = [0, 2, 4, 7, 11, 15];
+
+const ALBEDO = {
+ slab: 1,
+ column: 0.85,
+ core: 0.72,
+ rebar: 0.75,
+ glass: 0.7,
+ finishedGlass: 0.92,
+ crane: 1,
+ counterweight: 0.6,
+ cabin: 0.82,
+ cabinWindow: 0.25,
+ truck: 0.85,
+ drum: 0.95,
+ tire: 0.9,
+ hub: 0.2,
+ load: 0.8,
+ machine: 0.82,
+ glazingFrame: 0.9,
+ brace: 0.95,
+ recess: 0.22,
+} as const;
+
+const clampToUnitRange = (value: number) => Math.max(0, Math.min(1, value));
+const smootherStep = (ratio: number) =>
+ ratio * ratio * ratio * (ratio * (ratio * 6 - 15) + 10);
+
+const getRevealStage = (stageCounts: readonly number[], index: number) => {
+ const stageIndex = stageCounts.findIndex((count) => count > index);
+ return stageIndex === -1
+ ? ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX
+ : stageIndex;
+};
+
+export type OnboardingConstructionSiteLayout = {
+ halfWidth: number;
+ halfHeight: number;
+ contentHalfWidth: number;
+ groundY: number;
+};
+
+type BuildOnboardingConstructionSiteSceneArgs = {
+ instances: OnboardingConstructionSiteInstances;
+ layout: OnboardingConstructionSiteLayout;
+ construction: OnboardingConstructionSiteConstruction;
+ truckConstruction?: OnboardingConstructionSiteConstruction;
+ craneMotion: number;
+};
+
+export const buildOnboardingConstructionSiteScene = ({
+ instances,
+ layout,
+ construction,
+ truckConstruction = construction,
+ craneMotion,
+}: BuildOnboardingConstructionSiteSceneArgs) => {
+ instances.cube.count = 0;
+ instances.cylinder.count = 0;
+ instances.cone.count = 0;
+ instances.mixerDrum.count = 0;
+
+ const { halfWidth, halfHeight, contentHalfWidth, groundY } = layout;
+ const sceneHeight = halfHeight * SCENE_HEIGHT_TO_HALF_HEIGHT_RATIO;
+
+ const addInstance = (
+ meshName: OnboardingConstructionSiteMeshName,
+ position: OnboardingConstructionSiteVector,
+ rotation: OnboardingConstructionSiteVector,
+ scale: OnboardingConstructionSiteVector,
+ albedo: number,
+ ) => {
+ const batch = instances[meshName];
+ const offset =
+ batch.count * ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE;
+ if (
+ offset + ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE >
+ batch.data.length ||
+ scale[0] <= 0 ||
+ scale[1] <= 0 ||
+ scale[2] <= 0
+ ) {
+ return;
+ }
+ writeTransformMatrix(batch.data, offset, position, rotation, scale);
+ batch.data[offset + 16] = albedo;
+ batch.count++;
+ };
+
+ const getAppearance = (revealStageIndex: number, worldY: number) => {
+ if (revealStageIndex <= construction.builtStageIndex) {
+ return 1;
+ }
+ const growth =
+ construction.growingStageGrowths[
+ revealStageIndex - construction.builtStageIndex - 1
+ ];
+ if (!isDefined(growth)) {
+ return 0;
+ }
+
+ const heightRatio = clampToUnitRange((worldY - groundY) / sceneHeight);
+ return smootherStep(
+ clampToUnitRange(
+ growth * (1 + REVEAL_SWEEP) - heightRatio * REVEAL_SWEEP,
+ ),
+ );
+ };
+
+ const stagePosition =
+ truckConstruction.builtStageIndex +
+ truckConstruction.growingStageGrowths.reduce(
+ (total, growth) => total + growth,
+ 0,
+ );
+ const getStageValue = (valuesByStage: readonly number[]) => {
+ const position = Math.max(
+ 0,
+ Math.min(valuesByStage.length - 1, stagePosition),
+ );
+ const lowerStageIndex = Math.floor(position);
+ const upperStageIndex = Math.min(
+ lowerStageIndex + 1,
+ valuesByStage.length - 1,
+ );
+ return (
+ valuesByStage[lowerStageIndex] +
+ (valuesByStage[upperStageIndex] - valuesByStage[lowerStageIndex]) *
+ (position - lowerStageIndex)
+ );
+ };
+
+ const createFrame = (
+ originX: number,
+ originZ: number,
+ scale: number,
+ yaw = 0,
+ ) => {
+ const cosineYaw = Math.cos(yaw);
+ const sineYaw = Math.sin(yaw);
+ const toWorld = (
+ localPosition: OnboardingConstructionSiteVector,
+ ): OnboardingConstructionSiteVector => [
+ originX +
+ (localPosition[0] * cosineYaw + localPosition[2] * sineYaw) * scale,
+ groundY + localPosition[1] * scale,
+ originZ +
+ (-localPosition[0] * sineYaw + localPosition[2] * cosineYaw) * scale,
+ ];
+ const toWorldRotation = (
+ rotation: OnboardingConstructionSiteVector,
+ ): OnboardingConstructionSiteVector => [
+ rotation[0],
+ rotation[1] + yaw,
+ rotation[2],
+ ];
+ const toWorldScale = (
+ localScale: OnboardingConstructionSiteVector,
+ ): OnboardingConstructionSiteVector => [
+ localScale[0] * scale,
+ localScale[1] * scale,
+ localScale[2] * scale,
+ ];
+
+ return {
+ scale,
+ worldX: (localX: number) => originX + localX * scale,
+ worldY: (localY: number) => groundY + localY * scale,
+ worldZ: (localZ: number) => originZ + localZ * scale,
+ box: (
+ localPosition: OnboardingConstructionSiteVector,
+ localScale: OnboardingConstructionSiteVector,
+ albedo: number,
+ rotation: OnboardingConstructionSiteVector = NO_ROTATION,
+ ) =>
+ addInstance(
+ 'cube',
+ toWorld(localPosition),
+ toWorldRotation(rotation),
+ toWorldScale(localScale),
+ albedo,
+ ),
+ round: (
+ meshName: Exclude<OnboardingConstructionSiteMeshName, 'cube'>,
+ localPosition: OnboardingConstructionSiteVector,
+ localScale: OnboardingConstructionSiteVector,
+ albedo: number,
+ rotation: OnboardingConstructionSiteVector = NO_ROTATION,
+ ) =>
+ addInstance(
+ meshName,
+ toWorld(localPosition),
+ toWorldRotation(rotation),
+ toWorldScale(localScale),
+ albedo,
+ ),
+ };
+ };
+
+ type Frame = ReturnType<typeof createFrame>;
+
+ const getGlassAlbedo = (worldY: number) =>
+ ALBEDO.glass +
+ (ALBEDO.finishedGlass - ALBEDO.glass) *
+ getAppearance(ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX, worldY);
+
+ const addBeam = (
+ { box }: Frame,
+ start: OnboardingConstructionSiteVector,
+ end: OnboardingConstructionSiteVector,
+ thickness: number,
+ albedo: number,
+ ) => {
+ const deltaX = end[0] - start[0];
+ const deltaY = end[1] - start[1];
+ const deltaZ = end[2] - start[2];
+ const horizontalLength = Math.hypot(deltaX, deltaZ);
+ box(
+ [
+ (start[0] + end[0]) / 2,
+ (start[1] + end[1]) / 2,
+ (start[2] + end[2]) / 2,
+ ],
+ [Math.hypot(horizontalLength, deltaY), thickness, thickness],
+ albedo,
+ [0, Math.atan2(-deltaZ, deltaX), Math.atan2(deltaY, horizontalLength)],
+ );
+ };
+
+ const addWheel = ({ round }: Frame, wheelX: number, wheelZ: number) => {
+ const side = Math.sign(wheelZ);
+ round(
+ 'cylinder',
+ [wheelX, WHEEL_RADIUS, wheelZ],
+ [WHEEL_RADIUS * 2, 0.1, WHEEL_RADIUS * 2],
+ ALBEDO.tire,
+ [Math.PI / 2, 0, 0],
+ );
+ round(
+ 'cylinder',
+ [wheelX, WHEEL_RADIUS, wheelZ + side * 0.055],
+ [WHEEL_RADIUS * 1.25, 0.025, WHEEL_RADIUS * 1.25],
+ ALBEDO.hub,
+ [Math.PI / 2, 0, 0],
+ );
+ round(
+ 'cylinder',
+ [wheelX, WHEEL_RADIUS, wheelZ + side * 0.075],
+ [WHEEL_RADIUS * 0.5, 0.025, WHEEL_RADIUS * 0.5],
+ ALBEDO.slab,
+ [Math.PI / 2, 0, 0],
+ );
+ };
+
+ const addTruckCab = ({ box }: Frame) => {
+ box([0.43, 0.32, 0], [0.3, 0.2, 0.4], ALBEDO.truck);
+ box([0.41, 0.47, 0], [0.26, 0.18, 0.38], ALBEDO.truck);
+ box([0.41, 0.565, 0], [0.3, 0.04, 0.43], ALBEDO.slab);
+ for (const side of [-1, 1]) {
+ box([0.42, 0.48, side * 0.196], [0.19, 0.12, 0.025], ALBEDO.cabinWindow);
+ box([0.36, 0.27, side * 0.225], [0.21, 0.045, 0.09], ALBEDO.slab);
+ box([0.56, 0.37, side * 0.21], [0.06, 0.06, 0.035], ALBEDO.slab);
+ box([0.5, 0.48, side * 0.27], [0.055, 0.075, 0.065], ALBEDO.machine);
+ }
+ box([0.55, 0.48, 0], [0.025, 0.12, 0.3], ALBEDO.cabinWindow);
+ box([0.59, 0.31, 0], [0.025, 0.09, 0.26], ALBEDO.recess);
+ box([0.6, 0.23, 0], [0.06, 0.06, 0.44], ALBEDO.slab);
+ };
+
+ const buildMixerTruck = (frame: Frame) => {
+ const { box, round } = frame;
+ box([0, 0.18, 0], [1.1, 0.1, 0.34], ALBEDO.recess);
+ addTruckCab(frame);
+ box([-0.18, 0.29, 0], [0.68, 0.1, 0.3], ALBEDO.truck);
+ round('mixerDrum', [-0.14, 0.49, 0], [0.5, 0.72, 0.5], ALBEDO.drum, [
+ 0,
+ 0,
+ -Math.PI / 2 + 0.28,
+ ]);
+ for (const side of [-1, 1]) {
+ box([-0.26, 0.265, side * 0.22], [0.58, 0.055, 0.09], ALBEDO.slab);
+ box([0.08, 0.2, side * 0.2], [0.16, 0.13, 0.09], ALBEDO.machine);
+ for (const wheelX of [0.36, -0.12, -0.36]) {
+ addWheel(frame, wheelX, side * 0.2);
+ }
+ }
+ box([-0.52, 0.4, 0], [0.16, 0.13, 0.23], ALBEDO.machine);
+ addBeam(frame, [-0.48, 0.37, 0.08], [-0.69, 0.24, 0.15], 0.08, ALBEDO.slab);
+ };
+
+ type TowerCraneOptions = {
+ mastX: number;
+ mastZ: number;
+ mastHeight: number;
+ loadTarget: OnboardingConstructionSiteVector;
+ jibLength: number;
+ counterJibLength: number;
+ hasOpenMast?: boolean;
+ };
+
+ const addTowerCrane = (
+ frame: Frame,
+ {
+ mastX,
+ mastZ,
+ mastHeight,
+ loadTarget,
+ jibLength,
+ counterJibLength,
+ hasOpenMast = false,
+ }: TowerCraneOptions,
+ ) => {
+ const { box } = frame;
+ if (mastHeight <= 0.001) {
+ return;
+ }
+ const beamWidth = Math.max(0.1, 0.09 / frame.scale);
+ const braceWidth = Math.max(0.06, 0.055 / frame.scale);
+ const cableWidth = Math.max(0.075, 0.065 / frame.scale);
+ const jibBeamWidth = beamWidth * 1.2;
+ const jibBraceWidth = braceWidth * 1.1;
+ const jibHeight = 0.42;
+ const mastHalfWidth = hasOpenMast ? 0.23 : 0.17;
+ const mastHalfDepth = hasOpenMast ? 0.11 : 0.17;
+ const mastBeamWidth = beamWidth * (hasOpenMast ? 0.65 : 1);
+ const mastBraceWidth = braceWidth * (hasOpenMast ? 0.7 : 1);
+
+ box([mastX, 0.06, mastZ], [0.5, 0.12, 0.5], ALBEDO.counterweight);
+ for (const sideX of [-1, 1]) {
+ for (const sideZ of [-1, 1]) {
+ box(
+ [
+ mastX + sideX * mastHalfWidth,
+ mastHeight / 2,
+ mastZ + sideZ * mastHalfDepth,
+ ],
+ [mastBeamWidth, mastHeight, mastBeamWidth],
+ ALBEDO.crane,
+ );
+ }
+ }
+ const mastBayCount = Math.ceil(mastHeight / (hasOpenMast ? 0.78 : 0.52));
+ for (let bayIndex = 0; bayIndex < mastBayCount; bayIndex++) {
+ const bottomY = (bayIndex / mastBayCount) * mastHeight;
+ const topY = ((bayIndex + 1) / mastBayCount) * mastHeight;
+ for (const sideZ of [-1, 1]) {
+ box(
+ [mastX, topY, mastZ + sideZ * mastHalfDepth],
+ [mastHalfWidth * 2 + mastBeamWidth, mastBraceWidth, mastBraceWidth],
+ ALBEDO.crane,
+ );
+ const diagonalDirection = bayIndex % 2 === 0 ? 1 : -1;
+ addBeam(
+ frame,
+ [
+ mastX - diagonalDirection * mastHalfWidth,
+ bottomY,
+ mastZ + sideZ * mastHalfDepth,
+ ],
+ [
+ mastX + diagonalDirection * mastHalfWidth,
+ topY,
+ mastZ + sideZ * mastHalfDepth,
+ ],
+ mastBraceWidth,
+ ALBEDO.brace,
+ );
+ }
+ }
+
+ const targetDeltaX = loadTarget[0] - mastX;
+ const targetDeltaZ = loadTarget[2] - mastZ;
+ const yaw = Math.atan2(-targetDeltaZ, targetDeltaX);
+ const directionX = Math.cos(yaw);
+ const directionZ = -Math.sin(yaw);
+ const jibPoint = (
+ distance: number,
+ height: number,
+ ): OnboardingConstructionSiteVector => [
+ mastX + directionX * distance,
+ mastHeight + height,
+ mastZ + directionZ * distance,
+ ];
+
+ for (const height of [0, jibHeight]) {
+ addBeam(
+ frame,
+ jibPoint(-counterJibLength, height),
+ jibPoint(jibLength, height),
+ jibBeamWidth,
+ ALBEDO.crane,
+ );
+ }
+ const jibBayCount = Math.ceil((jibLength + counterJibLength) / 0.42);
+ for (let bayIndex = 0; bayIndex < jibBayCount; bayIndex++) {
+ const start =
+ -counterJibLength +
+ ((jibLength + counterJibLength) * bayIndex) / jibBayCount;
+ const end =
+ -counterJibLength +
+ ((jibLength + counterJibLength) * (bayIndex + 1)) / jibBayCount;
+ addBeam(
+ frame,
+ jibPoint(start, 0),
+ jibPoint(start, jibHeight),
+ jibBraceWidth,
+ ALBEDO.crane,
+ );
+ addBeam(
+ frame,
+ jibPoint(start, bayIndex % 2 === 0 ? 0 : jibHeight),
+ jibPoint(end, bayIndex % 2 === 0 ? jibHeight : 0),
+ jibBraceWidth,
+ ALBEDO.brace,
+ );
+ }
+ addBeam(
+ frame,
+ jibPoint(jibLength, 0),
+ jibPoint(jibLength, jibHeight),
+ jibBeamWidth,
+ ALBEDO.crane,
+ );
+ box(
+ [mastX, mastHeight + 0.42, mastZ],
+ [beamWidth, 0.7, beamWidth],
+ ALBEDO.crane,
+ );
+ addBeam(
+ frame,
+ jibPoint(0, 0.76),
+ jibPoint(jibLength * 0.6, jibHeight),
+ jibBeamWidth,
+ ALBEDO.crane,
+ );
+ addBeam(
+ frame,
+ jibPoint(0, 0.76),
+ jibPoint(-counterJibLength + 0.1, jibHeight),
+ jibBeamWidth,
+ ALBEDO.crane,
+ );
+ box(
+ jibPoint(-counterJibLength + 0.24, -0.1),
+ [0.4, 0.32, 0.3],
+ ALBEDO.counterweight,
+ [0, yaw, 0],
+ );
+ box(jibPoint(0.2, -0.12), [0.26, 0.24, 0.24], ALBEDO.cabin, [0, yaw, 0]);
+ const cabinWindow = jibPoint(0.2, -0.1);
+ box(
+ [
+ cabinWindow[0] + Math.sin(yaw) * 0.13,
+ cabinWindow[1],
+ cabinWindow[2] + Math.cos(yaw) * 0.13,
+ ],
+ [0.18, 0.12, 0.025],
+ ALBEDO.cabinWindow,
+ [0, yaw, 0],
+ );
+
+ const trolleyDistance = Math.hypot(targetDeltaX, targetDeltaZ);
+ const loadY = loadTarget[1] + 0.06 + 0.65 * (1 - craneMotion);
+ const cableLength = Math.max(0.08, mastHeight - 0.14 - loadY);
+ const [hookX, , hookZ] = jibPoint(trolleyDistance, 0);
+ box([hookX, mastHeight - 0.04, hookZ], [0.2, 0.08, 0.16], ALBEDO.crane, [
+ 0,
+ yaw,
+ 0,
+ ]);
+ box(
+ [hookX, mastHeight - 0.08 - cableLength / 2, hookZ],
+ [cableWidth, cableLength, cableWidth],
+ ALBEDO.crane,
+ );
+ const hookY = mastHeight - 0.08 - cableLength;
+ box([hookX, hookY, hookZ], [0.1, 0.12, 0.1], ALBEDO.machine);
+ const workProgress = construction.growingStageGrowths.at(-1) ?? 1;
+ const loadVisibility =
+ workProgress > 0
+ ? smootherStep(clampToUnitRange((0.5 - workProgress) / 0.04))
+ : 0;
+ if (loadVisibility > 0) {
+ box(
+ [hookX, hookY - 0.06, hookZ],
+ [0.45, 0.12 * loadVisibility, 0.18],
+ ALBEDO.load,
+ [0, yaw, 0],
+ );
+ }
+ };
+
+ const addRoundTower = (
+ frame: Frame,
+ {
+ builtFloorsByStage = ROUND_TOWER_BUILT_FLOORS_BY_STAGE,
+ cladFloorsByStage = ROUND_TOWER_CLAD_FLOORS_BY_STAGE,
+ hasCrane = true,
+ }: {
+ builtFloorsByStage?: readonly number[];
+ cladFloorsByStage?: readonly number[];
+ hasCrane?: boolean;
+ } = {},
+ ) => {
+ const { box, round, worldY } = frame;
+ const floorCount = builtFloorsByStage[builtFloorsByStage.length - 1];
+ let builtHeight = 0;
+
+ for (let floorIndex = 0; floorIndex < floorCount; floorIndex++) {
+ const baseY = floorIndex * ROUND_TOWER_FLOOR_HEIGHT;
+ const rise = getAppearance(
+ getRevealStage(builtFloorsByStage, floorIndex),
+ worldY(baseY),
+ );
+ if (rise <= 0.001) {
+ break;
+ }
+ const riseHeight = ROUND_TOWER_FLOOR_HEIGHT * rise;
+ builtHeight = baseY + riseHeight;
+ const columnHeight = Math.max(0, riseHeight - SLAB_THICKNESS);
+ for (
+ let columnIndex = 0;
+ columnIndex < ROUND_TOWER_COLUMN_COUNT;
+ columnIndex++
+ ) {
+ const angle = (columnIndex / ROUND_TOWER_COLUMN_COUNT) * Math.PI * 2;
+ round(
+ 'cylinder',
+ [
+ ROUND_TOWER_X + Math.cos(angle) * ROUND_TOWER_COLUMN_RADIUS,
+ baseY + columnHeight / 2,
+ ROUND_TOWER_Z + Math.sin(angle) * ROUND_TOWER_COLUMN_RADIUS,
+ ],
+ [0.13, columnHeight, 0.13],
+ ALBEDO.column,
+ );
+ }
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, baseY + riseHeight - SLAB_THICKNESS / 2, ROUND_TOWER_Z],
+ [
+ ROUND_TOWER_SLAB_RADIUS * 2,
+ SLAB_THICKNESS,
+ ROUND_TOWER_SLAB_RADIUS * 2,
+ ],
+ ALBEDO.slab,
+ );
+
+ const cladding = getAppearance(
+ getRevealStage(cladFloorsByStage, floorIndex),
+ worldY(baseY),
+ );
+ const glassHeight = columnHeight * cladding;
+ if (glassHeight > 0.001) {
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, baseY + glassHeight / 2, ROUND_TOWER_Z],
+ [
+ ROUND_TOWER_GLASS_RADIUS * 2,
+ glassHeight,
+ ROUND_TOWER_GLASS_RADIUS * 2,
+ ],
+ getGlassAlbedo(worldY(baseY)),
+ );
+ for (
+ let mullionIndex = 0;
+ mullionIndex < ROUND_TOWER_COLUMN_COUNT;
+ mullionIndex++
+ ) {
+ const angle =
+ Math.PI / 2 -
+ (mullionIndex / ROUND_TOWER_COLUMN_COUNT) * Math.PI * 2;
+ box(
+ [
+ ROUND_TOWER_X + Math.sin(angle) * ROUND_TOWER_GLASS_RADIUS,
+ baseY + glassHeight / 2,
+ ROUND_TOWER_Z + Math.cos(angle) * ROUND_TOWER_GLASS_RADIUS,
+ ],
+ [0.055, glassHeight, 0.045],
+ ALBEDO.recess,
+ [0, angle, 0],
+ );
+ }
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, baseY + glassHeight - 0.02 * cladding, ROUND_TOWER_Z],
+ [
+ ROUND_TOWER_GLASS_RADIUS * 2 + 0.025,
+ 0.04 * cladding,
+ ROUND_TOWER_GLASS_RADIUS * 2 + 0.025,
+ ],
+ ALBEDO.recess,
+ );
+ }
+ }
+
+ const towerTopY = floorCount * ROUND_TOWER_FLOOR_HEIGHT;
+ const crown = getAppearance(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ worldY(towerTopY),
+ );
+ if (crown > 0.001) {
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, towerTopY + 0.17 * crown, ROUND_TOWER_Z],
+ [0.9, 0.34 * crown, 0.9],
+ ALBEDO.finishedGlass,
+ );
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, towerTopY + 0.34 * crown + 0.04, ROUND_TOWER_Z],
+ [1.02, 0.08, 1.02],
+ ALBEDO.slab,
+ );
+ for (let finIndex = 0; finIndex < ROUND_TOWER_COLUMN_COUNT; finIndex++) {
+ const angle =
+ Math.PI / 2 - (finIndex / ROUND_TOWER_COLUMN_COUNT) * Math.PI * 2;
+ box(
+ [
+ ROUND_TOWER_X + Math.sin(angle) * 0.45,
+ towerTopY + 0.17 * crown,
+ ROUND_TOWER_Z + Math.cos(angle) * 0.45,
+ ],
+ [0.055, 0.34 * crown, 0.06],
+ ALBEDO.recess,
+ [0, angle, 0],
+ );
+ }
+ round(
+ 'cylinder',
+ [ROUND_TOWER_X, towerTopY + 0.42 + 0.07 * crown, ROUND_TOWER_Z],
+ [0.3, 0.14 * crown, 0.3],
+ ALBEDO.core,
+ );
+ round(
+ 'cone',
+ [ROUND_TOWER_X, towerTopY + 0.42 + 0.4 * crown, ROUND_TOWER_Z],
+ [0.16, 0.8 * crown, 0.16],
+ ALBEDO.crane,
+ );
+ }
+
+ if (!hasCrane) {
+ return;
+ }
+
+ const craneRise = getAppearance(0, worldY(0));
+ const workHeight = builtHeight + 0.42 * crown;
+ addTowerCrane(frame, {
+ mastX: 0.45,
+ mastZ: -1.1,
+ mastHeight: Math.max(2.4, workHeight + 1) * craneRise,
+ loadTarget: [ROUND_TOWER_X - 0.32, workHeight, ROUND_TOWER_Z - 0.18],
+ jibLength: 2.3,
+ counterJibLength: 0.75,
+ hasOpenMast: true,
+ });
+ };
+
+ const addSmallRoundTower = (frame: Frame) => {
+ const { round, worldY } = frame;
+ const floorHeight = 0.36;
+ for (let floorIndex = 0; floorIndex < 4; floorIndex++) {
+ const baseY = floorIndex * floorHeight;
+ const rise = getAppearance(
+ getRevealStage(SMALL_ROUND_TOWER_BUILT_FLOORS_BY_STAGE, floorIndex),
+ worldY(baseY),
+ );
+ if (rise <= 0.001) {
+ break;
+ }
+ const radius = 0.45 - floorIndex * 0.025;
+ const height = floorHeight * rise;
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
+ const angle = (columnIndex * Math.PI) / 4;
+ round(
+ 'cylinder',
+ [
+ Math.cos(angle) * (radius - 0.06),
+ baseY + height / 2,
+ Math.sin(angle) * (radius - 0.06),
+ ],
+ [0.065, height, 0.065],
+ ALBEDO.column,
+ );
+ }
+ round(
+ 'cylinder',
+ [0, baseY + height - 0.03, 0],
+ [radius * 2 + 0.2, 0.06, radius * 2 + 0.2],
+ ALBEDO.slab,
+ );
+ }
+ };
+
+ const addBracedTower = (frame: Frame) => {
+ const { box, round, worldY } = frame;
+ const towerHeight = BRACED_TOWER_FLOOR_COUNT * BRACED_TOWER_FLOOR_HEIGHT;
+ const halfWidthAtHeight = (height: number) =>
+ BRACED_TOWER_WIDTH / 2 - 0.3 * clampToUnitRange(height / towerHeight);
+ const cornerAtHeight = (
+ sideX: number,
+ sideZ: number,
+ height: number,
+ ): OnboardingConstructionSiteVector => [
+ BRACED_TOWER_X + sideX * halfWidthAtHeight(height),
+ height,
+ BRACED_TOWER_Z + sideZ * halfWidthAtHeight(height),
+ ];
+ let builtHeight = 0;
+
+ for (
+ let floorIndex = 0;
+ floorIndex < BRACED_TOWER_FLOOR_COUNT;
+ floorIndex++
+ ) {
+ const baseY = floorIndex * BRACED_TOWER_FLOOR_HEIGHT;
+ const rise = getAppearance(
+ getRevealStage(BRACED_TOWER_BUILT_FLOORS_BY_STAGE, floorIndex),
+ worldY(baseY),
+ );
+ if (rise <= 0.001) {
+ break;
+ }
+ const topY = baseY + BRACED_TOWER_FLOOR_HEIGHT * rise;
+ builtHeight = topY;
+ for (const sideX of [-1, 1]) {
+ for (const sideZ of [-1, 1]) {
+ addBeam(
+ frame,
+ cornerAtHeight(sideX, sideZ, baseY),
+ cornerAtHeight(sideX, sideZ, topY),
+ 0.08,
+ ALBEDO.column,
+ );
+ }
+ }
+ const floorWidth = halfWidthAtHeight(topY) * 2;
+ box(
+ [BRACED_TOWER_X, topY - 0.014, BRACED_TOWER_Z],
+ [floorWidth, 0.028, floorWidth],
+ ALBEDO.slab,
+ );
+ for (const side of [-1, 1]) {
+ box(
+ [
+ BRACED_TOWER_X,
+ topY - 0.04,
+ BRACED_TOWER_Z + (side * floorWidth) / 2,
+ ],
+ [floorWidth + 0.035, 0.07, 0.035],
+ ALBEDO.slab,
+ );
+ box(
+ [
+ BRACED_TOWER_X + (side * floorWidth) / 2,
+ topY - 0.04,
+ BRACED_TOWER_Z,
+ ],
+ [0.035, 0.07, floorWidth + 0.035],
+ ALBEDO.slab,
+ );
+ box(
+ [
+ BRACED_TOWER_X,
+ topY - 0.065,
+ BRACED_TOWER_Z + side * floorWidth * 0.2,
+ ],
+ [floorWidth - 0.06, 0.04, 0.035],
+ ALBEDO.column,
+ );
+ }
+ }
+
+ for (
+ let floorIndex = 0;
+ floorIndex < BRACED_TOWER_FLOOR_COUNT;
+ floorIndex += 4
+ ) {
+ const baseY = floorIndex * BRACED_TOWER_FLOOR_HEIGHT;
+ const topY = Math.min(baseY + 4 * BRACED_TOWER_FLOOR_HEIGHT, builtHeight);
+ if (topY <= baseY + 0.001) {
+ break;
+ }
+ const direction = (floorIndex / 4) % 2 === 0 ? 1 : -1;
+ for (const side of [-1, 1]) {
+ addBeam(
+ frame,
+ cornerAtHeight(-direction, side, baseY),
+ cornerAtHeight(direction, side, topY),
+ 0.09,
+ ALBEDO.slab,
+ );
+ addBeam(
+ frame,
+ cornerAtHeight(side, direction, baseY),
+ cornerAtHeight(side, -direction, topY),
+ 0.09,
+ ALBEDO.slab,
+ );
+ }
+ for (const sideX of [-1, 1]) {
+ for (const sideZ of [-1, 1]) {
+ const corner = cornerAtHeight(sideX, sideZ, topY);
+ box(
+ [corner[0], topY - 0.02, corner[2] + sideZ * 0.045],
+ [0.14, 0.13, 0.035],
+ ALBEDO.column,
+ );
+ for (const boltOffset of [-0.03, 0.03]) {
+ round(
+ 'cylinder',
+ [corner[0], topY - 0.02 + boltOffset, corner[2] + sideZ * 0.068],
+ [0.03, 0.018, 0.03],
+ ALBEDO.recess,
+ [Math.PI / 2, 0, 0],
+ );
+ }
+ }
+ }
+ }
+
+ const crown = getAppearance(
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX,
+ worldY(towerHeight),
+ );
+ if (crown > 0.001) {
+ const peak: OnboardingConstructionSiteVector = [
+ BRACED_TOWER_X,
+ towerHeight + 0.48 * crown,
+ BRACED_TOWER_Z,
+ ];
+ for (const sideX of [-1, 1]) {
+ for (const sideZ of [-1, 1]) {
+ const corner = cornerAtHeight(sideX, sideZ, towerHeight);
+ addBeam(frame, corner, peak, 0.07, ALBEDO.slab);
+ box(
+ [corner[0], towerHeight + 0.09 * crown, corner[2]],
+ [0.035, 0.18 * crown, 0.035],
+ ALBEDO.rebar,
+ );
+ }
+ }
+ const crownTieHeight = towerHeight + 0.22 * crown;
+ for (const side of [-1, 1]) {
+ box(
+ [BRACED_TOWER_X + side * 0.135, crownTieHeight, BRACED_TOWER_Z],
+ [0.035, 0.035, 0.27],
+ ALBEDO.slab,
+ );
+ box(
+ [BRACED_TOWER_X, crownTieHeight, BRACED_TOWER_Z + side * 0.135],
+ [0.27, 0.035, 0.035],
+ ALBEDO.slab,
+ );
+ }
+ box(
+ [peak[0], peak[1] + 0.05 * crown, peak[2]],
+ [0.045, 0.14 * crown, 0.045],
+ ALBEDO.rebar,
+ );
+ }
+ return builtHeight;
+ };
+
+ const addBracedTowerCluster = (frame: Frame) => {
+ const workHeight = addBracedTower(frame);
+ const craneFrame = createFrame(
+ halfWidth - 0.35 * frame.scale,
+ 0.35 * frame.scale,
+ frame.scale * 0.75,
+ );
+ const loadTarget: OnboardingConstructionSiteVector = [
+ (frame.worldX(BRACED_TOWER_X + 0.15) - craneFrame.worldX(0)) /
+ craneFrame.scale,
+ (workHeight * frame.scale) / craneFrame.scale,
+ (frame.worldZ(BRACED_TOWER_Z + 0.12) - craneFrame.worldZ(0)) /
+ craneFrame.scale,
+ ];
+ addTowerCrane(craneFrame, {
+ mastX: 0,
+ mastZ: 0,
+ mastHeight:
+ Math.max(2.4, loadTarget[1] + 1) *
+ getAppearance(1, craneFrame.worldY(0)),
+ loadTarget,
+ jibLength: Math.max(2.3, Math.hypot(loadTarget[0], loadTarget[2]) + 0.3),
+ counterJibLength: 0.75,
+ hasOpenMast: true,
+ });
+ const turnStartX = frame.worldX(0.05);
+ const endX = halfWidth + 1.2 * frame.scale;
+ const exitProgress = getStageValue(MIXER_TRUCK_EXIT_PROGRESS_BY_STAGE);
+ const approachProgress = smootherStep(
+ clampToUnitRange(exitProgress / MIXER_TRUCK_TURN_START_PROGRESS),
+ );
+ const parkingOffset = 0.4 * frame.scale * (1 - approachProgress);
+ const turnProgress = smootherStep(
+ clampToUnitRange(
+ (exitProgress - MIXER_TRUCK_TURN_START_PROGRESS) /
+ (MIXER_TRUCK_TURN_END_PROGRESS - MIXER_TRUCK_TURN_START_PROGRESS),
+ ),
+ );
+ const driveProgress = Math.pow(
+ clampToUnitRange(
+ (exitProgress - MIXER_TRUCK_TURN_END_PROGRESS) /
+ (1 - MIXER_TRUCK_TURN_END_PROGRESS),
+ ),
+ 2,
+ );
+ const turnAngle = Math.PI * turnProgress;
+ const turnRadius = MIXER_TRUCK_TURN_RADIUS * frame.scale;
+ buildMixerTruck(
+ createFrame(
+ turnStartX +
+ parkingOffset -
+ Math.sin(turnAngle) * turnRadius +
+ (endX - turnStartX) * driveProgress,
+ frame.worldZ(0.75) + (1 - Math.cos(turnAngle)) * turnRadius,
+ frame.scale,
+ Math.PI + turnAngle,
+ ),
+ );
+ };
+
+ const addEdgeBuilding = (
+ frame: Frame,
+ {
+ builtFloorsByStage = EDGE_BUILDING_BUILT_FLOORS_BY_STAGE,
+ framedFloorsByStage = EDGE_BUILDING_FRAMED_FLOORS_BY_STAGE,
+ hasDiagonalBraces = false,
+ }: {
+ builtFloorsByStage?: readonly number[];
+ framedFloorsByStage?: readonly number[];
+ hasDiagonalBraces?: boolean;
+ } = {},
+ ) => {
+ const { box, worldY } = frame;
+ const floorCount = builtFloorsByStage[builtFloorsByStage.length - 1];
+ const framedFloorCount =
+ framedFloorsByStage[framedFloorsByStage.length - 1];
+ const buildingWidth = EDGE_BUILDING_BAY_COUNT * EDGE_BUILDING_BAY_WIDTH;
+ const buildingDepth = EDGE_BUILDING_FRONT_Z - EDGE_BUILDING_BACK_Z;
+ const centerZ = (EDGE_BUILDING_FRONT_Z + EDGE_BUILDING_BACK_Z) / 2;
+ let builtFloors = 0;
+ let builtHeight = 0;
+
+ for (let floorIndex = 0; floorIndex < floorCount; floorIndex++) {
+ const baseY = floorIndex * EDGE_BUILDING_FLOOR_HEIGHT;
+ const rise = getAppearance(
+ getRevealStage(builtFloorsByStage, floorIndex),
+ worldY(baseY),
+ );
+ if (rise <= 0.001) {
+ break;
+ }
+ builtFloors += rise;
+
+ const riseHeight = EDGE_BUILDING_FLOOR_HEIGHT * rise;
+ builtHeight = baseY + riseHeight;
+ const slabThickness =
+ hasDiagonalBraces && floorIndex % 2 === 0 ? 0.04 : SLAB_THICKNESS;
+ const columnHeight = Math.max(0, riseHeight - slabThickness);
+ for (
+ let lineIndex = 0;
+ lineIndex <= EDGE_BUILDING_BAY_COUNT;
+ lineIndex++
+ ) {
+ for (const columnZ of [EDGE_BUILDING_FRONT_Z, EDGE_BUILDING_BACK_Z]) {
+ box(
+ [
+ lineIndex * EDGE_BUILDING_BAY_WIDTH,
+ baseY + columnHeight / 2,
+ columnZ,
+ ],
+ [
+ EDGE_BUILDING_COLUMN_WIDTH,
+ columnHeight,
+ EDGE_BUILDING_COLUMN_WIDTH,
+ ],
+ ALBEDO.column,
+ );
+ }
+ }
+ box(
+ [buildingWidth / 2, baseY + riseHeight - slabThickness / 2, centerZ],
+ [buildingWidth + 0.1, slabThickness, buildingDepth + 0.1],
+ ALBEDO.slab,
+ );
+
+ if (hasDiagonalBraces || floorIndex >= framedFloorCount) {
+ continue;
+ }
+ const frameHeight =
+ columnHeight *
+ getAppearance(
+ getRevealStage(framedFloorsByStage, floorIndex),
+ worldY(baseY),
+ );
+ if (frameHeight <= 0.001) {
+ continue;
+ }
+ for (let bayIndex = 0; bayIndex < EDGE_BUILDING_BAY_COUNT; bayIndex++) {
+ box(
+ [
+ (bayIndex + 0.5) * EDGE_BUILDING_BAY_WIDTH,
+ baseY + frameHeight / 2,
+ EDGE_BUILDING_FRONT_Z,
+ ],
+ [0.05, frameHeight, 0.04],
+ ALBEDO.glazingFrame,
+ );
+ }
+ }
+
+ if (hasDiagonalBraces) {
+ for (let floorIndex = 0; floorIndex < floorCount; floorIndex += 2) {
+ const baseY = floorIndex * EDGE_BUILDING_FLOOR_HEIGHT;
+ const height = Math.min(
+ EDGE_BUILDING_FLOOR_HEIGHT * 2,
+ builtHeight - baseY,
+ );
+ if (height <= 0.001) {
+ break;
+ }
+ for (let bayIndex = 0; bayIndex < EDGE_BUILDING_BAY_COUNT; bayIndex++) {
+ for (const direction of [-1, 1]) {
+ const centerX = (bayIndex + 0.5) * EDGE_BUILDING_BAY_WIDTH;
+ addBeam(
+ frame,
+ [
+ centerX - (direction * EDGE_BUILDING_BAY_WIDTH) / 2,
+ baseY,
+ EDGE_BUILDING_FRONT_Z + 0.06,
+ ],
+ [
+ centerX + (direction * EDGE_BUILDING_BAY_WIDTH) / 2,
+ baseY + height,
+ EDGE_BUILDING_FRONT_Z + 0.06,
+ ],
+ 0.065,
+ ALBEDO.slab,
+ );
+ }
+ }
+ }
+ }
+
+ const topY = builtFloors * EDGE_BUILDING_FLOOR_HEIGHT;
+ if (builtFloors <= 0.001) {
+ return;
+ }
+ for (let lineIndex = 0; lineIndex <= EDGE_BUILDING_BAY_COUNT; lineIndex++) {
+ for (const columnZ of [EDGE_BUILDING_FRONT_Z, EDGE_BUILDING_BACK_Z]) {
+ for (const barOffset of [-0.025, 0.025]) {
+ box(
+ [
+ lineIndex * EDGE_BUILDING_BAY_WIDTH + barOffset,
+ topY + 0.09,
+ columnZ,
+ ],
+ [0.03, 0.18, 0.03],
+ ALBEDO.rebar,
+ );
+ }
+ }
+ }
+ };
+
+ const getClusterScale = (
+ zoneWidth: number,
+ clusterWidth: number,
+ clusterHeight: number,
+ ) =>
+ Math.max(
+ MINIMUM_CLUSTER_SCALE,
+ Math.min(
+ MAXIMUM_CLUSTER_SCALE,
+ zoneWidth / clusterWidth,
+ sceneHeight / clusterHeight,
+ ),
+ );
+
+ const zoneInnerX = contentHalfWidth + CONTENT_GAP;
+ const zoneOuterX = halfWidth - EDGE_MARGIN;
+ const zoneWidth = zoneOuterX - zoneInnerX;
+
+ if (
+ zoneWidth <
+ Math.max(ROUND_TOWER_CLUSTER_WIDTH, BRACED_TOWER_CLUSTER_WIDTH) *
+ MINIMUM_CLUSTER_SCALE
+ ) {
+ return;
+ }
+ const siteScale = Math.min(
+ getClusterScale(
+ zoneWidth,
+ ROUND_TOWER_CLUSTER_WIDTH,
+ ROUND_TOWER_CLUSTER_HEIGHT,
+ ),
+ getClusterScale(
+ zoneWidth,
+ BRACED_TOWER_CLUSTER_WIDTH,
+ BRACED_TOWER_CLUSTER_HEIGHT,
+ ),
+ );
+
+ const roundClusterWidth = ROUND_TOWER_CLUSTER_WIDTH * siteScale;
+ const bracedClusterWidth = BRACED_TOWER_CLUSTER_WIDTH * siteScale;
+ const roundClusterLeftX = -Math.min(
+ (zoneInnerX + zoneOuterX + roundClusterWidth) / 2,
+ zoneOuterX,
+ );
+ const bracedClusterLeftX = Math.min(
+ (zoneInnerX + zoneOuterX - bracedClusterWidth) / 2,
+ zoneOuterX - bracedClusterWidth,
+ );
+ addRoundTower(createFrame(roundClusterLeftX, 0, siteScale));
+ addSmallRoundTower(
+ createFrame(
+ bracedClusterLeftX + 0.55 * siteScale,
+ -0.15 * siteScale,
+ siteScale,
+ ),
+ );
+ addBracedTowerCluster(createFrame(bracedClusterLeftX, 0, siteScale));
+ addEdgeBuilding(
+ createFrame(
+ -halfWidth -
+ (EDGE_BUILDING_BAY_COUNT * EDGE_BUILDING_BAY_WIDTH -
+ LEFT_EDGE_TOWER_VISIBLE_WIDTH) *
+ siteScale,
+ 0,
+ siteScale,
+ ),
+ {
+ builtFloorsByStage: LEFT_EDGE_TOWER_BUILT_FLOORS_BY_STAGE,
+ framedFloorsByStage: LEFT_EDGE_TOWER_FRAMED_FLOORS_BY_STAGE,
+ },
+ );
+ addEdgeBuilding(
+ createFrame(
+ halfWidth - EDGE_BUILDING_VISIBLE_WIDTH * siteScale,
+ 0,
+ siteScale,
+ ),
+ { hasDiagonalBraces: true },
+ );
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteRenderer.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteRenderer.ts
new file mode 100644
index 00000000000..fd9d3f5d55e
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteRenderer.ts
@@ -0,0 +1,675 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import {
+ buildOnboardingConstructionSiteScene,
+ ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+ type OnboardingConstructionSiteLayout,
+} from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import { createOnboardingConstructionSiteTimeline } from '@/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteTimeline';
+import {
+ type OnboardingConstructionSiteInstanceBatch,
+ type OnboardingConstructionSiteInstances,
+ type OnboardingConstructionSiteMeshName,
+} from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteInstances';
+import {
+ createLookAtMatrix,
+ createPerspectiveMatrix,
+ multiplyMatrices,
+} from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices';
+import { ONBOARDING_CONSTRUCTION_SITE_MESHES } from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMeshes';
+import { type OnboardingConstructionSiteSettings } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteSettings';
+import { ONBOARDING_CONSTRUCTION_SITE_SHADERS } from '@/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteShaders';
+import { type OnboardingConstructionSiteStage } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteStage';
+
+const MESH_NAMES: readonly OnboardingConstructionSiteMeshName[] = [
+ 'cube',
+ 'cylinder',
+ 'cone',
+ 'mixerDrum',
+];
+const INSTANCE_CAPACITY: Record<OnboardingConstructionSiteMeshName, number> = {
+ cube: 1024,
+ cylinder: 256,
+ cone: 16,
+ mixerDrum: 4,
+};
+
+const MAXIMUM_DEVICE_PIXEL_RATIO = 2;
+const MAXIMUM_CANVAS_PIXELS = 9_000_000;
+const VIRTUAL_RENDER_HEIGHT_CSS_PIXELS = 768;
+const FIELD_OF_VIEW_RADIANS = (32 * Math.PI) / 180;
+const CAMERA_DISTANCE = 12;
+const CONTENT_GAP_CSS_PIXELS = 44;
+const CONTENT_FEATHER_CSS_PIXELS = 70;
+const FILL_LIGHT_DIRECTION = [-0.9045, -0.3015, 0.3015] as const;
+const FINALE_WAVE_AMOUNT = 0.35;
+const FINALE_SCATTER_AMOUNT = 0.06;
+const SOFTWARE_RENDERER_PATTERN =
+ /swiftshader|llvmpipe|software|basic render driver/i;
+
+const compileProgram = (
+ gl: WebGL2RenderingContext,
+ vertexSource: string,
+ fragmentSource: string,
+) => {
+ const compileShader = (shaderType: number, source: string) => {
+ const shader = gl.createShader(shaderType);
+ if (!isDefined(shader)) {
+ return null;
+ }
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+ if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) !== true) {
+ gl.deleteShader(shader);
+ return null;
+ }
+ return shader;
+ };
+
+ const vertexShader = compileShader(gl.VERTEX_SHADER, vertexSource);
+ const fragmentShader = compileShader(gl.FRAGMENT_SHADER, fragmentSource);
+ const program = gl.createProgram();
+ if (
+ !isDefined(vertexShader) ||
+ !isDefined(fragmentShader) ||
+ !isDefined(program)
+ ) {
+ return null;
+ }
+
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+ gl.deleteShader(vertexShader);
+ gl.deleteShader(fragmentShader);
+
+ return gl.getProgramParameter(program, gl.LINK_STATUS) ? program : null;
+};
+
+type MeshResources = {
+ vertexArray: WebGLVertexArrayObject;
+ vertexBuffer: WebGLBuffer;
+ instanceBuffer: WebGLBuffer;
+ vertexCount: number;
+};
+
+type UniformLookup = (name: string) => WebGLUniformLocation | null;
+
+type GlResources = {
+ sceneProgram: WebGLProgram;
+ halftoneProgram: WebGLProgram;
+ sceneUniform: UniformLookup;
+ halftoneUniform: UniformLookup;
+ meshes: Record<OnboardingConstructionSiteMeshName, MeshResources>;
+ sceneTexture: WebGLTexture;
+ sceneDepthBuffer: WebGLRenderbuffer;
+ sceneFramebuffer: WebGLFramebuffer;
+ emptyVertexArray: WebGLVertexArrayObject;
+};
+
+const deleteResources = (
+ gl: WebGL2RenderingContext,
+ resources: GlResources,
+) => {
+ gl.deleteProgram(resources.sceneProgram);
+ gl.deleteProgram(resources.halftoneProgram);
+ Object.values(resources.meshes).forEach(
+ ({ vertexArray, vertexBuffer, instanceBuffer }) => {
+ gl.deleteVertexArray(vertexArray);
+ gl.deleteBuffer(vertexBuffer);
+ gl.deleteBuffer(instanceBuffer);
+ },
+ );
+ gl.deleteTexture(resources.sceneTexture);
+ gl.deleteRenderbuffer(resources.sceneDepthBuffer);
+ gl.deleteFramebuffer(resources.sceneFramebuffer);
+ gl.deleteVertexArray(resources.emptyVertexArray);
+};
+
+type OnboardingConstructionSiteColor = readonly [number, number, number];
+
+export type OnboardingConstructionSiteColors = {
+ dashColor: OnboardingConstructionSiteColor;
+};
+
+type CreateOnboardingConstructionSiteRendererOptions = {
+ canvas: HTMLCanvasElement;
+ colors: OnboardingConstructionSiteColors;
+ settings: OnboardingConstructionSiteSettings;
+ contentColumnWidth: number;
+ prefersReducedMotion: boolean;
+};
+
+export type OnboardingConstructionSiteRenderer = {
+ setStage: (stage: OnboardingConstructionSiteStage) => void;
+ setColors: (colors: OnboardingConstructionSiteColors) => void;
+ resize: () => void;
+ destroy: () => void;
+};
+
+export const createOnboardingConstructionSiteRenderer = ({
+ canvas,
+ colors: initialColors,
+ settings,
+ contentColumnWidth,
+ prefersReducedMotion,
+}: CreateOnboardingConstructionSiteRendererOptions): OnboardingConstructionSiteRenderer | null => {
+ const gl = canvas.getContext('webgl2', {
+ alpha: true,
+ antialias: false,
+ depth: false,
+ premultipliedAlpha: true,
+ powerPreference: 'low-power',
+ });
+ if (!isDefined(gl)) {
+ return null;
+ }
+
+ const debugRendererInfo = gl.getExtension('WEBGL_debug_renderer_info');
+ const shouldReduceMotion =
+ prefersReducedMotion ||
+ (isDefined(debugRendererInfo) &&
+ SOFTWARE_RENDERER_PATTERN.test(
+ gl.getParameter(debugRendererInfo.UNMASKED_RENDERER_WEBGL),
+ ));
+
+ const createInstanceBatch = (
+ meshName: OnboardingConstructionSiteMeshName,
+ ): OnboardingConstructionSiteInstanceBatch => ({
+ data: new Float32Array(
+ INSTANCE_CAPACITY[meshName] *
+ ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+ ),
+ count: 0,
+ });
+
+ const instances: OnboardingConstructionSiteInstances = {
+ cube: createInstanceBatch('cube'),
+ cylinder: createInstanceBatch('cylinder'),
+ cone: createInstanceBatch('cone'),
+ mixerDrum: createInstanceBatch('mixerDrum'),
+ };
+
+ let resources: GlResources | null = null;
+ let colors = initialColors;
+ let cssWidth = 0;
+ let cssHeight = 0;
+ let devicePixelRatio = 1;
+ let sceneWidth = 1;
+ let sceneHeight = 1;
+ const timeline = createOnboardingConstructionSiteTimeline();
+ const truckTimeline = createOnboardingConstructionSiteTimeline({
+ transitionSecondsPerStep: 2.2,
+ easing: (ratio) => ratio,
+ });
+ let hasStage = false;
+ let animationFrameHandle: number | null = null;
+ let elapsedSeconds = 0;
+ let lastFrameTimeMs: number | null = null;
+ let isDestroyed = false;
+
+ const createResources = (): GlResources | null => {
+ const sceneProgram = compileProgram(
+ gl,
+ ONBOARDING_CONSTRUCTION_SITE_SHADERS.sceneVertex,
+ ONBOARDING_CONSTRUCTION_SITE_SHADERS.sceneFragment,
+ );
+ const halftoneProgram = compileProgram(
+ gl,
+ ONBOARDING_CONSTRUCTION_SITE_SHADERS.fullScreenVertex,
+ ONBOARDING_CONSTRUCTION_SITE_SHADERS.halftoneFragment,
+ );
+ const sceneTexture = gl.createTexture();
+ const sceneDepthBuffer = gl.createRenderbuffer();
+ const sceneFramebuffer = gl.createFramebuffer();
+ const emptyVertexArray = gl.createVertexArray();
+ if (
+ !isDefined(sceneProgram) ||
+ !isDefined(halftoneProgram) ||
+ !isDefined(sceneTexture) ||
+ !isDefined(sceneDepthBuffer) ||
+ !isDefined(sceneFramebuffer) ||
+ !isDefined(emptyVertexArray)
+ ) {
+ return null;
+ }
+
+ const positionLocation = gl.getAttribLocation(sceneProgram, 'position');
+ const normalLocation = gl.getAttribLocation(sceneProgram, 'normal');
+ const columnLocations = [0, 1, 2, 3].map((columnIndex) =>
+ gl.getAttribLocation(sceneProgram, `instanceColumn${columnIndex}`),
+ );
+ const albedoLocation = gl.getAttribLocation(sceneProgram, 'instanceAlbedo');
+ const instanceStride = ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE * 4;
+
+ const createMeshResources = (
+ meshName: OnboardingConstructionSiteMeshName,
+ ): MeshResources | null => {
+ const vertexData = ONBOARDING_CONSTRUCTION_SITE_MESHES[meshName];
+ const vertexArray = gl.createVertexArray();
+ const vertexBuffer = gl.createBuffer();
+ const instanceBuffer = gl.createBuffer();
+ if (
+ !isDefined(vertexArray) ||
+ !isDefined(vertexBuffer) ||
+ !isDefined(instanceBuffer)
+ ) {
+ return null;
+ }
+
+ gl.bindVertexArray(vertexArray);
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.STATIC_DRAW);
+ gl.enableVertexAttribArray(positionLocation);
+ gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 24, 0);
+ gl.enableVertexAttribArray(normalLocation);
+ gl.vertexAttribPointer(normalLocation, 3, gl.FLOAT, false, 24, 12);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, instanceBuffer);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ instances[meshName].data.byteLength,
+ gl.DYNAMIC_DRAW,
+ );
+ columnLocations.forEach((columnLocation, columnIndex) => {
+ gl.enableVertexAttribArray(columnLocation);
+ gl.vertexAttribPointer(
+ columnLocation,
+ 4,
+ gl.FLOAT,
+ false,
+ instanceStride,
+ columnIndex * 16,
+ );
+ gl.vertexAttribDivisor(columnLocation, 1);
+ });
+ gl.enableVertexAttribArray(albedoLocation);
+ gl.vertexAttribPointer(
+ albedoLocation,
+ 1,
+ gl.FLOAT,
+ false,
+ instanceStride,
+ 64,
+ );
+ gl.vertexAttribDivisor(albedoLocation, 1);
+
+ return {
+ vertexArray,
+ vertexBuffer,
+ instanceBuffer,
+ vertexCount: vertexData.length / 6,
+ };
+ };
+
+ const cubeMesh = createMeshResources('cube');
+ const cylinderMesh = createMeshResources('cylinder');
+ const coneMesh = createMeshResources('cone');
+ const mixerDrumMesh = createMeshResources('mixerDrum');
+ gl.bindVertexArray(null);
+
+ if (
+ !isDefined(cubeMesh) ||
+ !isDefined(cylinderMesh) ||
+ !isDefined(coneMesh) ||
+ !isDefined(mixerDrumMesh)
+ ) {
+ return null;
+ }
+
+ const createUniformLookup = (program: WebGLProgram): UniformLookup => {
+ const locations = new Map<string, WebGLUniformLocation | null>();
+ return (name) => {
+ if (!locations.has(name)) {
+ locations.set(name, gl.getUniformLocation(program, name));
+ }
+ return locations.get(name) ?? null;
+ };
+ };
+
+ return {
+ sceneProgram,
+ halftoneProgram,
+ sceneUniform: createUniformLookup(sceneProgram),
+ halftoneUniform: createUniformLookup(halftoneProgram),
+ meshes: {
+ cube: cubeMesh,
+ cylinder: cylinderMesh,
+ cone: coneMesh,
+ mixerDrum: mixerDrumMesh,
+ },
+ sceneTexture,
+ sceneDepthBuffer,
+ sceneFramebuffer,
+ emptyVertexArray,
+ };
+ };
+
+ const allocateSceneTarget = () => {
+ if (!isDefined(resources)) {
+ return;
+ }
+
+ gl.bindTexture(gl.TEXTURE_2D, resources.sceneTexture);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA8,
+ sceneWidth,
+ sceneHeight,
+ 0,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ null,
+ );
+ gl.texParameteri(
+ gl.TEXTURE_2D,
+ gl.TEXTURE_MIN_FILTER,
+ gl.LINEAR_MIPMAP_LINEAR,
+ );
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+ gl.bindRenderbuffer(gl.RENDERBUFFER, resources.sceneDepthBuffer);
+ gl.renderbufferStorage(
+ gl.RENDERBUFFER,
+ gl.DEPTH_COMPONENT24,
+ sceneWidth,
+ sceneHeight,
+ );
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, resources.sceneFramebuffer);
+ gl.framebufferTexture2D(
+ gl.FRAMEBUFFER,
+ gl.COLOR_ATTACHMENT0,
+ gl.TEXTURE_2D,
+ resources.sceneTexture,
+ 0,
+ );
+ gl.framebufferRenderbuffer(
+ gl.FRAMEBUFFER,
+ gl.DEPTH_ATTACHMENT,
+ gl.RENDERBUFFER,
+ resources.sceneDepthBuffer,
+ );
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ };
+
+ const getLayout = (): OnboardingConstructionSiteLayout => {
+ const halfHeight = Math.tan(FIELD_OF_VIEW_RADIANS / 2) * CAMERA_DISTANCE;
+ const halfWidth = halfHeight * (cssWidth / Math.max(cssHeight, 1));
+ return {
+ halfWidth,
+ halfHeight,
+ contentHalfWidth:
+ ((contentColumnWidth / 2 + CONTENT_GAP_CSS_PIXELS) /
+ Math.max(cssWidth, 1)) *
+ 2 *
+ halfWidth,
+ groundY: -halfHeight,
+ };
+ };
+
+ const renderFrame = () => {
+ if (!isDefined(resources) || cssWidth < 1 || cssHeight < 1 || !hasStage) {
+ return;
+ }
+
+ const finaleBump = timeline.getFinaleBump();
+
+ const layout = getLayout();
+ buildOnboardingConstructionSiteScene({
+ instances,
+ layout,
+ construction: timeline.getConstruction(),
+ truckConstruction: truckTimeline.getConstruction(),
+ craneMotion: timeline.getMotion(),
+ });
+
+ const eye = [0, layout.groundY, CAMERA_DISTANCE] as const;
+ const viewProjection = multiplyMatrices(
+ createPerspectiveMatrix(
+ FIELD_OF_VIEW_RADIANS,
+ cssWidth / cssHeight,
+ 0.1,
+ 60,
+ layout.groundY / layout.halfHeight,
+ ),
+ createLookAtMatrix(eye, [0, layout.groundY, 0]),
+ );
+
+ const lightAngle = (settings.keyLightAngleDegrees * Math.PI) / 180;
+ const lightHeight = settings.keyLightHeight;
+ const lightX = Math.cos(lightAngle) * 5;
+ const lightZ = Math.sin(lightAngle) * 5;
+ const lightLength = Math.hypot(lightX, lightHeight, lightZ);
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, resources.sceneFramebuffer);
+ gl.viewport(0, 0, sceneWidth, sceneHeight);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clearDepth(1);
+ gl.enable(gl.DEPTH_TEST);
+ gl.disable(gl.BLEND);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ const { sceneUniform, halftoneUniform } = resources;
+ gl.useProgram(resources.sceneProgram);
+ gl.uniformMatrix4fv(sceneUniform('viewProjection'), false, viewProjection);
+ gl.uniform3f(
+ sceneUniform('keyLightDirection'),
+ lightX / lightLength,
+ lightHeight / lightLength,
+ lightZ / lightLength,
+ );
+ gl.uniform1f(sceneUniform('keyLightIntensity'), settings.keyLightIntensity);
+ gl.uniform3f(
+ sceneUniform('fillLightDirection'),
+ FILL_LIGHT_DIRECTION[0],
+ FILL_LIGHT_DIRECTION[1],
+ FILL_LIGHT_DIRECTION[2],
+ );
+ gl.uniform1f(
+ sceneUniform('fillLightIntensity'),
+ settings.fillLightIntensity,
+ );
+ gl.uniform1f(sceneUniform('ambientIntensity'), settings.ambientIntensity);
+ gl.uniform1f(
+ sceneUniform('environmentIntensity'),
+ settings.environmentIntensity,
+ );
+ gl.uniform1f(sceneUniform('roughness'), settings.materialRoughness);
+ gl.uniform1f(sceneUniform('metalness'), settings.materialMetalness);
+ gl.uniform3f(sceneUniform('cameraPosition'), eye[0], eye[1], eye[2]);
+
+ for (const meshName of MESH_NAMES) {
+ const batch = instances[meshName];
+ if (batch.count === 0) {
+ continue;
+ }
+ const mesh = resources.meshes[meshName];
+ gl.bindVertexArray(mesh.vertexArray);
+ gl.bindBuffer(gl.ARRAY_BUFFER, mesh.instanceBuffer);
+ gl.bufferSubData(
+ gl.ARRAY_BUFFER,
+ 0,
+ batch.data,
+ 0,
+ batch.count * ONBOARDING_CONSTRUCTION_SITE_FLOATS_PER_INSTANCE,
+ );
+ gl.drawArraysInstanced(gl.TRIANGLES, 0, mesh.vertexCount, batch.count);
+ }
+ gl.bindVertexArray(null);
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.viewport(0, 0, canvas.width, canvas.height);
+ gl.disable(gl.DEPTH_TEST);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.bindTexture(gl.TEXTURE_2D, resources.sceneTexture);
+ gl.generateMipmap(gl.TEXTURE_2D);
+
+ gl.useProgram(resources.halftoneProgram);
+ const tileSize =
+ settings.dashPitch *
+ Math.min(1, cssHeight / VIRTUAL_RENDER_HEIGHT_CSS_PIXELS) *
+ devicePixelRatio;
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, resources.sceneTexture);
+ gl.uniform1i(halftoneUniform('sceneTexture'), 0);
+ gl.uniform1f(
+ halftoneUniform('sceneLod'),
+ Math.log2(
+ Math.max(
+ (tileSize / devicePixelRatio / 2) * (sceneWidth / cssWidth),
+ 1,
+ ),
+ ),
+ );
+ gl.uniform2f(halftoneUniform('canvasSize'), canvas.width, canvas.height);
+ gl.uniform1f(halftoneUniform('tileSize'), tileSize);
+ gl.uniform1f(halftoneUniform('power'), settings.halftonePower);
+ gl.uniform1f(halftoneUniform('width'), settings.dashWidth);
+ gl.uniform1f(halftoneUniform('dashScale'), settings.dashScale);
+ gl.uniform1f(halftoneUniform('dashThreshold'), settings.dashThreshold);
+ gl.uniform1f(halftoneUniform('dashOpacity'), settings.dashOpacity);
+ gl.uniform3f(
+ halftoneUniform('dashColor'),
+ colors.dashColor[0],
+ colors.dashColor[1],
+ colors.dashColor[2],
+ );
+ gl.uniform1f(halftoneUniform('time'), elapsedSeconds);
+ gl.uniform1f(
+ halftoneUniform('waveAmount'),
+ shouldReduceMotion ? 0 : FINALE_WAVE_AMOUNT * finaleBump,
+ );
+ gl.uniform1f(halftoneUniform('waveSpeed'), 1);
+ gl.uniform1f(
+ halftoneUniform('scatterAmount'),
+ FINALE_SCATTER_AMOUNT * finaleBump,
+ );
+ gl.uniform3f(
+ halftoneUniform('contentColumn'),
+ canvas.width / 2,
+ (contentColumnWidth / 2 + CONTENT_GAP_CSS_PIXELS / 2) * devicePixelRatio,
+ CONTENT_FEATHER_CSS_PIXELS * devicePixelRatio,
+ );
+ gl.uniform1f(
+ halftoneUniform('contentColumnOpacity'),
+ settings.contentColumnOpacity,
+ );
+
+ gl.enable(gl.BLEND);
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
+ gl.bindVertexArray(resources.emptyVertexArray);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+ gl.bindVertexArray(null);
+ };
+
+ const tick = (nowMs: number) => {
+ animationFrameHandle = null;
+ if (isDestroyed || cssWidth < 1 || cssHeight < 1) {
+ return;
+ }
+
+ const deltaSeconds = isDefined(lastFrameTimeMs)
+ ? Math.min((nowMs - lastFrameTimeMs) / 1000, 0.1)
+ : 0;
+ elapsedSeconds += deltaSeconds;
+ timeline.advance(deltaSeconds);
+ truckTimeline.advance(deltaSeconds);
+ renderFrame();
+
+ if (timeline.isTransitioning() || truckTimeline.isTransitioning()) {
+ lastFrameTimeMs = nowMs;
+ animationFrameHandle = requestAnimationFrame(tick);
+ } else {
+ lastFrameTimeMs = null;
+ }
+ };
+
+ const requestRender = () => {
+ if (shouldReduceMotion) {
+ renderFrame();
+ return;
+ }
+ if (!isDefined(animationFrameHandle)) {
+ animationFrameHandle = requestAnimationFrame(tick);
+ }
+ };
+
+ const resize = () => {
+ cssWidth = canvas.clientWidth;
+ cssHeight = canvas.clientHeight;
+ devicePixelRatio = Math.min(
+ Math.max(1, window.devicePixelRatio || 1),
+ MAXIMUM_DEVICE_PIXEL_RATIO,
+ Math.sqrt(MAXIMUM_CANVAS_PIXELS / Math.max(cssWidth * cssHeight, 1)),
+ );
+ const sceneScale = Math.min(1, devicePixelRatio);
+ canvas.width = Math.max(1, Math.round(cssWidth * devicePixelRatio));
+ canvas.height = Math.max(1, Math.round(cssHeight * devicePixelRatio));
+ sceneWidth = Math.max(1, Math.round(cssWidth * sceneScale));
+ sceneHeight = Math.max(1, Math.round(cssHeight * sceneScale));
+ allocateSceneTarget();
+ renderFrame();
+ };
+
+ const handleContextLost = (event: Event) => {
+ event.preventDefault();
+ resources = null;
+ };
+
+ const handleContextRestored = () => {
+ resources = createResources();
+ allocateSceneTarget();
+ requestRender();
+ };
+
+ resources = createResources();
+ if (!isDefined(resources)) {
+ return null;
+ }
+
+ canvas.addEventListener('webglcontextlost', handleContextLost);
+ canvas.addEventListener('webglcontextrestored', handleContextRestored);
+ resize();
+
+ return {
+ setStage: ({ stageIndex }) => {
+ if (shouldReduceMotion) {
+ timeline.jumpToStageIndex(stageIndex);
+ truckTimeline.jumpToStageIndex(stageIndex);
+ } else {
+ timeline.setTargetStageIndex(stageIndex);
+ if (hasStage) {
+ truckTimeline.setTargetStageIndex(stageIndex);
+ } else {
+ truckTimeline.jumpToStageIndex(stageIndex);
+ }
+ }
+ hasStage = true;
+ requestRender();
+ },
+ setColors: (nextColors) => {
+ colors = nextColors;
+ requestRender();
+ },
+ resize,
+ destroy: () => {
+ isDestroyed = true;
+ if (isDefined(animationFrameHandle)) {
+ cancelAnimationFrame(animationFrameHandle);
+ }
+ canvas.removeEventListener('webglcontextlost', handleContextLost);
+ canvas.removeEventListener('webglcontextrestored', handleContextRestored);
+ if (isDefined(resources)) {
+ deleteResources(gl, resources);
+ resources = null;
+ }
+ },
+ };
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteTimeline.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteTimeline.ts
new file mode 100644
index 00000000000..bc04a75a4e4
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/createOnboardingConstructionSiteTimeline.ts
@@ -0,0 +1,183 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX } from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import { type OnboardingConstructionSiteConstruction } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteConstruction';
+
+const INITIAL_STAGE_INDEX = -1;
+const TRANSITION_SECONDS_PER_STEP = 1.6;
+
+type Transition = {
+ lowerStageIndex: number;
+ segments: { upperStageIndex: number; startPosition: number }[];
+ position: number;
+ direction: 1 | -1;
+ durationSeconds: number;
+};
+
+const clampToUnitRange = (value: number) => Math.max(0, Math.min(1, value));
+
+const easeInOutCubic = (ratio: number) =>
+ ratio < 0.5 ? 4 * ratio * ratio * ratio : 1 - Math.pow(-2 * ratio + 2, 3) / 2;
+
+export type OnboardingConstructionSiteTimeline = {
+ setTargetStageIndex: (stageIndex: number) => void;
+ jumpToStageIndex: (stageIndex: number) => void;
+ advance: (deltaSeconds: number) => void;
+ isTransitioning: () => boolean;
+ getConstruction: () => OnboardingConstructionSiteConstruction;
+ getMotion: () => number;
+ getFinaleBump: () => number;
+};
+
+export const createOnboardingConstructionSiteTimeline = ({
+ transitionSecondsPerStep = TRANSITION_SECONDS_PER_STEP,
+ easing = easeInOutCubic,
+}: {
+ transitionSecondsPerStep?: number;
+ easing?: (ratio: number) => number;
+} = {}): OnboardingConstructionSiteTimeline => {
+ const getTransitionSeconds = (stepCount: number) =>
+ transitionSecondsPerStep * Math.sqrt(stepCount);
+ let settledStageIndex = INITIAL_STAGE_INDEX;
+ let transition: Transition | null = null;
+ let pendingStageIndex: number | null = null;
+
+ const getUpperStageIndex = (activeTransition: Transition) =>
+ activeTransition.segments[activeTransition.segments.length - 1]
+ .upperStageIndex;
+
+ const getTargetStageIndex = (activeTransition: Transition) =>
+ activeTransition.direction > 0
+ ? getUpperStageIndex(activeTransition)
+ : activeTransition.lowerStageIndex;
+
+ const getSourceStageIndex = (activeTransition: Transition) =>
+ activeTransition.direction > 0
+ ? activeTransition.lowerStageIndex
+ : getUpperStageIndex(activeTransition);
+
+ const startTransition = (targetStageIndex: number) => {
+ if (targetStageIndex === settledStageIndex) {
+ return;
+ }
+
+ const isBuildingUp = targetStageIndex > settledStageIndex;
+ transition = {
+ lowerStageIndex: Math.min(settledStageIndex, targetStageIndex),
+ segments: [
+ {
+ upperStageIndex: Math.max(settledStageIndex, targetStageIndex),
+ startPosition: 0,
+ },
+ ],
+ position: isBuildingUp ? 0 : 1,
+ direction: isBuildingUp ? 1 : -1,
+ durationSeconds: getTransitionSeconds(
+ Math.abs(targetStageIndex - settledStageIndex),
+ ),
+ };
+ };
+
+ const extendTransition = (
+ activeTransition: Transition,
+ targetStageIndex: number,
+ ) => {
+ const remainingRatio = Math.max(1 - activeTransition.position, 0.001);
+ const remainingSeconds = Math.max(
+ remainingRatio * activeTransition.durationSeconds,
+ getTransitionSeconds(
+ targetStageIndex - getUpperStageIndex(activeTransition),
+ ),
+ );
+ activeTransition.segments.push({
+ upperStageIndex: targetStageIndex,
+ startPosition: activeTransition.position,
+ });
+ activeTransition.durationSeconds = remainingSeconds / remainingRatio;
+ };
+
+ const getGrowth = () =>
+ isDefined(transition) ? easing(transition.position) : 1;
+
+ return {
+ setTargetStageIndex: (stageIndex) => {
+ if (!isDefined(transition)) {
+ startTransition(stageIndex);
+ } else if (stageIndex === getTargetStageIndex(transition)) {
+ pendingStageIndex = null;
+ } else if (stageIndex === getSourceStageIndex(transition)) {
+ transition.direction = transition.direction > 0 ? -1 : 1;
+ pendingStageIndex = null;
+ } else if (
+ transition.direction > 0 &&
+ stageIndex > getUpperStageIndex(transition)
+ ) {
+ extendTransition(transition, stageIndex);
+ pendingStageIndex = null;
+ } else {
+ pendingStageIndex = stageIndex;
+ }
+ },
+ jumpToStageIndex: (stageIndex) => {
+ settledStageIndex = stageIndex;
+ transition = null;
+ pendingStageIndex = null;
+ },
+ advance: (deltaSeconds) => {
+ if (!isDefined(transition)) {
+ return;
+ }
+
+ transition.position = clampToUnitRange(
+ transition.position +
+ (transition.direction * deltaSeconds) / transition.durationSeconds,
+ );
+ if (transition.position !== (transition.direction > 0 ? 1 : 0)) {
+ return;
+ }
+
+ settledStageIndex = getTargetStageIndex(transition);
+ transition = null;
+ if (isDefined(pendingStageIndex)) {
+ startTransition(pendingStageIndex);
+ pendingStageIndex = null;
+ }
+ },
+ isTransitioning: () => isDefined(transition),
+ getConstruction: () => {
+ if (!isDefined(transition)) {
+ return {
+ builtStageIndex: settledStageIndex,
+ growingStageGrowths: [],
+ };
+ }
+
+ const { lowerStageIndex, segments, position } = transition;
+ const growingStageGrowths = segments.flatMap(
+ ({ upperStageIndex, startPosition }, segmentIndex) => {
+ const segmentLowerStageIndex =
+ segmentIndex === 0
+ ? lowerStageIndex
+ : segments[segmentIndex - 1].upperStageIndex;
+ const growth = easing(
+ clampToUnitRange((position - startPosition) / (1 - startPosition)),
+ );
+ return Array.from(
+ { length: upperStageIndex - segmentLowerStageIndex },
+ () => growth,
+ );
+ },
+ );
+
+ return { builtStageIndex: lowerStageIndex, growingStageGrowths };
+ },
+ getMotion: () =>
+ isDefined(transition) ? Math.sin(Math.PI * getGrowth()) : 0,
+ getFinaleBump: () =>
+ isDefined(transition) &&
+ getUpperStageIndex(transition) ===
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX
+ ? Math.pow(Math.sin(Math.PI * getGrowth()), 2)
+ : 0,
+ };
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/getOnboardingConstructionSiteStage.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/getOnboardingConstructionSiteStage.ts
new file mode 100644
index 00000000000..fad755ba125
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/getOnboardingConstructionSiteStage.ts
@@ -0,0 +1,40 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX } from '@/onboarding/components/OnboardingConstructionSite/buildOnboardingConstructionSiteScene';
+import { type OnboardingConstructionSiteStage } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteStage';
+import { ONBOARDING_STATUS_ORDER } from '@/onboarding/constants/OnboardingStatusOrder';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+// The site starts on the first step rendered by OnboardingStepLayout, and its
+// final stage is kept for the finale, which only the last onboarding step
+// reaches, whichever status that is for the workspace.
+const FIRST_STAGE_STATUS_INDEX = ONBOARDING_STATUS_ORDER.indexOf(
+ OnboardingStatus.SYNC_EMAIL,
+);
+const LAST_REGULAR_STAGE_INDEX =
+ ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX - 1;
+
+type GetOnboardingConstructionSiteStageArgs = {
+ onboardingStatus: OnboardingStatus | null | undefined;
+ isLastOnboardingStep: boolean;
+};
+
+export const getOnboardingConstructionSiteStage = ({
+ onboardingStatus,
+ isLastOnboardingStep,
+}: GetOnboardingConstructionSiteStageArgs): OnboardingConstructionSiteStage => {
+ if (isLastOnboardingStep) {
+ return { stageIndex: ONBOARDING_CONSTRUCTION_SITE_FINAL_STAGE_INDEX };
+ }
+
+ const statusIndex = isDefined(onboardingStatus)
+ ? ONBOARDING_STATUS_ORDER.indexOf(onboardingStatus)
+ : -1;
+
+ return {
+ stageIndex: Math.min(
+ Math.max(statusIndex - FIRST_STAGE_STATUS_INDEX, 0),
+ LAST_REGULAR_STAGE_INDEX,
+ ),
+ };
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteDefaultSettings.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteDefaultSettings.ts
new file mode 100644
index 00000000000..c4d920ca44e
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteDefaultSettings.ts
@@ -0,0 +1,20 @@
+import { type OnboardingConstructionSiteSettings } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSiteSettings';
+
+export const ONBOARDING_CONSTRUCTION_SITE_DEFAULT_SETTINGS: OnboardingConstructionSiteSettings =
+ {
+ dashPitch: 6,
+ dashWidth: 0.7,
+ dashScale: 0.5,
+ dashThreshold: 0.18,
+ dashOpacity: 1,
+ halftonePower: 0.5,
+ contentColumnOpacity: 0.45,
+ keyLightAngleDegrees: 40,
+ keyLightHeight: 2,
+ keyLightIntensity: 1.6,
+ fillLightIntensity: 0.15,
+ ambientIntensity: 0.08,
+ environmentIntensity: 0.25,
+ materialRoughness: 0.42,
+ materialMetalness: 0.16,
+ };
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices.ts
new file mode 100644
index 00000000000..c64202bc6cf
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMatrices.ts
@@ -0,0 +1,135 @@
+export type OnboardingConstructionSiteVector = readonly [
+ number,
+ number,
+ number,
+];
+
+export const createPerspectiveMatrix = (
+ verticalFieldOfViewRadians: number,
+ aspectRatio: number,
+ near: number,
+ far: number,
+ verticalShift = 0,
+) => {
+ const focalLength = 1 / Math.tan(verticalFieldOfViewRadians / 2);
+ const depthRange = 1 / (near - far);
+
+ return new Float32Array([
+ focalLength / aspectRatio,
+ 0,
+ 0,
+ 0,
+ 0,
+ focalLength,
+ 0,
+ 0,
+ 0,
+ -verticalShift,
+ (far + near) * depthRange,
+ -1,
+ 0,
+ 0,
+ 2 * far * near * depthRange,
+ 0,
+ ]);
+};
+
+export const createLookAtMatrix = (
+ eye: OnboardingConstructionSiteVector,
+ target: OnboardingConstructionSiteVector,
+) => {
+ const forwardX = eye[0] - target[0];
+ const forwardY = eye[1] - target[1];
+ const forwardZ = eye[2] - target[2];
+ const forwardLength = Math.hypot(forwardX, forwardY, forwardZ) || 1;
+ const zAxisX = forwardX / forwardLength;
+ const zAxisY = forwardY / forwardLength;
+ const zAxisZ = forwardZ / forwardLength;
+
+ const rightX = zAxisZ;
+ const rightZ = -zAxisX;
+ const rightLength = Math.hypot(rightX, rightZ) || 1;
+ const xAxisX = rightX / rightLength;
+ const xAxisZ = rightZ / rightLength;
+
+ const yAxisX = zAxisY * xAxisZ;
+ const yAxisY = zAxisZ * xAxisX - zAxisX * xAxisZ;
+ const yAxisZ = -zAxisY * xAxisX;
+
+ return new Float32Array([
+ xAxisX,
+ yAxisX,
+ zAxisX,
+ 0,
+ 0,
+ yAxisY,
+ zAxisY,
+ 0,
+ xAxisZ,
+ yAxisZ,
+ zAxisZ,
+ 0,
+ -(xAxisX * eye[0] + xAxisZ * eye[2]),
+ -(yAxisX * eye[0] + yAxisY * eye[1] + yAxisZ * eye[2]),
+ -(zAxisX * eye[0] + zAxisY * eye[1] + zAxisZ * eye[2]),
+ 1,
+ ]);
+};
+
+export const multiplyMatrices = (left: Float32Array, right: Float32Array) => {
+ const product = new Float32Array(16);
+
+ for (let column = 0; column < 4; column++) {
+ for (let row = 0; row < 4; row++) {
+ let sum = 0;
+ for (let index = 0; index < 4; index++) {
+ sum += left[index * 4 + row] * right[column * 4 + index];
+ }
+ product[column * 4 + row] = sum;
+ }
+ }
+
+ return product;
+};
+
+export const writeTransformMatrix = (
+ target: Float32Array,
+ offset: number,
+ position: OnboardingConstructionSiteVector,
+ rotation: OnboardingConstructionSiteVector,
+ scale: OnboardingConstructionSiteVector,
+) => {
+ const cosineX = Math.cos(rotation[0]);
+ const sineX = Math.sin(rotation[0]);
+ const cosineY = Math.cos(rotation[1]);
+ const sineY = Math.sin(rotation[1]);
+ const cosineZ = Math.cos(rotation[2]);
+ const sineZ = Math.sin(rotation[2]);
+
+ const m00 = cosineY * cosineZ + sineY * sineX * sineZ;
+ const m01 = cosineX * sineZ;
+ const m02 = -sineY * cosineZ + cosineY * sineX * sineZ;
+ const m10 = -cosineY * sineZ + sineY * sineX * cosineZ;
+ const m11 = cosineX * cosineZ;
+ const m12 = sineY * sineZ + cosineY * sineX * cosineZ;
+ const m20 = sineY * cosineX;
+ const m21 = -sineX;
+ const m22 = cosineY * cosineX;
+
+ target[offset] = m00 * scale[0];
+ target[offset + 1] = m01 * scale[0];
+ target[offset + 2] = m02 * scale[0];
+ target[offset + 3] = 0;
+ target[offset + 4] = m10 * scale[1];
+ target[offset + 5] = m11 * scale[1];
+ target[offset + 6] = m12 * scale[1];
+ target[offset + 7] = 0;
+ target[offset + 8] = m20 * scale[2];
+ target[offset + 9] = m21 * scale[2];
+ target[offset + 10] = m22 * scale[2];
+ target[offset + 11] = 0;
+ target[offset + 12] = position[0];
+ target[offset + 13] = position[1];
+ target[offset + 14] = position[2];
+ target[offset + 15] = 1;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMeshes.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMeshes.ts
new file mode 100644
index 00000000000..4e3daa6a2fe
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteMeshes.ts
@@ -0,0 +1,196 @@
+const ROUND_MESH_SEGMENT_COUNT = 48;
+
+type Vertex = readonly [number, number, number, number, number, number];
+
+const toVertexData = (vertices: Vertex[]) => Float32Array.from(vertices.flat());
+
+const buildCubeVertices = () => {
+ const faces: {
+ normal: readonly [number, number, number];
+ corners: readonly (readonly [number, number, number])[];
+ }[] = [
+ {
+ normal: [1, 0, 0],
+ corners: [
+ [0.5, -0.5, 0.5],
+ [0.5, -0.5, -0.5],
+ [0.5, 0.5, -0.5],
+ [0.5, 0.5, 0.5],
+ ],
+ },
+ {
+ normal: [-1, 0, 0],
+ corners: [
+ [-0.5, -0.5, -0.5],
+ [-0.5, -0.5, 0.5],
+ [-0.5, 0.5, 0.5],
+ [-0.5, 0.5, -0.5],
+ ],
+ },
+ {
+ normal: [0, 1, 0],
+ corners: [
+ [-0.5, 0.5, 0.5],
+ [0.5, 0.5, 0.5],
+ [0.5, 0.5, -0.5],
+ [-0.5, 0.5, -0.5],
+ ],
+ },
+ {
+ normal: [0, -1, 0],
+ corners: [
+ [-0.5, -0.5, -0.5],
+ [0.5, -0.5, -0.5],
+ [0.5, -0.5, 0.5],
+ [-0.5, -0.5, 0.5],
+ ],
+ },
+ {
+ normal: [0, 0, 1],
+ corners: [
+ [-0.5, -0.5, 0.5],
+ [0.5, -0.5, 0.5],
+ [0.5, 0.5, 0.5],
+ [-0.5, 0.5, 0.5],
+ ],
+ },
+ {
+ normal: [0, 0, -1],
+ corners: [
+ [0.5, -0.5, -0.5],
+ [-0.5, -0.5, -0.5],
+ [-0.5, 0.5, -0.5],
+ [0.5, 0.5, -0.5],
+ ],
+ },
+ ];
+
+ return toVertexData(
+ faces.flatMap(({ normal, corners }) =>
+ [0, 1, 2, 0, 2, 3].map(
+ (cornerIndex): Vertex => [...corners[cornerIndex], ...normal],
+ ),
+ ),
+ );
+};
+
+type RoundProfile = readonly (readonly [height: number, radius: number])[];
+
+const buildRoundVertices = (profile: RoundProfile) => {
+ const vertices: Vertex[] = [];
+
+ for (let segment = 0; segment < ROUND_MESH_SEGMENT_COUNT; segment++) {
+ const startAngle = (segment / ROUND_MESH_SEGMENT_COUNT) * Math.PI * 2;
+ const endAngle = ((segment + 1) / ROUND_MESH_SEGMENT_COUNT) * Math.PI * 2;
+ const startCosine = Math.cos(startAngle);
+ const startSine = Math.sin(startAngle);
+ const endCosine = Math.cos(endAngle);
+ const endSine = Math.sin(endAngle);
+
+ for (let ringIndex = 0; ringIndex < profile.length - 1; ringIndex++) {
+ const [bottomHeight, bottomRadius] = profile[ringIndex];
+ const [topHeight, topRadius] = profile[ringIndex + 1];
+ const slope = (bottomRadius - topRadius) / (topHeight - bottomHeight);
+ const sideNormalLength = Math.hypot(1, slope);
+ const sideNormal = (cosine: number, sine: number) =>
+ [
+ cosine / sideNormalLength,
+ slope / sideNormalLength,
+ sine / sideNormalLength,
+ ] as const;
+
+ const bottomStart: Vertex = [
+ startCosine * bottomRadius,
+ bottomHeight,
+ startSine * bottomRadius,
+ ...sideNormal(startCosine, startSine),
+ ];
+ const bottomEnd: Vertex = [
+ endCosine * bottomRadius,
+ bottomHeight,
+ endSine * bottomRadius,
+ ...sideNormal(endCosine, endSine),
+ ];
+ const topStart: Vertex = [
+ startCosine * topRadius,
+ topHeight,
+ startSine * topRadius,
+ ...sideNormal(startCosine, startSine),
+ ];
+ const topEnd: Vertex = [
+ endCosine * topRadius,
+ topHeight,
+ endSine * topRadius,
+ ...sideNormal(endCosine, endSine),
+ ];
+
+ vertices.push(
+ bottomStart,
+ topEnd,
+ bottomEnd,
+ bottomStart,
+ topStart,
+ topEnd,
+ );
+ }
+
+ const [bottomHeight, bottomRadius] = profile[0];
+ const [topHeight, topRadius] = profile[profile.length - 1];
+ vertices.push(
+ [0, bottomHeight, 0, 0, -1, 0],
+ [
+ endCosine * bottomRadius,
+ bottomHeight,
+ endSine * bottomRadius,
+ 0,
+ -1,
+ 0,
+ ],
+ [
+ startCosine * bottomRadius,
+ bottomHeight,
+ startSine * bottomRadius,
+ 0,
+ -1,
+ 0,
+ ],
+ );
+
+ if (topRadius > 0) {
+ vertices.push(
+ [0, topHeight, 0, 0, 1, 0],
+ [startCosine * topRadius, topHeight, startSine * topRadius, 0, 1, 0],
+ [endCosine * topRadius, topHeight, endSine * topRadius, 0, 1, 0],
+ );
+ }
+ }
+
+ return toVertexData(vertices);
+};
+
+export const ONBOARDING_CONSTRUCTION_SITE_MESHES = {
+ cube: buildCubeVertices(),
+ cylinder: buildRoundVertices([
+ [-0.5, 0.47],
+ [-0.47, 0.5],
+ [0.47, 0.5],
+ [0.5, 0.47],
+ ]),
+ cone: buildRoundVertices([
+ [-0.5, 0.5],
+ [0.5, 0],
+ ]),
+ mixerDrum: buildRoundVertices([
+ [-0.5, 0.18],
+ [-0.43, 0.2],
+ [-0.2, 0.43],
+ [-0.17, 0.48],
+ [-0.1, 0.48],
+ [-0.07, 0.46],
+ [0.2, 0.46],
+ [0.23, 0.49],
+ [0.3, 0.49],
+ [0.34, 0.44],
+ [0.5, 0.28],
+ ]),
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteShaders.ts b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteShaders.ts
new file mode 100644
index 00000000000..f27f43d5cbf
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingConstructionSite/onboardingConstructionSiteShaders.ts
@@ -0,0 +1,205 @@
+const SCENE_VERTEX_SHADER = `#version 300 es
+ in vec3 position;
+ in vec3 normal;
+ in vec4 instanceColumn0;
+ in vec4 instanceColumn1;
+ in vec4 instanceColumn2;
+ in vec4 instanceColumn3;
+ in float instanceAlbedo;
+
+ uniform mat4 viewProjection;
+
+ out vec3 worldNormal;
+ out vec3 worldPosition;
+ out float albedo;
+
+ void main() {
+ mat4 model = mat4(instanceColumn0, instanceColumn1, instanceColumn2, instanceColumn3);
+ vec4 world = model * vec4(position, 1.0);
+ worldPosition = world.xyz;
+ worldNormal = transpose(inverse(mat3(model))) * normal;
+ albedo = instanceAlbedo;
+ gl_Position = viewProjection * world;
+ }
+`;
+
+const SCENE_FRAGMENT_SHADER = `#version 300 es
+ precision highp float;
+
+ const float PI = 3.141592653589793;
+
+ in vec3 worldNormal;
+ in vec3 worldPosition;
+ in float albedo;
+
+ uniform vec3 keyLightDirection;
+ uniform float keyLightIntensity;
+ uniform vec3 fillLightDirection;
+ uniform float fillLightIntensity;
+ uniform float ambientIntensity;
+ uniform float environmentIntensity;
+ uniform float roughness;
+ uniform float metalness;
+ uniform vec3 cameraPosition;
+
+ out vec4 fragmentColor;
+
+ float getDistribution(float normalDotHalf, float alpha) {
+ float alphaSquared = alpha * alpha;
+ float denominator = normalDotHalf * normalDotHalf * (alphaSquared - 1.0) + 1.0;
+ return alphaSquared / (PI * denominator * denominator);
+ }
+
+ float getVisibility(float normalDotLight, float normalDotView, float alpha) {
+ float alphaSquared = alpha * alpha;
+ float viewTerm = normalDotLight *
+ sqrt(normalDotView * normalDotView * (1.0 - alphaSquared) + alphaSquared);
+ float lightTerm = normalDotView *
+ sqrt(normalDotLight * normalDotLight * (1.0 - alphaSquared) + alphaSquared);
+ return 0.5 / max(viewTerm + lightTerm, 0.00001);
+ }
+
+ vec3 getFresnel(vec3 reflectance, float viewDotHalf) {
+ float fresnel = exp2((-5.55473 * viewDotHalf - 6.98316) * viewDotHalf);
+ return reflectance * (1.0 - fresnel) + fresnel;
+ }
+
+ vec3 getDirectLight(
+ vec3 surfaceNormal,
+ vec3 viewDirection,
+ vec3 lightDirection,
+ float intensity,
+ vec3 diffuseColor,
+ vec3 specularColor,
+ float alpha
+ ) {
+ float normalDotLight = clamp(dot(surfaceNormal, lightDirection), 0.0, 1.0);
+ vec3 halfVector = normalize(lightDirection + viewDirection);
+ float normalDotHalf = clamp(dot(surfaceNormal, halfVector), 0.0, 1.0);
+ float normalDotView = clamp(dot(surfaceNormal, viewDirection), 0.0001, 1.0);
+ float viewDotHalf = clamp(dot(viewDirection, halfVector), 0.0, 1.0);
+ vec3 specular = getFresnel(specularColor, viewDotHalf) *
+ getVisibility(normalDotLight, normalDotView, alpha) *
+ getDistribution(normalDotHalf, alpha);
+ return normalDotLight * intensity * (diffuseColor / PI + specular);
+ }
+
+ float getEnvironmentRadiance(vec3 direction) {
+ return 0.42 + 0.38 * direction.y;
+ }
+
+ void main() {
+ vec3 surfaceNormal = normalize(worldNormal);
+ vec3 viewDirection = normalize(cameraPosition - worldPosition);
+ vec3 baseColor = vec3(albedo);
+ vec3 diffuseColor = baseColor * (1.0 - metalness);
+ vec3 specularColor = mix(vec3(0.04), baseColor, metalness);
+ float alpha = roughness * roughness;
+
+ vec3 radiance =
+ getDirectLight(surfaceNormal, viewDirection, keyLightDirection, keyLightIntensity, diffuseColor, specularColor, alpha) +
+ getDirectLight(surfaceNormal, viewDirection, fillLightDirection, fillLightIntensity, diffuseColor, specularColor, alpha) +
+ diffuseColor * ambientIntensity / PI;
+
+ float normalDotView = clamp(dot(surfaceNormal, viewDirection), 0.0, 1.0);
+ vec3 reflected = reflect(-viewDirection, surfaceNormal);
+ radiance += environmentIntensity * (
+ diffuseColor * getEnvironmentRadiance(surfaceNormal) +
+ getFresnel(specularColor, normalDotView) *
+ getEnvironmentRadiance(reflected) * (1.0 - roughness * 0.5)
+ );
+
+ fragmentColor = vec4(clamp(radiance, 0.0, 1.0), 1.0);
+ }
+`;
+
+const FULL_SCREEN_VERTEX_SHADER = `#version 300 es
+ const vec2 corners[3] = vec2[3](vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0));
+
+ void main() {
+ gl_Position = vec4(corners[gl_VertexID], 0.0, 1.0);
+ }
+`;
+
+const HALFTONE_FRAGMENT_SHADER = `#version 300 es
+ precision highp float;
+
+ uniform sampler2D sceneTexture;
+ uniform float sceneLod;
+ uniform vec2 canvasSize;
+ uniform float tileSize;
+ uniform float power;
+ uniform float width;
+ uniform vec3 dashColor;
+ uniform float dashScale;
+ uniform float dashThreshold;
+ uniform float time;
+ uniform float waveAmount;
+ uniform float waveSpeed;
+ uniform float scatterAmount;
+ uniform vec3 contentColumn;
+ uniform float contentColumnOpacity;
+ uniform float dashOpacity;
+
+ out vec4 fragmentColor;
+
+ float getCapsuleDistance(vec2 cellPosition, float radius, float thickness) {
+ vec2 segmentStart = vec2(0.5 - radius, 0.5);
+ vec2 segment = vec2(2.0 * radius, 0.0);
+ vec2 offset = cellPosition - segmentStart;
+ float projection = clamp(
+ dot(offset, segment) / max(dot(segment, segment), 0.000001),
+ 0.0,
+ 1.0
+ );
+ return length(offset - segment * projection) - thickness * radius;
+ }
+
+ float hash(vec2 value) {
+ return fract(sin(dot(value, vec2(127.1, 311.7))) * 43758.5453);
+ }
+
+ void main() {
+ vec2 effectPosition = gl_FragCoord.xy;
+ float row = floor(effectPosition.y / tileSize);
+ effectPosition.x += waveAmount * sin(time * waveSpeed + row * 0.5) * tileSize;
+
+ vec2 cellIndex = floor(effectPosition / tileSize);
+ vec2 cellPosition = fract(effectPosition / tileSize);
+ vec2 cellCenter = (cellIndex + 0.5) * tileSize;
+ vec2 scatterOffset =
+ (vec2(hash(cellIndex), hash(cellIndex + 17.0)) - 0.5) * scatterAmount * 6.0;
+ vec2 sampleCell = cellIndex + floor(scatterOffset + 0.5);
+ vec4 sceneSample = textureLod(
+ sceneTexture,
+ clamp((sampleCell + 0.5) * tileSize / canvasSize, 0.0, 1.0),
+ sceneLod
+ );
+
+ float columnDistance = abs(cellCenter.x - contentColumn.x) - contentColumn.y;
+ float outsideColumn =
+ smoothstep(-contentColumn.z, contentColumn.z, columnDistance);
+ float belowContent =
+ 1.0 - smoothstep(canvasSize.y * 0.12, canvasSize.y * 0.24, cellCenter.y);
+
+ float tone = (sceneSample.r + sceneSample.g + sceneSample.b) / 3.0;
+ float toneLevel = clamp(tone + power * 0.2357, 0.0, 1.0);
+ float radius =
+ max(toneLevel - dashThreshold, 0.0) / (1.0 - dashThreshold) * dashScale;
+ float signedDistance = getCapsuleDistance(cellPosition, radius, width);
+ float edge = 0.5 * fwidth(signedDistance);
+ float alpha =
+ (1.0 - smoothstep(-edge, edge, signedDistance)) * step(0.0001, radius);
+ alpha *= mix(contentColumnOpacity, 1.0, max(outsideColumn, belowContent));
+ alpha *= dashOpacity;
+
+ fragmentColor = vec4(dashColor * alpha, alpha);
+ }
+`;
+
+export const ONBOARDING_CONSTRUCTION_SITE_SHADERS = {
+ sceneVertex: SCENE_VERTEX_SHADER,
+ sceneFragment: SCENE_FRAGMENT_SHADER,
+ fullScreenVertex: FULL_SCREEN_VERTEX_SHADER,
+ halftoneFragment: HALFTONE_FRAGMENT_SHADER,
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingLayout.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingLayout.tsx
index d4d3e2ac453..3258f520413 100644
--- a/packages/twenty-front/src/modules/onboarding/components/OnboardingLayout.tsx
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingLayout.tsx
@@ -1,21 +1,34 @@
import { OnboardingHeader } from '@/onboarding/components/OnboardingHeader';
+import { ONBOARDING_BACKGROUND_COMPONENT_MIN_VIEWPORT_WIDTH } from '@/onboarding/constants/OnboardingBackgroundComponentMinViewportWidth';
import { styled } from '@linaria/react';
import { type ReactNode } from 'react';
+import { isDefined } from 'twenty-shared/utils';
import { themeCssVariables } from 'twenty-ui/theme';
+import { useMediaQuery } from 'twenty-ui/utilities';
const StyledBackground = styled.div`
background: ${themeCssVariables.background.secondary};
display: flex;
flex-direction: column;
height: calc(100dvh / var(--t-zoom, 1));
+ isolation: isolate;
+ position: relative;
width: 100%;
`;
+const StyledBackgroundLayer = styled.div`
+ inset: 0;
+ pointer-events: none;
+ position: absolute;
+ z-index: -1;
+`;
+
type OnboardingLayoutProps = {
children: ReactNode;
onBack?: () => void;
isBackDisabled?: boolean;
headerRightComponent?: ReactNode;
+ backgroundComponent?: ReactNode;
};
export const OnboardingLayout = ({
@@ -23,13 +36,23 @@ export const OnboardingLayout = ({
onBack,
isBackDisabled,
headerRightComponent,
-}: OnboardingLayoutProps) => (
- <StyledBackground>
- <OnboardingHeader
- onBack={onBack}
- isBackDisabled={isBackDisabled}
- rightComponent={headerRightComponent}
- />
- {children}
- </StyledBackground>
-);
+ backgroundComponent,
+}: OnboardingLayoutProps) => {
+ const isBackgroundComponentVisible = useMediaQuery(
+ `(min-width: ${ONBOARDING_BACKGROUND_COMPONENT_MIN_VIEWPORT_WIDTH}px)`,
+ );
+
+ return (
+ <StyledBackground>
+ {isDefined(backgroundComponent) && isBackgroundComponentVisible && (
+ <StyledBackgroundLayer>{backgroundComponent}</StyledBackgroundLayer>
+ )}
+ <OnboardingHeader
+ onBack={onBack}
+ isBackDisabled={isBackDisabled}
+ rightComponent={headerRightComponent}
+ />
+ {children}
+ </StyledBackground>
+ );
+};
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
index 3ca41386b5c..e8994707668 100644
--- a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
@@ -1,4 +1,5 @@
import { currentUserState } from '@/auth/states/currentUserState';
+import { OnboardingConstructionSite } from '@/onboarding/components/OnboardingConstructionSite/OnboardingConstructionSite';
import { OnboardingLayout } from '@/onboarding/components/OnboardingLayout';
import { OnboardingTransitionOutlet } from '@/onboarding/components/OnboardingTransitionOutlet';
import { OnboardingHeaderFreeCredits } from '@/onboarding/components/free-credits/OnboardingHeaderFreeCredits';
@@ -30,6 +31,7 @@ export const OnboardingStepLayout = () => {
}
isBackDisabled={isGoingBackToPreviousOnboardingStep}
headerRightComponent={<OnboardingHeaderFreeCredits />}
+ backgroundComponent={<OnboardingConstructionSite />}
>
<PrefetchBookCallStepEffect />
<PrefetchPlanRequiredStepEffect />
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepPageLoader.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepPageLoader.tsx
index a76220ead75..7b2b68b99de 100644
--- a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepPageLoader.tsx
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepPageLoader.tsx
@@ -1,8 +1,6 @@
import { styled } from '@linaria/react';
-import { themeCssVariables } from 'twenty-ui/theme';
const StyledContainer = styled.div`
- background: ${themeCssVariables.background.secondary};
flex: 1;
min-height: 0;
width: 100%;
diff --git a/packages/twenty-front/src/modules/onboarding/components/StyledOnboardingStepPage.ts b/packages/twenty-front/src/modules/onboarding/components/StyledOnboardingStepPage.ts
index af7c285d9cb..7e925f7ad54 100644
--- a/packages/twenty-front/src/modules/onboarding/components/StyledOnboardingStepPage.ts
+++ b/packages/twenty-front/src/modules/onboarding/components/StyledOnboardingStepPage.ts
@@ -3,7 +3,6 @@ import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme';
export const StyledOnboardingStepPage = styled.div`
align-items: center;
- background-color: ${themeCssVariables.background.secondary};
box-sizing: border-box;
display: flex;
flex: 1 1 0;
diff --git a/packages/twenty-front/src/modules/onboarding/constants/OnboardingBackgroundComponentMinViewportWidth.ts b/packages/twenty-front/src/modules/onboarding/constants/OnboardingBackgroundComponentMinViewportWidth.ts
new file mode 100644
index 00000000000..2dba11d0780
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/constants/OnboardingBackgroundComponentMinViewportWidth.ts
@@ -0,0 +1 @@
+export const ONBOARDING_BACKGROUND_COMPONENT_MIN_VIEWPORT_WIDTH = 1100;
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts b/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
index f4252e2da5d..13a88729c1e 100644
--- a/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
+++ b/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
@@ -1,13 +1,7 @@
import { isDefined } from 'twenty-shared/utils';
-import {
- type CurrentUser,
- currentUserState,
-} from '@/auth/states/currentUserState';
-import {
- type CurrentWorkspace,
- currentWorkspaceState,
-} from '@/auth/states/currentWorkspaceState';
+import { currentUserState } from '@/auth/states/currentUserState';
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { billingState } from '@/client-config/states/billingState';
import { isBookCallOnboardingStepEnabledState } from '@/client-config/states/isBookCallOnboardingStepEnabledState';
import { isOnboardingAiChatEnabledState } from '@/client-config/states/isOnboardingAiChatEnabledState';
@@ -15,75 +9,14 @@ import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAni
import { onboardingNavigationDirectionState } from '@/onboarding/states/onboardingNavigationDirectionState';
import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { getHasJustCompletedOnboarding } from '@/onboarding/utils/getHasJustCompletedOnboarding';
-import { getIsBookCallOnboardingStepPending } from '@/onboarding/utils/getIsBookCallOnboardingStepPending';
-import { getIsPlanRequired } from '@/onboarding/utils/getIsPlanRequired';
+import { getIsBookCallRequired } from '@/onboarding/utils/getIsBookCallRequired';
+import { getNextOnboardingStatus } from '@/onboarding/utils/getNextOnboardingStatus';
import { getNextPreviousOnboardingStatus } from '@/onboarding/utils/getNextPreviousOnboardingStatus';
import { type OnboardingStepHistoryEffect } from '@/onboarding/types/OnboardingStepHistoryEffect';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useStore } from 'jotai';
import { useCallback } from 'react';
-import { OnboardingStatus } from '~/generated-metadata/graphql';
-
-type GetNextOnboardingStatusArgs = {
- currentUser: CurrentUser | null;
- currentWorkspace: CurrentWorkspace | null;
- isBillingEnabled: boolean;
- isBookCallRequired: boolean;
-};
-
-const getNextOnboardingStatus = ({
- currentUser,
- currentWorkspace,
- isBillingEnabled,
- isBookCallRequired,
-}: GetNextOnboardingStatusArgs) => {
- const isPlanRequired = getIsPlanRequired({
- isBillingEnabled,
- currentWorkspace,
- });
-
- const statusAfterBookCall = isPlanRequired
- ? OnboardingStatus.PLAN_REQUIRED
- : OnboardingStatus.COMPLETED;
-
- const statusAfterInviteTeam =
- isBookCallRequired && isPlanRequired
- ? OnboardingStatus.BOOK_CALL
- : statusAfterBookCall;
-
- if (currentUser?.onboardingStatus === OnboardingStatus.WORKSPACE_ACTIVATION) {
- return OnboardingStatus.SYNC_EMAIL;
- }
-
- if (currentUser?.onboardingStatus === OnboardingStatus.SYNC_EMAIL) {
- if (currentWorkspace?.workspaceMembersCount === 1) {
- return OnboardingStatus.APPS_INSTALLATION;
- }
- return OnboardingStatus.PROFILE_CREATION;
- }
-
- if (currentUser?.onboardingStatus === OnboardingStatus.APPS_INSTALLATION) {
- return OnboardingStatus.PROFILE_CREATION;
- }
-
- if (currentUser?.onboardingStatus === OnboardingStatus.PROFILE_CREATION) {
- if (currentWorkspace?.workspaceMembersCount === 1) {
- return OnboardingStatus.INVITE_TEAM;
- }
- return statusAfterInviteTeam;
- }
- if (currentUser?.onboardingStatus === OnboardingStatus.INVITE_TEAM) {
- return statusAfterInviteTeam;
- }
- if (
- currentUser?.onboardingStatus === OnboardingStatus.BOOK_CALL ||
- currentUser?.onboardingStatus === OnboardingStatus.PLAN_REQUIRED
- ) {
- return statusAfterBookCall;
- }
- return OnboardingStatus.COMPLETED;
-};
export const useSetNextOnboardingStatus = () => {
const store = useStore();
@@ -105,9 +38,12 @@ export const useSetNextOnboardingStatus = () => {
currentUser,
currentWorkspace,
isBillingEnabled,
- isBookCallRequired:
- store.get(isBookCallOnboardingStepEnabledState.atom) &&
- getIsBookCallOnboardingStepPending(store.get(currentUserState.atom)),
+ isBookCallRequired: getIsBookCallRequired({
+ isBookCallOnboardingStepEnabled: store.get(
+ isBookCallOnboardingStepEnabledState.atom,
+ ),
+ currentUser: store.get(currentUserState.atom),
+ }),
});
store.set(onboardingNavigationDirectionState.atom, 'forward');
diff --git a/packages/twenty-front/src/modules/onboarding/utils/__tests__/getIsLastOnboardingStep.test.ts b/packages/twenty-front/src/modules/onboarding/utils/__tests__/getIsLastOnboardingStep.test.ts
new file mode 100644
index 00000000000..1da0036bf33
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/__tests__/getIsLastOnboardingStep.test.ts
@@ -0,0 +1,84 @@
+import { getIsLastOnboardingStep } from '@/onboarding/utils/getIsLastOnboardingStep';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+import {
+ mockCurrentWorkspace,
+ mockedUserData,
+} from '~/testing/mock-data/users';
+
+type BuildArgsOptions = {
+ onboardingStatus: OnboardingStatus;
+ isBillingEnabled?: boolean;
+ hasSubscription?: boolean;
+ workspaceMembersCount?: number;
+};
+
+const buildArgs = ({
+ onboardingStatus,
+ isBillingEnabled = false,
+ hasSubscription = false,
+ workspaceMembersCount = 1,
+}: BuildArgsOptions) => ({
+ currentUser: { ...mockedUserData, onboardingStatus },
+ currentWorkspace: {
+ ...mockCurrentWorkspace,
+ workspaceMembersCount,
+ billingSubscriptions: hasSubscription
+ ? mockCurrentWorkspace.billingSubscriptions
+ : [],
+ },
+ isBillingEnabled,
+ isBookCallRequired: false,
+});
+
+describe('getIsLastOnboardingStep', () => {
+ it('should treat the invite step as the last one when no plan is required', () => {
+ expect(
+ getIsLastOnboardingStep(
+ buildArgs({ onboardingStatus: OnboardingStatus.INVITE_TEAM }),
+ ),
+ ).toBe(true);
+ });
+
+ it('should not treat the invite step as the last one when a plan is still required', () => {
+ expect(
+ getIsLastOnboardingStep(
+ buildArgs({
+ onboardingStatus: OnboardingStatus.INVITE_TEAM,
+ isBillingEnabled: true,
+ }),
+ ),
+ ).toBe(false);
+ });
+
+ it('should always treat the plan step as the last one', () => {
+ expect(
+ getIsLastOnboardingStep(
+ buildArgs({
+ onboardingStatus: OnboardingStatus.PLAN_REQUIRED,
+ isBillingEnabled: true,
+ }),
+ ),
+ ).toBe(true);
+ });
+
+ it('should treat profile creation as the last step for someone joining a team', () => {
+ expect(
+ getIsLastOnboardingStep(
+ buildArgs({
+ onboardingStatus: OnboardingStatus.PROFILE_CREATION,
+ workspaceMembersCount: 3,
+ isBillingEnabled: true,
+ hasSubscription: true,
+ }),
+ ),
+ ).toBe(true);
+ });
+
+ it('should not treat an intermediate step as the last one', () => {
+ expect(
+ getIsLastOnboardingStep(
+ buildArgs({ onboardingStatus: OnboardingStatus.SYNC_EMAIL }),
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/utils/getIsBookCallRequired.ts b/packages/twenty-front/src/modules/onboarding/utils/getIsBookCallRequired.ts
new file mode 100644
index 00000000000..52d95c9d543
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/getIsBookCallRequired.ts
@@ -0,0 +1,12 @@
+import { type CurrentUser } from '@/auth/states/currentUserState';
+import { getIsBookCallOnboardingStepPending } from '@/onboarding/utils/getIsBookCallOnboardingStepPending';
+
+export const getIsBookCallRequired = ({
+ isBookCallOnboardingStepEnabled,
+ currentUser,
+}: {
+ isBookCallOnboardingStepEnabled: boolean;
+ currentUser: Pick<CurrentUser, 'userVars'> | null;
+}) =>
+ isBookCallOnboardingStepEnabled &&
+ getIsBookCallOnboardingStepPending(currentUser);
diff --git a/packages/twenty-front/src/modules/onboarding/utils/getIsLastOnboardingStep.ts b/packages/twenty-front/src/modules/onboarding/utils/getIsLastOnboardingStep.ts
new file mode 100644
index 00000000000..c55818efe71
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/getIsLastOnboardingStep.ts
@@ -0,0 +1,9 @@
+import {
+ type GetNextOnboardingStatusArgs,
+ getNextOnboardingStatus,
+} from '@/onboarding/utils/getNextOnboardingStatus';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+export const getIsLastOnboardingStep = (args: GetNextOnboardingStatusArgs) =>
+ args.currentUser?.onboardingStatus === OnboardingStatus.PLAN_REQUIRED ||
+ getNextOnboardingStatus(args) === OnboardingStatus.COMPLETED;
diff --git a/packages/twenty-front/src/modules/onboarding/utils/getNextOnboardingStatus.ts b/packages/twenty-front/src/modules/onboarding/utils/getNextOnboardingStatus.ts
new file mode 100644
index 00000000000..4fa4bbead02
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/getNextOnboardingStatus.ts
@@ -0,0 +1,64 @@
+import { type CurrentUser } from '@/auth/states/currentUserState';
+import { type CurrentWorkspace } from '@/auth/states/currentWorkspaceState';
+import { getIsPlanRequired } from '@/onboarding/utils/getIsPlanRequired';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+export type GetNextOnboardingStatusArgs = {
+ currentUser: CurrentUser | null;
+ currentWorkspace: CurrentWorkspace | null;
+ isBillingEnabled: boolean;
+ isBookCallRequired: boolean;
+};
+
+export const getNextOnboardingStatus = ({
+ currentUser,
+ currentWorkspace,
+ isBillingEnabled,
+ isBookCallRequired,
+}: GetNextOnboardingStatusArgs) => {
+ const isPlanRequired = getIsPlanRequired({
+ isBillingEnabled,
+ currentWorkspace,
+ });
+
+ const statusAfterBookCall = isPlanRequired
+ ? OnboardingStatus.PLAN_REQUIRED
+ : OnboardingStatus.COMPLETED;
+
+ const statusAfterInviteTeam =
+ isBookCallRequired && isPlanRequired
+ ? OnboardingStatus.BOOK_CALL
+ : statusAfterBookCall;
+
+ if (currentUser?.onboardingStatus === OnboardingStatus.WORKSPACE_ACTIVATION) {
+ return OnboardingStatus.SYNC_EMAIL;
+ }
+
+ if (currentUser?.onboardingStatus === OnboardingStatus.SYNC_EMAIL) {
+ if (currentWorkspace?.workspaceMembersCount === 1) {
+ return OnboardingStatus.APPS_INSTALLATION;
+ }
+ return OnboardingStatus.PROFILE_CREATION;
+ }
+
+ if (currentUser?.onboardingStatus === OnboardingStatus.APPS_INSTALLATION) {
+ return OnboardingStatus.PROFILE_CREATION;
+ }
+
+ if (currentUser?.onboardingStatus === OnboardingStatus.PROFILE_CREATION) {
+ if (currentWorkspace?.workspaceMembersCount === 1) {
+ return OnboardingStatus.INVITE_TEAM;
+ }
+ return statusAfterInviteTeam;
+ }
+ if (currentUser?.onboardingStatus === OnboardingStatus.INVITE_TEAM) {
+ return statusAfterInviteTeam;
+ }
+ if (
+ currentUser?.onboardingStatus === OnboardingStatus.BOOK_CALL ||
+ currentUser?.onboardingStatus === OnboardingStatus.PLAN_REQUIRED
+ ) {
+ return statusAfterBookCall;
+ }
+ return OnboardingStatus.COMPLETED;
+};