修改粗糙金属度
This commit is contained in:
@ -35,7 +35,7 @@ const init = async (customConfig = {}) => {
|
|||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
container: document.querySelector('#renderDom'),
|
container: document.querySelector('#renderDom'),
|
||||||
modelUrlList: [],
|
modelUrlList: [],
|
||||||
env: { envPath: 'https://cdn.files.zguiy.com/zt/environment.env', intensity: 1.5, rotationY: 0.3, background: false },
|
env: { envPath: 'https://cdn.files.zguiy.com/zt/environment.env', intensity: 1.2, rotationY: 0.3, background: false },
|
||||||
gizmo: {
|
gizmo: {
|
||||||
position: false,
|
position: false,
|
||||||
rotation: false,
|
rotation: false,
|
||||||
@ -362,14 +362,16 @@ const executeEvent2 = async (result, sku) => {
|
|||||||
for (const event of result.data.events) {
|
for (const event of result.data.events) {
|
||||||
if (event.event_type === 'change_color') {
|
if (event.event_type === 'change_color') {
|
||||||
const materialName = event.material_name;
|
const materialName = event.material_name;
|
||||||
|
console.log('替换模型颜色:', event);
|
||||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||||
console.log('替换模型颜色:', event.target_data);
|
|
||||||
|
|
||||||
kernel.material.apply({
|
kernel.material.apply({
|
||||||
target: materialName,
|
target: materialName,
|
||||||
albedoColor: color,
|
albedoColor: color,
|
||||||
albedoTexture: color_map_url,
|
albedoTexture: color_map_url,
|
||||||
normalMap: normal_map_url,
|
normalMap: normal_map_url,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||||
|
|||||||
@ -585,7 +585,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="https://sdk.zguiy.com/zt/assets/index.global.js?v=1234"></script>
|
<!-- <script src="https://sdk.zguiy.com/zt/assets/index.global.js?v=1234"></script> -->
|
||||||
|
<script src="./index.global.js?v=1234"></script>
|
||||||
<script src="./app-global.js"></script>
|
<script src="./app-global.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// 从全局对象获取 SDK kernel
|
// 从全局对象获取 SDK kernel
|
||||||
|
|||||||
@ -29855,6 +29855,10 @@ var kernel = (function (exports) {
|
|||||||
rotationY: 0,
|
rotationY: 0,
|
||||||
background: false
|
background: false
|
||||||
},
|
},
|
||||||
|
camera: {
|
||||||
|
position: { x: 0, y: 2, z: 5 },
|
||||||
|
target: { x: 0, y: 1, z: 0 }
|
||||||
|
},
|
||||||
gizmo: {
|
gizmo: {
|
||||||
position: true,
|
position: true,
|
||||||
rotation: false,
|
rotation: false,
|
||||||
@ -70348,14 +70352,22 @@ var kernel = (function (exports) {
|
|||||||
const scene = this.mainApp.appScene.object;
|
const scene = this.mainApp.appScene.object;
|
||||||
const canvas = AppConfig.container;
|
const canvas = AppConfig.container;
|
||||||
if (!scene || !canvas) return;
|
if (!scene || !canvas) return;
|
||||||
this.object = new ArcRotateCamera("Camera", Tools.ToRadians(70), Tools.ToRadians(85), 5, new Vector3(0, 2, 0), scene);
|
const { position, target } = AppConfig.camera;
|
||||||
|
this.object = new ArcRotateCamera(
|
||||||
|
"Camera",
|
||||||
|
Tools.ToRadians(70),
|
||||||
|
Tools.ToRadians(85),
|
||||||
|
5,
|
||||||
|
new Vector3(target.x, target.y, target.z),
|
||||||
|
scene
|
||||||
|
);
|
||||||
this.object.attachControl(canvas, true);
|
this.object.attachControl(canvas, true);
|
||||||
this.object.minZ = 0.01;
|
this.object.minZ = 0.01;
|
||||||
this.object.wheelPrecision = 200;
|
this.object.wheelPrecision = 200;
|
||||||
this.object.panningSensibility = 0;
|
this.object.panningSensibility = 0;
|
||||||
this.object.upperBetaLimit = Tools.ToRadians(90);
|
this.object.upperBetaLimit = Tools.ToRadians(90);
|
||||||
this.object.position = new Vector3(0, 0, 10);
|
this.object.position = new Vector3(position.x, position.y, position.z);
|
||||||
this.setTarget(0, 0.5, 0);
|
this.setTarget(target.x, target.y, target.z);
|
||||||
}
|
}
|
||||||
/** 设置相机目标点 */
|
/** 设置相机目标点 */
|
||||||
setTarget(x, y, z) {
|
setTarget(x, y, z) {
|
||||||
@ -354678,16 +354690,6 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
});
|
});
|
||||||
return min.add(max).scaleInPlace(0.5);
|
return min.add(max).scaleInPlace(0.5);
|
||||||
}
|
}
|
||||||
setupShadows(meshes) {
|
|
||||||
const appLight = this.mainApp.appLight;
|
|
||||||
if (!appLight) return;
|
|
||||||
meshes.forEach((mesh) => {
|
|
||||||
if (mesh.getTotalVertices() > 0) {
|
|
||||||
appLight.addShadowCaster(mesh);
|
|
||||||
mesh.receiveShadows = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/** 获取缓存的网格 */
|
/** 获取缓存的网格 */
|
||||||
getCachedMeshes(name) {
|
getCachedMeshes(name) {
|
||||||
return this.modelDic.Get(name);
|
return this.modelDic.Get(name);
|
||||||
@ -355956,6 +355958,8 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
material.albedoTexture = null;
|
material.albedoTexture = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
material.roughness = 0.8;
|
||||||
|
material.metallic = 0;
|
||||||
material.markDirty();
|
material.markDirty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -358085,9 +358089,6 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
if (this.config.position) {
|
if (this.config.position) {
|
||||||
this.ground.position = this.config.position;
|
this.ground.position = this.config.position;
|
||||||
}
|
}
|
||||||
if (this.config.receiveShadows) {
|
|
||||||
this.ground.receiveShadows = true;
|
|
||||||
}
|
|
||||||
this.ground.isPickable = false;
|
this.ground.isPickable = false;
|
||||||
}
|
}
|
||||||
/** 创建材质 */
|
/** 创建材质 */
|
||||||
@ -358226,6 +358227,7 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
AppConfig.container = config.container;
|
AppConfig.container = config.container;
|
||||||
AppConfig.modelUrlList = config.modelUrlList || [];
|
AppConfig.modelUrlList = config.modelUrlList || [];
|
||||||
AppConfig.env = { ...AppConfig.env, ...config.env || {} };
|
AppConfig.env = { ...AppConfig.env, ...config.env || {} };
|
||||||
|
AppConfig.camera = { ...AppConfig.camera, ...config.camera || {} };
|
||||||
AppConfig.gizmo = { ...AppConfig.gizmo, ...config.gizmo || {} };
|
AppConfig.gizmo = { ...AppConfig.gizmo, ...config.gizmo || {} };
|
||||||
AppConfig.outline = { ...AppConfig.outline, ...config.outline || {} };
|
AppConfig.outline = { ...AppConfig.outline, ...config.outline || {} };
|
||||||
this.appPositionGizmo.configure(AppConfig.gizmo);
|
this.appPositionGizmo.configure(AppConfig.gizmo);
|
||||||
@ -358362,6 +358364,7 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
* @param options 材质应用选项
|
* @param options 材质应用选项
|
||||||
*/
|
*/
|
||||||
apply: (options) => {
|
apply: (options) => {
|
||||||
|
console.log(options);
|
||||||
this.mainApp.gameManager.applyMaterial(options);
|
this.mainApp.gameManager.applyMaterial(options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -358704,6 +358707,7 @@ clipPos=viewProjection*worldPos;previousClipPos=previousViewProjection*previousW
|
|||||||
container,
|
container,
|
||||||
modelUrlList: params.modelUrlList || [],
|
modelUrlList: params.modelUrlList || [],
|
||||||
env: params.env,
|
env: params.env,
|
||||||
|
camera: params.camera,
|
||||||
gizmo: params.gizmo,
|
gizmo: params.gizmo,
|
||||||
outline: params.outline
|
outline: params.outline
|
||||||
});
|
});
|
||||||
|
|||||||
360193
examples/index.js
360193
examples/index.js
File diff suppressed because one or more lines are too long
4
index.js
4
index.js
@ -263,6 +263,8 @@ export const executeEvent = async (dropzone_data, result, sku) => {
|
|||||||
const materialName = event.material_name;
|
const materialName = event.material_name;
|
||||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
kernel.material.apply({
|
kernel.material.apply({
|
||||||
target: materialName,
|
target: materialName,
|
||||||
modelId: modelName + '_' + modelId, // 传入 modelId,只替换该模型的材质
|
modelId: modelName + '_' + modelId, // 传入 modelId,只替换该模型的材质
|
||||||
@ -378,6 +380,8 @@ export const executeEvent2 = async (result, sku) => {
|
|||||||
albedoColor: color,
|
albedoColor: color,
|
||||||
albedoTexture: color_map_url,
|
albedoTexture: color_map_url,
|
||||||
normalMap: normal_map_url,
|
normalMap: normal_map_url,
|
||||||
|
metallic: +metallic,
|
||||||
|
roughness: +roughness,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||||
|
|||||||
@ -97,9 +97,6 @@ export class AppGround extends Monobehiver {
|
|||||||
this.ground.position = this.config.position;
|
this.ground.position = this.config.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.receiveShadows) {
|
|
||||||
this.ground.receiveShadows = true;
|
|
||||||
}
|
|
||||||
this.ground.isPickable = false;
|
this.ground.isPickable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,6 @@ export class AppLight extends Monobehiver {
|
|||||||
Awake(): void {
|
Awake(): void {
|
||||||
// 主光源(模拟太阳)
|
// 主光源(模拟太阳)
|
||||||
const light = new DirectionalLight("sun", new Vector3(-1, -2, -1), this.mainApp.appScene.object);
|
const light = new DirectionalLight("sun", new Vector3(-1, -2, -1), this.mainApp.appScene.object);
|
||||||
light.intensity = 1.2;
|
light.intensity = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -215,18 +215,6 @@ export class AppModel extends Monobehiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setupShadows(meshes: AbstractMesh[]): void {
|
|
||||||
const appLight = this.mainApp.appLight;
|
|
||||||
if (!appLight) return;
|
|
||||||
|
|
||||||
meshes.forEach(mesh => {
|
|
||||||
if (mesh.getTotalVertices() > 0) {
|
|
||||||
appLight.addShadowCaster(mesh);
|
|
||||||
mesh.receiveShadows = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取缓存的网格 */
|
/** 获取缓存的网格 */
|
||||||
getCachedMeshes(name: string): AbstractMesh[] | undefined {
|
getCachedMeshes(name: string): AbstractMesh[] | undefined {
|
||||||
return this.modelDic.Get(name);
|
return this.modelDic.Get(name);
|
||||||
|
|||||||
@ -19,5 +19,6 @@ export class AppScene extends Monobehiver {
|
|||||||
this.object = new Scene(this.mainApp.appEngin.object);
|
this.object = new Scene(this.mainApp.appEngin.object);
|
||||||
this.object.clearColor = new Color4(0, 0, 0, 0); // 透明背景
|
this.object.clearColor = new Color4(0, 0, 0, 0); // 透明背景
|
||||||
this.object.skipFrustumClipping = true; // 跳过视锥剔除优化性能
|
this.object.skipFrustumClipping = true; // 跳过视锥剔除优化性能
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -810,6 +810,7 @@ export class GameManager extends Monobehiver {
|
|||||||
material.albedoColor.copyFrom(color);
|
material.albedoColor.copyFrom(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//应用反照率纹理(颜色贴图)
|
//应用反照率纹理(颜色贴图)
|
||||||
if (options.albedoTexture !== undefined) {
|
if (options.albedoTexture !== undefined) {
|
||||||
if (options.albedoTexture) {
|
if (options.albedoTexture) {
|
||||||
@ -820,37 +821,8 @@ export class GameManager extends Monobehiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 应用法线贴图
|
material.roughness = 0.8;
|
||||||
// if (options.normalMap !== undefined) {
|
material.metallic = 0;
|
||||||
// if (options.normalMap) {
|
|
||||||
// material.bumpTexture = new Texture(options.normalMap);
|
|
||||||
// } else {
|
|
||||||
// // 传入空字符串或 null 时清空贴图
|
|
||||||
// material.bumpTexture = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 应用金属度贴图
|
|
||||||
// if (options.metallicTexture !== undefined) {
|
|
||||||
// if (options.metallicTexture) {
|
|
||||||
// material.metallicTexture = new Texture(options.metallicTexture);
|
|
||||||
// } else {
|
|
||||||
// // 传入空字符串或 null 时清空贴图
|
|
||||||
// material.metallicTexture = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
console.log(options);
|
|
||||||
|
|
||||||
// 应用粗糙度值
|
|
||||||
if (options.roughness !== undefined) {
|
|
||||||
material.roughness = options.roughness;
|
|
||||||
}
|
|
||||||
|
|
||||||
// // 应用金属度值
|
|
||||||
if (options.metallic !== undefined) {
|
|
||||||
material.metallic = options.metallic;
|
|
||||||
}
|
|
||||||
// alert(typeof options.metallic + ' ' + typeof options.roughness);
|
|
||||||
|
|
||||||
// 强制刷新材质
|
// 强制刷新材质
|
||||||
material.markDirty();
|
material.markDirty();
|
||||||
@ -858,4 +830,7 @@ console.log(options);
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user