We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad C++ API
About Archicad add-on development using the C++ API.

about Windows & Doors transformations

stefan
Advisor
In my Radiance exporter, when exporting the bodies one by one, I can't seem to get the transformation for the Windows and/or Doors right.

I start from a list of body-indices.
Then I request the API_Component3D.
From the component, I can query vertices & edges & Polygons and also the "tranmat" (the transformation matrix).

I was trying to derive transformation, scaling & rotation out of it and it seems to work fine for regular objects (e.g. chairs), but they only have a Z-rotation.

I used the function "Geometry::TM2dDecompose" which gave me the correct Z-angle, but I guess this is not usable for the Windows or Doors.

Can I request the actual rotation values around the different axes?
Or should I receive this from the Wall in which they are located?
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
9 REPLIES 9
stefan
Advisor
The rendering from within ArchiCAD
raddd_LW.jpg
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
stefan
Advisor
And from Radiance...

Notice that the Window is not rotated in X or Y axis.
The wall runs from 0,0 to 1500,1500.
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Andras Babos
Graphisoft Alumni
Graphisoft Alumni
stefan wrote:
In my Radiance exporter, when exporting the bodies one by one, I can't seem to get the transformation for the Windows and/or Doors right.

I start from a list of body-indices.
Then I request the API_Component3D.
From the component, I can query vertices & edges & Polygons and also the "tranmat" (the transformation matrix).

I was trying to derive transformation, scaling & rotation out of it and it seems to work fine for regular objects (e.g. chairs), but they only have a Z-rotation.

I used the function "Geometry::TM2dDecompose" which gave me the correct Z-angle, but I guess this is not usable for the Windows or Doors.

Can I request the actual rotation values around the different axes?
Or should I receive this from the Wall in which they are located?


There are a few problems in your method:
1. First of all you are using a function to decompose the 2D part of a transformation -> you simply can't get Z-rotation with this function.
2. The "tranmat" matrix you are using is not a universal transformation matrix - as the 3D datastructure you are applying it on may already be transformed. What I mean is that right now the "normal" objects are simply placed in the origo and transformed from there, but doors and windows are already transformed: they have a 90 degree rotation around the X axis. What's more we cannot guarantee that this behavior stays this way - we may change this first transformation for any reason from optimization to "we like it better this way" 🙂.
This means that even if you decompose the 3D "tranmat" matrix - which is quite difficult - the resulting transformations may result in displaced objects.
3. For some object you may not have any "tranmat" at all - in these cases you get the final location of the object from AC.
4. What you should do is applying the "tranmat" matrix to the 3D datastructure you got from AC and then store the resulting object in your format of choice. (Relevant Geometry functions are: Geometry::TMVector and Geometry::TMPoint.)

I hope my explanation was clear enough. If you have any more questions feel free to write.

Regards:
Andras Babos.
stefan
Advisor
Well, suppose the Window is always rotated 90 degrees (it is), can I know from the 3D-Body alone that this was actually a window? I only need to add this additional rotation for Doors & Windows, don't I?

Edit: I'll answer this myself 😉
API_Elem_Head parent = component.body.parent;
bool IsWindowOrDoor = false;
if (parent.typeID == API_WindowID || parent.typeID == API_DoorID)
	IsWindowOrDoor = true;
Would it make sense to request the window's rotation from the wall it is inserted in? Can I access that?

---

But what do you exactly mean by "applying the tranmat to the 3D Datastructure"? Transform a vector and see what angle it gives me?

What I need to do in my exporter is to give the correct X, Y & Z rotation for each object (in degrees), since the polygons are given in local coordinates.

---

In my example: ArchiCAD returns the transformation for the Window as
tranmat[0] = 0.707;
tranmat[1] = 0.000;
tranmat[2] = 0.707;
tranmat[3] = 0.616;
tranmat[4] = 0.707;
tranmat[5] = 0.000;
tranmat[6] = -0.707;
tranmat[7] = 0.884;
tranmat[8] = 0.000;
tranmat[9] = 1.000;
tranmat[10] = 0.000;
tranmat[11] = 0.900;

Now I now that 0.616, 0.884 and 0.9 is the translation.
I also know that the actual rotation I need is 45 degrees, for which cos(45°) is 0.707. I also know that no scalling occurs, so this is a pure rotation matrix.

Edit: Just using RX = 90, RY = 0 and RZ = (acos(tranmat.tmx[0]) * 57.29) is giving nice results.

But I guess you are suggesting me not to follow this approach...
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Oleg
Expert
Perhaps I am not quite understand your problem.
Bu tas Andras told, in any case you should apply the matrix to vectors.
x ' = tmx [0] * x + tmx [1] * y + tmx [2] * z + tmx [3]
y ' = tmx [4] * x + tmx [5] * y + tmx [6] * z + tmx [7]
z ' = tmx [8] * x + tmx [9] * y + tmx [10] * z + tmx [11]

( Actually you can not get anything useful of this matrix as for example for objects cutted by roof this matrix will be identity. I think it is items 2,3 of Andras's post )

After application of a matrix, your geometry will be transformed to real, world coordinates.
Is it what you want
Ralph Wessel
Mentor
stefan wrote:
But what do you exactly mean by "applying the tranmat to the 3D Datastructure"? Transform a vector and see what angle it gives me?
What I need to do in my exporter is to give the correct X, Y & Z rotation for each object (in degrees), since the polygons are given in local coordinates.
Would I be correct in thinking that you could simply transform the 3D vertices to their true orientation and export them with the x/y/z rotations set to 0?

If so, use 'tranmat' from the API_BodyType structure to transform the normal to the faces and the 3D vertices (i.e. multiply the vertex by the matrix). You needn't do this if 'tranmat' is an identity matrix.
Ralph Wessel BArch
Software Engineer Speckle Systems
Andras Babos
Graphisoft Alumni
Graphisoft Alumni
stefan wrote:
But what do you exactly mean by "applying the tranmat to the 3D Datastructure"?

I mean exactly what Oleg suggested in his post. By transforming all points with that matrix you get a real world position of the object in question. I understand that you'd like to store rotation/displacement/mirroring info in your format (radiance), but since the datastructures you get through the API don't use a fix starting location from where you could apply these transformations, you are out of luck.
You can do two things: first, you can use Oleg's suggestion (and what I was trying to imply) and store the transformed object with 0 rotation (as Ralph suggested), or second, you may take a few things for granted (like that we transform from origo, etc.), check for the exceptional cases, and modify your addon when Graphisoft changes the internal workings of the 3D engine. Of course doing it the first way is highly recommended... 🙂

Andras.
stefan
Advisor
I'd like to inform that I tried it and it worked OK. I transformed all the vertices before writing them out and everything seemed to end up on the right spot.

Thanks again.
sb_proof.jpg
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Andras Babos
Graphisoft Alumni
Graphisoft Alumni
Glad to hear that. The rendered image looks nice...