|
@@ -0,0 +1,56 @@
|
|
|
+<template></template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import { useRender, useStageProps, useTree } from "../../hook/use-stage";
|
|
|
+import { fullMesh, getModel } from "../line-icon/resource";
|
|
|
+import { Group, MathUtils, Matrix4 } from "three";
|
|
|
+import { computed, ref, watch, watchEffect } from "vue";
|
|
|
+import { setMat } from "../../util";
|
|
|
+import { IconData } from "@/core/components/icon";
|
|
|
+import { Transform } from "konva/lib/Util";
|
|
|
+
|
|
|
+const props = defineProps<{ data: IconData }>();
|
|
|
+const render = useRender();
|
|
|
+
|
|
|
+const group = new Group();
|
|
|
+watch(
|
|
|
+ () => props.data.url,
|
|
|
+ async (type, _, onCleanup) => {
|
|
|
+ let typeModel = await getModel(type);
|
|
|
+ if (typeModel && type === props.data.url) {
|
|
|
+ typeModel = typeModel.clone();
|
|
|
+ group.add(typeModel);
|
|
|
+ render();
|
|
|
+ onCleanup(() => {
|
|
|
+ group.remove(typeModel!);
|
|
|
+ render();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+);
|
|
|
+
|
|
|
+const getScaleZ = () => 1;
|
|
|
+const mat = computed(() => {
|
|
|
+ const data = props.data;
|
|
|
+ const dec = new Transform(data.mat).decompose();
|
|
|
+ const mat = new Matrix4()
|
|
|
+ .makeTranslation(dec.x, 0, dec.y)
|
|
|
+ .multiply(new Matrix4().makeScale(dec.scaleX, 1, dec.scaleY))
|
|
|
+ .multiply(new Matrix4().makeScale(props.data.width, 100, props.data.height))
|
|
|
+ .multiply(new Matrix4().makeRotationY(MathUtils.degToRad(dec.rotation)))
|
|
|
+ .multiply(new Matrix4().makeTranslation(0, 0.5, 0));
|
|
|
+ return mat;
|
|
|
+});
|
|
|
+
|
|
|
+watch(
|
|
|
+ mat,
|
|
|
+ (mat) => {
|
|
|
+ setMat(group, mat);
|
|
|
+ render();
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+);
|
|
|
+
|
|
|
+useTree().value = group;
|
|
|
+</script>
|