如何在Vizard Python中绘制10,000多个对象并移动它们并获得60fps +

时间:2013-05-09 14:52:01

标签: python object optimization graphics vizard

我正在尝试在Vizard 4.0中创建一个自动生成10,000多个对象的世界。一旦制作了这些物体,我想飞过它们或让它们以我想要的任何方向以一定的速度移动。

我已为此编写代码,但它没有给我我想要的fps。目前我只使用此代码获得大约7fps,我需要最多达到60fps。我试过移动它们并移动相机。但两者都给出了相同的fps。我已经写出了移动的部分,球只是在一个方向上自己移动,并且为了使相机移动,您需要按住鼠标左键或鼠标右键或两者。

要运行此程序,首先需要从worldviz安装Vizard。它提供90天免费试用。我对Vizard相当新,所以任何帮助都会非常感激。谢谢

以下代码:

enter code here

import viz
import vizact
import vizshape
import random
import vizinfo
import viztask


#Enable full screen anti-aliasing (FSAA) to smooth edges
viz.setMultiSample(4)

#Start World
viz.go(viz.FULLSCREEN)


#Increase the Field of View
viz.MainWindow.fov(60)

#Set my location 8 meters back from 0,0,0
viz.move([0,0,-8])


def Create_Shape(Number,x_pace,y_pace,z_pace,set_Time) :
    #create an array of shapes
    shapes = []
    #Generate Shapes
    for i in range(Number):
        #Generate random values for position and orientation
        x = random.randint(-100,100)
        y = random.randint(-100,100)
        z = random.randint(-100,100)

        #generate shapes

        shape = vizshape.addSphere()
        #shape.setScale(0.25,0.25,0.25)
        shape.setPosition([x,y,z])
    shapes.append(shape)

    #Move shapes
    move = vizact.move(x_pace,y_pace,z_pace,set_Time)
    #Loop through all shapes and move them
    for shape in shapes:
        shape.addAction(move)
        #return shapes
        return shapes

#Calls create shape with the number of shapes needed to be made and
#the speed and time for the shapes to move at
Create_Shape(10000,0,0,10,10000000)

1 个答案:

答案 0 :(得分:0)

很久以前,当我在Vizard上工作时,我记得加载它们,因为实例会表现得更好,内存和速度明智,不幸的是我不记得语法,但它是这样的事情

shape = vizshape.addSphere(x) // where x is a flag for loading as instance, cant recall it well :)