mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-02-17 16:20:13 +08:00
Add basic mesh element setup
This commit is contained in:
parent
4b52856b8c
commit
49b1da4dd9
@ -96,6 +96,7 @@
|
||||
<script src="js/edit_sessions.js"></script>
|
||||
<script src="js/outliner/outliner.js"></script>
|
||||
<script src="js/outliner/group.js"></script>
|
||||
<script src="js/outliner/mesh.js"></script>
|
||||
<script src="js/outliner/cube.js"></script>
|
||||
<script src="js/outliner/locator.js"></script>
|
||||
<script src="js/outliner/null_object.js"></script>
|
||||
|
@ -1272,8 +1272,8 @@ const Animator = {
|
||||
if (!Timeline.is_setup) {
|
||||
Timeline.setup()
|
||||
}
|
||||
if (outlines.children.length) {
|
||||
outlines.children.empty()
|
||||
if (Canvas.outlines.children.length) {
|
||||
Canvas.outlines.children.empty()
|
||||
Canvas.updateAllPositions()
|
||||
}
|
||||
if (Animation.all.length && !Animation.all.includes(Animation.selected)) {
|
||||
|
@ -1466,8 +1466,8 @@ enterDisplaySettings = function() { //Enterung Display Setting Mode, changes th
|
||||
|
||||
display_area.updateMatrixWorld()
|
||||
Transformer.center()
|
||||
if (outlines.children.length) {
|
||||
outlines.children.length = 0
|
||||
if (Canvas.outlines.children.length) {
|
||||
Canvas.outlines.children.empty();
|
||||
}
|
||||
}
|
||||
exitDisplaySettings = function() { //Enterung Display Setting Mode, changes the scene etc
|
||||
|
@ -18,6 +18,7 @@ class ModelFormat {
|
||||
this.centered_grid = false;
|
||||
this.rotate_cubes = false;
|
||||
this.integer_size = false;
|
||||
this.meshes = false;
|
||||
this.locators = false;
|
||||
this.canvas_limit = false;
|
||||
this.rotation_limit = false;
|
||||
@ -40,6 +41,7 @@ class ModelFormat {
|
||||
Merge.boolean(this, data, 'centered_grid');
|
||||
Merge.boolean(this, data, 'rotate_cubes');
|
||||
Merge.boolean(this, data, 'integer_size');
|
||||
Merge.boolean(this, data, 'meshes');
|
||||
Merge.boolean(this, data, 'locators');
|
||||
Merge.boolean(this, data, 'canvas_limit');
|
||||
Merge.boolean(this, data, 'rotation_limit');
|
||||
@ -138,6 +140,13 @@ class ModelFormat {
|
||||
})
|
||||
}
|
||||
|
||||
//Meshes
|
||||
if (!Format.meshes && old_format.meshes) {
|
||||
Mesh.all.slice().forEach(mesh => {
|
||||
mesh.remove()
|
||||
})
|
||||
}
|
||||
|
||||
//Locators
|
||||
if (!Format.locators && old_format.locators) {
|
||||
Locator.all.slice().forEach(locator => {
|
||||
@ -205,6 +214,7 @@ class ModelFormat {
|
||||
new ModelFormat({
|
||||
id: 'free',
|
||||
icon: 'icon-format_free',
|
||||
meshes: true,
|
||||
rotate_cubes: true,
|
||||
bone_rig: true,
|
||||
centered_grid: true,
|
||||
|
@ -112,8 +112,7 @@ class Cube extends OutlinerElement {
|
||||
this.rotation = [0, 0, 0];
|
||||
this.origin = [0, 0, 0];
|
||||
this.visibility = true;
|
||||
this.autouv = 0
|
||||
this.parent = 'root';
|
||||
this.autouv = 0;
|
||||
|
||||
for (var key in Cube.properties) {
|
||||
Cube.properties[key].reset(this);
|
||||
@ -252,25 +251,6 @@ class Cube extends OutlinerElement {
|
||||
get mesh() {
|
||||
return Project.nodes_3d[this.uuid];
|
||||
}
|
||||
remove() {
|
||||
super.remove();
|
||||
if (this.visibility) {
|
||||
var mesh = this.mesh
|
||||
if (mesh) {
|
||||
if (mesh.parent) {
|
||||
mesh.parent.remove(mesh)
|
||||
}
|
||||
delete Project.nodes_3d[this.uuid]
|
||||
mesh.geometry.dispose()
|
||||
if (mesh.outline && mesh.outline.geometry) mesh.outline.geometry.dispose()
|
||||
}
|
||||
}
|
||||
delete Project.nodes_3d[this.uuid]
|
||||
if (Transformer.dragging) {
|
||||
outlines.remove(outlines.getObjectByName(this.uuid+'_ghost_outline'))
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
getUndoCopy(aspects = 0) {
|
||||
var copy = new Cube(this)
|
||||
if (aspects.uv_only) {
|
||||
@ -857,7 +837,6 @@ new NodePreviewController(Cube, {
|
||||
|
||||
this.updateTransform(element);
|
||||
this.updateGeometry(element);
|
||||
this.updateHierarchy(element);
|
||||
this.updateFaces(element);
|
||||
|
||||
if (Prop.view_mode === 'textured') {
|
||||
|
153
js/outliner/mesh.js
Normal file
153
js/outliner/mesh.js
Normal file
@ -0,0 +1,153 @@
|
||||
|
||||
class Mesh extends OutlinerElement {
|
||||
constructor(data, uuid) {
|
||||
super(data, uuid)
|
||||
|
||||
for (var key in Mesh.properties) {
|
||||
Mesh.properties[key].reset(this);
|
||||
}
|
||||
if (data && typeof data === 'object') {
|
||||
this.extend(data)
|
||||
}
|
||||
}
|
||||
extend(object) {
|
||||
for (var key in Mesh.properties) {
|
||||
Mesh.properties[key].merge(this, object)
|
||||
}
|
||||
this.sanitizeName();
|
||||
return this;
|
||||
}
|
||||
get mesh() {
|
||||
return Project.nodes_3d[this.uuid];
|
||||
}
|
||||
getUndoCopy() {
|
||||
var copy = new Mesh(this)
|
||||
copy.uuid = this.uuid;
|
||||
delete copy.parent;
|
||||
return copy;
|
||||
}
|
||||
getSaveCopy() {
|
||||
var el = {}
|
||||
for (var key in Mesh.properties) {
|
||||
Mesh.properties[key].copy(this, el)
|
||||
}
|
||||
el.uuid = this.uuid
|
||||
return el;
|
||||
}
|
||||
}
|
||||
Mesh.prototype.title = tl('data.mesh');
|
||||
Mesh.prototype.type = 'mesh';
|
||||
Mesh.prototype.icon = 'fa far fa-gem';
|
||||
Mesh.prototype.movable = true;
|
||||
Mesh.prototype.rotatable = true;
|
||||
Mesh.prototype.needsUniqueName = false;
|
||||
Mesh.prototype.menu = new Menu([
|
||||
'group_elements',
|
||||
'_',
|
||||
'copy',
|
||||
'paste',
|
||||
'duplicate',
|
||||
'_',
|
||||
'rename',
|
||||
{name: 'menu.cube.color', icon: 'color_lens', children: [
|
||||
{icon: 'bubble_chart', color: markerColors[0].standard, name: 'cube.color.'+markerColors[0].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(0)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[1].standard, name: 'cube.color.'+markerColors[1].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(1)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[2].standard, name: 'cube.color.'+markerColors[2].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(2)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[3].standard, name: 'cube.color.'+markerColors[3].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(3)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[4].standard, name: 'cube.color.'+markerColors[4].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(4)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[5].standard, name: 'cube.color.'+markerColors[5].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(5)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[6].standard, name: 'cube.color.'+markerColors[6].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(6)}, 'change color')}},
|
||||
{icon: 'bubble_chart', color: markerColors[7].standard, name: 'cube.color.'+markerColors[7].name, click: function(cube) {cube.forSelected(function(obj){obj.setColor(7)}, 'change color')}}
|
||||
]},
|
||||
{name: 'menu.cube.texture', icon: 'collections', condition: () => !Project.single_texture, children: function() {
|
||||
var arr = [
|
||||
{icon: 'crop_square', name: 'menu.cube.texture.blank', click: function(cube) {
|
||||
cube.forSelected(function(obj) {
|
||||
obj.applyTexture(false, true)
|
||||
}, 'texture blank')
|
||||
}},
|
||||
{icon: 'clear', name: 'menu.cube.texture.transparent', click: function(cube) {
|
||||
cube.forSelected(function(obj) {
|
||||
obj.applyTexture(null, true)
|
||||
}, 'texture transparent')
|
||||
}}
|
||||
]
|
||||
Texture.all.forEach(function(t) {
|
||||
arr.push({
|
||||
name: t.name,
|
||||
icon: (t.mode === 'link' ? t.img : t.source),
|
||||
click: function(cube) {
|
||||
cube.forSelected(function(obj) {
|
||||
obj.applyTexture(t, true)
|
||||
}, 'apply texture')
|
||||
}
|
||||
})
|
||||
})
|
||||
return arr;
|
||||
}},
|
||||
'toggle_visibility',
|
||||
'delete'
|
||||
]);
|
||||
Mesh.prototype.buttons = [
|
||||
Outliner.buttons.export,
|
||||
Outliner.buttons.locked,
|
||||
Outliner.buttons.visibility,
|
||||
];
|
||||
|
||||
new Property(Mesh, 'string', 'name', {default: 'mesh'})
|
||||
new Property(Mesh, 'number', 'color', {default: Math.floor(Math.random()*8)});
|
||||
new Property(Mesh, 'vector', 'origin');
|
||||
new Property(Mesh, 'vector', 'rotation');
|
||||
new Property(Mesh, 'boolean', 'visibility', {default: true});
|
||||
|
||||
OutlinerElement.registerType(Mesh, 'mesh');
|
||||
|
||||
new NodePreviewController(Mesh)
|
||||
|
||||
BARS.defineActions(function() {
|
||||
new Action({
|
||||
id: 'add_mesh',
|
||||
icon: 'fa-gem',
|
||||
category: 'edit',
|
||||
keybind: new Keybind({key: 'n', ctrl: true}),
|
||||
condition: () => (Modes.edit && Format.meshes),
|
||||
click: function () {
|
||||
|
||||
Undo.initEdit({outliner: true, elements: [], selection: true});
|
||||
var base_mesh = new Mesh({
|
||||
autouv: (settings.autouv.value ? 1 : 0)
|
||||
}).init()
|
||||
var group = getCurrentGroup();
|
||||
base_mesh.addTo(group)
|
||||
|
||||
if (Texture.all.length && Format.single_texture) {
|
||||
for (var face in base_mesh.faces) {
|
||||
base_mesh.faces[face].texture = Texture.getDefault().uuid
|
||||
}
|
||||
main_uv.loadData()
|
||||
}
|
||||
if (Format.bone_rig) {
|
||||
if (group) {
|
||||
var pos1 = group.origin.slice()
|
||||
base_mesh.extend({
|
||||
from:[ pos1[0]-0, pos1[1]-0, pos1[2]-0 ],
|
||||
to:[ pos1[0]+1, pos1[1]+1, pos1[2]+1 ],
|
||||
origin: pos1.slice()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (Group.selected) Group.selected.unselect()
|
||||
base_mesh.select()
|
||||
Undo.finishEdit('Add mesh', {outliner: true, elements: selected, selection: true});
|
||||
Blockbench.dispatchEvent( 'add_mesh', {object: base_mesh} )
|
||||
|
||||
Vue.nextTick(function() {
|
||||
if (settings.create_rename.value) {
|
||||
base_mesh.rename()
|
||||
}
|
||||
})
|
||||
return base_mesh
|
||||
}
|
||||
})
|
||||
})
|
@ -530,12 +530,31 @@ class NodePreviewController {
|
||||
let {mesh} = element;
|
||||
if (mesh.parent) mesh.parent.remove(mesh);
|
||||
if (mesh.geometry) mesh.geometry.dispose();
|
||||
if (mesh.outline && mesh.outline.geometry) mesh.outline.geometry.dispose();
|
||||
if (mesh.outline && mesh.outline.geometry) {
|
||||
mesh.outline.geometry.dispose();
|
||||
if (Transformer.dragging) {
|
||||
Canvas.outlines.remove(Canvas.outlines.getObjectByName(this.uuid+'_ghost_outline'))
|
||||
}
|
||||
}
|
||||
delete Project.nodes_3d[obj.uuid];
|
||||
}
|
||||
updateHierarchy(element) {
|
||||
let {mesh} = element;
|
||||
console.log
|
||||
updateTransform(element) {
|
||||
let mesh = element.mesh;
|
||||
|
||||
|
||||
mesh.scale.set(1, 1, 1)
|
||||
mesh.rotation.set(0, 0, 0)
|
||||
|
||||
if (element.movable) {
|
||||
mesh.position.set(element.origin[0], element.origin[1], element.origin[2])
|
||||
}
|
||||
|
||||
if (element.rotatable) {
|
||||
mesh.rotation.x = Math.degToRad(element.rotation[0]);
|
||||
mesh.rotation.y = Math.degToRad(element.rotation[1]);
|
||||
mesh.rotation.z = Math.degToRad(element.rotation[2]);
|
||||
}
|
||||
|
||||
if (Format.bone_rig) {
|
||||
if (element.parent instanceof Group) {
|
||||
element.parent.mesh.add(mesh);
|
||||
@ -548,28 +567,7 @@ class NodePreviewController {
|
||||
} else if (mesh.parent !== scene) {
|
||||
Project.model_3d.add(mesh)
|
||||
}
|
||||
}
|
||||
updateTransform(element) {
|
||||
let mesh = element.mesh;
|
||||
|
||||
this.updateHierarchy(element);
|
||||
|
||||
mesh.scale.set(1, 1, 1)
|
||||
mesh.rotation.set(0, 0, 0)
|
||||
if (element.movable) {
|
||||
mesh.position.set(element.origin[0], element.origin[1], element.origin[2])
|
||||
if (Format.bone_rig && element.parent instanceof Group) {
|
||||
mesh.position.x -= element.parent.origin[0];
|
||||
mesh.position.y -= element.parent.origin[1];
|
||||
mesh.position.z -= element.parent.origin[2];
|
||||
}
|
||||
}
|
||||
if (element.rotatable) {
|
||||
|
||||
mesh.rotation.x = Math.degToRad(element.rotation[0]);
|
||||
mesh.rotation.y = Math.degToRad(element.rotation[1]);
|
||||
mesh.rotation.z = Math.degToRad(element.rotation[2]);
|
||||
}
|
||||
mesh.updateMatrixWorld();
|
||||
}
|
||||
updateVisibility(element) {
|
||||
|
@ -123,7 +123,7 @@ const Canvas = {
|
||||
edit(Canvas.side_grids.x)
|
||||
edit(Canvas.side_grids.z)
|
||||
edit(Transformer)
|
||||
edit(outlines)
|
||||
edit(Canvas.outlines)
|
||||
edit(rot_origin)
|
||||
edit(Vertexsnap.vertexes)
|
||||
edit(Animator.motion_trail)
|
||||
@ -389,7 +389,7 @@ const Canvas = {
|
||||
mesh.getWorldScale(line.scale)
|
||||
|
||||
line.name = obj.uuid+'_ghost_outline'
|
||||
outlines.add(line)
|
||||
Canvas.outlines.add(line)
|
||||
})
|
||||
},
|
||||
updateAllBones(bones = Group.all) {
|
||||
|
@ -1823,9 +1823,9 @@ function initCanvas() {
|
||||
scene.add(Vertexsnap.vertexes)
|
||||
Vertexsnap.vertexes.name = 'vertex_handles'
|
||||
|
||||
outlines = new THREE.Object3D();
|
||||
outlines.name = 'outline_group'
|
||||
scene.add(outlines)
|
||||
Canvas.outlines = new THREE.Object3D();
|
||||
Canvas.outlines.name = 'outline_group'
|
||||
scene.add(Canvas.outlines)
|
||||
|
||||
|
||||
canvas_scenes = {
|
||||
|
@ -1489,7 +1489,7 @@
|
||||
mouseUpEvent.mode = _mode;
|
||||
scope.dispatchEvent( mouseUpEvent );
|
||||
scope.orbit_controls.stopMovement();
|
||||
outlines.children.length = 0;
|
||||
Canvas.outlines.children.length = 0;
|
||||
originalValue = null;
|
||||
|
||||
extendTransformLine(false);
|
||||
|
@ -60,7 +60,7 @@ class UndoSystem {
|
||||
}
|
||||
cancelEdit() {
|
||||
if (!this.current_save) return;
|
||||
outlines.children.length = 0
|
||||
Canvas.outlines.children.empty();
|
||||
this.loadSave(this.current_save, new UndoSystem.save(this.current_save.aspects))
|
||||
delete this.current_save;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user