简体   繁体   English

带有JavaScript的pdf 3d:简单示例

[英]pdf 3d with JavaScript : simple example

I need to do a simple pdf with some 3D objects for an oral presentation. 我需要对一些3D对象进行简单的pdf口头介绍。 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). 我发现javascript命令runtime.setView(N,x)切换到N中的第x个视图,但是我不知道将其放置在哪里(我不想定义一个在我调用时会被调用的函数按下一个按钮,因为我希望一切都自动化)。 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. 我相信您正在寻找setInterval(fn, time) ,它将以您设置的时间间隔定期调用一个函数。 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. 我不熟悉您提到的setView()方法,但是这里有一些伪代码,您可以将它们放在文档正文末尾的标记中。

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. 2000是2000毫秒,是执行该功能之间的时间间隔。 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. 您必须runtime.setView(N, viewNum)行,因为我对在此使用的任何库都不熟悉。 The operative part of this code is the viewNum variable which configures which view in rotation should be next. 该代码的执行部分是viewNum变量,该变量配置下一个旋转视图。

I think the runtime.SetView(..) Methods works with the name of the view as a string instead of the viewnumber. 我认为runtime.SetView(..)方法将视图名称作为字符串而不是视图编号。 I have this function in a Dokument-level script and it works for me: 我在Dokument级别的脚本中具有此功能,并且对我有用:

 // 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. 将此与jfriend00的答案中的setInterval(..)结合使用,您将得到所需的东西。 Best regards 最好的祝福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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