Show Image from colorComponentData

Show Image from colorComponentData

marc.winter2
Advocate Advocate
711 Views
8 Replies
Message 1 of 9

Show Image from colorComponentData

marc.winter2
Advocate
Advocate

Hi,

 

i need to create a QIMage or QPixmap from the pixel intArray of the image in (for example) the diffuseComponent.

Im not sure how to choose the QImage.Format or the ByteperLine Parameter. Or maybe im doing something other wrong?

 

 

tempMaterial = vrMaterialEditor.getSelectedMaterials()[0]
tempColorComponentData = vrFieldAccess(tempMaterial.fields().getFieldContainer('colorComponentData'))
tempColorComponent = vrFieldAccess(tempColorComponentData.getFieldContainer('displacementComponent'))
tempImage = vrFieldAccess(tempColorComponent.getFieldContainer('image'))
tempPixel = tempImage.getMUInt8('pixel')
tempWidth = tempImage.getInt32('width')
tempHeight = tempImage.getInt32('height')
tempBpp = tempImage.getInt32('bpp')

tempBytes = bytes(tempPixel)
tempImg = QtGui.QImage(tempBytes, tempWidth, tempHeight, tempWidth*tempBpp, QtGui.QImage.Format_RGB16)
print(tempImg.save(r'd:\aaa.png'))

 

 

marcwinter2_0-1718094041391.png

 

 

The image still not looks like as expected:

aaa.png

 

Best regards,

Marc

0 Likes
Accepted solutions (1)
712 Views
8 Replies
Replies (8)
Message 2 of 9

marc.winter2
Advocate
Advocate

No idea anyone? 🙄

0 Likes
Message 3 of 9

michael_nikelsky
Autodesk
Autodesk

In the new Python API the vrdImage has a function toQImage that should give you a QImage, I strongly recommend to use that function instead of trying to do the conversion yourself.

 

If you need to do this manually you will need to check the datatype and in combination with the bpp and pixel format  so you can actually derive the proper format for the QImage from it. And you will have to flip the image upside down since QImage uses a top-left origin while we use a bottom-left origin.



Michael Nikelsky
Sr. Principal Engineer
0 Likes
Message 4 of 9

marc.winter2
Advocate
Advocate

Hi Michael,

 

yes i know it in API V2, but i need to show textures (first displacement) from substanceMaterials.

Do you have further Information on datatype, bpp and pixelFormat?

Thank you

 

Best regards,

Marc

0 Likes
Message 5 of 9

marc.winter2
Advocate
Advocate

API V2 solution

 

def getSubstancePropertyValue(_substanceMaterial, _propName):
    tempObject = QtCore.QObject()
    _substanceMaterial.getProperties().update(tempObject, 0)
    for tempPropName in tempObject.dynamicPropertyNames():
        tempPropName = bytes(tempPropName).decode()
        if tempPropName.startswith('__vred_'):
            tempPropValue = tempObject.property(tempPropName)
            tempPropName = tempPropName[len('__vred_'):]
            if tempPropName == _propName:
                return tempPropValue
    return None

tempQImage = getSubstancePropertyValue(vrMaterialService.getMaterialSelection()[0], 'displacementTexture').getImage().toQImage()
print(tempQImage.save(r'd:\aaa.jpg'))

 😄

0 Likes
Message 6 of 9

sinje_thiedemann
Autodesk
Autodesk

Hi Marc,

in case you simply want to view the textures in VRED (as your thread title says "Show Image.."), you can do that in the UV Editor. Select an object with the material assigned and in UV Editor enable "Show Texture" (and select which one), and disable "Show Wireframe" (and Grid) to be able to see the texture.

0 Likes
Message 7 of 9

marc.winter2
Advocate
Advocate

Hi Sinje,

 

yes i'm aware of the uvEditor. But i need the images in my own ui, prepared for non expert users.

It started with the displacement but now i need also the other textures, but besides bumpTexture and displacementTexture i found nothing useable:

__vred_objectId "31271"

__vred_graphs "0"

__vred_resetGraph "False"

__vred_syncOutputSize "True"

__vred_textureSettings "<vrKernelServices.vrdTexture object at 0x0000015FE8279F00>"

__vred_common "<vrKernelServices.vrdBRDFCommonSettings object at 0x0000015FE81CB4C0>"

__vred_raytracing "<vrKernelServices.vrdMaterialRaytracingSettings object at 0x0000015FE81CB1C0>"

__vred_roundedEdges "<vrKernelServices.vrdRoundedEdges object at 0x0000015FE81CB4C0>"

__vred_bumpTexture "<vrKernelServices.vrdBumpTexture object at 0x0000015FE81CB1C0>"

__vred_displacementTexture "<vrKernelServices.vrdDisplacementTexture object at 0x0000015FE81CB4C0>"

 

__vred_textureSettings has an empty image.

I can't find diffuse-, roughness-, metallic- and ao-Textures. Am i missing something?

 

P.S. with vrdSVBRDFMaterials i have similar problems 😞

 

Many thanks in advance

Best regards,

Marc

0 Likes
Message 8 of 9

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

Hi Marc,

no, you're not missing anything, the mentioned textures from Substance and SVBRDF are currently not part of the API v2 classes.

So I think the only way right now is to get the images via vrFieldAccess.
I found we have vrObjectService.getSceneObjectFromId(id) where you can pass an vrFieldAccess(image).getID() from API v1 and get a vrd object back. This function is exposed since some versions but undocumented so please use at the risk of it being renamed or removed in the future.
A (not so nice) alternative to this function would be to set the image to the diffuse component of a helper plastic material with field access and get the vrdImage from that via API v2...

0 Likes
Message 9 of 9

marc.winter2
Advocate
Advocate
Hi Sinje,
sorry for taking that long for the answer. That's it. Very nice!!! Thank you very much.
Best regards,
Marc
0 Likes