This commit is contained in:
IDONTSUDO 2024-02-19 14:36:27 +03:00
parent de5b493c77
commit 0d825f7f63
3 changed files with 39 additions and 33 deletions

View file

@ -20,6 +20,7 @@ export async function createEditor(container: HTMLElement) {
setTimeout(async () => { setTimeout(async () => {
const node = new ClassicPreset.Node(event.name); const node = new ClassicPreset.Node(event.name);
const { x, y } = areaContainer.area.pointer; const { x, y } = areaContainer.area.pointer;
console.log(x, y);
await editor.addNode(node); await editor.addNode(node);
await areaContainer.translate(node.id, { x, y }); await areaContainer.translate(node.id, { x, y });
}, 50); }, 50);

View file

@ -5,10 +5,10 @@ import { CoreVector3 } from "../../core/model/core_vector3";
export class StickObjectsMarkingThreeRepository extends CoreThreeRepository { export class StickObjectsMarkingThreeRepository extends CoreThreeRepository {
stickyObjects: StickyHelper[]; stickyObjects: StickyHelper[];
updatePoint: Function; drawUiPoint: Function;
constructor(htmlCanvasRef: HTMLCanvasElement, watcherSceneEditorObject: Function, updatePoint: Function) { constructor(htmlCanvasRef: HTMLCanvasElement, watcherSceneEditorObject: Function, updatePoint: Function) {
super(htmlCanvasRef, watcherSceneEditorObject); super(htmlCanvasRef, watcherSceneEditorObject);
this.updatePoint = updatePoint; this.drawUiPoint = updatePoint;
this.sceneWatcher(); this.sceneWatcher();
} }
@ -45,7 +45,9 @@ export class StickObjectsMarkingThreeRepository extends CoreThreeRepository {
); );
}); });
} }
getCenter(obj: Object3D) {
return new Box3().setFromObject(obj).getCenter(new Vector3());
}
sceneWatcher() { sceneWatcher() {
this.transformControls.addEventListener("objectChange", (event) => { this.transformControls.addEventListener("objectChange", (event) => {
//@ts-expect-error //@ts-expect-error
@ -54,41 +56,44 @@ export class StickObjectsMarkingThreeRepository extends CoreThreeRepository {
this.stickyObjects.forEach((stickyHelper) => { this.stickyObjects.forEach((stickyHelper) => {
if (sceneActiveObject.name === stickyHelper.objectThatSticksName) { if (sceneActiveObject.name === stickyHelper.objectThatSticksName) {
//локальные векторы точек //локальные векторы точек
const objectThatSticksName = stickyHelper.objectThatSticksNamePoints[0]; const objectThatSticksNameLocalVector = stickyHelper.objectThatSticksNamePoints[0];
const objectsToWhichItSticksPoint = stickyHelper.objectsToWhichItSticksPoints[0]; const objectsToWhichItSticksPointLocalVector = stickyHelper.objectsToWhichItSticksPoints[0];
//глобальные векторы обьектов //глобальные векторы обьектов
const globalVectorObjStickyName = this.scene.getObjectByName(stickyHelper.objectThatSticksName); const globalVectorObjStickyName = this.scene.getObjectByName(stickyHelper.objectThatSticksName);
const globalVectorObjToWhichSticks = this.scene.getObjectByName(
stickyHelper.objectsToWhichItSticksName
)!.position;
//глобальные векторы точек const globalVectorObjToWhichSticks = this.scene.getObjectByName(stickyHelper.objectsToWhichItSticksName);
const objectThatSticksNamePosition = new CoreVector3(globalVectorObjStickyName!.position).add(
objectThatSticksName const objectsToWhichItSticksNamePosition = new CoreVector3(globalVectorObjToWhichSticks!.position).add(
).vector; objectsToWhichItSticksPointLocalVector
const objectsToWhichItSticksNamePosition = new CoreVector3(globalVectorObjToWhichSticks).add(
objectsToWhichItSticksPoint
).vector; ).vector;
this.updatePoint("objectThatSticksNamePosition", JSON.stringify(objectThatSticksNamePosition)); this.scene
this.updatePoint("objectsToWhichItSticksNamePosition", JSON.stringify(objectsToWhichItSticksNamePosition)); .getObjectByName("cube2:point:0objectThatSticksNamePoints")
const distance = objectThatSticksNamePosition.distanceTo(objectsToWhichItSticksNamePosition); ?.position.copy(objectsToWhichItSticksNamePosition);
this.updatePoint("distnace", JSON.stringify(distance));
const pos = objectThatSticksNamePosition.sub(objectsToWhichItSticksNamePosition); // this.scene.getObjectByName("cube2:point:0objectThatSticksNamePoints")?.position;
this.updatePoint("position", pos);
if (distance < 20) {
this.transformControls.detach();
return;
}
if (distance < 1000) {
this.scene.getObjectByName(stickyHelper.objectsToWhichItSticksName)?.position.copy(pos);
this.updatePoint( globalVectorObjStickyName?.position.copy(
"update", this.scene
JSON.stringify(objectThatSticksNamePosition.sub(objectsToWhichItSticksNamePosition)) .getObjectByName("cube2:point:0objectThatSticksNamePoints")!
); .position.add(objectsToWhichItSticksPointLocalVector)
} );
// console.log(this.scene.children.map((e) => console.log(e.name)));
// cube2:point:0objectThatSticksNamePoints
// cube1:point:0objectsToWhichItSticksPoints
// this.makePoint(objectThatSticksNamePosition, "red", 1.1);
// this.makePoint(objectsToWhichItSticksNamePosition, "red", 1.1);
// const movePosition = objectThatSticksNamePosition.sub(objectsToWhichItSticksNamePosition);
// const movePosition = new Vector3().subVectors(
// objectThatSticksNamePosition,
// objectsToWhichItSticksNamePosition
// );
// this.scene.getObjectByName(stickyHelper.objectsToWhichItSticksName)?.position.copy(movePosition);
} }
}); });
}); });

View file

@ -23,9 +23,9 @@ root.render(
{/* </SocketLister> */} {/* </SocketLister> */}
<> <>
{/* <SceneManger></SceneManger> */} {/* <SceneManger></SceneManger> */}
<StickObjectsMarkingScreen /> {/* <StickObjectsMarkingScreen /> */}
{/* <BehaviorTreeBuilderScreen /> */} <BehaviorTreeBuilderScreen />
</> </>
</> </>
); );