Beispiel #1
0
    def fromFbxNode(self, node):
        lMesh = node.GetNodeAttribute()
        print "load:", node.GetName()

        controlPointsCount = lMesh.GetControlPointsCount()
        controlPoints = lMesh.GetControlPoints()
        indexCount = lMesh.GetPolygonVertexCount()
        indexData = lMesh.GetPolygonVertices()
        leNormals = lMesh.GetLayer(0).GetNormals()

        self.readTextures(lMesh)

        print len(indexData), indexData
        self.vertexData = []
        for i in xrange(indexCount):
            index = indexData[i]
            position = controlPoints[index]
            normal = (0, 0, 0)
            if leNormals:
                if leNormals.GetMappingMode(
                ) == FbxLayerElement.eByPolygonVertex:
                    if leNormals.GetReferenceMode() == FbxLayerElement.eDirect:
                        normal = leNormals.GetDirectArray().GetAt(i)
            color = (1, 1, 1, 1)
            vertexDef = []
            for v in self.desc.vtdesc:
                if v[0] == 'POSITION':
                    vertexDef += list(position)
                elif v[0] == 'NORMAL':
                    vertexDef += list(normal)
                elif v[0] == 'COLOR':
                    vertexDef += list(color)
            self.vertexData.append(vertexDef)
            print index, normal
        self.indexData = [(int(i), ) for i in indexData]
        self.indexCount = indexCount

        self.indexBuffer = d3d11.Buffer(indexLayoutDesc32, self.indexData,
                                        BIND_INDEX_BUFFER, USAGE_IMMUTABLE)
        self.vertexBuffer = d3d11.Buffer(
            self.vertexDesc,
            self.vertexData,  # D3D11_SUBRESOURCE_DATA
            BIND_VERTEX_BUFFER,  # D3D11_BUFFER_DESC.BinadFlags
            USAGE_DYNAMIC,  # D3D11_BUFFER_DESC.Usage
            CPU_ACCESS_WRITE,  # D3D11_BUFFER_DESC.CPUAccessFlags
        )
Beispiel #2
0
    def build(self):
        super(CubeMarker, self).build()
        vertex_list, index_list = mesh_builder.build_cube(1.0)
        vertexData = []
        for v in vertex_list:
            vertexData.append((v[0], v[1], v[2], 1, 1, 1, 1))

        indexData = [(int(i), ) for i in index_list]
        self.indexBuffer = d3d11.Buffer(g_indexLayoutDesc32, indexData,
                                        BIND_INDEX_BUFFER, USAGE_IMMUTABLE)
        self.vertexBuffer = d3d11.Buffer(
            g_vertexDesc,
            vertexData,  # D3D11_SUBRESOURCE_DATA
            BIND_VERTEX_BUFFER,  # D3D11_BUFFER_DESC.BinadFlags
            USAGE_DYNAMIC,  # D3D11_BUFFER_DESC.Usage
            CPU_ACCESS_WRITE,  # D3D11_BUFFER_DESC.CPUAccessFlags
        )

        print len(self.indexBuffer)
Beispiel #3
0
    def build(self):
        effectName = self.effecName
        if not self.effecName:
            effectName = "marker.fx"
        effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
        self.effect = d3d11.Effect(effectPath)
        #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
        #the pass's input signature is compatible with that combination.
        self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)

        vertexData = []
        for i in xrange(self.gridx + 1):
            if i % 2 == 0:
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
            else:
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))

        for i in xrange(self.gridy + 1):
            if self.height % 2 == 0:
                if i % 2 == 0:
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
            else:
                if i % 2 == 0:
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))

        self.vertexBuffer = d3d11.Buffer(
            g_vertexDesc,
            vertexData,  # D3D11_SUBRESOURCE_DATA
            BIND_VERTEX_BUFFER,  # D3D11_BUFFER_DESC.BinadFlags
            USAGE_DYNAMIC,  # D3D11_BUFFER_DESC.Usage
            CPU_ACCESS_WRITE,  # D3D11_BUFFER_DESC.CPUAccessFlags
        )
    def __init__(self, parent, id, title, pos, size=(800, 600)):
        wx.Frame.__init__(self, parent, id, title, pos, size)

        self.mainpanel = wx.Panel(self, -1, size=(800, 600))
        self.mainpanel.SetAutoLayout(True)

        self.leftwindow = wx.Panel(self.mainpanel, -1, (10, 10), (380, 450))
        self.leftwindow.SetBackgroundColour(wx.WHITE)
        self.leftwindow.SetConstraints(
            anchors.LayoutAnchors(self.leftwindow, True, True, True, True))

        self.rightwindow = wx.Panel(self.mainpanel, -1, (400, 10), (380, 450))
        self.rightwindow.SetBackgroundColour(wx.WHITE)
        self.rightwindow.SetConstraints(
            anchors.LayoutAnchors(self.rightwindow, False, True, True, True))

        playvideo = wx.Button(self.mainpanel, -1,
                              "Play media on this window...", (500, 500))
        playvideo.SetConstraints(
            anchors.LayoutAnchors(playvideo, False, False, True, True))
        self.Bind(wx.EVT_BUTTON, self.playVideo, playvideo)

        #Create a DirectPython window from an existing wxPython window.
        tempWindow = d3d11.Window(handle=self.leftwindow.GetHandle())

        #Create our resources. Note that if the size of the window
        #changes, you should call self.device.reset().
        self.device = d3d11.Device(tempWindow, DRIVER_TYPE_WARP)
        self.effect = d3d11.Effect(
            d3d11x.getResourceDir("Effects", "Tutorial2.fx"))
        self.inputLayout = d3d11.InputLayout(vertexDesc, self.effect, 0, 0)
        self.vertexBuffer = d3d11.Buffer(vertexDesc, triangle,
                                         BIND_VERTEX_BUFFER)

        #We need to detach() the window. This means that it is up to
        #us (or wxPython) to mange the window from now on.
        tempWindow.detach()

        self.media = None

        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.Bind(wx.EVT_TIMER, self.onTimer)
        self.Bind(wx.EVT_IDLE, self.onIdle)
        self.leftwindow.Bind(wx.EVT_SIZE, self.onSize)

        #Use a timer for rendering. It is not a very smooth
        #solution, you might want to tweak the time interval
        #or do something else, now it is jerky.
        self.timer = wx.Timer(self)
        self.timer.Start(10)
