question

Ameen M Shabeer avatar image
0 Likes"
Ameen M Shabeer asked tannerp commented

Draw directly in the model Coordinates

Hi,

Is there any option to draw directly in the model? Like 'Model On draw'.

I am trying to draw in the model coordinates without using On draw trigger of the secondary object.

model-example.fsm Refer to the Attached Model, whenever changing the base object (Plan) size or Move, the drawing gets distorted.

FlexSim 18.2.2
drawingon drawcustom draw
model-example.fsm (57.7 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

tannerp avatar image tannerp commented ·

One alternative to using the secondary object's triggers could be to use an "On Model Open" trigger. This can be found in the toolbox under Toolbox -> Modeling Logic -> Model Trigger -> On Model Open.

0 Likes 0 ·
Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo edited

In your On Draw trigger, use the following command to undo the object's size scaling:

drawtomodelscale(current);

Also, if you want to undo the object's translation, you can use fglTranslate(). For example:

drawtomodelscale(current);
Vec3 loc = current.location;
fglTranslate(-loc.x, -loc.z, loc.y);

drawsphere(3,0,0,1,255,0,0,1,1);
drawsphere(0,3,0,1,0,255,0,1,1);
drawsphere(0,0,3,1,0,0,255,1,1);

(Note: The OpenGL coordinate space during On Draw doesn't match the FlexSim model coordinate space. The drawsphere() command already accounts for this, but the fgl() commands affect the OpenGL coordinate space directly, so Z and Y are flipped in the example fglTranslate() above. You could also fglRotate() -90 degrees around the X axis, but that would mess up the drawsphere() accounting for the different coordinate spaces.)

If you wanted to undo the object's entire transformation matrix caused by its position, rotation, and scale, then you could use fglScale(), fglTranslate(), and fglRotate():

Vec3 loc = current.location;
Vec3 rot = current.rotation;
Vec3 size = current.size;

// undo size scaling, same as drawtomodelscale(current);
fglScale(1/size.x, 1/size.z, 1/size.y);

// undo rotation
fglTranslate(size.x*0.5, size.z*0.5, size.y*0.5); // compensate for centroid rotation
fglRotate(rot.x, -1, 0, 0);
fglRotate(rot.y, 0, 0, 1);
fglRotate(rot.z, 0, -1, 0);
fglTranslate(-size.x*0.5, -size.z*0.5, -size.y*0.5);// compensate for centroid rotation

// undo position
fglTranslate(-loc.x, -loc.z, loc.y);

The "direct spatials" location [0, 0, 0] rotation [0, 0, 0] and size [1, 1, 1] is the correct size and position of an object to "draw a 1:1 sketch."

Rather than undoing the object transformations, you could alternatively just force the object's location, rotation, and size to be the values you want in an On Pre Draw trigger. That way, if something tries to change the object's position, rotation, or size, then the object simply sets it back before it draws:

current.location = Vec3(0,0,0);
current.rotation = Vec3(0,0,0);
current.size = Vec3(1,1,1);

direct-spatials.png (61.9 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Phil BoBo converted comment to answer

I don't think there is a way to draw without an object. Why do you need to move or resize the plane? If you are trying to prevent accidental moves, use the No Select option on the Plane. Additionally, if you don't want the plane to draw at all, but you just want the points, you can return 1 from the draw trigger, and that will stop the plane from drawing.

model-example-modified.fsm


· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ameen M Shabeer avatar image Ameen M Shabeer commented ·

The drawing is fully depended on the Size and Position of the Object.

if there is no option to avoid Object, what is the correct size and position of the Object to draw a 1:1 sketch using On Draw?

0 Likes 0 ·
capture.jpg (43.4 KiB)