Commit 5d6eba45 authored by huangwenjie's avatar huangwenjie

fix:添加使用说明

parent c33f03b1
......@@ -68,7 +68,7 @@
"specularColor":{R: 0.3 G:0.3 B:0.3},
"specularPower":17.92,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Details_A.jpg",
"diffuseTexture":"E:/WorkFiles/NW_Sword_Material_IDEA/SwordMaterialIDEA/models/babylon/car_1/Car_Camaro_Paint_A_Game.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
......
This diff is collapsed.
{
'meshName':'mutong',
'materialName':'mutong',
'customType':'StandardMaterial',
'wireframe':false,
'backFaceCulling':true
'needDepthPrePass':false,
'alpha':1,
'ambientColor':{R: 0 G:0 B:0},
'diffuseColor':{R: 1 G:1 B:1},
'emissiveColor':{R: 0 G:0 B:0},
'specularColor':{R: 1 G:1 B:1},
'specularPower':9.605383909452431,
'useSpecularOverAlpha':false,
'diffuseTexture':'E:/WorkFiles/NW_Sword_Material_IDEA/SwordMaterialIDEA/models/obj/mutong/Diffuse.png',
'ambientTexture':'E:/WorkFiles/NW_Sword_Material_IDEA/SwordMaterialIDEA/models/obj/mutong/Ambient Occlusion Map from Mesh MuShuiTong_ML_initialShadingGroup.png',
'emissiveTexture':'undefined',
'lightmapTexture':'undefined',
'opacityTexture':'undefined',
'reflectionTexture':'undefined',
'refractionTexture':'undefined',
'bumpTexture':'E:/WorkFiles/NW_Sword_Material_IDEA/SwordMaterialIDEA/models/obj/mutong/Normal.png'
}
\ No newline at end of file
import { FilesManager } from './filesManager';
import { ExportConfigs } from './exportConfigs';
import { SceneManager } from './sceneManager';
import { ImportConfigs } from './importConfigs';
let sceneManager:any;
......@@ -48,6 +49,8 @@ export class UiFrame {
}
private filesManager = new FilesManager();
public init(){
......@@ -260,7 +263,6 @@ export class UiFrame {
let texture:BABYLON.Texture = null;
let textureName:string;
let texturePath:string;
let filesManager = new FilesManager();
if(!matName || matName === ''){
alert('请输入新材质的名称!')
}else{
......@@ -282,7 +284,7 @@ export class UiFrame {
$('.w2ui-msg-button.w2ui-msg-close').click();
}else{
// 如果图片路径在不同路径下,则先复制到当前路径再读取当前路径下的图片
filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
scope.filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
currObj.material = new BABYLON.StandardMaterial(matName,sceneManager.scene)
texture = new BABYLON.Texture(`${currFilePath}${textureName}`, sceneManager.scene);
currObj.material.diffuseTexture = texture;
......@@ -310,7 +312,7 @@ export class UiFrame {
$('.w2ui-msg-button.w2ui-msg-close').click();
}else{
// 如果图片路径在不同路径下,则先复制到当前路径再读取当前路径下的图片
filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
scope.filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
currObj.material = new BABYLON.PBRMaterial(matName,sceneManager.scene)
texture = new BABYLON.Texture(`${currFilePath}${textureName}`, sceneManager.scene);
currObj.material.albedoTexture = texture;
......@@ -411,7 +413,6 @@ export class UiFrame {
let index:any;
let textureName:string;
let texturePath:string;
let filesManager:FilesManager = new FilesManager();;
sceneManager.scene.meshes.forEach(mesh=>{
if(mesh.name === currObjName){
if(mesh.material == null){
......@@ -423,7 +424,6 @@ export class UiFrame {
index = newUrl.lastIndexOf("\\");
textureName = newUrl.substring(index + 1, newUrl.length);
texturePath = newUrl.split(textureName)[0];
debugger
if(texturePath === currFilePath){
// 如果图片路径在当前指定文件夹路径下则直接读取
let texture = new BABYLON.Texture(newUrl, sceneManager.scene)
......@@ -435,7 +435,7 @@ export class UiFrame {
$('#currTexture .uploadTexture').text('更换贴图')
}else{
// 如果图片路径在不同路径下,则先复制到当前路径再读取当前路径下的图片
filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
scope.filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
let texture = new BABYLON.Texture(`${currFilePath}${textureName}`, sceneManager.scene)
mat[currTextureType] = texture;
$('.currTextureImg img').attr('src', `${currFilePath}${textureName}`)
......@@ -452,7 +452,6 @@ export class UiFrame {
index = newUrl.lastIndexOf("\\");
textureName = newUrl.substring(index + 1, newUrl.length);
texturePath = newUrl.split(textureName)[0];
debugger
if(texturePath === currFilePath){
// 如果图片路径在当前指定文件夹路径下则直接读取
let texture = new BABYLON.Texture(newUrl, sceneManager.scene)
......@@ -464,7 +463,7 @@ export class UiFrame {
$('#currTexture .uploadTexture').text('更换贴图')
}else{
// 如果图片路径在不同路径下,则先复制到当前路径再读取当前路径下的图片
filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
scope.filesManager.copyFile(newUrl,`${currFilePath}${textureName}`).then(()=>{
let texture = new BABYLON.Texture(`${currFilePath}${textureName}`, sceneManager.scene)
mesh.material[currTextureType] = texture;
$('.currTextureImg img').attr('src', `${currFilePath}${textureName}`)
......@@ -481,7 +480,7 @@ export class UiFrame {
// $('.currTextureImg .revocation').css('display','block')
});
// 撤销更改
// $('.currTextureImg .revocation').click(()=>{
// let oldMat:BABYLON.Material;
// sceneManager.changedMats.forEach(mat=>{
......@@ -657,7 +656,7 @@ export class UiFrame {
}
private loadNewModel(e){
let scope = this;
// 重置属性,清空场景
currObj = null
currObjName = null
......@@ -683,14 +682,14 @@ export class UiFrame {
currFilePath = abUrl;
let to = `${abUrl}${fileName}`;
// 复制文件到指定目录下
console.log(from,to)
let filesManager = new FilesManager();
let copyfile = filesManager.filesOperation(from, to);
console.log(from,to);
let copyfile = scope.filesManager.filesOperation(from, to);
copyfile.then(()=>{
// 导入模型到场景
sceneManager.loadMeshes('default', rootUrl, fileName, sceneManager.scene);
// 查询是否有材质配置文件,如果有则加载配置文件,没有则不加载
let importConfigs = new ImportConfigs();
importConfigs.load(currFilePath);
$('#currTexture .TextureTabs ul li:first-child').click();
})
}
......
......@@ -31,34 +31,34 @@ export class ExportConfigs {
}
multiMat = `${multiMat},
{
"materialName":"${mat.name}",
"customType":${matType},
"wireframe":${mat.wireframe},
"backFaceCulling":${mat.backFaceCulling}
"needDepthPrePass":${mat.needDepthPrePass},
"alpha":${mat.alpha},
"ambientColor":${mat.ambientColor},
"diffuseColor":${mat.diffuseColor},
"emissiveColor":${mat.emissiveColor},
"specularColor":${mat.specularColor},
"specularPower":${mat.specularPower},
"useSpecularOverAlpha":${mat.useSpecularOverAlpha},
"diffuseTexture":"${mat.diffuseTexture}",
"ambientTexture":"${mat.ambientTexture}",
"emissiveTexture":"${mat.emissiveTexture}",
"lightmapTexture":"${mat.lightmapTexture}",
"opacityTexture":"${mat.opacityTexture}",
"reflectionTexture":"${mat.reflectionTexture}",
"refractionTexture":"${mat.refractionTexture}",
'materialName':'${mat.name}',
'customType':${matType},
'wireframe':${mat.wireframe},
'backFaceCulling':${mat.backFaceCulling}
'needDepthPrePass':${mat.needDepthPrePass},
'alpha':${mat.alpha},
'ambientColor':${mat.ambientColor},
'diffuseColor':${mat.diffuseColor},
'emissiveColor':${mat.emissiveColor},
'specularColor':${mat.specularColor},
'specularPower':${mat.specularPower},
'useSpecularOverAlpha':${mat.useSpecularOverAlpha},
'diffuseTexture':'${mat.diffuseTexture}',
'ambientTexture':'${mat.ambientTexture}',
'emissiveTexture':'${mat.emissiveTexture}',
'lightmapTexture':'${mat.lightmapTexture}',
'opacityTexture':'${mat.opacityTexture}',
'reflectionTexture':'${mat.reflectionTexture}',
'refractionTexture':'${mat.refractionTexture}',
}`
});
this.configJson = `
${this.configJson},
{
"meshName":"${currentObj.name}",
"materialName":"${material.name}",
"customType":"MultiMaterial",
"subMaterial":"${multiMat}"
'meshName':'${currentObj.name}',
'materialName':'${material.name}',
'customType':'MultiMaterial',
'subMaterial':'${multiMat}'
}`
} else if (currentObj.material instanceof BABYLON.StandardMaterial) {
// 是标准材质时
......@@ -66,27 +66,27 @@ export class ExportConfigs {
this.configJson = `
${this.configJson},
{
"meshName":"${currentObj.name}",
"materialName":"${mat.name}",
"customType":"StandardMaterial",
"wireframe":${mat.wireframe},
"backFaceCulling":${mat.backFaceCulling}
"needDepthPrePass":${mat.needDepthPrePass},
"alpha":${mat.alpha},
"ambientColor":${mat.ambientColor},
"diffuseColor":${mat.diffuseColor},
"emissiveColor":${mat.emissiveColor},
"specularColor":${mat.specularColor},
"specularPower":${mat.specularPower},
"useSpecularOverAlpha":${mat.useSpecularOverAlpha},
"diffuseTexture":"${mat.diffuseTexture}",
"ambientTexture":"${mat.ambientTexture}",
"emissiveTexture":"${mat.emissiveTexture}",
"lightmapTexture":"${mat.lightmapTexture}",
"opacityTexture":"${mat.opacityTexture}",
"reflectionTexture":"${mat.reflectionTexture}",
"refractionTexture":"${mat.refractionTexture}",
"bumpTexture":"${mat.bumpTexture}"
'meshName':'${currentObj.name}',
'materialName':'${mat.name}',
'customType':'StandardMaterial',
'wireframe':${mat.wireframe},
'backFaceCulling':${mat.backFaceCulling}
'needDepthPrePass':${mat.needDepthPrePass},
'alpha':${mat.alpha},
'ambientColor':${mat.ambientColor},
'diffuseColor':${mat.diffuseColor},
'emissiveColor':${mat.emissiveColor},
'specularColor':${mat.specularColor},
'specularPower':${mat.specularPower},
'useSpecularOverAlpha':${mat.useSpecularOverAlpha},
'diffuseTexture':'${mat.diffuseTexture}',
'ambientTexture':'${mat.ambientTexture}',
'emissiveTexture':'${mat.emissiveTexture}',
'lightmapTexture':'${mat.lightmapTexture}',
'opacityTexture':'${mat.opacityTexture}',
'reflectionTexture':'${mat.reflectionTexture}',
'refractionTexture':'${mat.refractionTexture}',
'bumpTexture':'${mat.bumpTexture}'
}`
} else if (currentObj.material instanceof BABYLON.PBRMaterial) {
// 是PBR材质时
......@@ -94,35 +94,35 @@ export class ExportConfigs {
this.configJson = `
${this.configJson},
{
"meshName":"${currentObj.name}",
"materialName":"${mat.name}",
"customType":"PBRMaterial",
"wireframe":${mat.wireframe},
"backFaceCulling":${mat.backFaceCulling}
"needDepthPrePass":${mat.needDepthPrePass},
"alpha":${mat.alpha},
"ambientColor":${mat.ambientColor},
"diffuseColor":${mat.diffuseColor},
"emissiveColor":${mat.emissiveColor},
"specularColor":${mat.specularColor},
"specularPower":${mat.specularPower},
"useSpecularOverAlpha":${mat.useSpecularOverAlpha},
"albedoTexture":"${mat.albedoTexture}",
"ambientTexture":"${mat.ambientTexture}",
"emissiveTexture":"${mat.emissiveTexture}",
"lightmapTexture":"${mat.lightmapTexture}",
"opacityTexture":"${mat.opacityTexture}",
"reflectionTexture":"${mat.reflectionTexture}",
"refractionTexture":"${mat.refractionTexture}",
"bumpTexture":"${mat.bumpTexture}"
'meshName':'${currentObj.name}',
'materialName':'${mat.name}',
'customType':'PBRMaterial',
'wireframe':${mat.wireframe},
'backFaceCulling':${mat.backFaceCulling}
'needDepthPrePass':${mat.needDepthPrePass},
'alpha':${mat.alpha},
'ambientColor':${mat.ambientColor},
'diffuseColor':${mat.diffuseColor},
'emissiveColor':${mat.emissiveColor},
'specularColor':${mat.specularColor},
'specularPower':${mat.specularPower},
'useSpecularOverAlpha':${mat.useSpecularOverAlpha},
'albedoTexture':'${mat.albedoTexture}',
'ambientTexture':'${mat.ambientTexture}',
'emissiveTexture':'${mat.emissiveTexture}',
'lightmapTexture':'${mat.lightmapTexture}',
'opacityTexture':'${mat.opacityTexture}',
'reflectionTexture':'${mat.reflectionTexture}',
'refractionTexture':'${mat.refractionTexture}',
'bumpTexture':'${mat.bumpTexture}'
}`
}
} else {
// 没材质
this.configJson = `${this.configJson},
{
"meshName":"${currentObj.name}",
"customType":"none"
'meshName':'${currentObj.name}',
'customType':'none'
}`
}
})
......@@ -130,11 +130,12 @@ export class ExportConfigs {
// 将材质配置写入到对应目录的配置文件中
filesManager.readConfig().then((path)=>{
filesManager.configPath = path;
filesManager.writeFile(`${to}matConfig.json`, this.configJson, { flag: "w" }, (err) => {
filesManager.writeFile(`${to}matConfig.json`, this.configJson, { flag: 'w' }, (err) => {
if (err) {
throw err;
} else {
console.log("写入成功");
console.log('写入成功');
}
})
});
......
......@@ -106,7 +106,7 @@ export class FilesManager{
let rootUrl = `./models/${format}/${name}/`;
let abUrl = `E:/WorkFiles/NW_Sword_Material_IDEA/SwordMaterialIDEA/models/${format}/${name}/`;
let textureUrls:string[] = [];
fs.readFile(from, 'utf-8', (err, data) => {
fs.readFile(from, {encoding:"utf-8"}, (err, data) => {
// 读取文件失败/错误
if (err) {
throw err;
......@@ -117,7 +117,7 @@ export class FilesManager{
let mtlUrl = data.toString().split("mtllib ")[1].split('#')[0].replace(/[\r\n]/g,"");
let abMtlUrl = `${fromPath}${mtlUrl}`
this.copyFile(`${fromPath}/${name}.mtl`,`${abUrl}${name}.mtl`).then(()=>{
fs.readFile(abMtlUrl,'utf-8',(err, data)=>{
fs.readFile(abMtlUrl,{encoding:"utf-8"},(err, data)=>{
if(err){
throw err
}
......
import { FilesManager } from './filesManager';
export class ImportConfigs{
// 导入材质配置
constructor(){
}
private fs = window['require']('fs');
public load(from){
let filesManager = new FilesManager()
const fs = window['require']('fs');
fs.readFile(from, {encoding:'unf8'}, )
let scope = this;
let url = `${from}matConfig.json`
scope.fs.exists(url, function(exists) {
if(exists){
// 如果存在材质的配置文件,则读取
scope.fs.readFile(url, {encoding:"utf-8"}, (err, data) => {
// 读取文件失败/错误
debugger
if (err) {
throw err;
}
// 读取文件成功
console.log('已读')
console.log(data)
let obj = JSON.parse(data)
console.log(obj)
})
}
});
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ export class SceneManager {
scope.camera.attachControl(canvas, true);
// 相机的自动旋转行为
scope.camera.useAutoRotationBehavior = true;
scope.camera.inertia = 0;
scope.camera.inertia = 0.75;
// 设置相机旋转速度
scope.camera.behaviors.forEach(behabior=>{
if(behabior instanceof BABYLON.AutoRotationBehavior){
......
,
{
"meshName":"Car_DBS_S",
"customType":"none"
},
{
"meshName":"Mesh",
"customType":"none"
},
{
"meshName":"MeshWithAnim",
"materialName":"Material #69",
"customType":"MultiMaterial",
"subMaterial":"{},
{
"materialName":"Car_DBS_Paint_S_Game",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0 G:0 B:0},
"specularPower":25.6,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Paint_S_Game.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"undefined",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_Dipan_All",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0.3 G:0.3 B:0.3},
"specularPower":17.92,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_Dipan_All.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"undefined",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_DBS_Details_A",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0.3 G:0.3 B:0.3},
"specularPower":17.92,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Details_A.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"undefined",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_DBS_Logo_A",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 0.4179 G:0.4179 B:0.4179},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0.3 G:0.3 B:0.3},
"specularPower":17.92,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Logo_A.png",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"Car_DBS_Logo_A.png",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_DBS_Glass_A",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0 G:0 B:0},
"specularPower":25.6,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Glass_A.png",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"Car_DBS_Glass_A.png",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_DBS_Wheel_S",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0 G:0 B:0},
"specularPower":25.6,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_Wheel_S.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"undefined",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
},
{
"materialName":"Car_DBS_UpS_Game",
"customType":StandardMaterial,
"wireframe":false,
"backFaceCulling":true,
"needDepthPrePass":false,
"alpha":1,
"ambientColor":{R: 1 G:1 B:1},
"diffuseColor":{R: 1 G:1 B:1},
"emissiveColor":{R: 0 G:0 B:0},
"specularColor":{R: 0 G:0 B:0},
"specularPower":25.6,
"useSpecularOverAlpha":true,
"diffuseTexture":"Car_DBS_UpS_Game.jpg",
"ambientTexture":"undefined",
"emissiveTexture":"undefined",
"lightmapTexture":"undefined",
"opacityTexture":"undefined",
"reflectionTexture":"undefined",
"refractionTexture":"undefined",
}"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment