We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

drag rotate spots ?

Home Forums Puzzles drag rotate spots ?

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #86954
    xeon
    Customer

    I have tried to recreate the problem you are having…in a simplified app.
    How are you parenting the cloned light to the appended object? More to the point how are you trying to parent a cloned light to a cloned Letter?

    I have have no issue adding cloning a light to the first imported object or even a newly added append of the same letter (not recommended). No reason to append another letter A if one is already in the scene so I am cloning that letter. Then I am trying to parent a clone of an existing spot light to that cloned letter (the second letter A). This is where things break down.

    Thats were I am having the problem you are describing…its as if the parent doesnt work.
    I can parent it to the append object…no problem…but after that…things get wonky at best.

    I have tried parenting groups, lights parented to empties and then parenting the empty, I have tried various things but no luck so far.

    If you can show me the puzzles you are using to parent I can try those out.

    Xeon
    Route 66 Digital
    Interactive Solutions - https://www.r66d.com
    Tutorials - https://www.xeons3dlab.com

    #86958
    NaxosCG
    Customer

    Prepare draggable, it is setting events in the loop. But if that is getting called every time you type a letter you are assigning a new event handler to the mesh – it will cause memory leakage and you’ll have all sorts of side effects because you are reassigning it to meshes that already have it.

    Oh i see.
    To be fair, i copied a puzzle i saw here.
    It is working quite well, except for my spot problem…
    Did not tested with lots of letters, so maybe it well become more and more laggy.

    "1+1=3... for large values of 1"

    #86960
    NaxosCG
    Customer

    If you can show me the puzzles you are using to parent I can try those out.

    Here is the test link, can you find what you need here ?

    https://v3d.net/1g09

    go in the menu, add letters, then clic and drag (left button : move – right button rotate)

    All works, except for the spot that stay looking at it’s target

    "1+1=3... for large values of 1"

    #86970
    xeon
    Customer

    Happy to help and try a few things but the application is not as useful.
    If you can zip up your project I can take a look.
    If you want to send the link privately you can email me at xeons3dlab at gmail dot com.

    Xeon
    Route 66 Digital
    Interactive Solutions - https://www.r66d.com
    Tutorials - https://www.xeons3dlab.com

    #86978
    bigmike814
    Participant

    Ok look at the console errors.

    I don’t know if you know this, but since you said you arent a coder, im going to assume you don’t, but look at the errors your console is throwing and then look at the stack trace. You can see the visual logic is throwing the error (they are written into the puzzle behind the scenes) and the function that is calling the function throwing errors in the stack is your function PrepareDraggable puzzle I was telling you about.

    Here is the claude report I put together for you. Hope this helps.
    # prepareDraggable() Fix — Plain Language Summary

    ## The Core Issue

    Your prepareDraggable() is calling **get all objects** on ListeDraggablesObj
    which traverses the full hierarchy — so it picks up your cloned Fspot lights as
    well as your letter meshes. Lights have no material, hence the console flood.

    Then it loops the **entire list** every time a new letter is added. So by letter 3,
    letter 1 has been registered 3 times, letter 2 twice, etc. Handlers stack up fast.

    ## Fix Part 1 — Switch from “get all” to “get mesh”

    Instead of:
    `
    getObjectsFrom(ListeDraggablesObj, ‘ALL’, …)
    `

    Just use MeshIdentifier directly — it’s already the newly added letter,
    it’s already a mesh, no traversal, no lights getting caught up in it.

    You don’t need to loop the whole list at all. prepareDraggable() only
    needs to register the one letter that was just added.

    ## Fix Part 2 — Guard Against Re-registration (the delete/re-add case)

    Since V3D has no puzzle to remove event handlers, you need a simple
    registered items list to track what’s already been set up.

    Add a variable at the top of your app (alongside ListeDraggablesObj):

    `
    ListeRegistered = [] ← new list, starts empty
    `

    Then at the top of prepareDraggable(), before registering anything:

    `
    IF MeshIdentifier is already in ListeRegistered
    → DO NOTHING, return early

    IF MeshIdentifier is NOT in ListeRegistered
    → register the drag handlers as normal
    → add MeshIdentifier to ListeRegistered
    `

    This handles the case where a user adds “M”, deletes it, then adds “M” again.
    Without the check, the second add would stack a second handler on top.
    With the check, it sees “M” already exists in ListeRegistered and skips.

    **Important:** When the user hits delete and unloadScene() runs,
    also clear ListeRegistered for that position:

    `
    on BT_Delete click:
    → unload scenes (already doing this)
    → clear ListeDraggablesObj (already doing this)
    → also clear ListeRegistered ← add this
    `

    Or if you have separate registered lists per position (bot/mid/top),
    clear only the relevant one.

    ## Fix Part 3 — Remove the Fspot-1 Rotation Line

    In prepareDraggable() you have this on the rotate handler:

    `
    dragRotateAdv(‘Fspot-1’, ‘Z’, ‘WORLD’, …)
    `

    Remove this line entirely. Here’s why it’s not needed:

    In Merge_gltf() you already do:
    `
    tempoSpot = cloneObject(‘Fspot-1’, …)
    makeParent(tempoSpot, metal_mesh_of_letter)
    `

    The cloned spot (Fspot-2, Fspot-3 etc.) is **parented to the letter’s metal mesh**.
    When the letter rotates via dragRotateAdv, the spot clone rotates with it
    automatically — that’s just how parent-child hierarchy works in Three.js/V3D.

    Fspot-1 is the hidden template. Rotating it does nothing visible.
    And even if it weren’t hidden, targeted spotlights ignore direct rotation
    because their look-at constraint recalculates direction every frame anyway.

    ## The Fixed prepareDraggable() Logic (pseudocode)

    `
    function prepareDraggable():

    obj_id = MeshIdentifier ← use this directly, not getObjectsFrom(ListeDraggablesObj)

    IF obj_id already in ListeRegistered → return, do nothing

    IF position is ‘bot’:
    IF material of obj_id ≠ material of ‘A-douille-000’
    AND material of obj_id ≠ material of ‘A-aniso-000’:

    registerOnDrag(obj_id, mouseButton[0]):
    → dragMoveAdv(obj_id, ‘XY’, ‘WORLD’, …)

    registerOnDrag(obj_id, mouseButton[2]):
    → dragRotateAdv(obj_id, ‘Z’, ‘WORLD’, …)
    ← no Fspot-1 rotation here, spot clone follows parent automatically

    add obj_id to ListeRegistered
    `

    ## Summary

    | What to change | Why |
    |—|—|
    | Use MeshIdentifier instead of getObjectsFrom(ListeDraggablesObj, 'ALL', ...) | Stops traversal picking up light children, stops the loop re-registering old letters |
    | Add ListeRegistered check before registering | Handles delete + re-add without stacking duplicate handlers |
    | Clear ListeRegistered on BT_Delete | Keeps the registered list in sync with the actual scene |
    | Remove dragRotateAdv('Fspot-1', ...) | Spot clone already follows letter rotation via parent hierarchy |

    Hope this helps! The stacking bug especially was subtle — it would have gotten worse with every letter added.

    • This reply was modified 1 month, 2 weeks ago by bigmike814.
    • This reply was modified 1 month, 2 weeks ago by bigmike814.
    • This reply was modified 1 month, 2 weeks ago by bigmike814.
    #86986
    NaxosCG
    Customer

    Many thanks, i’ll try to figure out and to implement this.

    "1+1=3... for large values of 1"

Viewing 6 posts - 16 through 21 (of 21 total)
  • You must be logged in to reply to this topic.