import { Matrix3d , Point3d , Transform , YawPitchRollAngles } from "@itwin/core-geometry" ; import { IModelApp , Tool } from "@itwin/core-frontend" ; import { parseArgs } from "@itwin/frontend-devtools" ; class TransformProvider { public constructor ( private readonly _models , private readonly _transform ) { } public getModelDisplayTransform ( modelId , baseTransform ) { if ( ! this . _models . has ( modelId ) ) return baseTransform ; return baseTransform . multiplyTransformTransform ( this . _transform ) ; } } /** Apply a display transform to all currently displayed models. */ export class ApplyModelTransformTool extends Tool { public static override toolId = "ApplyModelTransform" ; public static override get minArgs ( ) { return 0 ; } public static override get maxArgs ( ) { return 5 ; } public override async run ( origin ? , ypr ? ) { const vp = IModelApp . viewManager . selectedView ; if ( ! vp ) return false ; if ( ! origin || origin . isAlmostZero ) if ( ! ypr || ypr . isIdentity ( ) ) return false ; const models = new Set < string > ( ) ; vp . view . forEachModel ( ( model ) => models . add ( model . id ) ) ; const mat = ypr ? ypr . toMatrix3d ( ) : Matrix3d . createIdentity ( ) ; const tf = Transform . createRefs ( origin , mat ) ; vp . setModelDisplayTransformProvider ( new TransformProvider ( models , tf ) ) ; return true ; } public override async parseAndRun ( ... input ) { const args = parseArgs ( input ) ; const origin = new Point3d ( args . getInteger ( "x" ) ?? 0 , args . getInteger ( "y" ) ?? 0 , args . getInteger ( "z" ) ?? 0 ) ; const ypr = YawPitchRollAngles . createDegrees ( 0 , args . getFloat ( "p" ) ?? 0 , args . getFloat ( "r" ) ?? 0 ) ; return this . run ( origin , ypr ) ; } }