C++ adding mesh faces

Hi,

I would like to ask why contrary to .NET in C++ adding mesh faces requires specifying additional vertex id.
For instance when adding 1 quad face it requires 5 vertex ids, and when adding triangle face 4 vertex ids (instead of 3 in .NET) What is the reason for that? And it is not necessary the same id first and last vertex.

Example from Dale Tutorials:
mesh1.SetVertex(0, ON_3fPoint(0.0f, 0.0f, 1.0f));
mesh1.SetVertex(1, ON_3fPoint(1.0f, 0.0f, 1.0f));
mesh1.SetVertex(2, ON_3fPoint(2.0f, 0.0f, 1.0f));
mesh1.SetVertex(3, ON_3fPoint(3.0f, 0.0f, 0.0f));
mesh1.SetVertex(4, ON_3fPoint(0.0f, 1.0f, 1.0f));
mesh1.SetVertex(5, ON_3fPoint(1.0f, 1.0f, 2.0f));
…
mesh1.SetQuad(0, 0, 1, 5, 4);
mesh1.SetQuad(5,6,7,11,10);

Hi @Petras_Vestartas,

I guess don’t understand the question. ON_Mesh::SetQuad requires the face index (to set) and four vertex indices (to reference). Perhaps you can rephrase your question?

– Dale

Thanks now I get it, that first number is face id.

I have another question learning from you tutorials.

Following this example:

When I write ON_BinaryFile archive(ON::write3dm, fp);
I get error on write3dm, that ON does not have this member.

What I am missing?

Use ON::archive_mode::write3dm.

– Dale

Thanks Dale, I am going through the same exercise and have following question.
In ReadCurveFile method you have input as reference to pointer curve, while in the sample file you just call function and pass the pointer (without reference) -> This produce error.

What is correct way passing pointer or passing pointer with reference?
Here is the mistake I think:

(click on image to extend the full height)

Hi @Petras_Vestartas,

I’m confused - I am not getting any warning or error. And the example code works here.

Passing a reference to a pointer is no different that passing a reference to any other variable type.

– Dale

It was my mistake. I was used to .NET compiler that shows errors before building project, while C++ is only showing errors after building.

This is my problem of not knowing C++ but could you tell me why compiler does not recognize ReadCurveFile method below?

Hi @Petras_Vestartas,

The error is because you’ve tried to use a function before it was declared. Either move the function above where you are calling or provide a forward declaration of the function.

– Dale

Dear Dale,

Thank you, now it builds successfully.

One more question regarding this exercise:

What is correct way of specifying the filename?
If I specify filename like this, it builds successfully, but the writing method fails:
Rhino Command line after selecting curve says: Errors while writing myfile.3dm.

Hi @Petras_Vestartas,

You should always specify filenames in their full path form.

– Dale

I should add above that I used C:/filename.3dm and C:
\filename.3dm.

On Windows, either:

const wchar_t* filename = L"C:\\filename.3dm";

or

const wchar_t* filename = L"C:/filename.3dm";

Shoud do the trick, given you have enough rights to write the root folder on drive C:.

– Dale

Thank you, I it was an issue about rights, I had to create in C drive a folder then it could be written correctly.
Now everything works good.

I would like to ask if the file that is generated here is an actual Rhino file (the written file is only 301 bytes)?
I can write and read information from the file generated as screenshot attached.

But if I open this file with Rhino, I get this error message window:
Learning

Hi @Petras_Vestartas,

No, the sample code does not write 3dm file. It writes (and reads) a binary file that contains a curve.

If you want to write 3dm files, then download the openNURBS toolkit and review the samples.

https://www.rhino3d.com/opennurbs

– Dale

1 Like