@babylonjs/serializers
Advanced tools
Comparing version 7.47.2 to 7.47.3
/* eslint-disable babylonjs/available */ | ||
import { Vector2 } from "@babylonjs/core/Maths/math.vector.js"; | ||
import { Color3 } from "@babylonjs/core/Maths/math.color.js"; | ||
@@ -11,2 +10,3 @@ import { Scalar } from "@babylonjs/core/Maths/math.scalar.js"; | ||
import { DumpTools } from "@babylonjs/core/Misc/dumpTools.js"; | ||
import { SpecularPowerToRoughness } from "@babylonjs/core/Helpers/materialConversionHelper.js"; | ||
const epsilon = 1e-6; | ||
@@ -53,37 +53,6 @@ const dielectricSpecular = new Color3(0.04, 0.04, 0.04); | ||
export function _ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial) { | ||
// Defines a cubic bezier curve where x is specular power and y is roughness | ||
const P0 = new Vector2(0, 1); | ||
const P1 = new Vector2(0, 0.1); | ||
const P2 = new Vector2(0, 0.1); | ||
const P3 = new Vector2(1300, 0.1); | ||
/** | ||
* Given the control points, solve for x based on a given t for a cubic bezier curve | ||
* @param t a value between 0 and 1 | ||
* @param p0 first control point | ||
* @param p1 second control point | ||
* @param p2 third control point | ||
* @param p3 fourth control point | ||
* @returns number result of cubic bezier curve at the specified t | ||
*/ | ||
function cubicBezierCurve(t, p0, p1, p2, p3) { | ||
return (1 - t) * (1 - t) * (1 - t) * p0 + 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t * p3; | ||
} | ||
/** | ||
* Evaluates a specified specular power value to determine the appropriate roughness value, | ||
* based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis) | ||
* and roughness on the ordinant axis (y-axis) | ||
* @param specularPower specular power of standard material | ||
* @returns Number representing the roughness value | ||
*/ | ||
function solveForRoughness(specularPower) { | ||
// Given P0.x = 0, P1.x = 0, P2.x = 0 | ||
// x = t * t * t * P3.x | ||
// t = (x / P3.x)^(1/3) | ||
const t = Math.pow(specularPower / P3.x, 0.333333); | ||
return cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y); | ||
} | ||
const diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace(babylonStandardMaterial.getScene().getEngine().useExactSrgbConversions).scale(0.5); | ||
const opacity = babylonStandardMaterial.alpha; | ||
const specularPower = Scalar.Clamp(babylonStandardMaterial.specularPower, 0, maxSpecularPower); | ||
const roughness = solveForRoughness(specularPower); | ||
const roughness = SpecularPowerToRoughness(specularPower); | ||
const glTFPbrMetallicRoughness = { | ||
@@ -90,0 +59,0 @@ baseColorFactor: [diffuse.r, diffuse.g, diffuse.b, opacity], |
@@ -188,7 +188,5 @@ /* eslint-disable jsdoc/require-jsdoc */ | ||
export function RotateNode180Y(node) { | ||
if (node.rotation) { | ||
const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]); | ||
rotation180Y.multiplyToRef(rotation, rotation); | ||
node.rotation = rotation.asArray(); | ||
} | ||
const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]); | ||
rotation180Y.multiplyToRef(rotation, rotation); | ||
node.rotation = rotation.asArray(); | ||
} | ||
@@ -195,0 +193,0 @@ /** |
{ | ||
"name": "@babylonjs/serializers", | ||
"version": "7.47.2", | ||
"version": "7.47.3", | ||
"main": "index.js", | ||
@@ -21,6 +21,6 @@ "module": "index.js", | ||
"devDependencies": { | ||
"@babylonjs/core": "^7.47.2", | ||
"@babylonjs/core": "^7.47.3", | ||
"@dev/build-tools": "^1.0.0", | ||
"@lts/serializers": "^1.0.0", | ||
"babylonjs-gltf2interface": "^7.47.2" | ||
"babylonjs-gltf2interface": "^7.47.3" | ||
}, | ||
@@ -27,0 +27,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
895218
7183