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.

Cloning and Picking

Home Forums Puzzles Cloning and Picking

Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #36400
    Avatarjdock
    Customer

    Hi,

    There seems to be an change with 3.5 that is affecting an approach I have used for ‘When Clicked’ events and cloned objects. I have been creating a When Clicked event with no object, then using the ‘if missed do…’ to return the Picked Object name, then decide what to do based on the name.

    I have attached an example puzzle using the standard Cube template. This seemed to be an efficient approach compared to creating an event for every object I clone. In my project, I need to clone a lot of objects (think of Legos).

    It seems with 3.5, the picked object name is coming back null. It seemed to work after updating the project, then stopped after I saved it. Seems to be replicable with the simple puzzle attached. It works at first, then stops returning the name with the Picked Object.

    Perhaps this is not a good approach? Maybe it is a small bug in 3.5?

    Thanks,
    Jon

    Attachments:
    You must be logged in to view attached files.
    #36402
    GlifTekGlifTek
    Customer

    Sometimes while debugging verge projects using its live server, things get stuck in the browser cache.

    I find it useful to close it all down, including the verge process…

    … clear browser cache (maybe not cookies).. Then try again. :scratch: :wacko:

    Might be a solution to your issue.

    #36415

    Hi,

    since you are using when clicked without a target object, then picked object should always return null. It still can be not null if you’re using another when clicked puzzle somewhere else. The reason is that picked object is a global variable, so depending on previous events happened in your app it may be null or not null.

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #36419
    Avatarjdock
    Customer

    Thanks guys – browser cache did not seem to affect the behavior, but a good thought.

    Yuri, I know this is an odd approach, but in 3.4 and prior, the picked object always returned the mesh name. I put an example of 3.4 with this puzzle attached. Check out the console output. I was careful to name the original mesh Cube.0 so the clone name would be predictable (Cube.1, Cube.2, etc.). Here’s the 3.4 example: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:091950d814/applications/CloneTest/CloneTest.html
    Here’s the exact same in 3.5: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/CloneTest35/CloneTest.html

    Just updating the project after upgrade to 3.5 does not affect the behavior, but changing a puzzle and saving does.

    Again, if this is a terrible approach, I am open to other ideas to be able to capture click events of cloned objects. Here’s my production project that involves a lot of cloning: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/ShoreStationDock/index.html

    Perhaps a custom routine? I’m not a great coder, so I’d need help:)

    Thanks,
    Jon

    • This reply was modified 2 months, 3 weeks ago by Avatarjdock.
    #36467

    Just updating the project after upgrade to 3.5 does not affect the behavior, but changing a puzzle and saving does.

    Yep, re-saving your Puzzles after updating to a new version is a right (and sometimes necessary) thing to do. Or you mean it gets broken after resaving the Puzzles? If so, please attach your cube test application so that we take a look!

    Here’s my production project that involves a lot of cloning: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/ShoreStationDock/index.html

    Perfect! :good: :good: :good:

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #36483
    Avatarjdock
    Customer

    Here are the two versions. CloneTest.zip if from 3.4, CloneTest35.zip is from 3.5.

    Attachments:
    You must be logged in to view attached files.
    #36485
    Avatarjdock
    Customer

    Here’s 3.5

    Attachments:
    You must be logged in to view attached files.
    #36487
    Avatarjdock
    Customer

    If the ’empty when clicked’ approach is bad, maybe some guidance in creating a custom event handler that just returns the mesh name from any click?

    #36518

    Yep, CloneTest35 works for me, and CloneTest does not (I’m not sure how it even worked for you :scratch: )

    maybe some guidance in creating a custom event handler that just returns the mesh name from any click?

    well, may be you could use a variable, to which you can save your object name, and which will be updated with new object names from the picked object puzzle.

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #36541
    Avatarjdock
    Customer

    Yuri,

    I gave this a try. I created a list called ‘AllObjects’ and added all mesh objects to it. I have attached the puzzle where I add any new cloned objects to the ‘AllObjects’ list. It seems the When Clicked event does not see the change to the list. It looks like the event only pays attention to the contents of the list when it is initiated – correct?

    Thanks,
    Jon

    Attachments:
    You must be logged in to view attached files.
    #36549
    Avatarjdock
    Customer

    OK, so I did find a workaround: The attached puzzle worked (not in the preview window though). The code in the ‘Exec Script’ puzzle is:

    // Built-in variables: app, v3d, VARS, PROC
    var mouse = new v3d.Vector2();
    var raycaster = new v3d.Raycaster();
    mouse.set((VARS[‘mouseX’] / window.innerWidth) * 2 – 1, – (VARS[‘mouseY’] / window.innerHeight) * 2 + 1);
    raycaster.setFromCamera(mouse, app.camera);

    var intersects = raycaster.intersectObjects(app.scene.children);
    if (intersects.length > 0) {
    VARS[‘temp’] = intersects[0].object.name;
    } else {
    VARS[‘temp’] = null;
    }

    This returns the name of the mesh if hit, or null if not.

    Thanks,
    Jon

    Attachments:
    You must be logged in to view attached files.
    #36561

    It seems the When Clicked event does not see the change to the list. It looks like the event only pays attention to the contents of the list when it is initiated – correct?

    Yep, the event listener is only applied to the original contents.

    OK, so I did find a workaround

    Awesome! Thanks for sharing your solution. :good:

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #36789
    Avatarjdock
    Customer

    Yuri,

    I have having difficulty getting the ‘code puzzle’ to work with the 3D embedded. I have the 3D window in an iframe with an id = 3dFrame. I seem to be getting the correct mouse coordinates, but the raycaster doesn’t seem to intersect anything. Any ideas?

    Here’s my attempt to refer to the embedded window height and width:
    `// Built-in variables: app, v3d, VARS, PROC
    var mouse = new v3d.Vector2();
    var raycaster = new v3d.Raycaster();
    var x = document.getElementsByName(‘3dFrame’);
    mouse.set((VARS[‘mouseX’] / x.innerWidth) * 2 – 1, – (VARS[‘mouseY’] / x.innerHeight) * 2 + 1);
    raycaster.setFromCamera(mouse, app.camera);

    var intersects = raycaster.intersectObjects(app.scene.children);
    if (intersects.length > 0) {
    VARS[‘temp’] = intersects[0].object.name;
    } else {
    VARS[‘temp’] = null;
    }

    Jon

    #36822

    Hi Jon,

    Can you isolate this issue in a simple project that you could share with us?

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #36849
    Avatarjdock
    Customer

    Yuri,

    I tried something slightly different. If you look at the visual_logic.js content and go to the function initObjectPicking function inside registerOnClick, this changed from 3.4 to 3.5:

    if (!isPicked) {
    _pGlob.pickedObject = ”;
    cbIfMissedDo(event);
    }

    if I change this to as it was in 3.4, any intersected object from the mouse event gets returned with PickedObject, but isPicked remains false:
    if (!isPicked) {
    _pGlob.pickedObject = objName;
    cbIfMissedDo(event);
    }

    I changed this in the visual_logic.js and it works as before. Any chance this could be put back into 3.5? If not, I can just remember to tweak it.

    Thanks,
    Jon

Viewing 15 posts - 1 through 15 (of 25 total)
  • You must be logged in to reply to this topic.