EihiS

June 26, 2014

Blender 2.69 python script for vertex,normals, and UV coords export

Filed under: Raspberry 3.14, linux — Tags: , , , , , , — admin @ 11:36 am

A simple script that can be run from a ‘text’ window in blender 2.69.
This a raw script,up to you to get what’s useful from it.

Obviously ,the script assumes the mesh is called ‘Cube’.
It writes to the file each vertices composing a face of the mesh, with each vertice’s normal and each face’s normal plus the face’s vertices group number + the face’s material number.
a face’s description is 3 lines, with the start char beein ‘A’,'B’ or ‘C’, corresponding to the 3 vertices of the face.

If a vertex is in multiple groups, the script takes the first group’s number for that vertex.
Groups and Materials output are Numbers, from 0…n , directly linked to the Material or Group’s blender - SLOT , whatever the name is.
Vertices are treated as individual (the real vertices coords are used , assuming the user’s program wich will use this output file will make it’s own ‘indexing’ of vertices wich have same coords  in common )
Finally, faces have to be triangulated :the script outputs only the 3 first vertices of a meshe’s face .

Hope this helps!

#!BPY

import bpy

cubedata = bpy.data.meshes['Cube']
v=cubedata.vertices
f=cubedata.polygons
print("\n\n-------------------------------------\n\n")
out = open("/home/path_to_your_dir/custom_output.txt", "w")
idx=0
for f in cubedata.polygons :
    # FACES MUST BE TRIANGULATED
    g=cubedata.vertices[f.vertices[0]]
    uvx=0
    uvy=0
    if cubedata.uv_layers.active!=None:
        uvx=cubedata.uv_layers.active.data[idx].uv.x
        uvy=cubedata.uv_layers.active.data[idx].uv.y
    else:
        print("UV error,face vertex[0]\n")
    out.write("A=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    print("A=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    g=cubedata.vertices[f.vertices[1]]
    uvx=0
    uvy=0
    if cubedata.uv_layers.active!=None:
        uvx=cubedata.uv_layers.active.data[idx+1].uv.x
        uvy=cubedata.uv_layers.active.data[idx+1].uv.y
    else:
        print("UV error,face vertex[1]\n")  
    out.write("B=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    print("B=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    g=cubedata.vertices[f.vertices[2]]
    uvx=0
    uvy=0
    if cubedata.uv_layers.active!=None:
        uvx=cubedata.uv_layers.active.data[idx+2].uv.x
        uvy=cubedata.uv_layers.active.data[idx+2].uv.y
    else:
        print("UV error,face vertex[2]\n")
    out.write("C=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    print("C=%3.3f %3.3f %3.3f VN=%2.5f %2.5f %2.5f FN=%2.5f %2.5f %2.5f G=%u M=%u U=%2.5f V=%2.5f\n" % (g.co.x,g.co.y,g.co.z,g.normal.x,g.normal.y,g.normal.z,f.normal[0],f.normal[1],f.normal[2],g.groups[0].group,f.material_index,uvx,uvy))
    #
    idx=idx+3
    #   
out.close()

The output file (ascii) will look like :

A=0.351 -0.679 0.733 VN=0.93976 -0.23081 0.25208 FN=0.88620 -0.21390 0.41097 G=0 M=9 U=0.74219 V=0.25781
B=0.349 -0.221 0.975 VN=0.93954 -0.07318 0.33445 FN=0.88620 -0.21390 0.41097 G=0 M=9 U=0.74219 V=0.50000
C=0.249 -0.311 1.144 VN=0.41011 0.22208 0.88455 FN=0.88620 -0.21390 0.41097 G=0 M=9 U=0.74219 V=0.50000
A=0.245 1.119 -0.397 VN=0.41014 0.89917 0.15235 FN=-0.00437 0.84659 -0.53222 G=0 M=0 U=0.50781 V=0.49219
B=0.246 0.843 -0.835 VN=0.41194 0.25422 -0.87500 FN=-0.00437 0.84659 -0.53222 G=0 M=0 U=0.50781 V=0.74219
C=-0.251 1.116 -0.397 VN=-0.41353 0.89776 0.15146 FN=-0.00437 0.84659 -0.53222 G=0 M=0 U=0.25781 V=0.49219
A=-0.345 -0.957 0.295 VN=-0.93915 -0.32841 0.10056 FN=-0.00010 0.03756 0.99929 G=0 M=9 U=0.00000 V=1.00000
B=-0.245 -1.148 0.302 VN=-0.41090 -0.65740 0.63161 FN=-0.00010 0.03756 0.99929 G=0 M=9 U=0.00000 V=1.00000
C=0.251 -1.146 0.302 VN=0.41246 -0.65545 0.63262 FN=-0.00010 0.03756 0.99929 G=0 M=9 U=0.25781 V=1.00000
A=0.352 -0.954 0.295 VN=0.93982 -0.32621 0.10154 FN=0.88526 -0.46476 0.01753 G=0 M=9 U=0.25781 V=1.00000
B=0.251 -1.146 0.302 VN=0.41246 -0.65545 0.63262 FN=0.88526 -0.46476 0.01753 G=0 M=9 U=0.25781 V=1.00000
C=0.251 -1.165 -0.215 VN=0.41252 -0.70116 -0.58150 FN=0.88526 -0.46476 0.01753 G=0 M=9 U=0.25781 V=0.75000
A=0.247 0.216 -1.166 VN=0.41008 0.58296 -0.70138 FN=0.00010 -0.03762 -0.99929 G=0 M=0 U=1.00781 V=0.75781
314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

Linux : Reading the Mouse events datas from /dev/input/mouse0

Filed under: Raspberry 3.14, linux — Tags: , , , — admin @ 8:53 am

A simple program to check the /dev/input/mouse0 datas

Tested on the raspberry PI with GPM installed

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>

#define MOUSEFILE "/dev/input/mouse0"
//
int main()
{
    int fd;
    struct input_event ie;
    //
    unsigned char button,bLeft,bMiddle,bRight;
    char x,y;
    int absolute_x,absolute_y;

    if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
        printf("Device open ERROR\n");
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("Device open OK\n");
    }
    //
    printf("right-click to set absolute x,y coordinates origin (0,0)\n");
    while(read(fd, &ie, sizeof(struct input_event)))
    {
        unsigned char *ptr = (unsigned char*)&ie;
        int i;       
        //
        button=ptr[0];
        bLeft = button & 0x1;
        bMiddle = ( button & 0x4 ) > 0;
        bRight = ( button & 0x2 ) > 0;
        x=(char) ptr[1];y=(char) ptr[2];
        printf("bLEFT:%d, bMIDDLE: %d, bRIGHT: %d, rx: %d  ry=%d\n",bLeft,bMiddle,bRight, x,y);
        //
        absolute_x+=x;
        absolute_y-=y;
        if (bRight==1)
        {
            absolute_x=0;
            absolute_y=0;
            printf("Absolute x,y coords origin recorded\n");
        }
        //
        printf("Absolute coords from TOP_LEFT= %i %i\n",absolute_x,absolute_y);
        //
        // comment to disable the display of raw event structure datas
        //
        for(i=0; i<sizeof(ie); i++)
        {
            printf("%02X ", *ptr++);
        }
        printf("\n");
    }

return 0;
}

The read() command is blocking for now.
The following C code does almost the same thing, with non-blocking option enabled this time:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>

#define MOUSEFILE "/dev/input/mouse0\0"
//
int main()
{
    int fd;
    struct input_event ie;
    unsigned char *ptr = (unsigned char*)&ie;
    //
    unsigned char button,bLeft,bMiddle,bRight;
    char x,y;                                                            // the relX , relY datas
    int absolute_x,absolute_y;

    if((fd = open(MOUSEFILE, O_RDONLY | O_NONBLOCK )) == -1)
    {
        printf("NonBlocking %s open ERROR\n",MOUSEFILE);
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("NonBlocking %s open OK\n",MOUSEFILE);
    }
    //
    printf("--------------------------------------------------------\n");
    printf("right-click to set absolute x,y coordinates origin (0,0)\n");
    printf("left+right click to EXIT\n");
    printf("--------------------------------------------------------\n");
    //
    while(1)
    {       
        if(read(fd, &ie, sizeof(struct input_event))!=-1)
        {
            //
            button=ptr[0];
            bLeft = button & 0x1;
            bMiddle = ( button & 0x4 ) > 0;
            bRight = ( button & 0x2 ) > 0;
            x=(char) ptr[1];y=(char) ptr[2];
            if(bLeft&bRight) { printf("\nright+left ,EXIT\n");break;}
            // computes absolute x,y coordinates
            absolute_x+=x;
            absolute_y-=y;
            // set absolute reference ?
            if (bRight==1)
            {
                absolute_x=0;
                absolute_y=0;
                printf("Absolute x,y coords origin recorded\n");
            }
            // show it!
            printf("X%i Y%i\n",absolute_x,absolute_y);
            fflush(stdout);
        }
    }
    //
    close(fd);
return 0;
}
314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

June 13, 2014

Pi 3D reference files ( GLSL language, example shaders )

Filed under: Raspberry 3.14 — Tags: , , , , — admin @ 8:39 am

The files listed here are hosted on eihis.com’s website.
Reference for openGL ES 2.0 shader language aka ‘GLSL’ on the raspberry PI :

GL_shader_language_specifications_1-0-17 ( language specifications for OPENGL ES 2.0  )

Using this specifications, the ‘vertex’ and ‘fragment’ shader programs starts with preprocessor directive:

#version 100

Example vertex shader program using this specification’s syntax and types :

#version 100
attribute vec4 vPosition;
uniform mat4 viewMatrix, projMatrix,modelMatrix;
varying vec4 tcoord;
varying vec4 my_norm;
uniform float Scale;
void main(void)
{
lowp vec4 my_vector,my_test;
my_test=vPosition;
/* */
gl_Position = projMatrix * viewMatrix * modelMatrix * vPosition ;
my_vector=modelMatrix * vPosition;
my_norm=normalize(my_vector);
tcoord.x=my_norm.x;
tcoord.y=0.5;
tcoord.z=Scale;
}

Example fragment shader program, to be linked with the vertex’s one :

#version 100
precision mediump float;
varying vec4 tcoord;
/*out vec4 vOUTFragColor;*/
void main()
{
gl_FragColor = vec4(tcoord.x, tcoord.y , tcoord.z, 1.0);
}

Raspberry PI OpenGL es extensions :

GL_EXT_blend_minmax
GL_EXT_multi_draw_arrays
GL_EXT_texture_format_BGRA8888
GL_OES_compressed_ETC1_RGB8_texture
GL_OES_depth24
GL_OES_element_index_uint
GL_OES_fbo_render_mipmap
GL_OES_mapbuffer
GL_OES_rgb8_rgba8
GL_OES_standard_derivatives
GL_OES_stencil8
GL_OES_texture_3D
GL_OES_texture_npot
GL_OES_EGL_image
GL_OES_depth_texture
GL_OES_packed_depth_stencil
GL_EXT_texture_type_2_10_10_10_REV
GL_OES_get_program_binary
GL_APPLE_texture_max_level
GL_EXT_discard_framebuffer
GL_EXT_read_format_bgra
GL_NV_fbo_color_attachments
GL_OES_EGL_image_external
GL_OES_vertex_array_object
GL_EXT_texture_rg
GL_EXT_unpack_subimage
GL_NV_draw_buffers
GL_NV_read_buffer
GL_EXT_map_buffer_range
GL_OES_depth_texture_cube_map
GL_OES_surfaceless_context
GL_EXT_color_buffer_float

OpenGL ES 2.0 is very close to the CORE profile of OpenGL.
Forget about all built-in commands of the COMPATIBILITY profiles…

The Quick reference card for OPENGL ES 2.0 is here :  opengl-es-2_0-reference-card

You can also check this usefull link(s) :
http://en.wikibooks.org/wiki/GLSL_Programming/Vector_and_Matrix_Operations

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

January 6, 2014

Installing a brother MFC8880DN network printer on the PI

Filed under: Raspberry 3.14 — Tags: , , , — admin @ 1:15 pm

After installing the CUPS utilities :

sudo apt-get install cups

.. drink 5 coffees…

then  update Pi as a regular user of lpadmin group :

sudo usermod -a -G lpadmin pi

then access to the cups admin page, at localhost:631

adding the MFC8880DN printer was achieved, specifiyng LDP printer, with the lpd://IPofTheMachine/BINARY_P1

For successfull printing and status updates in the cups jobqueue, i had to use ‘MFC-8300 - CUPS + Gutenprint v5.2.9′ device , instead of the proposed ‘MFC8880DN postscript’  in the Brother device listings..

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808
« Newer PostsOlder Posts »

cat{ } { post_489 } { } 2009-2015 EIhIS Powered by WordPress