#how could I go about having 6 scenes that are placed on the sides of the bounding box of a mesh?
1 messages · Page 1 of 1 (latest)
Like this?
yeah
I think I have a solution for this. I'm gonna wait till I'm on my pc so I can convey it be better, maybe in 2 hours.
ok so I looked into it
it'd basically be getting the middle of each face of the bounding box and storing them in an array. then instancing a handle scene with a function that returns true whenever it's being held down by the mouse, and when it is it performs whatever the procedure is, since I'm focusing on moving it would be start to move it up based on the mouse and that I'm not really that sure of but the direction could be gotten by the name of the handles being the same as the array index that instanced it
ok so this is basically the code I came up with for this
if selected:
var aabb = selected.get_aabb()
var center = aabb.position + (aabb.size / 2)
var middle_faces = [
center + Vector3(aabb.size.x / 2, 0, 0), # Right face
center - Vector3(aabb.size.x / 2, 0, 0), # Left face
center + Vector3(0, aabb.size.y / 2, 0), # Top face
center - Vector3(0, aabb.size.y / 2, 0), # Bottom face
center + Vector3(0, 0, aabb.size.z / 2), # Front face
center - Vector3(0, 0, aabb.size.z / 2), # Back face
]
var handles = load("res://scenes/xyzpresets/handle.tscn").instantiate()
for check in selected.get_children():
if check.name != "Handle":
for c in middle_faces:
selected.add_child(handles)
handles.position = c
else:
break```
it only really puts it on a single face of the bounding box I think?
and it ends up copying thousands of times per frame instead of just once
which is what the check is supposed to do but it doesn't really work for some reason?
I think you should make a custom Cube class
It should hold the position of all its 4 points
I think I figured out the math to make the mouse resize the box. But first you have to set it up.
Right.
Uh give me 20 minutes, I need to get something done first.
okay so I'm trying to restructure the code to account for the fact the actual thing is now under an additional parent that has the class but now nothing works at all
would the logic end up being different though?
because it's running the same code and getting the same values just somewhere else
not sure if aabb might be useful here
I suggest making the mesh AFTER doing the math instead of before it and resizing it
You can create a custom mesh with SurfaceTool
With that tool you can also just make an outline of a cube instead of triangles, similar to the image I sent from Roblox but with lines being 1 pixel thick
I'm not making any meshes
like, the reason I'm using aabb is because it can get the bounding box of any object that is selected so it can properly spawn the handles on the faces
I'm not sure I'm following with everything else tbh
this is counting to 7 for some reason?
wait. You want to resize the mesh even if its not a cube?
the handles are used as display for rotating displacing and scaling
and yeah, it's meant to work for everything
like how you can stretch meshes
ok in this situation you're right to use aabb, but I'm not sure how this will scale to other transformations types in the future
Also the mechanic for the mouse dragging the gizmo is relative to this too, so you gotta see the bigger picture in a way.
yeah since this is all on process in a check the bounding box would update after resizing or displacing or whatever
so what am I doing wrong that they only spawn on one of the sides?
# "updated" code
1:
if selected:
var aabb = selected.get_aabb()
var center = aabb.position + (aabb.size / 2)
var middle_faces = [
center + Vector3(aabb.size.x / 2, 0, 0), # Right face
center - Vector3(aabb.size.x / 2, 0, 0), # Left face
center + Vector3(0, aabb.size.y / 2, 0), # Top face
center - Vector3(0, aabb.size.y / 2, 0), # Bottom face
center + Vector3(0, 0, aabb.size.z / 2), # Front face
center - Vector3(0, 0, aabb.size.z / 2), # Back face
]
var handles = load("res://scenes/xyzpresets/handle.tscn").instantiate()
for check in selected.get_children():
if not check.name.contains("Handle"):
for c in middle_faces:
faceIndex += 1
if faceIndex >= 6:
break
print(faceIndex)
selected.add_child(handles)
handles.position = middle_faces[faceIndex]
else:
break
```
send screnshot
(ignore them being too large)
I'll probably have to figure out a different way to show they're selected too
Blue is selected?
Im still not sure what the code does, it cuts off and I dont know what the variables are
or what handle.tscb holds
basically just the blue sphere
and no scripts for now
you should make mode an enum
what's an enum
A cleaner way of representing constants (numbers)
now you know what mode is being set to rather than mere numbers with no meaning
not exactly?
there u go
no yeah but it still prints kind of the same thing
or well... do you now have some idea of what went wrong with this?
you can now use it on the match statement too
i know im just trying to make the code more readable so I can know whats going on
mode 1 is move?
ok
what is inside the handles scene?
nothing
ok, and every clickable body has a Handle, got it
when you select it, others that are not selected don't so you don't get forty handles for a house
You should make the meshes be children of the Body instead of the other way around
you're trying to get the aabb of the static body, not the mesh
I'm now trying to try and re arrange the code to make it work but now not even that works
no, of the mesh as well
and since the static body is supposed to be a convex hull of the mesh in the case of complex ones
Static body has no function get_aabb...
yeah, which is why selected is the parent
is it really necessary or just good practice
because frankly I'm starting to lose track of how this gets around and why it's not and I would strongly prefer the one that works
bodies are almost always on top
Its good practice, but for now i guess you can leave it like that
are you trying to add handles to the selected parent or the Handle node?
I'm trying to add the handles to the mesh, which would be selected normally
I think
(This is why having the staticbody as a child is also confusing, because the selected variable is actually the parent of the object you clicked, now we have to call the "the parent of the selected object" or something confusing)
Why are you checking if a node has the node "Handle" then?
because the nodes being added are called "handle", and when I first did it it just added the handles over and over and over. that was how I assumed I could make them only spawn once
um, idk what to say bout then then, i guess delete it?
Also here you're checking if the mesh PARENT has a child handle when in reallity the only node it has is StaticBody
this if statment will always break
Just structure the object like this, its less of a headache trust me
You should also set Rock to a group called "Selectable" or something like that
It is “slb”
Selectable. dont shorten words or you will not know what they mean in the future. make everything as readable as possible
But then I’d have to do a for loop to find the object with the mesh instance3D since its name isn’t constant
just get_node("MeshInstance3D")
There is only one mesh per selectable object anyways so there is no need to know their name
That’s
A thing?
I just made a whole find child of type function
I’ll see then brb

There are a bunch of functions to get nodes
get_node, get_parent, and has_node are the most used
so now it's complaining abt this
use MeshInstance3D not GeometryInstnace3D
MeshInstance3D has a mesh property
you can then set the material with this function on the mesh
surf_inx is 0 since there is only one material on the mesh
and to get it?
lastMaterial = selected.get_node("MeshInstance3D").material_override
selected.get_node("MeshInstance3D").mesh.surface......
sure
do keep in mind basically none of this should be name sensitive
or well it could but it's preferable if it isn't
okay it's not finding the node at all?
ah ok one sec then
weird
MeshInstance3D inherits GeometryInstance3D ,thats normal
If you want to set the mateirla of the MeshInstance then click the mesh and set it there
it's greyed out
There might be two solutions. Make it index sensitive, meaning make the Mesh be the first child on top of the parent
and the other one is attaching a script to the Body with a reference to the mesh instance
yes, I know
alright so it didn't crash but it doesn't seem it's assigning the materials either
it does select properly which is good
no
If its too much work to move the materials to the mesh itself then we can go back
you can use material_override again in code
It seems to be that the problem was MeshInstance3D not being found, but we fixed that now with the indexing thingy
so
it still doesn't?
if lastSelect:
lastSelect.get_child(0).material_override = lastMaterial
lastMaterial = selected.get_child(0).material_override
lastSelect = selected
selected.get_child(0).material_override = barrier
this isn't wrong is it?
wait
oh
nvm nvm
it works
finallyyy

