Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofMesh:addVertex() not working with ofVec3f #49

Open
grabanton opened this issue Jan 13, 2021 · 6 comments
Open

ofMesh:addVertex() not working with ofVec3f #49

grabanton opened this issue Jan 13, 2021 · 6 comments

Comments

@grabanton
Copy link

Hi! I am trying create ofMesh object and fill it with vertices.

I am writing in onSetup section:

mesh = ofMesh();
mesh:setMode(OF_PRIMITIVE_LINES);

In ofUpdate section:

mesh:clear()
mesh:addVertex(ofVec3f(0,0,0));

And I got this error:

- ofelia: [string "package.preload['__.x2687c30.c'] = nil packag..."]:4: Error in Mesh_addVertex (arg 2), expected 'ofDefaultNormalType *|ofDefaultVertexType *|glm::vec3 *' got 'ofPoint *|ofVec3f *'

also if I try writing:

mesh:addColor(ofColor(255));

error:

- ofelia: [string "package.preload['__.x2687610.c'] = nil packag..."]:4: Error in Mesh_addColor (arg 2), expected 'ofDefaultColorType *|ofColor_< float > *|ofFloatColor *' got 'ofColor_< unsigned char > *|ofColor *'

It say what I give wrong type of argument, but I do as in the openFrameworks documentation.

@cuinjune
Copy link
Owner

Hi, you should convert ofVec3f() to glm::vec3() by appending :vec3() to ofVec3f() as it says here: https://github.com/danomatika/ofxLua#glm

So your code should be

mesh:addVertex(ofVec3f(0,0,0):vec3());

@grabanton
Copy link
Author

grabanton commented Jan 13, 2021

@cuinjune, thank you! It works for addVertex, but what about color? How to convert ofColor_< unsigned char > to *|ofColor_< float >? And is there an approach to get a list of all methods of an object?

@cuinjune
Copy link
Owner

mesh:addColor() accepts ofFloatColor() instead of ofColor() which uses float r,g,b values between 0 and 1.

You can check the ofelia/examples/3d/coloredCube example to see how it can be used.

@grabanton
Copy link
Author

grabanton commented Jan 13, 2021

Where I can find information about mathematical operations with glm objects? When I try call any methods of glm::vec3() I got errors:

- ofelia: [string "package.preload['__.x25eb0c0.c'] = nil packag..."]:4: attempt to index a userdata value (local 'v')

I mean acces to vector components or length(), distance(), dot(), cross() etc...

UPD:
Found approch to doing it. I need wrap glm::vec3 back to ofVec3f type. And there available all needed methods.
like in this example:

local v1 = ofVec3f(mesh:getVertex(0));
local v2 = ofVec3f(mesh:getVertex(1));
print(v1:distance(v2));

But still actual question about getting list of object methods )

@cuinjune
Copy link
Owner

cuinjune commented Jan 13, 2021

You can access all the methods through ofVec3f() variable before converting it to glm::vec3().

So I'd suggest always define variables in ofVec3f() type and only covert them to glm::vec3() when needed.

Like the following example:

ofelia f;
local v = ofVec3f(3, 4, 1);
print(v:length());
local mesh = ofMesh();
mesh:addVertex(v:vec3());
local v2 = ofVec3f(mesh:getVertex(0));
print(v2:length());

I don't think it is currently possible to directly initialize glm::vec3() by doing something like local v = glm.vec3(0, 0, 0) in Ofelia. This could be a bug or recently supported feature of ofxLua. I will try to update ofxLua used in Ofelia soon and see if glm can be used directly.

@grabanton
Copy link
Author

grabanton commented Jan 14, 2021

@cuinjune, thank you very much! I have a number of questions and suggestions on how to improve the ofelia. Can we chat in person on Facebook or Telegram so as not to clog up the thread?
telegram
facebook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants