Skip to content

Commit

Permalink
💔 Broken attempts at fixing things
Browse files Browse the repository at this point in the history
  • Loading branch information
SnaveSutit committed May 31, 2024
1 parent b729ae6 commit 765169f
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 193 deletions.
9 changes: 8 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
- [ ] Add an option to switch the display entity between item and block display.
- [ ] Figure out a way to allow the user to scale the model of a bone with a display item set.
- [ ] Add Variants to the UndoSystem (Blocked by vanilla Blockbench not supporting custom undo actions)
- [x] Add a bone config option to replace the bone's display item with a custom item.
- [ ] Add vanilla item displays
- [x] Create a custom element type for item displays.
- [ ] Add rendering for vanilla item models.
- [x] Parent model inheritance
- [x] item/generated
Expand All @@ -73,10 +74,14 @@
- [ ] template_skull
- [ ] trident_in_hand
- [ ] trident_throwing
- [ ] Add vanilla block displays
- [x] Create a custom element type for block displays.
- [ ] Add rendering for vanilla block models.
- [ ] Use Blockstates to select models.
- [x] Parent model inheritance
- [x] block/block
- [ ] Edge Cases go here
- [ ]
- [ ] Locator rotation support

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

# Resource Pack

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "animated_java",
"title": "Animated Java",
"version": "1.0.0",
"min_blockbench_version": "4.9.4",
"min_blockbench_version": "4.10.0",
"author": {
"name": "Titus Evans (SnaveSutit)",
"email": "snavesutit@gmail.com",
Expand Down
3 changes: 3 additions & 0 deletions src/blockbenchTypeMods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare module 'three' {
isVanillaItemModel?: boolean
isVanillaBlockModel?: boolean
isTextDisplayText?: boolean
fix_scale?: THREE.Vector3
}
}

