#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)

vestal seal
#

so that when you click and drag on any of them the mesh extends from that direction
starting from the bounding box part itself tbh

hoary mantle
#

Like this?

vestal seal
hoary mantle
#

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.

vestal seal
# hoary mantle I think I have a solution for this. I'm gonna wait till I'm on my pc so I can co...

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

vestal seal
#

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?

hoary mantle
#

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.

vestal seal
#

Uh give me 20 minutes, I need to get something done first.

vestal seal
#

because it's running the same code and getting the same values just somewhere else

hoary mantle
#

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

vestal seal
#

I'm not sure I'm following with everything else tbh

#

this is counting to 7 for some reason?

hoary mantle
#

wait. You want to resize the mesh even if its not a cube?

vestal seal
vestal seal
#

like how you can stretch meshes

hoary mantle
#

ok

#

So right now your issue is placing the resize gizmos correct?

vestal seal
#

the gizmos in general tbh

#

yeah

hoary mantle
#

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.

vestal seal
#

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
                ```
hoary mantle
#

send screnshot

vestal seal
#

(ignore them being too large)

#

I'll probably have to figure out a different way to show they're selected too

hoary mantle
#

Blue is selected?

vestal seal
#

no

#

red is

#

blue is the handle

hoary mantle
#

Im still not sure what the code does, it cuts off and I dont know what the variables are

#

or what handle.tscb holds

vestal seal
#

and no scripts for now

hoary mantle
#

you should make mode an enum

vestal seal
#

what's an enum

hoary mantle
#

A cleaner way of representing constants (numbers)

#

now you know what mode is being set to rather than mere numbers with no meaning

vestal seal
hoary mantle
#

there u go

vestal seal
#

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?

hoary mantle
#

you can now use it on the match statement too

hoary mantle
#

mode 1 is move?

vestal seal
#

yes

#

mode two is scale

#

mode three is rotate

#

and four is add

hoary mantle
#

ok

vestal seal
#

uh

#

alright

hoary mantle
#

what is inside the handles scene?

vestal seal
#

nothing

hoary mantle
#

ok, and every clickable body has a Handle, got it

vestal seal
hoary mantle
#

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

vestal seal
#

I'm now trying to try and re arrange the code to make it work but now not even that works

vestal seal
#

and since the static body is supposed to be a convex hull of the mesh in the case of complex ones

hoary mantle
vestal seal
hoary mantle
#

oh i see

#

I still suggest making the mesh a child of the body

vestal seal
hoary mantle
#

bodies are almost always on top

hoary mantle
#

are you trying to add handles to the selected parent or the Handle node?

vestal seal
#

I think

hoary mantle
#

(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)

hoary mantle
vestal seal
hoary mantle
#

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

hoary mantle
hoary mantle
# vestal seal It is “slb”

Selectable. dont shorten words or you will not know what they mean in the future. make everything as readable as possible

vestal seal
hoary mantle
vestal seal
#

I’ll see then brb

hoary mantle
#

There are a bunch of functions to get nodes

#

get_node, get_parent, and has_node are the most used

vestal seal
#

so now it's complaining abt this

hoary mantle
vestal seal
#

that's what I did I just changed it

#

to see if it helped

hoary mantle
#

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

vestal seal
#

lastMaterial = selected.get_node("MeshInstance3D").material_override

hoary mantle
#

selected.get_node("MeshInstance3D").mesh.surface......

vestal seal
#

just surface_mater

#

oh

#

js checking

hoary mantle
#

and to get it back use this one

#

Rename Rock2 to MeshInstance3D

vestal seal
#

okay it's not finding the node at all?

vestal seal
hoary mantle
#

If you want to set the mateirla of the MeshInstance then click the mesh and set it there

vestal seal
#

okay but in terms of the script it

#

oh

vestal seal
hoary mantle
#

and the other one is attaching a script to the Body with a reference to the mesh instance

vestal seal
#

you know what index is fine

#

prefer that to a script

hoary mantle
#

ok

#

So make sure the MeshInstance node is the first child of the Body

vestal seal
#

yes, I know

hoary mantle
#

and then use get child to get it

#

any more material errors?

vestal seal
#

alright so it didn't crash but it doesn't seem it's assigning the materials either

#

it does select properly which is good

hoary mantle
#

Did you remove the material from the geometryinstance part?

vestal seal
#

no

hoary mantle
#

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

vestal seal
#

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

hoary mantle
vestal seal
#

ok so, next task

#

wait do I have to do the same indexing thing for the mesh here?

hoary mantle
#

yes

#

get_aabb is a mesh function

#

so selected.get_child(0).mesh.get_aabb()

vestal seal
#

.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

hoary mantle
#

Reading the code from top to bottom might help you refresh

vestal seal
#

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

hoary mantle
#

oh no not get_parent().get_parent().get_parent().get_parent().get_parent().get_parent()

vestal seal
#

it's to parent it to the root

hoary mantle
#

get_viewport()

#

that returns the project root node

vestal seal
#

oh

#

do you have any idea though?

hoary mantle
#

send me the updated code

vestal seal
#
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
                ```
