Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CRME #616

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@
"icon": "icon.png",
"description": "Allows creating, editing, importing and exporting Cosmic Reach block models.",
"tags": ["Cosmic Reach"],
"version": "1.3.2",
"version": "2.0.0",
"min_version": "4.8.0",
"variant": "both",
"creation_date": "2024-04-19",
Expand Down
15 changes: 15 additions & 0 deletions plugins/cosmic_reach_model_editor/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,20 @@
]
}
]
},
"2.0.0": {
"title": "2.0.0",
"date": "2024-09-16",
"author": "Z. Hoeshin",
"categories": [
{
"title": "Features",
"list": [
"Textureless faces now do not require empty.png(instead they are not exported)",
"Added model properties(Tools>Edit Model Properties)(used for cullsSelf and isTransparent block properties)(they aren't stored when saved as .bbmodel due to BB restrictions)",
"New assets hyerarchy format replaced the old one"
]
}
]
}
}
109 changes: 96 additions & 13 deletions plugins/cosmic_reach_model_editor/cosmic_reach_model_editor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(() => {
let codec, export_action_block_minimized, export_action_block_maximized, import_action_block, dialog, originalJavaBlockCond, lastOccuranceOfSequenceInArray
let codec, export_action_block_minimized, export_action_block_maximized, import_action_block, dialog, propertiesDialog, originalJavaBlockCond, lastOccuranceOfSequenceInArray
const id = "cosmic_reach_model_editor"
const name = "Cosmic Reach Model Editor"
const icon = "icon.png"
Expand All @@ -10,14 +10,28 @@
author: "Z. Hoeshin",
description: "Allows creating, editing, importing and exporting Cosmic Reach block models.",
tags: ["Cosmic Reach"],
version: "1.3.2",
version: "2.0.0",
min_version: "4.8.0",
creation_date: "2024-04-19",
variant: "both",
new_repository_format: true,
has_changelog: true,
onload() {
originalJavaBlockCond = Codecs.java_block.load_filter.condition
const blockPropertiesForm = {
cullsSelf: {
label: "Culls Self",
type: "checkbox",
value: true
},
isTransparent: {
label: "Is transparent",
type: "checkbox",
value: false
}
}


Codecs.java_block.load_filter.condition = (model) => {
return !model.cuboids && originalJavaBlockCond(model);
}
Expand All @@ -29,6 +43,17 @@
lines: [],
})

propertiesDialog = new Dialog("cosmic_reach_model_properties_dialog", {
id: "cosmic_reach_model_properties_dialog",
totle: "Properties",
lines: [],
onConfirm: (b, e) => {
let res = propertiesDialog.getFormResult()
Project.properties = res
},
onCancel: (b, e) => {},
})

codec = new Codec("cosmic_reach_block_model_codec", {
name: "Cosmic Reach",
extension: "json",
Expand Down Expand Up @@ -77,8 +102,10 @@
for(let f of Object.keys(obj.faces)){
let uv = obj.faces[f].uv

let texture = Texture.all.filter((x) => {return x.uuid == obj.faces[f].texture})[0]
texture = (texture === undefined) ? "empty.png" : texture.name
let textures = Texture.all.filter((x) => {return x.uuid == obj.faces[f].texture})
let texture = textures[0]
if (texture !== undefined) texture = texture.name
//texture = (texture === undefined) ? "empty.png" : texture.name

let face = obj.faces[f]

Expand All @@ -91,7 +118,7 @@
"localBounds": [...obj.from, ...obj.to],
"faces":
{
"localNegX": {"uv": uvs.west.slice(0, 4), "ambientocclusion": uvs.west[4].tint === 0,
/*"localNegX": {"uv": uvs.west.slice(0, 4), "ambientocclusion": uvs.west[4].tint === 0,
"cullFace": uvs.west[4].cullFace !== "", "texture": uvs.west[5]},
"localPosX": {"uv": uvs.east.slice(0, 4), "ambientocclusion": uvs.east[4].tint === 0,
"cullFace": uvs.east[4].cullFace !== "", "texture": uvs.east[5]},
Expand All @@ -104,7 +131,19 @@
"localNegZ": {"uv": uvs.north.slice(0, 4), "ambientocclusion": uvs.north[4].tint === 0,
"cullFace": uvs.north[4].cullFace !== "", "texture": uvs.north[5]},
"localPosZ": {"uv": uvs.south.slice(0, 4), "ambientocclusion": uvs.south[4].tint === 0,
"cullFace": uvs.south[4].cullFace !== "", "texture": uvs.south[5]}
"cullFace": uvs.south[4].cullFace !== "", "texture": uvs.south[5]}*/
}
}

for(let i = 0; i < 6; i++){
if ((uvs[facenamesbb[i]][5] === undefined) || (uvs[facenamesbb[i]][5] === "empty.png")){
continue
}
cube.faces[facenamescr[i]] = {
"uv": uvs[facenamesbb[i]].slice(0, 4),
"ambientocclusion": uvs[facenamesbb[i]][4].tint === 0,
"cullFace": uvs[facenamesbb[i]][4].cullFace !== "",
"texture": uvs[facenamesbb[i]][5]
}
}

Expand Down Expand Up @@ -155,8 +194,16 @@
//JSON.stringify({"textures": textures, "cuboids": cuboids}, undefined, options.maximize ? 4 : undefined)



return stringifyJSON({"textures": textures, "cuboids": cuboids})
let r = {"textures": textures, "cuboids": cuboids}
if (Project.properties){
if (Project.properties.isTransparent !== undefined){
r.isTransparent = Project.properties.isTransparent
}
if (!Project.properties.cullsSelf !== undefined){
r.cullsSelf = Project.properties.cullsSelf
}
}
return stringifyJSON(r)
},

parse(rawJSONstring, path, cuboidsOnly = false){
Expand Down Expand Up @@ -187,7 +234,7 @@
return []
}else{
let p = data.parent
Blockbench.read([...patharr.slice(undefined, root - 1), "models", "blocks", p + (/\.json$/gui.test(p) ? "" : ".json")].join("/"), {
Blockbench.read([...patharr.slice(undefined, patharr.length - 3), p.replace(":", "/")].join("/"), {
extensions: ['json'],
type: 'Cosmic Reach Model',
readtype: 'text',
Expand Down Expand Up @@ -218,7 +265,7 @@
}

for(let t of Object.keys(data.textures)){
let newtexture = new Texture().fromPath([...patharr.slice(undefined, root - 1), "textures", "blocks", data.textures[t].fileName].join("/"))
let newtexture = new Texture().fromPath([...patharr.slice(undefined, patharr.length - 3), data.textures[t].fileName.replace(":", "/")].join("/"))
newtexture.name = data.textures[t].fileName
loadedTextures[t] = newtexture.add()
}
Expand All @@ -235,7 +282,7 @@
throw Error(`No cuboids found in file ${path}`)
}else{
let p = data.parent
Blockbench.read([...patharr.slice(undefined, root - 1), "models", "blocks", p + (/\.json$/gui.test(p) ? "" : ".json")].join("/"), {
Blockbench.read([...patharr.slice(undefined, patharr.length - 3), p.replace(":", "/")].join("/"), {
extensions: ['json'],
type: 'Cosmic Reach Model',
readtype: 'text',
Expand Down Expand Up @@ -297,8 +344,12 @@
}catch(error){

}
cube.faces[facenamesbb[i]].cullface = cuboid.faces[facenamescr[i]].cullFace ? facenamesbb[i] : ""
cube.faces[facenamesbb[i]].tint = cuboid.faces[facenamescr[i]].ambientocclusion ? 0 : -1
if(cuboid.faces[facenamescr[i]] !== undefined){
cube.faces[facenamesbb[i]].cullface = cuboid.faces[facenamescr[i]].cullFace ? facenamesbb[i] : ""
cube.faces[facenamesbb[i]].tint = cuboid.faces[facenamescr[i]].ambientocclusion ? 0 : -1
}else{
cube.faces[facenamesbb[i]].enabled = false
}
}
cube.addTo(Group.all.last()).init()
}
Expand All @@ -307,6 +358,15 @@
Canvas.updateAll()
}, 50);

properties = {isTransparent: false, cullsSelf: true}
if (data.isTransparent !== undefined){
properties.isTransparent = data.isTransparent
}
if (data.cullsSelf !== undefined){
properties.cullsSelf = data.cullsSelf
}
Project.properties = properties

return true;
}
})
Expand Down Expand Up @@ -923,10 +983,31 @@
}
})

show_properties_dialog = new Action("cosmic_reach_show_properties_dialog", {
id: "cosmic_reach_show_properties_dialog",
icon: icon64,
description: "",
name: "Edit model properties",
category: "Tools",
click() {
switch (Project.format.id){
default:
propertiesDialog.form = {}
propertiesDialog.show()
case "cosmic_reach_model":
propertiesDialog.form = blockPropertiesForm
propertiesDialog.show()
propertiesDialog.setFormValues(Project.properties)
}
}
})


MenuBar.addAction(import_action_entity_animation, 'file.import')
MenuBar.addAction(export_action_entity_animation, 'file.export')

MenuBar.addAction(show_properties_dialog, 'tools')

lastOccuranceOfSequenceInArray = (array, sequence) => {
let count = 0

Expand Down Expand Up @@ -1033,6 +1114,8 @@
import_action_entity_animation.delete();
export_action_entity_animation.delete();
Codecs.java_block.load_filter.condition = originalJavaBlockCond

show_properties_dialog.delete()
}
})
})()
Loading