Skip to content

Commit 765169f

Browse files
committed
💔 Broken attempts at fixing things
1 parent b729ae6 commit 765169f

16 files changed

+559
-193
lines changed

TODO.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
- [ ] Add an option to switch the display entity between item and block display.
5252
- [ ] Figure out a way to allow the user to scale the model of a bone with a display item set.
5353
- [ ] Add Variants to the UndoSystem (Blocked by vanilla Blockbench not supporting custom undo actions)
54-
- [x] Add a bone config option to replace the bone's display item with a custom item.
54+
- [ ] Add vanilla item displays
55+
- [x] Create a custom element type for item displays.
5556
- [ ] Add rendering for vanilla item models.
5657
- [x] Parent model inheritance
5758
- [x] item/generated
@@ -73,10 +74,14 @@
7374
- [ ] template_skull
7475
- [ ] trident_in_hand
7576
- [ ] trident_throwing
77+
- [ ] Add vanilla block displays
78+
- [x] Create a custom element type for block displays.
7679
- [ ] Add rendering for vanilla block models.
80+
- [ ] Use Blockstates to select models.
7781
- [x] Parent model inheritance
7882
- [x] block/block
7983
- [ ] Edge Cases go here
84+
- [ ]
8085
- [ ] Locator rotation support
8186

8287
# Data Pack Compiler
@@ -97,6 +102,8 @@
97102
- [ ] Figure out how cameras will work.
98103
- [ ] Check for references to non-existant functions in merged function tags, and remove them.
99104
- [ ] Apply variant keyframes in animations.
105+
- [ ] Add support for vanilla item displays.
106+
- [ ] Add support for vanilla block displays.
100107

101108
# Resource Pack
102109

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "animated_java",
44
"title": "Animated Java",
55
"version": "1.0.0",
6-
"min_blockbench_version": "4.9.4",
6+
"min_blockbench_version": "4.10.0",
77
"author": {
88
"name": "Titus Evans (SnaveSutit)",
99
"email": "snavesutit@gmail.com",

src/blockbenchTypeMods.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ declare module 'three' {
2222
isVanillaItemModel?: boolean
2323
isVanillaBlockModel?: boolean
2424
isTextDisplayText?: boolean
25+
fix_scale?: THREE.Vector3
2526
}
2627
}
2728

@@ -106,6 +107,8 @@ declare global {
106107
BLUEPRINT_FORMAT: typeof BLUEPRINT_FORMAT
107108
BLUEPRINT_CODEC: typeof BLUEPRINT_CODEC
108109
TextDisplay: typeof TextDisplay
110+
VanillaItemDisplay: typeof VanillaItemDisplay
111+
VanillaBlockDisplay: typeof VanillaBlockDisplay
109112
}
110113
}
111114
}

