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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Translate the entire conversation x

How to generate a view with creo.js / web.link?

Mat
15-Moonstone
15-Moonstone

How to generate a view with creo.js / web.link?

Hi there,

 

I am trying to create a view in a part or assembly by web.link.

 

What works:

  • Rotate and pan view by mouse
  • OR: Rotate view by "CurrentModel.CurrentViewRotate(0, 30)"
  • Save view with "CurrentModel.SaveView("newView")

What does not work:

  • Create a transform matrix
  • Create a Transform3D object with "let newtrans = pfcCreate("pfcTransform3D").Create( newmatrix)
  • Rotate / transform the current view with "CurentModel.SetCurrentViewTransform(newtrans)"

What am I doing wrong?

 

( Creo 10.0.7.0 )

 

ACCEPTED SOLUTION

Accepted Solutions
RPN
17-Peridot
17-Peridot
(To:Mat)

I’m not sure but as far I remember a view matrix is not equal to a transformation matrix, the indices are swapped and you may need to normalize the matrix.

 

 

A4x4 transformation matrix describes a shift and a scaling, as well as a
reorientation. You set the view matrix to define a new orientation. Creo Parametric
applies its own shift and scaling to the view matrix you provide to ensure that the
solid fits properly into the view. This implies the following:
• The matrix output by ProViewMatrixGet() is not the same as the one
you previously input to the function ProViewMatrixSet(), although its
orientation is the same.
Each row of the matrix you provide to ProViewMatrixSet() must have a
length of 1.0, and the bottom row must be 0, 0, 0, 1.
• The matrix you provide to ProViewMatrixSet() must be normalized—it
cannot include scaling or shift. Example 1: Saving Three Views on page 511
shows how to normalize a matrix

 

 

View solution in original post

3 REPLIES 3
RPN
17-Peridot
17-Peridot
(To:Mat)

I’m not sure but as far I remember a view matrix is not equal to a transformation matrix, the indices are swapped and you may need to normalize the matrix.

 

 

A4x4 transformation matrix describes a shift and a scaling, as well as a
reorientation. You set the view matrix to define a new orientation. Creo Parametric
applies its own shift and scaling to the view matrix you provide to ensure that the
solid fits properly into the view. This implies the following:
• The matrix output by ProViewMatrixGet() is not the same as the one
you previously input to the function ProViewMatrixSet(), although its
orientation is the same.
Each row of the matrix you provide to ProViewMatrixSet() must have a
length of 1.0, and the bottom row must be 0, 0, 0, 1.
• The matrix you provide to ProViewMatrixSet() must be normalized—it
cannot include scaling or shift. Example 1: Saving Three Views on page 511
shows how to normalize a matrix

 

 

Mat
15-Moonstone
15-Moonstone
(To:RPN)

Thanks for Your help!

It now works (sort of).

I created a matrix and a plot function with 

 

let test = pfcCreate("pfcMatrix3D")

function plot_matrix(matrix){

	output = "";
	for (let i = 0; i <= 3; i++) {
		for (let j = 0; j <= 3; j++) {
			output += matrix.Item(i,j);
			output += " | ";
		}
		output += "\n";
	}
	console.log( output);
}

I filled the matrix, so I get this result:

1 | 0 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 |
0 | 0 | 0 | 1 |

 

This rotates the View.

let newtrans = pfcCreate("pfcTransform3D").Create(test)

CurModel.SetCurrentViewTransform(newtrans)

 

But somehow the illumination of the model gets weird.

 

Default Orientation:

Mat_0-1746000586373.png

Rotated by matrix above:

Mat_1-1746000614739.png

reoriented by using the mouse:


Mat_3-1746000687887.png

 

My guess is, that the last line of the matrix shifts the model outside the area of the default light sources.
But I will figure that out later.

 

BTW: The way creo.js handles matrices is totally of the rails. I mean, who at PTC came up with the idea to pack the matrix's elements in "matrix.Item(x,y)" and changing them through "matrix.Set(x,y, 123)"? Why not just use a (standard) javascript matrix Array, which would provide methods like ".join()".

 

 

 

 

 

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

Try everything with a new model, without using a template and create a csys first.  And now compare you template csys with the default one. If you have custom views like FRONT, BACK, TOP ... based on custom "not" default datum's you have to incorporate this matrix multiplication as well. If you just use a new matrix you will use Creo's default csys as create as a first feature with right hand rule.

 

In Toolkit I configure the values and set the Matrix, Refit and save the View.

viewmatrix.png

 

 

Have Fun 🙂

 

 

Announcements

Top Tags