Skip to content

Commit

Permalink
First go at Intro Screen Icon, see phetsims/buoyancy#48
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Apr 24, 2024
1 parent a93e8e1 commit 5d70307
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
51 changes: 50 additions & 1 deletion js/buoyancy/view/BuoyancyIntroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Vector3 from '../../../../dot/js/Vector3.js';
import { combineOptions } from '../../../../phet-core/js/optionize.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { AlignBox, HBox, Text, VBox } from '../../../../scenery/js/imports.js';
import { AlignBox, HBox, Node, Text, VBox } from '../../../../scenery/js/imports.js';
import AquaRadioButton from '../../../../sun/js/AquaRadioButton.js';
import Panel from '../../../../sun/js/Panel.js';
import VerticalAquaRadioButtonGroup from '../../../../sun/js/VerticalAquaRadioButtonGroup.js';
Expand All @@ -30,6 +30,9 @@ import ScreenView from '../../../../joist/js/ScreenView.js';
import { ReadoutItemOptions } from './ReadoutListAccordionBox.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import Mass from '../../common/model/Mass.js';
import DensityMaterials from '../../common/view/DensityMaterials.js';
import ThreeUtils from '../../../../mobius/js/ThreeUtils.js';
import DensityBuoyancyCommonColors from '../../common/view/DensityBuoyancyCommonColors.js';

// constants
const blockSetStringMap = {
Expand Down Expand Up @@ -226,6 +229,52 @@ export default class BuoyancyIntroScreenView extends DensityBuoyancyScreenView<B
super.layout( viewBounds );
this.layoutRightSidePanels();
}


public static getBuoyancyIntroIcon(): Node {
return DensityBuoyancyScreenView.getAngledIcon( 4, new Vector3( 0, 0, 0 ), scene => {

const boxGeometry = new THREE.BoxGeometry( 0.1, 0.1, 0.1 );

const box1 = new THREE.Mesh( boxGeometry, new THREE.MeshStandardMaterial( {
map: DensityMaterials.woodColorTexture,
normalMap: DensityMaterials.woodNormalTexture,
normalScale: new THREE.Vector2( 1, -1 ),
roughnessMap: DensityMaterials.woodRoughnessTexture,
metalness: 0
// NOTE: Removed the environment map for now
} ) );
box1.position.copy( ThreeUtils.vectorToThree( new Vector3( 0.08, 0, 0 ) ) );

scene.add( box1 );

const box2 = new THREE.Mesh( boxGeometry, new THREE.MeshStandardMaterial( {
map: DensityMaterials.brickColorTexture,
normalMap: DensityMaterials.brickNormalTexture,
normalScale: new THREE.Vector2( 1, -1 ),
metalness: 0
// NOTE: Removed the environment map for now
} ) );
box2.position.copy( ThreeUtils.vectorToThree( new Vector3( -0.08, -0.05, 0 ) ) );

scene.add( box2 );

const waterMaterial = new THREE.MeshLambertMaterial( {
transparent: true
} );
const waterColor = DensityBuoyancyCommonColors.materialWaterColorProperty.value;
waterMaterial.color = ThreeUtils.colorToThree( waterColor );
waterMaterial.opacity = waterColor.alpha;

// Fake it!
const waterGeometry = new THREE.BoxGeometry( 1, 1, 0.2 );

const water = new THREE.Mesh( waterGeometry, waterMaterial );
water.position.copy( ThreeUtils.vectorToThree( new Vector3( 0, -0.5, 0.12 ) ) );
scene.add( water );
} );

}
}

densityBuoyancyCommon.register( 'BuoyancyIntroScreenView', BuoyancyIntroScreenView );
27 changes: 17 additions & 10 deletions js/common/view/CuboidView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,10 @@ export default class CuboidView extends MeasurableMassView {
showForceValuesProperty: TReadOnlyProperty<boolean>,
forceScaleProperty: TReadOnlyProperty<number>,
showMassesProperty: TReadOnlyProperty<boolean> ) {
const size = cuboid.sizeProperty.value;

const positionArray = new Float32Array( numElements * 3 );
const normalArray = new Float32Array( numElements * 3 );
const uvArray = new Float32Array( numElements * 2 );

CuboidView.updateArrays( positionArray, normalArray, uvArray, size );
const size = cuboid.sizeProperty.value;

const cuboidGeometry = new THREE.BufferGeometry();
cuboidGeometry.addAttribute( 'position', new THREE.BufferAttribute( positionArray, 3 ) );
cuboidGeometry.addAttribute( 'normal', new THREE.BufferAttribute( normalArray, 3 ) );
cuboidGeometry.addAttribute( 'uv', new THREE.BufferAttribute( uvArray, 2 ) );
const cuboidGeometry = CuboidView.getCuboidGeometery( size );

super( cuboid, cuboidGeometry, modelViewTransform, dragBoundsProperty,

Expand Down Expand Up @@ -238,6 +230,21 @@ export default class CuboidView extends MeasurableMassView {

return writer.getOffset();
}

public static getCuboidGeometery( size: Bounds3 ): THREE.BufferGeometry {
const positionArray = new Float32Array( numElements * 3 );
const normalArray = new Float32Array( numElements * 3 );
const uvArray = new Float32Array( numElements * 2 );

CuboidView.updateArrays( positionArray, normalArray, uvArray, size );

const cuboidGeometry = new THREE.BufferGeometry();
cuboidGeometry.addAttribute( 'position', new THREE.BufferAttribute( positionArray, 3 ) );
cuboidGeometry.addAttribute( 'normal', new THREE.BufferAttribute( normalArray, 3 ) );
cuboidGeometry.addAttribute( 'uv', new THREE.BufferAttribute( uvArray, 2 ) );

return cuboidGeometry;
}
}

densityBuoyancyCommon.register( 'CuboidView', CuboidView );
3 changes: 3 additions & 0 deletions js/common/view/DensityMaterials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ export default class DensityMaterials {
public static readonly woodColorTexture = woodColorTexture;
public static readonly woodNormalTexture = woodNormalTexture;
public static readonly woodRoughnessTexture = woodRoughnessTexture;

public static readonly brickColorTexture = brickColorTexture;
public static readonly brickNormalTexture = brickNormalTexture;
}


Expand Down

0 comments on commit 5d70307

Please sign in to comment.