Expand Down Expand Up @@ -106,6 +107,8 @@ declare global {
BLUEPRINT_FORMAT: typeof BLUEPRINT_FORMAT
BLUEPRINT_CODEC: typeof BLUEPRINT_CODEC
TextDisplay: typeof TextDisplay
VanillaItemDisplay: typeof VanillaItemDisplay
VanillaBlockDisplay: typeof VanillaBlockDisplay
}
}
}
9 changes: 5 additions & 4 deletions src/blueprintFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,12 @@ export function saveBlueprint() {
export function updateRotationLock() {
if (!isCurrentFormat()) return
BLUEPRINT_FORMAT.rotation_limit = !(
Group.selected || !!AnimatedJava.API.TextDisplay.selected.length
)
BLUEPRINT_FORMAT.rotation_snap = !(
Group.selected || !!AnimatedJava.API.TextDisplay.selected.length
Group.selected ||
!!AnimatedJava.API.TextDisplay.selected.length ||
!!AnimatedJava.API.VanillaItemDisplay.selected.length ||
!!AnimatedJava.API.VanillaBlockDisplay.selected.length
)
BLUEPRINT_FORMAT.rotation_snap = BLUEPRINT_FORMAT.rotation_limit
}

export function disableRotationLock() {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import './mods/elementToolbarsMod'
import './mods/exportOverActionMod'
import './mods/groupContextMenuMod'
import './mods/groupNameMod'
import './mods/groupPreviewControllerMod'
import './mods/keyframeMod'
import './mods/locatorAnimatorMod'
import './mods/locatorContextMenuMod'
Expand All @@ -43,6 +42,7 @@ import './mods/saveAllAnimationsActionMod'
import './mods/saveProjectActionMod'
import './mods/saveProjectAsActionMod'
import './mods/variantPreviewCubeFaceMod'
import './mods/animatorShowDefaultPoseMod'
// Outliner
import './outliner/textDisplay'
import './outliner/vanillaItemDisplay'
Expand Down Expand Up @@ -71,6 +71,7 @@ import { getVanillaFont } from './systems/minecraft/fontManager'
import * as itemModelManager from './systems/minecraft/itemModelManager'
import * as blockModelManager from './systems/minecraft/blockModelManager'
import { VanillaItemDisplay } from './outliner/vanillaItemDisplay'
import { VanillaBlockDisplay } from './outliner/vanillaBlockDisplay'

// Show loading popup
void showLoadingPopup().then(async () => {
Expand Down Expand Up @@ -110,6 +111,7 @@ globalThis.AnimatedJava = {
itemModelManager,
blockModelManager,
VanillaItemDisplay,
VanillaBlockDisplay,
},
}

Expand Down
40 changes: 40 additions & 0 deletions src/mods/animatorShowDefaultPoseMod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { isCurrentFormat } from '../blueprintFormat'
import { PACKAGE } from '../constants'
import { createBlockbenchMod } from '../util/moddingTools'

createBlockbenchMod(
`${PACKAGE.name}:animatorShowDefaultPose`,
{
originalShowDefaultPose: Animator.showDefaultPose,
},
context => {
Animator.showDefaultPose = function (noMatrixUpdate?: boolean) {
if (isCurrentFormat()) {
const elements = [...Group.all, ...Outliner.elements]
for (const node of elements) {
// @ts-expect-error
if (!node.constructor.animator) continue
const mesh = node.mesh as THREE.Mesh
if (mesh.fix_rotation) mesh.rotation.copy(mesh.fix_rotation as THREE.Euler)
if (mesh.fix_position) mesh.position.copy(mesh.fix_position as THREE.Vector3)
if (
// @ts-expect-error
node.constructor.animator.prototype.channels &&
// @ts-expect-error
node.constructor.animator.prototype.channels.scale
) {
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1
}
}
if (!noMatrixUpdate) scene.updateMatrixWorld()
} else {
return context.originalShowDefaultPose(noMatrixUpdate)
}
}

return context
},
context => {
Animator.showDefaultPose = context.originalShowDefaultPose
}
)
60 changes: 0 additions & 60 deletions src/mods/groupPreviewControllerMod.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/mods/previewRaycastMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ createBlockbenchMod(
if ((!isClick && !isHover) || Transformer.dragging) return raycast(event)
convertTouchEvent(event)

if (isHover) {
for (const group of Group.all) {
Group.preview_controller.updateHighlight(group)
}
}

const canvasOffset = $(this.canvas).offset()!
this.mouse.x = ((event.clientX - canvasOffset.left) / this.width) * 2 - 1
this.mouse.y = -((event.clientY - canvasOffset.top) / this.height) * 2 + 1
Expand Down
74 changes: 71 additions & 3 deletions src/outliner/textDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ OutlinerElement.registerType(TextDisplay, TextDisplay.type)
export const PREVIEW_CONTROLLER = new NodePreviewController(TextDisplay, {
setup(el: TextDisplay) {
const textMesh = new THREE.Mesh(new THREE.PlaneGeometry(0, 0))
textMesh.fix_rotation = new THREE.Euler(0, 0, 0, 'ZYX')
textMesh.fix_position = new THREE.Vector3(0, 0, 0)
textMesh.fix_rotation = new THREE.Euler(...el.rotation, 'ZYX')
textMesh.fix_position = new THREE.Vector3(...el.position)
textMesh.fix_scale = new THREE.Vector3(...el.scale)
// Minecraft's transparency is funky 😭
textMesh.renderOrder = -1

Expand Down Expand Up @@ -401,9 +402,20 @@ export const PREVIEW_CONTROLLER = new NodePreviewController(TextDisplay, {
void el.updateText()
},
updateTransform(el: TextDisplay) {
NodePreviewController.prototype.updateTransform.call(this, el)
NodePreviewController.prototype.updateTransform.call(PREVIEW_CONTROLLER, el)
if (el.mesh.fix_position) {
el.mesh.fix_position.set(...el.position)
if (el.parent instanceof Group) {
el.mesh.fix_position.x -= el.parent.origin[0]
el.mesh.fix_position.y -= el.parent.origin[1]
el.mesh.fix_position.z -= el.parent.origin[2]
}
}
if (el.mesh.fix_rotation) {
el.mesh.fix_rotation.set(...el.rotation)
}
if (el.mesh.fix_scale) {
el.mesh.fix_scale.set(...el.scale)
}
},
})
Expand Down Expand Up @@ -500,6 +512,62 @@ class TextDisplayAnimator extends BoneAnimator {
this.getElement()
return !!(this.element && this.element.mesh)
}

displayRotation(arr: ArrayVector3 | ArrayVector4, multiplier = 1) {
const bone = this.getElement().mesh

if (bone.fix_rotation) {
bone.rotation.copy(bone.fix_rotation as THREE.Euler)
}

if (arr) {
if (arr.length === 4) {
const added_rotation = new THREE.Euler().setFromQuaternion(
new THREE.Quaternion().fromArray(arr),
'ZYX'
)
bone.rotation.x -= added_rotation.x * multiplier
bone.rotation.y -= added_rotation.y * multiplier
bone.rotation.z += added_rotation.z * multiplier
} else {
bone.rotation.x += Math.degToRad(-arr[0]) * multiplier
bone.rotation.y += Math.degToRad(-arr[1]) * multiplier
bone.rotation.z += Math.degToRad(arr[2]) * multiplier
}
}
if (this.rotation_global) {
const quat = bone.parent?.getWorldQuaternion(Reusable.quat1)
if (!quat) return this
quat.invert()
bone.quaternion.premultiply(quat)
}
return this
}

displayPosition(arr: ArrayVector3, multiplier = 1) {
const bone = this.getElement().mesh
if (bone.fix_position) {
bone.position.copy(bone.fix_position as THREE.Vector3)
}
if (arr) {
bone.position.x -= arr[0] * multiplier
bone.position.y += arr[1] * multiplier
bone.position.z += arr[2] * multiplier
}
return this
}

displayScale(arr: ArrayVector3, multiplier = 1) {
if (!arr) return this
const bone = this.getElement().mesh
if (bone.fix_scale) {
bone.scale.copy(bone.fix_scale)
}
bone.scale.x *= 1 + (arr[0] - 1) * multiplier || 0.00001
bone.scale.y *= 1 + (arr[1] - 1) * multiplier || 0.00001
bone.scale.z *= 1 + (arr[2] - 1) * multiplier || 0.00001
return this
}
}
TextDisplayAnimator.prototype.type = TextDisplay.type
TextDisplay.animator = TextDisplayAnimator as any
Expand Down
Loading

0 comments on commit 765169f

Please sign in to comment.