简体   繁体   中英

pdf 3d with JavaScript : simple example

I need to do a simple pdf with some 3D objects for an oral presentation. I made several views, each one with a camera viewpoint, an object and a display mode. To avoid the need to manually switch between the different viewpoints with the context menu, I would like the viewpoints to switch automatically with a Timer (each viewpoint staying for a few seconds). And I would like to not have to touch the mouse at all (nor the keyboard), so I would like to have the playback started as soon as the page appears.

I found the javascript command runtime.setView(N,x) to switch to the x'th view among N, but I don't know where to put it (I don't want to define a function which will be called when I press a button, since I want everything to be automated). Also, I don't know how to pause for a few seconds.

Any help ? Thanks !

I believe you're looking for setInterval(fn, time) which will call a function periodically at a time interval that you set. I'm not familiar with the setView() method you mentioned, but here's some pseudo code that you would put in tags at the end of the document body.

function startSwitcher()
    var viewNum = 0;
    var maxViews = 5;     // you set this to how many views there are
    setInterval(function()  {
        ++viewNum;
        if (viewNum >= maxViews) {
            viewNum = 0;
        }
        runtime.setView(N, viewNum);     // you will have to figure out this line 
    }, 2000);
}

startSwitcher();

The 2000 is 2000 milliseconds and is the time interval between executing the function. You can put any number of milliseconds there.

The runtime.setView(N, viewNum) line is something you will have to figure out as I am not familiar with whatever library you're trying to use there. The operative part of this code is the viewNum variable which configures which view in rotation should be next.

I think the runtime.SetView(..) Methods works with the name of the view as a string instead of the viewnumber. I have this function in a Dokument-level script and it works for me:

 // view is the name of the view for example "TopView" function setView(view){ console.println("Navigating to view: "+view); var pageIndex = this.pageNum; var annotIndex = 0; var c3d = this.getAnnots3D( pageIndex )[ annotIndex ].context3D; c3d.runtime.setView(view, true); } 

Combine this with the setInterval(..) from jfriend00´s answer und you should get what you need. Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM