Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/web-renderer/src/drawing/get-pretransform-rect.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// In some cases, we get a matrix that is too compressed:
// e.g. https://github.com/remotion-dev/remotion/issues/6185
// > You're rotating around the X-axis by ~89.96°, which means the Y-axis gets compressed to ⁠cos(89.96°) ≈ 0.000691 of its original size in the viewport.
const MAX_SCALE_FACTOR = 100;

export function getPreTransformRect(
targetRect: DOMRect,
matrix: DOMMatrix,
Expand All @@ -11,6 +16,17 @@ export function getPreTransformRect(
const basisX = {x: unitX.x - origin.x, y: unitX.y - origin.y};
const basisY = {x: unitY.x - origin.x, y: unitY.y - origin.y};

// Check effective scale in each axis
const scaleX = Math.hypot(basisX.x, basisX.y);
const scaleY = Math.hypot(basisY.x, basisY.y);

// If either axis is too compressed, the inverse will explode
const minScale = Math.min(scaleX, scaleY);
if (minScale < 1 / MAX_SCALE_FACTOR) {
// Content is nearly invisible, e.g. 89.96deg X rotation (edge-on view)
return new DOMRect(0, 0, 0, 0);
}

// 3. Build the effective 2D matrix and invert it
const effective2D = new DOMMatrix([
basisX.x,
Expand Down
2 changes: 2 additions & 0 deletions packages/web-renderer/src/test/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {hugeImageTransform} from './fixtures/huge-image-transform';
import {inside3dTransform} from './fixtures/inside-3d-transform';
import {lineHeight} from './fixtures/line-height';
import {linearGradient} from './fixtures/linear-gradient';
import {manyLayers} from './fixtures/many-layers';
import {maskImage} from './fixtures/mask-image';
import {multiLevelTransformOrigins} from './fixtures/multi-level-transform-origins';
import {nestedTranslateScale} from './fixtures/nested-translate-scale';
Expand Down Expand Up @@ -134,6 +135,7 @@ export const Root: React.FC = () => {
<Composition {...inside3dTransform} />
<Composition {...flexContainer} />
<Composition {...deeplyNestedTransform} />
<Composition {...manyLayers} />
</Folder>
</>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading