Loading a png file as texture

Discussion in 'Modeling' started by lakehanne, Nov 15, 2017.

  1. Hi there,

    Thanks again f0r this great software.

    I am trying to load a png file as a skybox texture.

    The relevant portion of the code where I have this is

    ```xml
    <asset>
    <mesh name="body model"
    file="/home/lex/Documents/NNs/RadOncol/meshes/body_model.stl"
    scale="0.01 0.01 0.01"/>
    <!-- <texture type="skybox" builtin="gradient" width="128" height="128" rgb1=".4 .6 .8"
    rgb2="0 0 0"/> -->
    <texture name="texgeom" type="cube" builtin="flat" mark="cross" width="128" height="128"
    rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" markrgb="1 1 1" random="0.01"/>
    <texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2"
    width="512" height="512"/>
    <texture type="skybox" builtin="none" file="/home/lex/Documents/NNs/RadOncol/meshes/cyberknife.png"
    width="960" height="540" rgb1="0.4 0.6, 0.7" rgb2="0.6 0.85 0.85" mark="random" random="0.7"/>

    <material name='MatPlane' reflectance='0.3' texture="texplane" texrepeat="1 1" texuniform="true"/>
    <material name='geom' texture="texgeom" texuniform="true"/>
    </asset>

    ```

    However, it keeps asking that the image size be an integer multiple of the height of the grid:

    ```bash
    \Error: PNG size must be integer multiple of gridsize in texture '/home/lex/Documents/NNs/RadOncol/meshes/cyberknife.png' (id 2)
    Object name = cyberknife, id = 2, line = 31, column = 9
    ```

    I have made the width and height fields of the png file exactly and double the size of the png file to no avail. What am I possibly missing?
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    lakehanne likes this.
  3. Thanks. I have the image in square form now. How can I have the same image repeated 6 times in the asset field?

    All I did was

    ```xml
    <asset>
    <texture type="skybox" builtin="none" file="/home/lex/Documents/NNs/RadOncol/beam_optim/meshes/cyberknife.png"
    rgb1="1 1 1" rgb2=".6 .8 1" />
    </asset>
    ```

    Yet I still have the same error: Error: PNG size must be integer multiple of gridsize in texture '/home/lex/Documents/NNs/RadOncol/beam_optim/meshes/cyberknife.png' (id 0)
    Object name = cyberknife, id = 0, line = 11, column = 9. The thing is the grid size is not defined in any of the examples. How do we know the gridsize of cube or skybox?
     
  4. Emo Todorov

    Emo Todorov Administrator Staff Member

    The gridsize defaults to "1 1" but you could set it explicitly to be sure.

    You can load 6 different files with the attributes fileleft, fileright, etc. See documentation.

    Not quite sure why you are getting this error. Are you certain your texture is square?
     
  5. You mean my texture file size? I know for sure it is square, 600 x 600 pixels exactly.
     
  6. Emo Todorov

    Emo Todorov Administrator Staff Member

    Can you send me your model and texture file so I can try it?
     
  7. Sure.

    It is attached below. The failure occurs on line 45.

    Commenting out the line, the code should run just fine.

    You may have to amend the file directory location when testing on your own computer.
     

    Attached Files:

  8. Emo Todorov

    Emo Todorov Administrator Staff Member

    Your image is 600 x 400. You have to edit the PNG so that it is square. Then, you can load it in the model with:

    <texture type="skybox" file="cyberknife.png"/>

    The remaining attributes are not needed in this case. Setting the width and height in the XML is not the way to do it. You have to change the PNG itself.
     

    Attached Files:

  9. Thanks! Can you please send me the rescaled image?

    I used imagemagick to rescale the png file to 600x600 but it seems it's not quite what it's meant to be.
     
  10. Emo Todorov

    Emo Todorov Administrator Staff Member

    I scaled it in Windows Paint, but it doesn't look good because of the stretching. You should crop it instead of scaling it -- just find some software that does cropping.
     
    lakehanne likes this.