Example #1
0
	def initialize(self, shader):
		# Retrieve and cache the actual node pointer
		if not shader.isNull():
			self.fShaderNode = omui.MPxHwShaderNode.getHwShaderNode(shader)

		# Set position requirement
		reqName = ""
		self.addGeometryRequirement(omr.MVertexBufferDescriptor(reqName, omr.MGeometry.kPosition, omr.MGeometry.kFloat, 3))

		# Set correct color requirement
		if self.fShaderNode is not None:
			reqName = self.fShaderNode.colorSetName()
		self.addGeometryRequirement(omr.MVertexBufferDescriptor(reqName, omr.MGeometry.kColor, omr.MGeometry.kFloat, 4))

		return "Autodesk Maya hwColorPerVertexShader"
Example #2
0
    def initBuffers(self):
        global soleCount, sole
        global heelCount, heel

        if self.mBoundingboxVertexBuffer is None:
            count = 8
            rawData = [[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5],
                       [-0.5, -0.5, 0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5],
                       [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]]

            desc = omr.MVertexBufferDescriptor("", omr.MGeometry.kPosition,
                                               omr.MGeometry.kFloat, 3)
            self.mBoundingboxVertexBuffer = omr.MVertexBuffer(desc)

            dataAddress = self.mBoundingboxVertexBuffer.acquire(count, True)
            data = ((ctypes.c_float * 3) * count).from_address(dataAddress)

            for i in range(count):
                data[i][0] = rawData[i][0]
                data[i][1] = rawData[i][1]
                data[i][2] = rawData[i][2]

            self.mBoundingboxVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mBoundingboxIndexBuffer is None:
            count = 24
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2,
                6, 3, 7
            ]

            self.mBoundingboxIndexBuffer = omr.MIndexBuffer(
                omr.MGeometry.kUnsignedInt32)

            dataAddress = self.mBoundingboxIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mBoundingboxIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleVertexBuffer is None:
            desc = omr.MVertexBufferDescriptor("", omr.MGeometry.kPosition,
                                               omr.MGeometry.kFloat, 3)
            self.mSoleVertexBuffer = omr.MVertexBuffer(desc)

            dataAddress = self.mSoleVertexBuffer.acquire(soleCount, True)
            data = ((ctypes.c_float * 3) * soleCount).from_address(dataAddress)

            for i in range(soleCount):
                data[i][0] = sole[i][0]
                data[i][1] = sole[i][1]
                data[i][2] = sole[i][2]

            self.mSoleVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelVertexBuffer is None:
            desc = omr.MVertexBufferDescriptor("", omr.MGeometry.kPosition,
                                               omr.MGeometry.kFloat, 3)
            self.mHeelVertexBuffer = omr.MVertexBuffer(desc)

            dataAddress = self.mHeelVertexBuffer.acquire(heelCount, True)
            data = ((ctypes.c_float * 3) * heelCount).from_address(dataAddress)

            for i in range(heelCount):
                data[i][0] = heel[i][0]
                data[i][1] = heel[i][1]
                data[i][2] = heel[i][2]

            self.mHeelVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleWireIndexBuffer is None:
            count = 2 * (soleCount - 1)
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
                10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
                18, 19, 19, 20
            ]

            self.mSoleWireIndexBuffer = omr.MIndexBuffer(
                omr.MGeometry.kUnsignedInt32)

            dataAddress = self.mSoleWireIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mSoleWireIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelWireIndexBuffer is None:
            count = 2 * (heelCount - 1)
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
                10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16
            ]

            self.mHeelWireIndexBuffer = omr.MIndexBuffer(
                omr.MGeometry.kUnsignedInt32)

            dataAddress = self.mHeelWireIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mHeelWireIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleShadedIndexBuffer is None:
            count = 3 * (soleCount - 2)
            rawData = [
                0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8,
                0, 8, 9, 0, 9, 10, 0, 10, 11, 0, 11, 12, 0, 12, 13, 0, 13, 14,
                0, 14, 15, 0, 15, 16, 0, 16, 17, 0, 17, 18, 0, 18, 19, 0, 19,
                20
            ]

            self.mSoleShadedIndexBuffer = omr.MIndexBuffer(
                omr.MGeometry.kUnsignedInt32)

            dataAddress = self.mSoleShadedIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mSoleShadedIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelShadedIndexBuffer is None:
            count = 3 * (heelCount - 2)
            rawData = [
                0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8,
                0, 8, 9, 0, 9, 10, 0, 10, 11, 0, 11, 12, 0, 12, 13, 0, 13, 14,
                0, 14, 15, 0, 15, 16
            ]

            self.mHeelShadedIndexBuffer = omr.MIndexBuffer(
                omr.MGeometry.kUnsignedInt32)

            dataAddress = self.mHeelShadedIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mHeelShadedIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        return True
Example #3
0
    def initBuffers(self):
        global soleCount, sole
        global heelCount, heel

        #EXPLANATION: VERTEX BUFFERS and INDEX BUFFERS Maya API:
        # https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2018/ENU/Maya-SDK/files/GUID-148A1EF1-B350-416F-A800-C47DA90D1369-htm.html
        if self.mBoundingBoxVertexBuffer is None:
            count = 8
            rawData = [[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5],
                       [-0.5, -0.5, 0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5],
                       [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]]

            desc = OpenMayaRender.MVertexBufferDescriptor(
                '', OpenMayaRender.MGeometry.kPosition,
                OpenMayaRender.MGeometry.kFloat, 3)
            self.mBoundingBoxVertexBuffer = OpenMayaRender.MVertexBuffer(desc)

            dataAddress = self.mBoundingBoxVertexBuffer.acquire(count, True)
            # is a foreign function library for Python.
            # It provides C compatible data types, and allows calling functions in DLLs or shared libraries.
            # It can be used to wrap these libraries in pure Python.
            data = ((ctypes.c_float * 3) * count).from_address(dataAddress)

            for i in range(count):
                data[i][0] = rawData[i][0]
                data[i][1] = rawData[i][1]
                data[i][2] = rawData[i][2]

            self.mBoundingBoxVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mBoundingBoxIndexBuffer is None:
            count = 24
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2,
                6, 3, 7
            ]

            # buffers EXPLANATION // explain better rawData // raw data is an indexBuffer
            # here we get a space in memory and the fill it with C Data types
            # https://vulkan-tutorial.com/Vertex_buffers/Index_buffer  <-- indexBuffer EXPLANATION

            # the indices need to be uploaded to ha vkBuffer for the GPU be able to them
            # MIndexBuffer represents an index buffer with a specific data. usable with MGeometry
            self.mBoundingBoxIndexBuffer = OpenMayaRender.MIndexBuffer(
                OpenMayaRender.MGeometry.kUnsignedInt32)

            # acquire() may be called to get a pointer to a block of memory to fill with said data.
            # args: size of the buffer(int) // writeOnly (bool)

            # Once filled, commit() must be called to apply the data to the buffer.
            dataAddress = self.mBoundingBoxIndexBuffer.acquire(count, True)
            # ctypes provides C compatible data types, and allows calling functions in DLLs or shared libraries.
            # It can be used to wrap these libraries in pure Python.

            # http://pyplusplus.readthedocs.io/en/latest/tutorials/functions/transformation/from_address.html  <-- from_address EXPLANATION
            # unsigned_int * count -> [c_uint][c_uint]... count times
            # from_address you can use ctypes package to create the data and than pass it to
            # the Boost.Python exposed function, in this case dataAddress
            data = (ctypes.c_uint * count).from_address(dataAddress)

            # fill our buffer
            for i in range(count):
                data[i] = rawData[i]

            # here is the commit(), once we filled dataAddress with c types through .from_address from data.
            # Commit the data stored in the memory given by acquire() to the buffer.
            self.mBoundingBoxIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleVertexBuffer is None:
            desc = OpenMayaRender.MVertexBufferDescriptor(
                '', OpenMayaRender.MGeometry.kPosition,
                OpenMayaRender.MGeometry.kFloat, 3)
            self.mSoleVertexBuffer = OpenMayaRender.MVertexBuffer(desc)

            dataAddress = self.mSoleVertexBuffer.acquire(soleCount, True)
            data = ((ctypes.c_float * 3) * soleCount).from_address(dataAddress)

            for i in range(soleCount):
                data[i][0] = sole[i][0]
                data[i][1] = sole[i][1]
                data[i][2] = sole[i][2]

            self.mSoleVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelVertexBuffer is None:
            desc = OpenMayaRender.MVertexBufferDescriptor(
                '', OpenMayaRender.MGeometry.kPosition,
                OpenMayaRender.MGeometry.kFloat, 3)
            self.mHeelVertexBuffer = OpenMayaRender.MVertexBuffer(desc)

            dataAddress = self.mHeelVertexBuffer.acquire(heelCount, True)
            data = ((ctypes.c_float * 3) * heelCount).from_address(dataAddress)

            for i in range(heelCount):
                data[i][0] = heel[i][0]
                data[i][1] = heel[i][1]
                data[i][2] = heel[i][2]

            self.mHeelVertexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleWireIndexBuffer is None:
            count = 2 * (soleCount - 1)
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
                10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
                18, 19, 19, 20
            ]

            self.mSoleWireIndexBuffer = OpenMayaRender.MIndexBuffer(
                OpenMayaRender.MGeometry.kUnsignedInt32)

            dataAddress = self.mSoleWireIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mSoleWireIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelWireIndexBuffer is None:
            count = 2 * (heelCount - 1)
            rawData = [
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
                10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16
            ]
            self.mHeelWireIndexBuffer = OpenMayaRender.MIndexBuffer(
                OpenMayaRender.MGeometry.kUnsignedInt32)

            dataAddress = self.mHeelWireIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mHeelWireIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mSoleShadedIndexBuffer is None:
            count = 3 * (soleCount - 2)
            rawData = [
                0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8,
                0, 8, 9, 0, 9, 10, 0, 10, 11, 0, 11, 12, 0, 12, 13, 0, 13, 14,
                0, 14, 15, 0, 15, 16, 0, 16, 17, 0, 17, 18, 0, 18, 19, 0, 19,
                20
            ]

            self.mSoleShadedIndexBuffer = OpenMayaRender.MIndexBuffer(
                OpenMayaRender.MGeometry.kUnsignedInt32)

            dataAddress = self.mSoleShadedIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mSoleShadedIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        if self.mHeelShadedIndexBuffer is None:
            count = 3 * (heelCount - 2)
            rawData = [
                0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 7, 0, 7, 8,
                0, 8, 9, 0, 9, 10, 0, 10, 11, 0, 11, 12, 0, 12, 13, 0, 13, 14,
                0, 14, 15, 0, 15, 16
            ]

            self.mHeelShadedIndexBuffer = OpenMayaRender.MIndexBuffer(
                OpenMayaRender.MGeometry.kUnsignedInt32)

            dataAddress = self.mHeelShadedIndexBuffer.acquire(count, True)
            data = (ctypes.c_uint * count).from_address(dataAddress)

            for i in range(count):
                data[i] = rawData[i]

            self.mHeelShadedIndexBuffer.commit(dataAddress)
            dataAddress = None
            data = None

        return True