Skip to content

Commit

Permalink
issue-38: stop timeline and release model when it is detached from th…
Browse files Browse the repository at this point in the history
…e scene
  • Loading branch information
jperedadnr committed Nov 3, 2018
1 parent db9af5e commit 41385e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Expand Up @@ -67,11 +67,17 @@ protected void createMesh() {
Pair<Node,Timeline> content = Importer3D.loadIncludingAnimation(ImportMaya.class.getResource("/org/fxyz3d/importers/King_WalkCycle.ma").toExternalForm(),
asPolygonMesh);
model = content.getKey();

Timeline timeline = content.getValue();
if (timeline != null) {
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();

model.sceneProperty().addListener((obs, ov, nv) -> {
if (nv == null) {
timeline.stop();
}
});
}
} catch (IOException ex) {
Logger.getLogger(ImportMaya.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
Expand Up @@ -31,6 +31,8 @@

import java.text.NumberFormat;
import java.util.concurrent.CountDownLatch;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
Expand Down Expand Up @@ -119,13 +121,11 @@ public abstract class ShapeBaseSample<T extends Node> extends FXyzSample {
private ProgressBar progressBar;
private long time;

private final BooleanProperty isActive = new SimpleBooleanProperty(this, "activeSample", false);
protected final BooleanProperty useSkybox = new SimpleBooleanProperty(this, "SkyBox Enabled", false);
private final BooleanProperty isPicking = new SimpleBooleanProperty(this, "isPicking");
protected final Property<DrawMode> drawMode = new SimpleObjectProperty<>(model, "drawMode", DrawMode.FILL);
protected final Property<CullFace> culling = new SimpleObjectProperty<>(model, "culling", CullFace.BACK);

private final CountDownLatch latch = new CountDownLatch(1);
private final NumberFormat numberFormat = NumberFormat.getInstance();

private Vec3d vecIni, vecPos;
Expand Down Expand Up @@ -425,6 +425,18 @@ protected void succeeded() {
}

if (model != null) {
// remove old model when it is detached from the scene
model.sceneProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
if (model.getScene() == null) {
model.sceneProperty().removeListener(this);
releaseBinders();
group.getChildren().remove(model);
model = null;
}
}
});
group.getChildren().add(model);
} else {
throw new UnsupportedOperationException("Model returned Null ... ");
Expand Down Expand Up @@ -492,16 +504,6 @@ public Node getSample() {
progressBar.setProgress(-1);
mainPane.getChildren().add(progressBar);

parentPane.parentProperty().addListener(l->{
if(parentPane.getScene() != null){
if(model != null){
attachBinders();
}
}else{
releaseBinders();
}
});

return parentPane;
}

Expand Down

0 comments on commit 41385e3

Please sign in to comment.