0

Apologies if my mistake is obvious. Started learning code a few weeks ago. Have searched copiously for an answer.

Attempting to control a variable of a graphical equation animated in three.js using Dat.Gui. By assigning the variable to nothing, I was able to see that the gui is linked because clinking anywhere on the slider immediately calls the intended graphed equation (for simplicity's sake I have replaced my more complicated equation with a simple parabola). The graphed equation also disappears when the gui slider is clicked again, as hoped, to clear the way for the 'redrawn' equation (wider or skinnier parabola as determined by gui slider), however it throws this error:

"[.CommandBufferContext]RENDER WARNING: Render count or primcount is 0."

I've been able to rearrange the code so it doesn't throw this error, but it still does not call the next visible iteration of the equation.... Below is the code that succeeds in drawing the parabola, removes it upon the next .onChange, but then throws the above error...

init function + scene, camera setup, etc....

  gui = new DAT.GUI();
  gui_a = gui.add(this, 'a').min(0.01).max(5).step(0.01).name('Width');
  gui_a.onChange(function(value){createGraph();});
}

function createGraph(){
  if(graphLine) scene.remove(graphLine);
  var graphGeometry = new THREE.Geometry();
  while (x<20){
    var y = a*(Math.pow(x,2));
    next_x = x+0.05;
    next_y = a*(Math.pow(next_x,2));
    x=x+0.05;

  graphGeometry.vertices.push(
    new THREE.Vector3(x, next_y),
    new THREE.Vector3(next_x, next_y)
  );};
  graphLine = new THREE.Line(graphGeometry, material);
  scene.add(graphLine);
};

Help would be hugely appreciated.

JDCoder
  • 1
  • 1

1 Answers1

0

Figured out my own problem... quite simple as I thought: the value of 'x' is not getting reset in creategraph();. It is defined with variables at the top of the code as "var x = -20" (which is not visible in my post..). Therefore the 'second' rendering of the graph is starting at x = 20, instead of reverting back to the original x=-20.

JDCoder
  • 1
  • 1