Closed asmwarrior closed 4 months ago
You need to replace the old geometry with a new one. Alternativly create a bigger list of points (with potentially unused data). The point is that you can not change the size of an existing geometry.
Edit: You should be able to use draw range (still fixed size), but this is untested territory.
You need to replace the old geometry with a new one.
Thanks for the help, the below code works:
void MyFrame::OnButtonAddPointClicked(wxCommandEvent& event)
{
auto scene = openGLCanvas->GetSceneObject();
auto line = scene->getObjectByName("line3d");
BufferGeometry* geometry = line->geometry();
const auto position = geometry->getAttribute<float>("position");
auto& array = position->array();
array.push_back(50.0); // point.x
array.push_back(50.0); // point.y
array.push_back(50.0); // point.z
geometry->setAttribute("position", FloatBufferAttribute::create(array, 3));
position->needsUpdate();
geometry->computeBoundingSphere();
Refresh(false);
}
The main change to my previous code is that I have add a line:
geometry->setAttribute("position", FloatBufferAttribute::create(array, 3));
So, I believe the geometry's vertices get updated. I'm not quite sure how the internal code works, but It does work.
Alternativly create a bigger list of points (with potentially unused data). The point is that you can not change the size of an existing geometry.
Edit: You should be able to use draw range (still fixed size), but this is untested territory.
Thanks, I see you have ported the drawRange
function in this library, I will try it later. Hopefully we could have a test code about this method.
BTW, is it possible to not use the
getAttribute<float>
, but instead use some kind ofVector3
?
About this question, I change the above code below:
void MyFrame::OnButtonAddPointClicked(wxCommandEvent& event)
{
auto scene = openGLCanvas->GetSceneObject();
auto line = scene->getObjectByName("line3d");
BufferGeometry* geometry = line->geometry();
const auto position = geometry->getAttribute<Vector3>("position");
auto& array = position->array();
array.push_back(Vector3(50.0, 50.0, 50.0)); // point
geometry->setAttribute("position", FloatBufferAttribute::create(array, 3));
position->needsUpdate();
geometry->computeBoundingSphere();
Refresh(false);
}
The build error is in the line:
geometry->setAttribute("position", FloatBufferAttribute::create(array, 3));
I believe the array
is a std::vector<Vector3> &
, but I'm not sure how to pass this variable to FloatBufferAttribute::create
function call.
Thanks.
array
for the "position"
attribute is std::vector<float>
.
If you want a one-liner, you could do array.insert(array.end(), {50, 50, 50});
.
Thanks, I see you have ported the drawRange function in this library, I will try it later. Hopefully we could have a test code about this method.
See tube_geometry.cpp
demo on dev. I added use of DrawRange there.
array
for the"position"
attribute isstd::vector<float>
.If you want a one-liner, you could do
array.insert(array.end(), {50, 50, 50});
.
OK, I see, thanks for the help!
Thanks, I see you have ported the drawRange function in this library, I will try it later. Hopefully we could have a test code about this method.
See
tube_geometry.cpp
demo on dev. I added use of DrawRange there.
OK, let me learn that code there. Thanks.
Hi, I have an object which has the type:
threepp::Line
I created it with such code:
Now, I have to update the points of the line by adding new points, so I wrote such code below:
I found that the above code does not change the 3d line. What I know is that the
array
has a field namedcount_
, see here:https://github.com/markaren/threepp/blob/258708f68cde3fbedbc8ae005e7eca1406fae4b0/include/threepp/core/BufferAttribute.hpp#L93-L102
But I don't see there is a way to modify the
count_
value.Any ideas?
Thanks.
BTW, is it possible to not use the
getAttribute<float>
, but instead use some kind ofVector3
?