cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Translate the entire conversation x

CREO JS API pfcViewOwner.GetCurrentViewTransform() and pfcViewOwner.SetCurrentViewTransform()

ilyachaban
16-Pearl

CREO JS API pfcViewOwner.GetCurrentViewTransform() and pfcViewOwner.SetCurrentViewTransform()

Hello, I'm having troubles using this two funcitons. 

Effect I'm expecting using this two functions one after each other. I see the same thing without changes by getting actual transformation and applying it to the model. 

Now let's see what's actually happens

 

let model = pfcGetCurrentSession().GetCurrentModel()
let transform = model.GetCurrentViewTransform()
model.SetCurrentViewTransform(transform)

This code retrieves transformation from opened model and i expect this transformation to be correct because I do actually see it in model and there is no errors in it. But:
 

Uncaught Error: pfcExceptions::XToolkitBadInputs in ProViewMatrixSet at <anonymous>:3:7


Is there any extra step needed to repair transformation gained directly from model?


12 REPLIES 12
RPN
17-Peridot
17-Peridot
(To:ilyachaban)

Normalize?

ilyachaban
16-Pearl
(To:RPN)

Is there a function for that so users don't have to do it by hand? 

As i can see C++ toolkit has it but no mention about this function in JS API.

Next question is about used documentation from programmers point of view there has to be at least a mention about necessity of normalization if i read documentation.


I've tried for like a couple of hours trying to input pfcTransform3D into SetCurrentViewTransform and didn't succeed but for some reason if i input Matrix Property of pfcTransform3D it works. Like WHYYYYYY?!?!?!?!?!?!? documentation says: give me pfcTransform3D

ilyachaban_0-1752644995358.png



let's follow with normalization:
that is a view I'm getting when i input any kind of matrix. Even normalized 

ilyachaban_1-1752645090537.png



this is view it has to give to me  

ilyachaban_2-1752645130783.png



i suspect i'm getting some kind of generic view in camera coordinate system so it doesn't thorow exception even if matrix is invalid

ilyachaban
16-Pearl
(To:RPN)

const session = pfcGetCurrentSession();
const model   = session.GetCurrentModel();      // fine – keeps the model handy

const view    = model.GetView("Narys");         // saved view to copy
const transform   = view.Transform;                 // keep the FULL transform object
//transform.Invert()
const matrix = transform.Matrix;
printMatrix(matrix);
const normmatrix = normaliseMatrix(matrix);
printMatrix(normmatrix);

model.SetCurrentViewTransform(normmatrix)



here is last example which i've tried 

RPN
17-Peridot
17-Peridot
(To:ilyachaban)

