Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zHoeshin authored Sep 16, 2024
1 parent af79153 commit 07b6a03
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 13 deletions.
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"
]
}
]
}
}
116 changes: 103 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,18 @@
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()
console.warn(res)
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 +103,11 @@
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})
console.error(textures)
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 +120,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 +133,22 @@
"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]}*/
}
}

console.log(cube)
for(let i = 0; i < 6; i++){
console.warn(i, uvs[facenamesbb[i]])
console.log(uvs[facenamesbb[i]][5])
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 +199,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 +239,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 +270,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 @@ -230,12 +282,14 @@
}, 50);
}

console.warn(data)

if(data.cuboids === undefined){
if(data.parent === undefined){
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 +351,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 +365,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 +990,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 +1121,8 @@
import_action_entity_animation.delete();
export_action_entity_animation.delete();
Codecs.java_block.load_filter.condition = originalJavaBlockCond

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

0 comments on commit 07b6a03

Please sign in to comment.