src/blueprintFormat.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,12 @@ export function saveBlueprint() {
601601
export function updateRotationLock() {
602602
if (!isCurrentFormat()) return
603603
BLUEPRINT_FORMAT.rotation_limit = !(
604-
Group.selected || !!AnimatedJava.API.TextDisplay.selected.length
605-
)
606-
BLUEPRINT_FORMAT.rotation_snap = !(
607-
Group.selected || !!AnimatedJava.API.TextDisplay.selected.length
604+
Group.selected ||
605+
!!AnimatedJava.API.TextDisplay.selected.length ||
606+
!!AnimatedJava.API.VanillaItemDisplay.selected.length ||
607+
!!AnimatedJava.API.VanillaBlockDisplay.selected.length
608608
)
609+
BLUEPRINT_FORMAT.rotation_snap = BLUEPRINT_FORMAT.rotation_limit
609610
}
610611

611612
export function disableRotationLock() {

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import './mods/elementToolbarsMod'
2828
import './mods/exportOverActionMod'
2929
import './mods/groupContextMenuMod'
3030
import './mods/groupNameMod'
31-
import './mods/groupPreviewControllerMod'
3231
import './mods/keyframeMod'
3332
import './mods/locatorAnimatorMod'
3433
import './mods/locatorContextMenuMod'
@@ -43,6 +42,7 @@ import './mods/saveAllAnimationsActionMod'
4342
import './mods/saveProjectActionMod'
4443
import './mods/saveProjectAsActionMod'
4544
import './mods/variantPreviewCubeFaceMod'
45+
import './mods/animatorShowDefaultPoseMod'
4646
// Outliner
4747
import './outliner/textDisplay'
4848
import './outliner/vanillaItemDisplay'
@@ -71,6 +71,7 @@ import { getVanillaFont } from './systems/minecraft/fontManager'
7171
import * as itemModelManager from './systems/minecraft/itemModelManager'
7272
import * as blockModelManager from './systems/minecraft/blockModelManager'
7373
import { VanillaItemDisplay } from './outliner/vanillaItemDisplay'
74+
import { VanillaBlockDisplay } from './outliner/vanillaBlockDisplay'
7475

7576
// Show loading popup
7677
void showLoadingPopup().then(async () => {
@@ -110,6 +111,7 @@ globalThis.AnimatedJava = {
110111
itemModelManager,
111112
blockModelManager,
112113
VanillaItemDisplay,
114+
VanillaBlockDisplay,
113115
},
114116
}
115117

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { isCurrentFormat } from '../blueprintFormat'
2+
import { PACKAGE } from '../constants'
3+
import { createBlockbenchMod } from '../util/moddingTools'
4+
5+
createBlockbenchMod(
6+
`${PACKAGE.name}:animatorShowDefaultPose`,
7+
{
8+
originalShowDefaultPose: Animator.showDefaultPose,
9+
},
10+
context => {
11+
Animator.showDefaultPose = function (noMatrixUpdate?: boolean) {
12+
if (isCurrentFormat()) {
13+
const elements = [...Group.all, ...Outliner.elements]
14+
for (const node of elements) {
15+
// @ts-expect-error
16+
if (!node.constructor.animator) continue
17+
const mesh = node.mesh as THREE.Mesh
18+
if (mesh.fix_rotation) mesh.rotation.copy(mesh.fix_rotation as THREE.Euler)
19+
if (mesh.fix_position) mesh.position.copy(mesh.fix_position as THREE.Vector3)
20+
if (
21+
// @ts-expect-error
22+
node.constructor.animator.prototype.channels &&
23+
// @ts-expect-error
24+
node.constructor.animator.prototype.channels.scale
25+
) {
26+
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1
27+
}
28+
}
29+
if (!noMatrixUpdate) scene.updateMatrixWorld()
30+
} else {
31+
return context.originalShowDefaultPose(noMatrixUpdate)
32+
}
33+
}
34+
35+
return context
36+
},
37+
context => {
38+
Animator.showDefaultPose = context.originalShowDefaultPose
39+
}
40+
)

src/mods/groupPreviewControllerMod.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/mods/previewRaycastMod.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ createBlockbenchMod(
3434
if ((!isClick && !isHover) || Transformer.dragging) return raycast(event)
3535
convertTouchEvent(event)
3636

37-
if (isHover) {
38-
for (const group of Group.all) {
39-
Group.preview_controller.updateHighlight(group)
40-
}
41-
}
42-
4337
const canvasOffset = $(this.canvas).offset()!
4438
this.mouse.x = ((event.clientX - canvasOffset.left) / this.width) * 2 - 1
4539
this.mouse.y = -((event.clientY - canvasOffset.top) / this.height) * 2 + 1

src/outliner/textDisplay.ts

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ OutlinerElement.registerType(TextDisplay, TextDisplay.type)
364364
export const PREVIEW_CONTROLLER = new NodePreviewController(TextDisplay, {
365365
setup(el: TextDisplay) {
366366
const textMesh = new THREE.Mesh(new THREE.PlaneGeometry(0, 0))
367-
textMesh.fix_rotation = new THREE.Euler(0, 0, 0, 'ZYX')
368-
textMesh.fix_position = new THREE.Vector3(0, 0, 0)
367+
textMesh.fix_rotation = new THREE.Euler(...el.rotation, 'ZYX')
368+
textMesh.fix_position = new THREE.Vector3(...el.position)
369+
textMesh.fix_scale = new THREE.Vector3(...el.scale)
369370
// Minecraft's transparency is funky 😭
370371
textMesh.renderOrder = -1
371372

@@ -401,9 +402,20 @@ export const PREVIEW_CONTROLLER = new NodePreviewController(TextDisplay, {
401402
void el.updateText()
402403
},
403404
updateTransform(el: TextDisplay) {
404-
NodePreviewController.prototype.updateTransform.call(this, el)
405+
NodePreviewController.prototype.updateTransform.call(PREVIEW_CONTROLLER, el)
405406
if (el.mesh.fix_position) {
406407
el.mesh.fix_position.set(...el.position)
408+
if (el.parent instanceof Group) {
409+
el.mesh.fix_position.x -= el.parent.origin[0]
410+
el.mesh.fix_position.y -= el.parent.origin[1]
411+
el.mesh.fix_position.z -= el.parent.origin[2]
412+
}
413+
}
414+
if (el.mesh.fix_rotation) {
415+
el.mesh.fix_rotation.set(...el.rotation)
416+
}
417+
if (el.mesh.fix_scale) {
418+
el.mesh.fix_scale.set(...el.scale)
407419
}
408420
},
409421
})
@@ -500,6 +512,62 @@ class TextDisplayAnimator extends BoneAnimator {
500512
this.getElement()
501513
return !!(this.element && this.element.mesh)
502514
}
515+
516+
displayRotation(arr: ArrayVector3 | ArrayVector4, multiplier = 1) {
517+
const bone = this.getElement().mesh
518+
519+
if (bone.fix_rotation) {
520+
bone.rotation.copy(bone.fix_rotation as THREE.Euler)
521+
}
522+
523+
if (arr) {
524+
if (arr.length === 4) {
525+
const added_rotation = new THREE.Euler().setFromQuaternion(
526+
new THREE.Quaternion().fromArray(arr),
527+
'ZYX'
528+
)
529+
bone.rotation.x -= added_rotation.x * multiplier
530+
bone.rotation.y -= added_rotation.y * multiplier
531+
bone.rotation.z += added_rotation.z * multiplier
532+
} else {
533+
bone.rotation.x += Math.degToRad(-arr[0]) * multiplier
534+
bone.rotation.y += Math.degToRad(-arr[1]) * multiplier
535+
bone.rotation.z += Math.degToRad(arr[2]) * multiplier
536+
}
537+
}
538+
if (this.rotation_global) {
539+
const quat = bone.parent?.getWorldQuaternion(Reusable.quat1)
540+
if (!quat) return this
541+
quat.invert()
542+
bone.quaternion.premultiply(quat)
543+
}
544+
return this
545+
}
546+
547+
displayPosition(arr: ArrayVector3, multiplier = 1) {
548+
const bone = this.getElement().mesh
549+
if (bone.fix_position) {
550+
bone.position.copy(bone.fix_position as THREE.Vector3)
551+
}
552+
if (arr) {
553+
bone.position.x -= arr[0] * multiplier
554+
bone.position.y += arr[1] * multiplier
555+
bone.position.z += arr[2] * multiplier
556+
}
557+
return this
558+
}
559+
560+
displayScale(arr: ArrayVector3, multiplier = 1) {
561+
if (!arr) return this
562+
const bone = this.getElement().mesh
563+
if (bone.fix_scale) {
564+
bone.scale.copy(bone.fix_scale)
565+
}
566+
bone.scale.x *= 1 + (arr[0] - 1) * multiplier || 0.00001
567+
bone.scale.y *= 1 + (arr[1] - 1) * multiplier || 0.00001
568+
bone.scale.z *= 1 + (arr[2] - 1) * multiplier || 0.00001
569+
return this
570+
}
503571
}
504572
TextDisplayAnimator.prototype.type = TextDisplay.type
505573
TextDisplay.animator = TextDisplayAnimator as any

0 commit comments

Comments
 (0)