.mesh?
I mean
ok so, I think just about the entire logic of this thing doesn't work
what I tried before was basically just, for each of the faces, make a handle that's linked by name to the index of the corresponding face on the array
and make its position said face
Reading the code from top to bottom might help you refresh
var handles = load("res://scenes/xyzpresets/handle.tscn").instantiate()
for c in middle_faces:
var current = selected.add_child(handles)
current.position = c
ok so it might be because it's using the same var.current and instantiate only works once?
so if I moved the handles inside
wait why doesn't it let me it had worked before?
yeah, it did
oh no not get_parent().get_parent().get_parent().get_parent().get_parent().get_parent()
it's to parent it to the root
send me the updated code
Mode.MOVE:
if selected:
var aabb = selected.get_child(0).mesh.get_aabb()
var center = aabb.position + (aabb.size / 2)
var middle_faces = [
center + Vector3(aabb.size.x / 2, 0, 0), # Right face
center - Vector3(aabb.size.x / 2, 0, 0), # Left face
center + Vector3(0, aabb.size.y / 2, 0), # Top face
center - Vector3(0, aabb.size.y / 2, 0), # Bottom face
center + Vector3(0, 0, aabb.size.z / 2), # Front face
center - Vector3(0, 0, aabb.size.z / 2), # Back face
]
for c in middle_faces:
var handles = load("res://scenes/xyzpresets/handle.tscn").instantiate()
var current = selected.add_child(handles)
current.position = c
```
add_child doesnt return anything
you cant set it to current
how many times?
no it's not a set number it just instances it each frame I'm p sure
and is this for one Body or all of them?
for the selected one, since the logic runs only for it
I suggest putting your input logic on the
func _input(event):
function
it doesnt have to run every frame
ideally by the end they should all be gone when deselecting, and should only spawn once
even in the case it's only on input
well. by the looks that you're using the projec root to instance stuff. I dont think its a good idea
what I could do is maybe like, have a counter or something that just goes up to 6 and it doesn't when it's 6
gets reset whenever something else is selected
so only the 6 spawn
right?
um
you should spawn the handle as close as possible to the StaticBody, maybe make it a sibling
aren't they?
alr
I'm gonna take a bath too
and yeah they're instanced on selected
the ones that are instanced on the root are the cubes
I might have to see the entire script.
I know
but like, even if it didn't it would after you dragged since that's an input as well
if I understand the _input thing correctly
nope
_input runs whenever the user does something on the keyboard, mouse, controller...etc instead of every frame
Inse it you still have to check what inputs were pressed or released
Input.is_action_just_pressed
Input.is_action_just_released
so then what would happen when we get to the part where you actually drag the handles
for example
like, if it only runs once for every input then the mouse holding would be a single run
have a variable that is set to true if the mouse is dragging
okay
wait does dragging the mouse count as well
ookay it does
uh
you click and hold with the right click to move the camera around
thats what the code does above
well, its using right click as an example
yyes but that's also input and as such the instance gets instanced in the process
what?
input gets called whenever you move your mouse
only if the if statment is true it runs the block
or click it or anything
so like
if the event isn't mouse related then it runs it?
or well, couldn't it just remove whichever the old ones were
yeah
Think of it like a conveyor belt.
these if statements just check what is on the belt, and the TAKES it if its what they want, then does something with it and puts it back to the belt so other ifs can take it too
if not then do nothing and let the other if statements check it too
yes, but then like,
I don't get how that would apply in this context since it's not just for the mouse dragging
or well
Its good practice to put input there, and let _process do other per frame tasks
alright
also _input has an event parameter which you can use to check mouse motion and its position on screen.
yeah I remember from when I did the camera
yeah but then it should only run once and that's when selected changes
sadly there's not magical way to have something run when a variable changes as an event
right?
or the mesh's properties are updated
sort of?
Setters to the rescue
w
look atp my head hurts, it's already like 10 pm and I'm tired for today
so I'll come back to this tmr, k? I'm going to sleep
ok
thanks
you cna call functions from them whenever a variable changes
gn
ok so, I moved most of the logic for changing the previous and current select to this set function
var selected:
set(value):
if lastSelect:
lastSelect.get_child(0).material_override = lastMaterial
for serov in lastSelect.get_children():
print(serov.name + "sssss")
if serov.name.contains("CSGSphere") or serov.name == "Handle":
serov.queue_free()
else:
lastMaterial = value.get_child(0).material_override
lastSelect = value
value.get_child(0).material_override = barrier
print(lastSelect.name + "ajvreeajow")
var aabb = value.get_child(0).mesh.get_aabb()
var center = aabb.position + (aabb.size / 2)
var middle_faces = [
center + Vector3(aabb.size.x / 2, 0, 0), # Right face
center - Vector3(aabb.size.x / 2, 0, 0), # Left face
center + Vector3(0, aabb.size.y / 2, 0), # Top face
center - Vector3(0, aabb.size.y / 2, 0), # Bottom face
center + Vector3(0, 0, aabb.size.z / 2), # Front face
center - Vector3(0, 0, aabb.size.z / 2), # Back face
]
for c in middle_faces:
var handles = load("res://scenes/xyzpresets/handle.tscn").instantiate()
value.add_child(handles)
handles.position = c
```
and it works
but like
only on the first seleciton
and
selected is null when printing it for some reason too?
I personally don't see what the logic flaws could be from here
ok uh
update
it works now
like
perfectly
I'm gonna spend a bit making the handles look more like gizmos and figuring stuff like being on top or scaling out
uh
what was that math that you told me?
also made the gizmos look nicer too
so, what I was thinking is the things could have a function which would return true if they were being clicked
and it would check on _input() if that function returns true. so when it does, it runs whatever the math you told me would be, maybe?
Its more complicated than I though, you might have to do the research yourself for a bit. Take a look at Vector math, Basis math, camera projections, planes, dot products, and cross products. I think it will be too much to explain all by myself here.
Much bigger in scope to what I can help with.
oh my
but can you give me an idea?
or smth
if you can