优化:模型材质颜色和渲染器同步

pull/1946/MERGE
ChenX 2 years ago
parent d179f3cdd7
commit 0adfad526c

@ -121,7 +121,7 @@
"react-virtualized-auto-sizer": "^1.0.6",
"react-window": "^1.8.7",
"stats.js": "^0.17.0",
"three": "^0.122.0",
"three": "npm:three-cf@0.122.1",
"xaop": "^2.0.0"
},
"resolutions": {

@ -1,4 +1,4 @@
import { DoubleSide, MeshPhongMaterial, MeshPhysicalMaterial, MirroredRepeatWrapping, RepeatWrapping, Texture } from "three";
import { DoubleSide, MeshPhongMaterial, MeshPhysicalMaterial, MeshPhysicalMaterial2, MirroredRepeatWrapping, RepeatWrapping, Texture } from "three";
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
import { HostApplicationServices } from "../../ApplicationServices/HostApplicationServices";
import { LoadImageFromUrl } from "../../Loader/ImageLoader";
@ -90,7 +90,7 @@ export async function ConverMaterial2(m: MeshPhongMaterial, url: string)
let dataString = await (await fetch(GenerateCdnUrl(`/Paks/paks_cooked_2/ue_resource/Content${encodeURI(url)}/${name}.json`))).text();
let data = JSON.parse(dataString);
let mtl = new MeshPhysicalMaterial({
let mtl = new MeshPhysicalMaterial2({
side: DoubleSide,
transparent: false,
metalness: Math.max(0.2, data.common_metallic),//至少给个比较小的金属性 保证它的反光,否则马桶会变成纯白
@ -167,33 +167,9 @@ export async function ConverMaterial2(m: MeshPhongMaterial, url: string)
);
}
}
// else
{
mtl.color.r = 1 - (1 - data.baseColor_lightColor.r) * (1 - data.baseColor_shadowColor.r);
mtl.color.g = 1 - (1 - data.baseColor_lightColor.g) * (1 - data.baseColor_shadowColor.g);
mtl.color.b = 1 - (1 - data.baseColor_lightColor.b) * (1 - data.baseColor_shadowColor.b);
if (data.baseColor_brightness > 0)
{
mtl.color.r = Math.pow(mtl.color.r, 1 - data.baseColor_brightness);
mtl.color.g = Math.pow(mtl.color.g, 1 - data.baseColor_brightness);
mtl.color.b = Math.pow(mtl.color.b, 1 - data.baseColor_brightness);
}
else
{
mtl.color.r = Math.pow(mtl.color.r, 1 - data.baseColor_brightness);
mtl.color.g = Math.pow(mtl.color.g, 1 - data.baseColor_brightness);
mtl.color.b = Math.pow(mtl.color.b, 1 - data.baseColor_brightness);
}
// mtl.color.convertLinearToGamma();
mtl.color.convertGammaToLinear(0.5);//本质上等于上一行代码
//下面的代码用于提亮,但是上面的代码已经实现了 所以废弃这个代码
// let sum = mtl.color.r + mtl.color.g + mtl.color.b;
// if (sum < 1)
// mtl.color.multiplyScalar(1 / sum);
}
mtl.lightColor.setRGB(data.baseColor_lightColor.r, data.baseColor_lightColor.g, data.baseColor_lightColor.b);
mtl.shadowColor.setRGB(data.baseColor_shadowColor.r, data.baseColor_shadowColor.g, data.baseColor_shadowColor.b);
return mtl;
}
catch (error)

Loading…
Cancel
Save