jersmi's picture

Possible with built-in nodes, at least in a basic way?

I imagine:

  1. Draw to the viewer with (for example) the mouse on the 2D plane like posted here
  2. Rotate the scene with a draggable camera (and/or animate rotation of a perspective camera, like here)
  3. Then (most importantly), draw to the current viewer 2D plane, rotate camera, keep drawing, rotate, etc.

(Pretty sure GeorgeToledo pursued this concept with some super interesting 3D sculpting stuff in QC (and for other devs?) as well. I suppose this is related to some of the VR/AR tools coming down the road, too.)

cwright made an awesome qtz called draw in space that does this, in response to this post at kineme.net. This was achieved with the following javascript:

var result = new Object();

function matrixMult(matrix, point)
{
    var temp = new Array();
    temp[0] = matrix[0][0] * point[0] + matrix[0][1] * point[1] + matrix[0][2] * point[2];
    temp[1] = matrix[1][0] * point[0] + matrix[1][1] * point[1] + matrix[1][2] * point[2];
    temp[2] = matrix[2][0] * point[0] + matrix[2][1] * point[1] + matrix[2][2] * point[2];
    point[0] = temp[0];
    point[1] = temp[1];
    point[2] = temp[2];
}

function transformPoint(point, xTheta, yTheta, zTheta)
{
    sinX = Math.sin(xTheta);
    cosX = Math.cos(xTheta);
    sinY = Math.sin(yTheta);
    cosY = Math.cos(yTheta);
    sinZ = Math.sin(zTheta);
    cosZ = Math.cos(zTheta);

    // todo:  do the math, and get this right
    //[[cosY*cosZ, cosX*-sinZ, sinY],
    //[sinX*sinY*cosZ+cosX*sinZ, sinX*sinY*-sinZ+cosX*cosZ, -sinX*cosY],
    //[cosX*-sinY*cosZ+sinX*sinZ, cosX*sinY*sinZ+sinX*cosZ, cosX*cosY]];
    var matrix;

    matrix =
        [[cosZ,-sinZ,0],
        [sinZ,cosZ,0],
        [0,0,1]];
    matrixMult(matrix, point);
    matrix =
        [[cosY,0,sinY],
        [0,1,0],
        [-sinY,0,cosY]];
    matrixMult(matrix, point);
    matrix = 
        [[1,0,0],
        [0,cosX,-sinX],
        [0,sinX,cosX]];
    matrixMult(matrix, point);
}

function (__structure points) main (__number inputX, __number inputY, __boolean draw, __boolean reset, __number xTheta, __number yTheta, __number zTheta)
{
    if(reset || result.points == undefined)
        result.points = new Array;
    if(draw)
    {
        var point = new Array;
        point[0] = inputX;
        point[1] = inputY;
        point[2] = 0;
        transformPoint(point, xTheta*Math.PI/180, yTheta*Math.PI/180, zTheta*Math.PI/180);
        result.points.push(point);
    }

    return result;
}

Moderator note: 

Adjusted formatting
, converted from Question to Discussion

Comments

Progress, still an unsolved

jersmi's picture
Submitted by

Progress, still an unsolved problem: the Draggable Camera stays active all the time, is there a way to disable it while drawing with the mouse?

In this comp I can draw to the 2D viewer plane, then I can drag the camera view, then I can draw again, but when I switch back to the camera again it jumps to the current transform value, because the camera is always active.

Ok, here's the first success.

jersmi's picture
Submitted by

Ok, here's the first bit of success, working except for one issue: when rendering, any drawn line disappears the moment the mouse button is released. Closing/reopening the viewer might fix it, or closing/reopening the comp usually does get it to work. Also, it takes a good bit of time for the viewer to open after hitting render.

Left mouse button draws, command button allows rotating the camera, right button to clear.

Link to DrawInSpace0 above is

jersmi's picture
Submitted by

Link to DrawInSpace0 above is updated.

Seems this comp should work fine, but the problem persists: when the viewer launches, it's 50/50 whether drawn lines will stay on the screen like they are supposed to. Show events looks good to me. I don't know what I can do to troubleshoot this. Is this a bug?

Besides this problem, which I realize now really threw me off when building it, I am super happy with this comp, so much cool Vuo potential!

Looks like there's a race

jstrecker's picture
Submitted by

Looks like there's a race between the Left Mouse Button : Released and Left Button to Draw : Drag Ended to reach the Enqueue node. The triggers fire at nearly the same time. When Drag Ended wins the race, the line is drawn as expected. When Released wins the race, the line gets cleared before it can be drawn.