UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 3.34 kB
{"version":3,"file":"applyProjectiveTransformationToPlane.mjs","sources":["../../../../src/scene/mesh-perspective/utils/applyProjectiveTransformationToPlane.ts"],"sourcesContent":["import type { ArrayFixed } from '../../../utils/types';\nimport type { PlaneGeometry } from '../../mesh-plane/PlaneGeometry';\n\n/**\n * Apply a projective transformation to a plane geometry\n * @param width - The width of the plane\n * @param height - The height of the plane\n * @param geometry - The plane geometry to apply the transformation to\n * @param transformationMatrix - The transformation matrix to apply\n * @internal\n */\nexport function applyProjectiveTransformationToPlane(\n width: number,\n height: number,\n geometry: PlaneGeometry,\n transformationMatrix: ArrayFixed<number, 9>\n)\n{\n const buffer = geometry.buffers[0];\n\n // Access the vertices of the mesh\n const vertices = buffer.data;\n\n const { verticesX, verticesY } = geometry;\n\n const sizeX = (width) / (verticesX - 1);\n const sizeY = (height) / (verticesY - 1);\n\n let index = 0;\n\n const a00 = transformationMatrix[0];\n const a01 = transformationMatrix[1];\n const a02 = transformationMatrix[2];\n const a10 = transformationMatrix[3];\n const a11 = transformationMatrix[4];\n const a12 = transformationMatrix[5];\n const a20 = transformationMatrix[6];\n const a21 = transformationMatrix[7];\n const a22 = transformationMatrix[8];\n\n // Apply the transformation to each vertex\n for (let i = 0; i < vertices.length; i += 2)\n {\n const x = (index % verticesX) * sizeX;\n const y = ((index / verticesX) | 0) * sizeY;\n\n const newX = (a00 * x) + (a01 * y) + a02;\n const newY = (a10 * x) + (a11 * y) + a12;\n const w = (a20 * x) + (a21 * y) + a22;\n\n vertices[i] = newX / w;\n vertices[i + 1] = newY / w;\n\n index++;\n }\n\n // Update the mesh geometry to reflect the changes\n buffer.update();\n}\n"],"names":[],"mappings":";AAWO,SAAS,oCAAA,CACZ,KAAA,EACA,MAAA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