extern ProError ProViewMatrixSet (ProMdl model,
ProView view_handle,
ProMatrix matrix);
/*
Purpose: Sets the orientation of a model in a view. The matrix argument
specifies the transformation between model coordinates and screen
coordinates. Each row of the matrix must have a length of 1.0,
and the bottom row must be 0,0,0,1.
<p>
Creo Parametric applies its own shift and scaling to the specified
view matrix to ensure that the model fits properly into the view.
Thus, subsequent calls to <b>ProViewMatrixGet()</b> don't return
the original matrix, though its rotation will be the same.

<p>
NOTE:
<p>
You must normalize the matrix you pass to ProViewMatrixSet() so that
it has no scaling or origin shift. ProViewMatrixSet() rejects
non-normalized matrices. See function UserMatrixNormalize.

Input Arguments:
model - The handle to part, assembly, or drawing. If this is
NULL, the function uses the current object.
view_handle - The view handle. If the view is NULL, the function uses
the current view.
matrix - The view transformation matrix.

Output Arguments:
None

ilyachaban
16-Pearl
(To:RPN)

Thank you for your answers. 

Let me start with documentation citation for JS API for CREO.

ilyachaban_0-1752663599746.png


in Creo JS there is no mention about normalization of a matrix at all i'm not againt normalizing matrix but it would be good to know when using this kind of functionality.

Second thing from documentation which is not coinside with data you've provided is that your data provided says that you need to input matrix 
When CREO JS API documentation says that you need to provide pfcTransform3D 

ilyachaban_1-1752663870922.png



now let me show you my complete code and what it does

function normaliseMatrix(m) {
  const n = pfcMatrix3D.create();      // identity to start with

  // --- copy & normalise the rotation part (cols 0-2) ---
  for (let c = 0; c < 3; c++) {
    const x = m.Item(0, c),
          y = m.Item(1, c),
          z = m.Item(2, c);
    const len = Math.hypot(x, y, z);   // √(x²+y²+z²)
    if (len === 0) {
      throw new Error(`Axis ${c} has zero length ― can’t normalise.`);
    }
    n.Set(0, c, x / len);
    n.Set(1, c, y / len);
    n.Set(2, c, z / len);
  }

  // --- copy translation column unchanged (col 3) ---
  for (let r = 0; r < 3; r++) {
    n.Set(r, 3, m.Item(r, 3));
  }

  // --- enforce homogeneous bottom row [0 0 0 1] ---
  n.Set(3, 0, 0);
  n.Set(3, 1, 0);
  n.Set(3, 2, 0);
  n.Set(3, 3, 1);

  return n;
}
function printMatrix(m, prec = 1) {
  for (let r = 0; r < 4; r++) {
    const row = [];
    for (let c = 0; c < 4; c++) {
      row.push(m.Item(r, c).toFixed(prec));
    }
    console.log(row.join('\t'));
  }
}
const session = pfcGetCurrentSession();
const model   = session.GetCurrentModel();      // fine – keeps the model handy

const view    = model.GetView("Narys");         // saved view to copy
const transform   = view.Transform;                 // keep the FULL transform object
//transform.Invert()
const matrix = transform.Matrix;
printMatrix(matrix);
const normmatrix = normaliseMatrix(matrix);
printMatrix(normmatrix);

model.SetCurrentViewTransform(normmatrix)

normmatrix which i insert to the method has form of

0.0	0.0	1.0	0.0
1.0	0.0	0.0	0.0
0.0	1.0	0.0	0.0
0.0	0.0	0.0	1.0

which result view :

ilyachaban_2-1752664040641.png

Now let's try to uncomment inversion of pfcTransform3D and insert to the function new matrix

0.0	1.0	0.0	0.0
0.0	0.0	1.0	0.0
1.0	0.0	0.0	0.0
0.0	0.0	0.0	1.0

which results:

ilyachaban_3-1752664121011.png



Those two views are absolutely identical. 

RPN
17-Peridot
17-Peridot
(To:ilyachaban)

How is the displayed csys created? Please test with a default csys as a first feature. Did you refresh the window?

Here I answered a similar question 

ilyachaban
16-Pearl
(To:RPN)

displayed csys is model csys 

ilyachaban_0-1752688580887.png


model is freshly created only to test functionality of SetCurrentViewTransform

Same behaviour i see when creating insructions for drawing view create absolutely the same mistake

RPN
17-Peridot
17-Peridot
(To:ilyachaban)

If the csys is not the first feature it may have an initial transformation based on the first 3 datum’s. To see that the transformation fit, please create a csys as a first feature. Then compare your matrix. Else you have to multiply by the first csys transformation. 

You can’t compare to the first csys, you may may dozen of them. That’s the reason to compare with the default. 

ilyachaban
16-Pearl
(To:RPN)

Here comes the problem.
Final position of the model is the same independent of what matrix i input into function

I've tried all zeroes, all ones, correct transformation matrix, incorrect transformation matrix, build from right handed CSYS left handed (which is also incorrect matrix).  tried 90 degrees turns tied non90 degrees turns and nothin NOTHING has changed in final view each time after repaint function i see the same image 

don't forget creo uses 2 types of transformation which defines final position of a model on monitor 

first one is rotattions which si SetCurrentViewTransform (only rotations)
second one defines Pan and Zoom vairables didn't even got to it for now because simple rotations which works everywhere (for the reference tried simple rotation matrices in blender and each position defined by me was flawlessly processed (bad positions was marked as bad positions as incorrect transformation matrix)) 

But this function. It drives me crazy. 

ilyachaban_0-1752753540516.png



Yes i can try to find your default coordinate system which is first in model tree but it won't change anything. If it didn't work with any thansformation matrix it won't work with different coordinate system and that's the point

RPN
17-Peridot
17-Peridot
(To:ilyachaban)

You wrote 

don't forget creo uses 2 types of transformation which defines final position of a model on monitor

 

You have an unique view of the model, in an assembly each assembled component has a transformation matrix (this is independent from the view), in part mode you may define your model by your own initial transformation, for example you start your first solid feature without any datum, or you setup a default csys and next 3 datum’s, or you start with 3 datum’s and orient the csys by any possible direction (I think these are “9”, but I need to think about 😉),  and so on. You can even start by creating your 3 base datum’s by a transformed csys. You have quite a lot of options, but at the end you specify one named view matrix. And this matrix, as far I know will use the initial world csys (first feature without datum’s). If you measure from a different matrix you have to multiply this.

 

Please evaluate your matrix values by using the default csys.

Here the simplest way is to create first a csys, and next 3 datum’s through it😎


What is „Front“ ? How you name it, this depends on you, this is not important, but the names may miss lead you😉

 

All here my 2 Cents 😵

 

And yes, at the end you view at your 2D screen with a height and a width, your ViewPort. 

 

 

 

Hello @ilyachaban,

 

You have some responses from a community member. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 
Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.

This issue has been recreated by PTC Support and now it has SPR ticket

Announcements

Top Tags