-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage material colors now that materials are mutable #268
Comments
10 TODOs left |
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
|
Patch for linear color mapping Subject: [PATCH] Linear color mapping
---
Index: js/common/model/Material.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/Material.ts b/js/common/model/Material.ts
--- a/js/common/model/Material.ts (revision ca655a7534626154b25b1e5c4c1ad922195b2db0)
+++ b/js/common/model/Material.ts (date 1721937114972)
@@ -133,14 +133,11 @@
/**
* Returns a lightness factor from 0-1 that can be used to map a density to a desired color.
- * TODO: This has a poor dynamic range for the bottle inside material, but is used elsewhere. Should it be changed/split/improved? https://github.com/phetsims/density-buoyancy-common/issues/268
+ * TODO AV: This has a poor dynamic range for the bottle inside material, but is used elsewhere. Should it be changed/split/improved? https://github.com/phetsims/density-buoyancy-common/issues/268
*/
public static getNormalizedLightness( density: number, densityRange: Range ): number {
- const scaleFactor = 1000;
- const scaleMax = Utils.log10( densityRange.max / scaleFactor ); // 1 for the default
- const scaleMin = Utils.log10( densityRange.min / scaleFactor ); // -2 for the default
- const scaleValue = Utils.log10( density / scaleFactor );
- return Utils.clamp( Utils.linear( scaleMax, scaleMin, 0, 1, scaleValue ), 0, 1 );
+ const scaling = 0.8;
+ return 0.5 - scaling * ( densityRange.getNormalizedValue( density ) - 0.5 );
}
/** |
@zepumph and I have a big question after taking a tour of this issue: Regarding the color-density relationship, do we want a global lightness map for the whole sim suite, or something more custom for every screen's achievable densities?? Some potential design problems:
Some additional remarks:
If we go with having custom color maps, how should they behave? Screen by screen basis? Sim by sim? |
Noting that the behavior right before this material change was actually in the MaterialMassVolumeControl, and made it so all blocks could go from white->black completely. density-buoyancy-common/js/common/view/MaterialControlNode.ts Lines 70 to 76 in e9d1887
UPDATE: This patch brings back the previous behavior above, as if we were attempting to go with (2) above instead of a global map: Subject: [PATCH] remove gravity-force-lab, too old
---
Index: js/common/view/MaterialControlNode.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/MaterialControlNode.ts b/js/common/view/MaterialControlNode.ts
--- a/js/common/view/MaterialControlNode.ts (revision ca655a7534626154b25b1e5c4c1ad922195b2db0)
+++ b/js/common/view/MaterialControlNode.ts (date 1721940690565)
@@ -19,6 +19,7 @@
import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import MaterialProperty from '../model/MaterialProperty.js';
import Utils from '../../../../dot/js/Utils.js';
+import Range from '../../../../dot/js/Range.js';
type SelfMaterialControlNodeOptions = {
@@ -76,6 +77,18 @@
};
};
+ // TODO: workable, but buggy with reset since the rangeProperty initialized to a min of .8
+ if ( customMaterials.length > 0 ) {
+ const customDensityRange = new Range(
+ options.minCustomMass / options.maxVolumeLiters * DensityBuoyancyCommonConstants.LITERS_IN_CUBIC_METER,
+
+ // Prevent divide by zero errors (infinity) with a manual, tiny number
+ options.maxCustomMass / ( options.minCustomVolumeLiters ) * DensityBuoyancyCommonConstants.LITERS_IN_CUBIC_METER
+ );
+ materialProperty.customMaterial.densityProperty.rangeProperty.value = customDensityRange;
+
+ }
+
// When switching to custom, set the custom density to the previous material's density (clamped just in case).
// However, when switching from a mystery material, do not change the custom value. This prevents clever students from discovering
// the mystery values by using the UI instead of by computing them, see https://github.com/phetsims/buoyancy/issues/54 |
Reminder: Try both of the above patches at once, to see how the linear mapping behaves for the other custom colors. |
Given how much @AgustinVallejo and I liked the patch above, I'd like to experiment with calculating the range in |
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
The compare case went really nicely, and makes a lot of sense for that screen. After thinking through each case above, I believe that seeing white/black for custom block materials fully on each screen is preferable. I will commit the above changes, and we can discuss sync tomorrow morning. |
When applying the patch in #268 (comment), I ran into a bug where the current log-based lightness function returns NaN when the range is [0,20000] and the density is 0, so I'll proceed with #268 (comment) too. |
Signed-off-by: Michael Kauzmann <[email protected]>
|
From design meeting:
|
We may want to go back to a log-based lightness function, as was used in density: density-buoyancy-common/js/common/model/Material.ts Lines 148 to 151 in 7bfaab3
|
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
Signed-off-by: Michael Kauzmann <[email protected]>
…ensity slider that already has a range, #268 Signed-off-by: Michael Kauzmann <[email protected]>
…ensity slider that already has a range, #268 Signed-off-by: Michael Kauzmann <[email protected]>
Alright. I fixed a couple bugs in cases where there was already a density slider and a range for a custom denstiy (blocks in B:B:explore and Bottle.materialInside). |
@AgustinVallejo and I got to an algorithm for color mapping in the compare screen that we liked. It involved linear mapping instead of log + exponential mapping, originally added back in phetsims/density#84. The rest of the TODOs are over to @AgustinVallejo. Thanks everyone! |
On friday I spoke with @arouinfar and she likes the new dynamic range. Also, in the above commit I made colorProperty read only implementing a function called createColorProperty, overriden in the children of Material. But I'm not totally sure if that's the right way to go, specially handling |
From TODOs in #256
The text was updated successfully, but these errors were encountered: