Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ae9d88c6d7 | |||
| 7e4b09133d | |||
| 9045cb79c2 |
7
.claude/settings.local.json
Normal file
7
.claude/settings.local.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"mcp__ide__getDiagnostics"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "material-editor",
|
||||
"private": true,
|
||||
"version": "1.0.33",
|
||||
"version": "1.0.36",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<legend>DEBUG</legend>
|
||||
<label>上传路径ID</label>
|
||||
<input v-model="materialInfo.dirId" type="text" placeholder="材质路径ID" />
|
||||
<label>配置JSON</label>
|
||||
<label>纹理(BASE64)</label>
|
||||
<input v-model="materialInfo.inputText" type="text" />
|
||||
<button class="btn-success" style="min-width: 110px;" @click="loadData">加载</button>
|
||||
</fieldset>
|
||||
@@ -214,7 +214,7 @@ watch(() => props.name, () => {
|
||||
});
|
||||
|
||||
watch(textureAdjustment, async (val) => {
|
||||
scene.UpdateTexture();
|
||||
scene.UpdateTexture(val);
|
||||
}, { deep: true });
|
||||
|
||||
// 监听纹理更新
|
||||
@@ -247,8 +247,7 @@ async function UpdateMaterial() {
|
||||
|
||||
async function loadData() {
|
||||
if (!materialInfo.inputText) return;
|
||||
const json = JSON.parse(materialInfo.inputText);
|
||||
const cadFile = FromDeflateBase64(json.file);
|
||||
const cadFile = FromDeflateBase64(materialInfo.inputText);
|
||||
scene.ImportMaterialAsync(cadFile)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +55,12 @@ async function HandleUpdateConfig() {
|
||||
await scene.ImportMaterialAsync(json);
|
||||
editMode.value = true;
|
||||
}
|
||||
else { editMode.value = false; }
|
||||
else {
|
||||
editMode.value = false;
|
||||
if (config.textures && config.textures.length > 0) {
|
||||
textures.value = Array.from(config.textures);
|
||||
await scene.ChangeTextureFromUrlAsync(textures.value[0].src); // 这一行是保证首次Mount组件时纹理能够立刻刷新
|
||||
await scene.ChangeTextureFromUrlAsync(textures.value[0].src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,18 @@ const sceneSetup = () => {
|
||||
|
||||
|
||||
/** 这是自定义材质更新方法,WebCAD库中的TextureTableRecord.TextureUpdate方法在导出的时候被删除了,所以需要自己实现 */
|
||||
function UpdateTexture() {
|
||||
function UpdateTexture(adjustment?: Partial<TextureAdjustment>) {
|
||||
const record = _currTexture.value;
|
||||
if (adjustment) {
|
||||
// 将用户修改的纹理配置项同步写回 TextureTableRecord,确保序列化时数据不丢失
|
||||
if (adjustment.wrapS !== undefined) record.WrapS = adjustment.wrapS;
|
||||
if (adjustment.wrapT !== undefined) record.WrapT = adjustment.wrapT;
|
||||
if (adjustment.rotation !== undefined) record.rotation = adjustment.rotation;
|
||||
if (adjustment.repeatX !== undefined) record.repeatX = adjustment.repeatX;
|
||||
if (adjustment.repeatY !== undefined) record.repeatY = adjustment.repeatY;
|
||||
if (adjustment.moveX !== undefined) record.moveX = adjustment.moveX;
|
||||
if (adjustment.moveY !== undefined) record.moveY = adjustment.moveY;
|
||||
}
|
||||
const texture = record['texture'] as Texture;
|
||||
texture.wrapS = record.WrapS;
|
||||
texture.wrapT = record.WrapT;
|
||||
@@ -99,7 +109,6 @@ const sceneSetup = () => {
|
||||
}
|
||||
|
||||
async function ChangeTextureFromUrlAsync(url?: string) {
|
||||
console.warn("Update texture from url:", url);
|
||||
// 关联贴图
|
||||
const db = Material.value.Db;
|
||||
// 材质未初始化
|
||||
@@ -108,11 +117,15 @@ const sceneSetup = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const record = new TextureTableRecord();
|
||||
// 如果url为空,则保留原有材质中的纹理(修改模式),否则重新实例化纹理对象
|
||||
let record = Material.value.map?.Object as TextureTableRecord;
|
||||
if (url) {
|
||||
record = new TextureTableRecord();
|
||||
record.Name = db.TextureTable.AllocateName();
|
||||
db.TextureTable.Add(record);
|
||||
// 替换map
|
||||
Material.value.map = record.Id;
|
||||
}
|
||||
|
||||
// 设置Store
|
||||
_currTexture.value = record;
|
||||
@@ -123,6 +136,7 @@ const sceneSetup = () => {
|
||||
}
|
||||
|
||||
if (!texture.image) {
|
||||
console.warn('Load Image: ', GetConfig().host + '/' + record.imageUrl);
|
||||
const img = await LoadImageFromUrl(GetConfig().host + '/' + record.imageUrl);
|
||||
texture.image = img;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user