feat: vehicle material position offset fix
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useThree, useFrame } from '@react-three/fiber';
|
import { useThree, useFrame } from '@react-three/fiber';
|
||||||
import * as THREE from 'three';
|
|
||||||
import { MaterialModel } from '../../../materials/instances/material/materialModel';
|
import { MaterialModel } from '../../../materials/instances/material/materialModel';
|
||||||
|
import { Object3D, Vector3 } from 'three';
|
||||||
|
|
||||||
const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
||||||
const meshRef = useRef<any>(null!);
|
const meshRef = useRef<any>(null!);
|
||||||
const [hasLoad, setHasLoad] = useState(false);
|
const [hasLoad, setHasLoad] = useState(false);
|
||||||
const [isAttached, setIsAttached] = useState(false);
|
const [isAttached, setIsAttached] = useState(false);
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
const offset = new THREE.Vector3(0, 0.85, 0);
|
const [offset, setOffset] = useState(new Vector3(0, 0.85, 0));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadState = agvDetail.currentLoad > 0;
|
const loadState = agvDetail.currentLoad > 0;
|
||||||
@@ -16,19 +16,24 @@ const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
|||||||
|
|
||||||
if (!loadState) {
|
if (!loadState) {
|
||||||
setIsAttached(false);
|
setIsAttached(false);
|
||||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||||
if (agvModel) {
|
if (agvModel) {
|
||||||
|
// update offset
|
||||||
|
let offsetY = agvDetail?.point.position[1];
|
||||||
|
if(offsetY) setOffset(new Vector3(0, offsetY, 0));
|
||||||
|
|
||||||
const material = agvModel.getObjectByName('Sample-Material');
|
const material = agvModel.getObjectByName('Sample-Material');
|
||||||
if (material) {
|
if (material) {
|
||||||
agvModel.remove(material);
|
agvModel.remove(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line
|
||||||
}, [agvDetail.currentLoad]);
|
}, [agvDetail.currentLoad]);
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
// if (agvDetail.currentMaterials.length === 0 || agvDetail.currentLoad === 0) {
|
// if (agvDetail.currentMaterials.length === 0 || agvDetail.currentLoad === 0) {
|
||||||
// const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
// const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||||
// if (agvModel) {
|
// if (agvModel) {
|
||||||
// const material = agvModel.getObjectByName('Sample-Material');
|
// const material = agvModel.getObjectByName('Sample-Material');
|
||||||
// if (material) {
|
// if (material) {
|
||||||
@@ -38,7 +43,7 @@ const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
|||||||
// }
|
// }
|
||||||
if (!hasLoad || !meshRef.current || isAttached) return;
|
if (!hasLoad || !meshRef.current || isAttached) return;
|
||||||
|
|
||||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||||
if (agvModel && !isAttached) {
|
if (agvModel && !isAttached) {
|
||||||
const material = agvModel.getObjectByName('Sample-Material');
|
const material = agvModel.getObjectByName('Sample-Material');
|
||||||
if (material) {
|
if (material) {
|
||||||
|
|||||||
Reference in New Issue
Block a user