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.

zoomCamera Puzzle with Offset

Home Forums Programming zoomCamera Puzzle with Offset

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #45005
    web
    Customer

    I just had to extend the zoomCamera function with a offset. If anyone got the same “issue” here is the altered function:

    // zoomCamera puzzle
    function zoomCamera(objSelector, duration, offset, doSlot) {
    
        duration = Math.max(0, duration);
    
        var objNames = retrieveObjectNames(objSelector);
    
        var zoomObjects = [];
        objNames.forEach(function(name) {
            var obj = getObjectByName(name);
            if (obj) {
                zoomObjects.push(obj);
            }
        });
    
        if (!zoomObjects.length) {
            return;
        }
    
        var camera = appInstance.getCamera();
    
        var pos = _pGlob.vec3Tmp, target = _pGlob.vec3Tmp2;
        v3d.CameraUtils.calcCameraZoomToObjectsParams(camera, zoomObjects,
                pos, target);
    
        if(offset){
            pos.x += offset;
            pos.y += offset;
            pos.z += offset;
        }
    
        if (appInstance.controls && appInstance.controls.tween) {
            // orbit and flying cameras
            if (!appInstance.controls.inTween) {
                appInstance.controls.tween(pos, target, duration, doSlot);
            }
        } else {
            // TODO: static camera, just position it for now
            if (camera.parent) {
                camera.parent.worldToLocal(pos);
            }
            camera.position.copy(pos);
            camera.lookAt(target);
            doSlot();
        }
    }

    I just added the variable offset which is just a number, which gets added to the calculated position when set. This way I can control the distance of the camera to the object I would like to zoom on.

    There will be for sure a better approach, but this one is working for me. Maybe the devs can implement that functionality in the future to the function “the right way”.

    • This topic was modified 1 month ago by web.
    #45043
    xeon
    Customer

    This is great.
    How / why did you need this? Whats the use case?

    Xeon
    Route 66 Digital
    Interactive Solutions

    #45107
    web
    Customer

    Got some clickable objects where I want the camera to zoom on. I liked the idea of the zoomCamera puzzle but was never happy that you cant control the offset. Because the zoom tries to get the object into the full viewport size, which is much to big.

    In the past I just created cameras by hand were I tweened the active camera to, but I was to lazy doing this to 11 objects, so I looked at the zoomCamera funtion a little bit closer.

    #45120

    Interesting! Thanks for sharing your approach. :good:

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

    #45728
    gaso
    Customer

    Something like this would be very useful for the camera tween as well, especially for responsive workflows.

    I have project with info popups that are on the left side of the screen in desktop, and bottom of the screen for mobile devices. The camera zoom locations that work for desktop are not optimal for mobile users. I could do different zoom locations for both mobile & desktop and switch accordingly, but that’s quite a lot of work to set up… Being able to define camera offset & zoom amount for each target would save a ton of time.

    • This reply was modified 3 weeks, 4 days ago by gaso.
    • This reply was modified 3 weeks, 4 days ago by gaso.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.