import { expect } from "chai" ; import { Id64 } from "@itwin/core-bentley" ; import { BackgroundMapSettings , ColorByName , ColorDef , GlobeMode , PlanProjectionSettings , PlanProjectionSettingsProps } from "@itwin/core-common" ; import { DisplayStyle3dState , GeometricModel3dState , IModelConnection , Pixel , SnapshotConnection } from "@itwin/core-frontend" ; import { rpcInterfaces } from "../../common/RpcInterfaces" ; import { TestUtility } from "../TestUtility" ; import { testOnScreenViewport } from "../TestViewport" ; describe ( "Plan projections" , ( ) => { let mirukuru ; before ( async ( ) => { const opts = { electronApp : { rpcInterfaces } , iModelApp : { renderSys : { dpiAwareViewports : false } } } ; await TestUtility . shutdownFrontend ( ) ; await TestUtility . startFrontend ( opts . iModelApp ) ; mirukuru = await SnapshotConnection . openFile ( "planprojection.bim" ) ; } ) ; after ( async ( ) => { await mirukuru . close ( ) ; await TestUtility . shutdownFrontend ( ) ; } ) ; it ( "is obscured by background map based on settings" , async ( ) => { const modelId = "0x17" ; await mirukuru . models . load ( modelId ) ; const model = mirukuru . models . getLoaded ( modelId ) as GeometricModel3dState ; expect ( model ) . not . to . be . undefined ; expect ( model . isPlanProjection ) . to . be . true ; interface Test extends PlanProjectionSettingsProps { expectMap : boolean ; mapDepth : boolean ; } const tests = [ { enforceDisplayPriority : true , mapDepth : false , expectMap : false } , { elevation : - 10 , mapDepth : false , expectMap : false } , { elevation : 10 , mapDepth : false , expectMap : false } , { elevation : - 10 , mapDepth : true , expectMap : true } , { elevation : 10 , mapDepth : true , expectMap : false } , { elevation : - 10 , overlay : true , mapDepth : false , expectMap : false } , { elevation : 10 , overlay : true , mapDepth : false , expectMap : false } , { elevation : - 10 , overlay : true , mapDepth : true , expectMap : false } , { elevation : 10 , overlay : true , mapDepth : true , expectMap : false } , ] ; await testOnScreenViewport ( "0x29" , mirukuru , 100 , 100 , async ( vp ) => { for ( const test of tests ) { vp . viewFlags = vp . viewFlags . copy ( { backgroundMap : true , lighting : false } ) ; vp . displayStyle . backgroundColor = ColorDef . fromJSON ( ColorByName . magenta ) ; vp . backgroundMapSettings = BackgroundMapSettings . fromJSON ( { useDepthBuffer : test . mapDepth , globeMode : GlobeMode . Plane , nonLocatable : false } ) ; const style = vp . displayStyle as DisplayStyle3dState ; style . settings . setPlanProjectionSettings ( modelId , PlanProjectionSettings . fromJSON ( test ) ) ; vp . invalidateScene ( ) ; await vp . waitForAllTilesToRender ( ) ; vp . invalidateRenderPlan ( ) ; await vp . waitForAllTilesToRender ( ) ; const expectPixel = ( x , y , expectMap ) => { const color = vp . readColor ( x , y ) ; expect ( color . equalsColorDef ( vp . displayStyle . backgroundColor ) ) . to . be . false ; expect ( color . equalsColorDef ( ColorDef . white ) ) . not . to . equal ( expectMap ) ; const pixel = vp . readPixel ( x , y , true ) ; expect ( pixel . type ) . to . equal ( Pixel . GeometryType . Surface ) ; expect ( pixel . featureTable ) . not . to . be . undefined ; expect ( Id64 . isTransient ( pixel . featureTable ! . modelId ) ) . to . equal ( expectMap ) ; } ; expectPixel ( 50 , 50 , test . expectMap ) ; } } ) ; } ) ; } ) ;