2 Commits

6 changed files with 39 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "material-editor", "name": "material-editor",
"private": true, "private": true,
"version": "1.0.19", "version": "1.0.23",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -36,10 +36,11 @@ export class MaterialRenderer
var ambient = new AmbientLight(); var ambient = new AmbientLight();
this.scene.add(ambient); this.scene.add(ambient);
//Pontual light // 这个点光源会导致生成的缩略图上有一个高光
var point = new PointLight(); // //Pontual light
point.position.set(-0.5, 1, 1.5); // var point = new PointLight();
this.scene.add(point); // point.position.set(-0.5, 1, 1.5);
// this.scene.add(point);
} }
//Set render size //Set render size

View File

@@ -1,4 +1,4 @@
import { CADFiler, CADObject, Database, DuplicateRecordCloning, Factory, LayerNode, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api"; import { CADFactory, CADFiler, CADObject, Database, DuplicateRecordCloning, Factory, LayerNode, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
// TODO: Danger: 注意入侵性代码 // TODO: Danger: 注意入侵性代码
// 疑似是WebCAD中的漏洞当传入new Database()时, // 疑似是WebCAD中的漏洞当传入new Database()时,
@@ -14,26 +14,22 @@ Database.prototype.AllocationObjectId = function (this: Database, object: CADObj
this.idMap.set(object.Id.Index, object.Id); this.idMap.set(object.Id.Index, object.Id);
} }
export function MaterialOut(material: PhysicalMaterialRecord): string export function MaterialOut(material: PhysicalMaterialRecord): string {
{ let db = new Database();
try { db.WblockCloneObejcts(
let db = new Database(); [material],
db.WblockCloneObejcts( db.MaterialTable,
[material], new Map(),
db.MaterialTable, DuplicateRecordCloning.Ignore
new Map(), );
DuplicateRecordCloning.Ignore let json = JSON.stringify(db.FileWrite().Data);
); // // TODO: Danger: 因为WebCAD依赖库中的部分类的构造函数名异常所以在生成JSON时需要对类名进行替换
let json = JSON.stringify(db.FileWrite().Data); json = json.replace(LayerNode.name, "LayerNode")
// // TODO: Danger: 因为WebCAD依赖库中的部分类的构造函数名异常所以在生成JSON时需要对类名进行替换 .replace(TextureTableRecord.name, "TextureTableRecord")
json = json.replace(LayerNode.name, "LayerNode") .replace(PhysicalMaterialRecord.name, "PhysicalMaterialRecord");
.replace(TextureTableRecord.name, "TextureTableRecord") console.debug("DEBUG CAD Object Name", CADFactory['factory'].objectNameMap);
.replace(PhysicalMaterialRecord.name, "PhysicalMaterialRecord"); console.debug("CURRENT PROTOTYPE NAME\n", "LAYERNODE:", LayerNode.name, "TEXTURETABLERECORD:", TextureTableRecord.name, "PHYSICALMATERIALRECORD:", PhysicalMaterialRecord.name);
return json; return json;
} catch (error) {
console.error("error in MaterialOut:", error, material);
throw error;
}
} }
export function MaterialIn(fileData: Object[]): PhysicalMaterialRecord export function MaterialIn(fileData: Object[]): PhysicalMaterialRecord

View File

@@ -16,6 +16,7 @@
<CfFlex gap="1em" v-if="debugMode"> <CfFlex gap="1em" v-if="debugMode">
<button class="btn-success" style="min-width: 110px;" @click="HandleUpload">保存</button> <button class="btn-success" style="min-width: 110px;" @click="HandleUpload">保存</button>
<button class="btn-danger" style="min-width: 110px;" @click="HandleCancel">取消</button> <button class="btn-danger" style="min-width: 110px;" @click="HandleCancel">取消</button>
<button v-if="debugMode" class="btn-primary" style="min-width: 110px;" @click="HandleGenerateLogo">预览缩略图</button>
</CfFlex> </CfFlex>
</div> </div>
@@ -115,6 +116,7 @@ import { DirectoryId } from "../api/Request";
import { IsNullOrWhitespace } from "../helpers/helper.string"; import { IsNullOrWhitespace } from "../helpers/helper.string";
import { FromDeflateBase64, ToDeflatedBase64 } from "../helpers/helper.material"; import { FromDeflateBase64, ToDeflatedBase64 } from "../helpers/helper.material";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { DownloadFile } from "../helpers/helper.web";
export interface MaterialRequest { export interface MaterialRequest {
/** 材质名 */ /** 材质名 */
@@ -273,6 +275,11 @@ function HandleCancel() {
emits('cancel'); emits('cancel');
} }
async function HandleGenerateLogo() {
const blob = await scene.GenerateMaterialLogoAsync();
DownloadFile("logo.png", blob);
}
defineExpose({ defineExpose({
Upload: HandleUpload, Upload: HandleUpload,
Cancel: HandleCancel Cancel: HandleCancel

View File

@@ -1,7 +1,7 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import { MaterialEditor } from "../common/MaterialEditor"; import { MaterialEditor } from "../common/MaterialEditor";
import { Database, ObjectId, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api"; import { Database, PhysicalMaterialRecord, TextureTableRecord } from "webcad_ue4_api";
import { LoadImageFromUrl } from "../helpers/helper.imageLoader"; import { LoadImageFromUrl } from "../helpers/helper.imageLoader";
import { Texture } from "three"; import { Texture } from "three";
import { materialRenderer } from "../common/MaterialRenderer"; import { materialRenderer } from "../common/MaterialRenderer";

View File

@@ -9,12 +9,19 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue(), dts({rollupTypes: true, tsconfigPath: './tsconfig.app.json',insertTypesEntry: true})], plugins: [vue(), dts({rollupTypes: true, tsconfigPath: './tsconfig.app.json',insertTypesEntry: true})],
define: { 'process.env.NODE_ENV': '"production"' },
resolve: {
alias: {
// 'vue': path.resolve(__dirname, './node_modules/vue/dist/vue.esm-browser.prod.js'),
// 'pinia': path.resolve(__dirname, './node_modules/pinia/dist/pinia.esm-browser.js'),
}
},
build: { build: {
lib: { lib: {
entry: resolve(__dirname, 'src/lib/index.ts'), entry: resolve(__dirname, 'src/lib/index.ts'),
name: 'MaterialEditor', name: 'MaterialEditor',
fileName: (format) => `material-editor.${format}.js`, fileName: (format) => `material-editor.${format}.js`,
formats: ['es'] formats: ['es', 'iife', 'umd']
}, },
rollupOptions: { rollupOptions: {
// external: ['vue'], // external: ['vue'],