Beispiel #5
0
    def load(self, res):
        self.res = res
        import resmgrdll
        import ResMgr
        print 'load primitive:', res
        noff = self.res.find('.primitives/')
        if noff < 0:
            raise Exception
        noff += 11
        fileName = self.res[:noff]
        tagName = self.res[noff + 1:]
        primFile = ResMgr.openSection(fileName)
        print 'open primitive', fileName
        if not primFile:
            raise Exception, 'load indices failed, %s' % fileName

        print 'read indices:', tagName
        indices = primFile.openSection(tagName)
        indices = indices.asBinary
        if indices:
            ih = IndexHeader()
            seg0 = 0
            seg1 = IndexHeader.SIZE
            print struct.calcsize(IndexHeader.FORMAT), IndexHeader.SIZE
            ih.indexFormat, ih.nIndices, ih.nTriangleGroups = struct.unpack(
                IndexHeader.FORMAT, indices[seg0:seg1])
            ih.indexFormat = ih.indexFormat.split('\0')[0]
            print ih.indexFormat, ih.nIndices, ih.nTriangleGroups

            if ih.indexFormat == 'list' or ih.indexFormat == 'list32':
                indexDesc = indexLayoutDesc16 if ih.indexFormat == 'list' else indexLayoutDesc32
                if ih.indexFormat == 'list32':
                    raise Exception, 'not considered index format:', ih.indexFormat
                self.primitiveType = PRIMITIVE_TOPOLOGY_TRIANGLELIST

                seg0, seg1 = seg1, seg1 + ih.nIndices * self.indexSize
                self.indices = struct.unpack('%dH' % ih.nIndices,
                                             indices[seg0:seg1])
                self.nIndices = ih.nIndices

                #create index buffer
                tmpindices = [(int(v), ) for v in self.indices]
                self.indexBuffer = d3d11.Buffer(indexLayoutDesc16, tmpindices,
                                                BIND_INDEX_BUFFER,
                                                USAGE_DYNAMIC,
                                                CPU_ACCESS_WRITE)
    def onCreate(self):
        self.renderTarget = None
        self.renderTargetView = None

        meshPath = d3d11x.getResourceDir("Mesh", "barrel.obj")
        self.mesh = d3d11x.Mesh(self.device, meshPath)
        self.mesh.textureView = self.loadTextureView("static-barrel.dds")

        self.skyBox = d3d11x.SkyBox(self.device)
        self.skyBox.textureView = self.loadTextureView("skybox-clear.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SamplePostProcess.fx")
        self.postEffect = d3d11.Effect(effectPath)
        self.postInputLayout = d3d11.InputLayout(vertexLayoutDesc,
                                                 self.postEffect, 0, 0)

        #Vertex buffer for 2D stuff.
        self.vertexBuffer = d3d11.Buffer(vertexLayoutDesc, 32,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)
    def onCreate(self):
        self.heightmap = d3d11x.HeightMap(self.device, None, (32, 32),
                                          heightFunc, (2, 1, 2), (10, 10),
                                          False)
        self.heightmap.textureView = self.loadTextureView("ground-marble.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SampleSprites.fx")
        self.spriteEffect = d3d11.Effect(effectPath)
        self.spriteInputLayout = d3d11.InputLayout(spriteLayoutDesc,
                                                   self.spriteEffect, 0, 0)
        self.spriteTexture = self.loadTextureView("misc-particle.dds")

        self.camera = d3d11x.Camera()

        #Create a dynamic vertex buffer for our sprites. Double the
        #size for shadow sprites.
        self.spriteBuffer = d3d11.Buffer(spriteLayoutDesc, POINT_COUNT * 2,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)

        self.points = []
Beispiel #8
0
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

vertices = []
for p in cdata.Box:
    vertices.append((p[0], p[1], p[2], 1, 1, 1, 1))

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "simple.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, vertices, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
        #Check all new messages.
        for msg in window.getMessages():
            if msg.code == WM_DESTROY:
                #Close the application.
                return

        #Set default render targets.
def createStagingBuffer(init, access):
    return d3d11.Buffer(layoutDesc, init, 0, USAGE_STAGING, access)
def createBufferAndView():
    buffer = d3d11.Buffer(layoutDesc, NUMITEMS,
                          BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE,
                          USAGE_DEFAULT, 0, RESOURCE_MISC_BUFFER_STRUCTURED)
    return buffer, d3d11.View(buffer)
Beispiel #11
0
#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1),  #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1),  #Green vertex.
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Tutorial2.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, triangle, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
        #Check all new messages.
        for msg in window.getMessages():
            if msg.code == WM_DESTROY:
                #Close the application.
                return

        #Set default render targets.