Skip to content

Commit

Permalink
Add debugging for 2D-in-3D-interaction for ComponentExplorerDworph
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Jan 30, 2024
1 parent 1296fc4 commit 6b76a3a
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions GReaSe-Tools/ComponentBrowserDworph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ ComponentBrowserDworph >> fontSize [
{ #category : #'as yet unclassified' }
ComponentBrowserDworph >> render: props [

| viewportTransform viewport spatial raycastPosStart raycastPosEnd world |
| viewportTransform viewport spatial raycastPosStart raycastPosEnd world movingButton |

"---Only needed for debug---"
world := self useWorldPortal.
raycastPosStart := self useState: Vector3 new.
raycastPosEnd := self useState: Vector3 new.
movingButton := self useGodotRef.
"---"
viewportTransform := self useState: nil.
viewport := self useGodotRef.
spatial := self useGodotRef.
Expand All @@ -35,24 +39,25 @@ ComponentBrowserDworph >> render: props [
rectSize: self resolution;
children: {
GDButton new
text: 'Test'.
text: 'Test';
rectSize: 100@100;
onButtonDown: [Transcript showln: 'Button pressed.'];
ref: movingButton.
});
meshDo: [:material |
GRGrabbableArea new children: {
GDCollisionShape new shape: (GDBoxShape new extents: 0.75 @ 0.5 @ 0.1); translation: 0 @ 1 @ -0.1 .
GDCollisionShape new shape: (GDBoxShape new extents: 0.75 @ 0.5 @ 0.1); translation: 0 @ 0 @ -0.1 .
GRInteractiveArea new
touch: false;
point: true;
children: {
GDSpatial new
ref: spatial;
subscribeTo: #global_transform do: [ :transform | viewportTransform set: transform].
GDCollisionShape new shape: (GDBoxShape new extents: 0.75 @ 0.5 @ 0.001); translation: 0 @ 1 @ 0.001.
GDCollisionShape new shape: (GDBoxShape new extents: 0.75 @ 0.5 @ 0.001); translation: 0 @ 0 @ 0.001.
};
onButtonPress: [:event |
onButtonPress: [:event || raycastResult |
"Raycast from event-hand transform with distance of hand object to find intersection coordinate"
| raycastResult |
Transcript showln: '---New button event---'.
raycastResult := spatial get getWorld directSpaceState
intersectRayFrom: event transform translation
to: (event transform localPointToGlobal: (0 @ 0 @ GRPointer laserLength negated))
Expand All @@ -62,47 +67,77 @@ ComponentBrowserDworph >> render: props [
collideWithAreas: true.
raycastPosStart set: event transform translation.
raycastPosEnd set: (event transform localPointToGlobal: (0 @ 0 @ GRPointer laserLength negated)).
Transcript showln: 'Raycast performed'.
"Convert intersection coordinate to coordinate in viewport"
raycastResult ifNotNil: [

(raycastResult at: #position ifAbsent: nil) ifNotNil: [

| viewportCoord3D viewportCoord2D inputEvent |
Transcript showln: 'INTERSECTION FOUND'.
(raycastResult at: #position ifAbsent: nil) ifNotNil: [ |viewportCoord3D viewportCoord2D |
raycastPosStart set: (viewportTransform get globalPointToLocal: (0@0@0)).
raycastPosEnd set: (raycastResult at: #position).
viewportCoord3D := viewportTransform get globalPointToLocal: (raycastResult at: #position).
Transcript showln: 'Local space:'.
Transcript showln: viewportCoord3D.
viewportCoord2D := (((viewportCoord3D x / 1.5) + 0.5) * self resolution x @ ((viewportCoord3D y / 1) + 0.5) * self resolution y ).
Transcript showln: 'Inverse transform space:'.
Transcript showln: viewportCoord2D.
viewportCoord2D := Point
x: ((viewportCoord3D x / 1.5) + 0.5) * self resolution x
y: ((viewportCoord3D y negated/ 1) + 0.5) * self resolution y.

"Generate viewport click event"
inputEvent := GDInputEventMouseButton new
GDInputEventMouseButton externalNewDuring: [ :mouseEvent |
mouseEvent
buttonIndex: 1;
pressed: true;
position: viewportCoord2D;
globalPosition: viewportCoord2D;
buttonMask: 1.

"@TODO find out why this does not work"
(viewport get) inputLocalEvent: inputEvent.
viewport get inputLocalEvent: mouseEvent.
] .

movingButton get setPosition: viewportCoord2D.
]]
].
GDMeshInstance new
translation: 0@1@0;
translation: 0@0@0;
mesh: (GDQuadMesh new
size: 1.5 @ 1;
material: material).


CMFReactNodePortal child: {AttentionDworph new target: raycastPosStart get} in: world.
CMFReactNodePortal child: {AttentionDworph new target: raycastPosEnd get} in: world.

}]
]

{ #category : #'as yet unclassified' }
ComponentBrowserDworph >> renderTreeUI [

"
generateUIForFiber: aCMFFiber inTree: aGDTree withRoot: aGDTreeItem
| currentItem |
currentItem := aGDTree createItemParent: aGDTreeItem.
currentItem
setTextColumn: 0 text: (aCMFFiber node asString copyWithRegex: '[\<\/\>]' matchesReplacedWith: '').
^ {
currentItem.
aCMFFiber sibling ifNotNil: [self generateUIForFiber: aCMFFiber sibling inTree: aGDTree withRoot: aGDTreeItem].
aCMFFiber child ifNotNil: [self generateUIForFiber: aCMFFiber child inTree: aGDTree withRoot: aCMFFiber].
}
render: props
| rootFiber tree |
rootFiber := ((GRReact current instVarNamed: #sessions) associations first) react currentRoot node.
tree := GDTree new.
self generateUIForFiber: rootFiber inTree: tree withRoot: nil.
^ GDControl new
rectSize: (1500@1000);
children: {
tree
}
"
]

{ #category : #'as yet unclassified' }
ComponentBrowserDworph >> resolution [

Expand Down

0 comments on commit 6b76a3a

Please sign in to comment.