hoary mantle
#

add_child doesnt return anything

vestal seal
#

wait

#

oh my

#

oh

hoary mantle
#

you cant set it to current

vestal seal
#

ohh

#

OK I THINK IT'S DOING IT

#

although it's still copying it over a few times

hoary mantle
#

how many times?

vestal seal
#

no it's not a set number it just instances it each frame I'm p sure

hoary mantle
#

and is this for one Body or all of them?

vestal seal
hoary mantle
#

I suggest putting your input logic on the

func _input(event):
function

#

it doesnt have to run every frame

vestal seal
#

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

hoary mantle
#

well. by the looks that you're using the projec root to instance stuff. I dont think its a good idea

vestal seal
#

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?

hoary mantle
#

um

#

you should spawn the handle as close as possible to the StaticBody, maybe make it a sibling

vestal seal
#

aren't they?

hoary mantle
#

idk lol

#

Im gonna eat. brb

vestal seal
#

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

hoary mantle
#

I might have to see the entire script.

vestal seal
#

alright

hoary mantle
#

See. You're instancing them every frame

#

All of this runs every frame

vestal seal
#

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

hoary mantle
#

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

vestal seal
#

so then what would happen when we get to the part where you actually drag the handles

hoary mantle
#

for example

vestal seal
#

like, if it only runs once for every input then the mouse holding would be a single run

hoary mantle
#

have a variable that is set to true if the mouse is dragging

vestal seal
#

okay

hoary mantle
#

now you can access dragging on _process

vestal seal
#

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

hoary mantle
#

well, its using right click as an example

vestal seal
#

yyes but that's also input and as such the instance gets instanced in the process

hoary mantle
#

what?

vestal seal
#

input gets called whenever you move your mouse

hoary mantle
#

only if the if statment is true it runs the block

vestal seal
#

or click it or anything

vestal seal
#

if the event isn't mouse related then it runs it?

#

or well, couldn't it just remove whichever the old ones were

hoary mantle
#

um

#

It runs for every input

vestal seal
#

yeah

hoary mantle
#

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

vestal seal
#

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

hoary mantle
#

Its good practice to put input there, and let _process do other per frame tasks

vestal seal
#

alright

hoary mantle
#

also _input has an event parameter which you can use to check mouse motion and its position on screen.

vestal seal
#

yeah I remember from when I did the camera

hoary mantle
#

yup

#

anyways

#

this is running every frame

#

you dont want that

vestal seal
#

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?

vestal seal
#

sort of?

hoary mantle
vestal seal
#

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

vestal seal
#

thanks

hoary mantle
hoary mantle
vestal seal
# hoary mantle 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?

vestal seal
#

I personally don't see what the logic flaws could be from here

vestal seal
#

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?

vestal seal
#

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?

hoary mantle
# vestal seal what was that math that you told me?

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.

vestal seal
#

but can you give me an idea?

#

or smth

#

if you can