carl.sutton Posted May 2, 2012 Share Posted May 2, 2012 Hello, I'm having some trouble with ObjectMeshDynamic. I want to be able to clear all the data (verts, indicies, etc...) from this object so I can add new data. Previously I was doing this by deleteing the node and creating a new one, but now this won't do as it does not retain its node id and thus causes problems with my custom undo/redo stack. So I tried using the functions clearSurfaces(), clearVertex(), clearIndices() and then adding the new mesh data afterwards. These functions however do not correctly reset the ObjectMeshDynamic as I do not get the correct mesh, some data is clearly being left in the object that is preventing me from essentially, reshaping my object. Why is my object not being cleared corrrectly? Are the functions not designed for this? Will there ever be any remove functions for ObjectMeshDynamic? Link to comment
ulf.schroeter Posted May 2, 2012 Share Posted May 2, 2012 Call ObjectMeshDynamic::flush() after mesh data modifications for uploading changes to GPU // create connectors geometry ObjectMeshDynamic connectors = node_cast( engine.editor.getNode( connectorsID ) ); connectors.clearVertex(); connectors.clearIndices(); for( int i=0; i<200; i++ ) { float longitudeStartDegrees = rand( -180.0f, 180.0f ); float latitudeStartDegrees = rand( -60.0f, 60.0f ); float longitudeEndDegrees = rand( -180.0f, 180.0f ); float latitudeEndDegrees = rand( -60.0f, 60.0f ); float timestamp = float(i) * 10.0f; createConnector( connectors, longitudeStartDegrees, latitudeStartDegrees, longitudeEndDegrees, latitudeEndDegrees, timestamp ); } connectors.updateBounds(); connectors.updateTangents(); connectors.flush(); Link to comment
unclebob Posted May 3, 2012 Share Posted May 3, 2012 Hi Carl, Try this use case: 1. Clear mesh data via clearSurfaces() \ clearVertex() \ clearIndices() calls 2. Fill mesh with new data 3. Call flush() to upload new data to GPU Does it solve your problem? Link to comment
carl.sutton Posted May 3, 2012 Author Share Posted May 3, 2012 I was calling flush in the wrong place. I was doing step 3 before I was doing step 2. It is working fine now thank you. Have you considered implementing script functions to remove/clear only specified verts, indicies and surfaces? It's not a necessity for me, but I imagine I could optimise my code by only changing the parts of the dynamic mesh that I needed to change rather than clearing and redeclaring what will mostly be the same mesh with some minor modifications. Link to comment
unclebob Posted May 5, 2012 Share Posted May 5, 2012 The problem is if you'll delete any vertex then index buffer become invalid by pointing at different vertices. So, we do not plan to add this functionality. Link to comment
manguste Posted May 6, 2012 Share Posted May 6, 2012 I've added info on clearing mesh data into docs. Link to comment
Recommended Posts