forked from JannisX11/blockbench-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight_generator.js
More file actions
86 lines (78 loc) · 3.13 KB
/
Copy pathhighlight_generator.js
File metadata and controls
86 lines (78 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(function(){
let button;
Plugin.register('highlight_generator', {
title: 'Highlight Mod Shape Generator',
author: 'ThatGravyBoat',
description: 'Generates Shape JSONs for the Highlight mod. Mod can be found at: https://links.resourcefulbees.com/highlight',
icon: 'fa-cube',
version: '1.0.0',
variant: 'both',
tags: ["Minecraft: Java Edition"],
onload(){
button = new Action("export_highlight", {
name : 'Export Highlight',
description : 'Exports Highlight mod shape JSON',
icon : 'fa-file-export',
click: function(){
Blockbench.export({
type : 'Highlight Shape Export',
extensions: ['json'],
savetype: 'text',
content: generateFile()
});
}
});
MenuBar.addAction(button, "file.export");
},
onunload(){
button.delete();
}
});
function generateFile(){
let data = [];
for (let cube of Cube.all) {
const formattedLines = cube.getGlobalVertexPositions().map(point => point.map(value => value / 16.0));
const convertedVertices = [
[formattedLines[2], formattedLines[3], formattedLines[6], formattedLines[7]],
[formattedLines[0], formattedLines[1], formattedLines[4], formattedLines[5]]
]
for (let convertedVertex of convertedVertices) {
for (let edge of createHorizontalEdges(convertedVertex)) {
let topFace = []
topFace.push(...edge[0])
topFace.push(...edge[1])
if (!data.includes(topFace)) {
data.push(topFace)
}
}
data.push(null)
}
for (let edge of createVerticalEdges(convertedVertices[0], convertedVertices[1])) {
let topFace = []
topFace.push(...edge[0])
topFace.push(...edge[1])
if (!data.includes(topFace)) {
data.push(topFace)
}
}
data.push(null)
}
data.pop()
// The json is formatted below like this so its easier to read as each "section" will be seperated by a newline.
let output = `{\n "lines": [\n`
for (let datum of data) {
if (datum == null) {
output += `\n`
} else {
output += ` [${datum[0]}, ${datum[1]}, ${datum[2]}, ${datum[3]}, ${datum[4]}, ${datum[5]}],\n`
}
}
return output.substr(0, output.length - 2) + `\n ]\n}`;
}
function createHorizontalEdges(vertices) {
return [[vertices[2], vertices[3]], [vertices[2], vertices[1]], [vertices[1], vertices[0]], [vertices[3], vertices[0]]]
}
function createVerticalEdges(top, bottom) {
return [[bottom[3], top[3]], [bottom[2], top[2]], [bottom[1], top[1]], [bottom[0], top[0]]]
}
})();