Reset Photofeature3D


#1

How do you “reset” the photofeature 3D to in essence look like it did when you first zapped the code? For example, it is centered and straight when it first pops up; however, once I zoom in and move it around with my fingers on the screen, I want to be able to hit a button and have it “reset” to what it looked like before I started moving it around.


#2

Hi Amanda,

Once you’ve created a button, you can add a reference to your 3D model by dragging the node into the top of your script (n3D_Model in the example below).

Then, declare a new variable in your script and store the 3D node’s original position using the ‘position getter’ function.

Within the button’s pointerdown script, you can use the ‘position setter’ function to assign the original position back to your 3D model.

const my_3D_Model = symbol.nodes.my_3D_Model;

var originalPosition = my_3D_Model.position();


parent.on("pointerdown", () => {
    my_3D_Model.position(originalPosition);
});

Hope this helps, all the best.
Seb


#3

Hi Seb,
I tried following the code that you said, but it still doesn’t work. I typed in the code I’m using below. Am I missing anything?

const photofeature3D0 = symbol.nodes.photofeature3D0;
var originalPosition = photofeature3D0.position();

parent.on(“pointerdown”, () => {
// Runs when pointerdown occurs on the parent node
// The argument e contains useful info about this event:
// https://docs.zap.works/studio/scripting/reference/object/events/pointerdown/
photofeature3D0.position(originalPosition);
});

Thanks,
Amanda


#4

Hi Amanda,

Apologies for the delay in getting back to you, your reply must have slipped through.

It seems I misread your request, my function would work for a lone 3D model, but not for a model within a photo feature, which is what you were looking for.

To reset the position of the whole photo feature there’s a few extra steps that need to be taken.

First, head into your photo feature symbol and then into the ‘onScreenObject’ subsymbol within it.


Find the ‘script’ node, and add the following block of code to the bottom of the script.

export function totalReset(){
    symbol.nodes.inner.rotation([0,0,0]);
    symbol.nodes.rotate.rotation([0, 0, 0]);
    symbol.nodes.outer.rotation([0, 0, 0]);
    
    symbol.nodes.movescale.position([0, 0, 0]);
    symbol.nodes.movescale.scale([1, 1, 1]);
};

Head back to the photo feature symbol using the breadcrumb bar.

Create a new button, and within its ‘pointerdown’ script create a reference to the ‘onScreenObject’ node by dragging it form the hierarchy into the top of the script.

Since we added the ‘export’ keyword to the previous function, we can call it from another symbol.

Within the button’s ‘pointerdown’ function add the following line of code:

onScreenObject.nodes.script.totalReset();

When the user taps on the button you’ve added, the 3D model’s transforms will be reset.

Hope this helps,
Seb