|
@@ -5,14 +5,12 @@ import { LineData, LineDataLine } from "@/core/components/line";
|
|
|
import { getLinePoints } from "@/core/components/line/attach-server";
|
|
|
import {
|
|
|
BufferGeometry,
|
|
|
- Color,
|
|
|
ExtrudeGeometry,
|
|
|
FrontSide,
|
|
|
Group,
|
|
|
Mesh,
|
|
|
MeshPhongMaterial,
|
|
|
Shape,
|
|
|
- Vector2,
|
|
|
} from "three";
|
|
|
import { computed, onUnmounted, Ref, ref, watch, watchEffect } from "vue";
|
|
|
import { useDrawHook, useRender, useStageProps, useTree } from "../../hook/use-stage";
|
|
@@ -22,6 +20,7 @@ import {
|
|
|
useGetExtendPolygon,
|
|
|
} from "@/core/components/line/renderer/wall/view";
|
|
|
import { BufferGeometryUtils } from "three/examples/jsm/Addons.js";
|
|
|
+import { skirtingHeight, skirtingMaterial } from "./material";
|
|
|
|
|
|
const props = defineProps<{
|
|
|
line: LineDataLine;
|
|
@@ -35,7 +34,6 @@ const gd = useDrawHook(() => useGetDiffLineIconPolygons(props.line, points));
|
|
|
const polygons = computed(() => gd.diff(polygon.value));
|
|
|
const wallGeo = ref() as Ref<BufferGeometry>;
|
|
|
const skirtingGeo = ref() as Ref<BufferGeometry>;
|
|
|
-const skirtingHeight = 20;
|
|
|
const sProps = useStageProps();
|
|
|
|
|
|
watch(
|
|
@@ -43,40 +41,19 @@ watch(
|
|
|
debounce(() => {
|
|
|
wallGeo.value && wallGeo.value.dispose();
|
|
|
skirtingGeo.value && skirtingGeo.value.dispose();
|
|
|
-
|
|
|
const polyGeos = polygons.value.map((poly) => {
|
|
|
- const wallShape = new Shape();
|
|
|
- const center = new Vector2();
|
|
|
- const vs = poly.map((p, ndx) => {
|
|
|
- if (ndx === 0) {
|
|
|
- wallShape.moveTo(p.x, p.y);
|
|
|
- } else {
|
|
|
- wallShape.lineTo(p.x, p.y);
|
|
|
- }
|
|
|
- const v = new Vector2(p.x, p.y);
|
|
|
- center.add(v);
|
|
|
- return v;
|
|
|
- });
|
|
|
- wallShape.closePath();
|
|
|
- center.divideScalar(vs.length);
|
|
|
-
|
|
|
- const skirtingShape = new Shape();
|
|
|
- vs.forEach((v, ndx) => {
|
|
|
- const p = v.clone().sub(center).multiplyScalar(1.1).add(center);
|
|
|
- if (ndx === 0) {
|
|
|
- skirtingShape.moveTo(p.x, p.y);
|
|
|
- } else {
|
|
|
- skirtingShape.lineTo(p.x, p.y);
|
|
|
- }
|
|
|
- });
|
|
|
- skirtingShape.closePath();
|
|
|
-
|
|
|
- const wallGeo = new ExtrudeGeometry(wallShape, {
|
|
|
+ const shape = new Shape();
|
|
|
+ shape.moveTo(poly[0].x, poly[0].y);
|
|
|
+ for (let i = 1; i < poly.length; i++) {
|
|
|
+ shape.lineTo(poly[i].x, poly[i].y);
|
|
|
+ }
|
|
|
+ shape.lineTo(poly[poly.length - 1].x, poly[poly.length - 1].y);
|
|
|
+ const wallGeo = new ExtrudeGeometry(shape, {
|
|
|
depth: sProps.value.height - skirtingHeight,
|
|
|
bevelEnabled: false,
|
|
|
steps: 1,
|
|
|
});
|
|
|
- const skirtingGeo = new ExtrudeGeometry(skirtingShape, {
|
|
|
+ const skirtingGeo = new ExtrudeGeometry(shape, {
|
|
|
depth: skirtingHeight,
|
|
|
bevelEnabled: false,
|
|
|
steps: 1,
|
|
@@ -112,10 +89,9 @@ const wall = new Mesh(
|
|
|
wall.castShadow = true;
|
|
|
wall.receiveShadow = true;
|
|
|
|
|
|
-const skirting = new Mesh(
|
|
|
- undefined,
|
|
|
- new MeshPhongMaterial({ side: FrontSide, color: 0xff0000 })
|
|
|
-);
|
|
|
+const skirting = new Mesh(undefined, skirtingMaterial);
|
|
|
+skirting.castShadow = true;
|
|
|
+skirting.receiveShadow = true;
|
|
|
|
|
|
watchEffect(() => {
|
|
|
wall.geometry = wallGeo.value;
|