Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.lgna.story.SpatialRelation;
import org.lgna.story.TurnDirection;
import org.lgna.story.implementation.JointImp;
import org.lgna.story.implementation.ProgramImp;
import org.lgna.story.resources.JointId;

import java.awt.event.MouseEvent;
Expand Down Expand Up @@ -180,7 +181,8 @@ private void performInitializeEvents() {
}

private OnscreenRenderTarget getOnscreenRenderTarget() {
return getImplementation().getProgram().getOnscreenRenderTarget();
ProgramImp program = getImplementation().getProgram();
return program == null ? null : program.getOnscreenRenderTarget();
}

public void jointSelected(JointSelectionSphere sphere, MouseEvent e) {
Expand All @@ -195,7 +197,10 @@ public void jointSelected(JointSelectionSphere sphere, MouseEvent e) {
public void addCustomDragAdapter() {
synchronized (dragListeners) {
poserAnimatorDragAdapter = new PoserAnimatorDragAdapter(this);
poserAnimatorDragAdapter.setAnimator(getImplementation().getProgram().getAnimator());
ProgramImp program = getImplementation().getProgram();
if (program != null) {
poserAnimatorDragAdapter.setAnimator(program.getAnimator());
}
poserAnimatorDragAdapter.setInteractionState(HandleStyle.ROTATION);
poserAnimatorDragAdapter.setTarget(model);
poserAnimatorDragAdapter.setOnscreenRenderTarget(getOnscreenRenderTarget());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.lgna.story.SSphere;
import org.lgna.story.implementation.CameraImp;
import org.lgna.story.implementation.EntityImp;
import org.lgna.story.implementation.ProgramImp;
import org.lgna.story.implementation.SceneImp;

import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -244,16 +245,18 @@ private JointSelectionSphere pickJoint(JointSelectionSphere one, JointSelectionS
}

private ManipulationHandle3D checkIfHandleSelected(MouseEvent e) {
SceneImp implementation = scene.getImplementation();
RenderTarget rt = implementation.getProgram().getOnscreenRenderTarget();
ProgramImp program = scene.getImplementation().getProgram();
if (program == null) {
return null;
}
RenderTarget rt = program.getOnscreenRenderTarget();
PickResult pickResult = rt.getSynchronousPicker().pickFrontMost(e.getPoint(), PickSubElementPolicy.NOT_REQUIRED);
if ((pickResult != null) && (pickResult.getVisual() != null)) {
Composite composite = pickResult.getVisual().getParent();
if (composite != null) {
if (composite.getParent() instanceof ManipulationHandle3D) {
return (ManipulationHandle3D) composite.getParent();
}
}
if ((pickResult == null) || (pickResult.getVisual() == null)) {
return null;
}
Composite composite = pickResult.getVisual().getParent();
if (composite != null && composite.getParent() instanceof ManipulationHandle3D) {
return (ManipulationHandle3D) composite.getParent();
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/story-api/src/main/java/org/lgna/story/SProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SScene getActiveScene() {

public void setActiveScene(SScene scene) {
if (this.activeScene != null) {
this.activeScene.getImplementation().deactivate(this.getImplementation());
this.activeScene.getImplementation().deactivate();
}
this.activeScene = scene;
if (this.activeScene != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,11 @@ public Animated getAnimated() {
}

public void strikePose(Pose<A> pose, double duration, Style style) {
this.getProgram().perform(new PoseAnimation(duration, style, this, pose), null);
ProgramImp program = getProgram();
if (program == null) {
return;
}
program.perform(new PoseAnimation(duration, style, this, pose), null);
}

private final A abstraction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* @author Dennis Cosgrove
*/
public class SceneImp extends EntityImp {
private static final Transformable createDirectionalLightTransformable(DirectionalLight sgDirectionalLight, Angle yaw, Angle pitch, float brightness) {
private static Transformable createDirectionalLightTransformable(DirectionalLight sgDirectionalLight, Angle yaw, Angle pitch, float brightness) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the removal of final here intentional? Just wondering since I don't see the method being overridden anywhere in the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It is static, so final adds nothing.

Transformable rv = new Transformable();
rv.applyRotationAboutYAxis(yaw);
rv.applyRotationAboutXAxis(pitch);
Expand Down Expand Up @@ -128,24 +128,17 @@ private void fireSceneActivationListeners() {
this.eventManager.sceneActivated();
}

private void changeActiveStatus(ProgramImp programImp, boolean isActive, int activationCount) {
double prevSimulationSpeedFactor = program.getSimulationSpeedFactor();
program.setSimulationSpeedFactor(Double.POSITIVE_INFINITY);
private void changeActiveStatus(boolean isActive) {
double prevSimulationSpeedFactor = 0;
if (program != null) {
prevSimulationSpeedFactor = program.getSimulationSpeedFactor();
program.setSimulationSpeedFactor(Double.POSITIVE_INFINITY);
}
if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) {
this.getAbstraction().handleActiveChanged(isActive, activationCount);
this.getAbstraction().handleActiveChanged(isActive, activeCount);
}
program.setSimulationSpeedFactor(prevSimulationSpeedFactor);
if (isActive) {
//This forces the scene to initialize itself to make sure we can properly query bounding boxes and other render dependent things
//All this info is critical to a scene running
AdapterFactory.getAdapterFor(this.sgScene);

this.addCamerasTo(programImp);
if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) {
this.fireSceneActivationListeners();
}
} else {
this.removeCamerasFrom(programImp);
if (program != null) {
program.setSimulationSpeedFactor(prevSimulationSpeedFactor);
}
}

Expand All @@ -156,20 +149,49 @@ public void activate(ProgramImp programImp) {
if (this.isGlobalLightBrightnessAnimationDesired) {
this.setGlobalBrightness(0.0f);
}
this.changeActiveStatus(program, true, activeCount);
this.changeActiveStatus(true);
initializeScene();
if (this.isGlobalLightBrightnessAnimationDesired) {
this.animateGlobalBrightness(1.0f, 0.5, TraditionalStyle.BEGIN_AND_END_GENTLY);
}
}

public void deactivate(ProgramImp programImp) {
private void setProgram(ProgramImp newImp) {
if (newImp.equals(this.program)) {
//no change
return;
}
if (program != null) {
eventManager.removeListenersFrom(program.getOnscreenRenderTarget());
}
this.program = newImp;
eventManager.addListenersTo(program.getOnscreenRenderTarget());
}

private void initializeScene() {
//This forces the scene to initialize itself to make sure we can properly query bounding boxes and other render dependent things
//All this info is critical to a scene running
AdapterFactory.getAdapterFor(this.sgScene);

this.addCamerasTo(program);
if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) {
this.fireSceneActivationListeners();
}
}

public void deactivate() {
deactiveCount++;
assert deactiveCount == activeCount;
if (this.isGlobalLightBrightnessAnimationDesired) {
this.animateGlobalBrightness(0.0f, 0.25, TraditionalStyle.BEGIN_AND_END_GENTLY);
}
this.changeActiveStatus(programImp, false, activeCount);
this.setProgram(null);
this.changeActiveStatus(false);
if (program == null) {
return;
}
this.removeCamerasFrom(program);
eventManager.removeListenersFrom(program.getOnscreenRenderTarget());
program = null;
}

@Override
Expand All @@ -192,41 +214,6 @@ public ProgramImp getProgram() {
return this.program;
}

public void setProgram(ProgramImp program) {
if (this.program != program) {
if (this.program != null) {
this.eventManager.removeListenersFrom(this.program.getOnscreenRenderTarget());
}
this.program = program;
if (program != null) {
this.eventManager.addListenersTo(program.getOnscreenRenderTarget());
}
}
this.program = program;
}

//todo
// private static class Capsule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no! My favorite class is going away!

// private final TransformableImp transformable;
// private EntityImp vehicle;
// private edu.cmu.cs.dennisc.math.AffineMatrix4x4 localTransformation;
//
// public Capsule( TransformableImp transformable ) {
// this.transformable = transformable;
// }
//
// public void preserve() {
// this.vehicle = this.transformable.getVehicle();
// this.localTransformation = this.transformable.getSgComposite().getLocalTransformation();
// }
//
// public void restore() {
// this.transformable.setVehicle( this.vehicle );
// this.transformable.getSgComposite().setLocalTransformation( this.localTransformation );
// }
// }
// private final java.util.List<Capsule> capsules = edu.cmu.cs.dennisc.java.util.Lists.newCopyOnWriteArrayList();

public void preserveStateAndEventListeners() {
this.eventManager.silenceAllListeners();
//todo: preserve state
Expand All @@ -237,7 +224,7 @@ public void restoreStateAndEventListeners() {
this.eventManager.restoreAllListeners();
}

public void addCamerasTo(ProgramImp program) {
private void addCamerasTo(ProgramImp program) {
for (AbstractCamera sgCamera : VisitUtilities.getAll(this.sgScene, AbstractCamera.class)) {
EntityImp entityImp = EntityImp.getInstance(sgCamera);
if (entityImp instanceof CameraImp cameraImp) {
Expand All @@ -246,7 +233,7 @@ public void addCamerasTo(ProgramImp program) {
}
}

public void removeCamerasFrom(ProgramImp program) {
private void removeCamerasFrom(ProgramImp program) {
for (AbstractCamera sgCamera : VisitUtilities.getAll(this.sgScene, AbstractCamera.class)) {
EntityImp entityImp = EntityImp.getInstance(sgCamera);
if (entityImp instanceof CameraImp cameraImp) {
Expand All @@ -260,11 +247,11 @@ public CameraImp findFirstCamera() {
return (CameraImp) EntityImp.getInstance(sgCamera);
}

public void setGlobalBrightness(float globalBrightness) {
private void setGlobalBrightness(float globalBrightness) {
this.sgScene.globalBrightness.setValue(globalBrightness);
}

public void animateGlobalBrightness(float globalBrightness, double duration, Style style) {
private void animateGlobalBrightness(float globalBrightness, double duration, Style style) {
duration = adjustDurationIfNecessary(duration);
if (EpsilonUtilities.isWithinReasonableEpsilon(duration, RIGHT_NOW)) {
this.setGlobalBrightness(globalBrightness);
Expand Down Expand Up @@ -296,7 +283,7 @@ public EventManager getEventManager() {
private int activeCount;
private int deactiveCount;

private boolean isGlobalLightBrightnessAnimationDesired = true;
private final boolean isGlobalLightBrightnessAnimationDesired = true;

private final Scene sgScene = new Scene();
private final Background sgBackground = new Background();
Expand Down Expand Up @@ -346,17 +333,6 @@ protected void handleSetValue(Color value) {
SceneImp.this.sgFromBelowDirectionalLight.color.setValue(value.toColor4f());
}
};
public final FloatProperty globalLightBrightness = new FloatProperty(SceneImp.this) {
@Override
public Float getValue() {
return SceneImp.this.sgScene.globalBrightness.getValue();
}

@Override
protected void handleSetValue(Float value) {
SceneImp.this.sgScene.globalBrightness.setValue(value);
}
};

private static class FogDensityProperty extends FloatProperty {
public FogDensityProperty(SceneImp owner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.lgna.story.SThing;
import org.lgna.story.Visual;
import org.lgna.story.event.*;
import org.lgna.story.implementation.ProgramImp;
import org.lgna.story.implementation.SceneImp;

import java.awt.*;
Expand Down Expand Up @@ -237,12 +238,15 @@ public void sceneActivated() {
public void addDragAdapter(Visual[] visuals) {
if (this.dragAdapter == null) {
this.dragAdapter = new RuntimeDragAdapter(visuals);
OnscreenRenderTarget renderTarget = this.scene.getProgram().getOnscreenRenderTarget();
ProgramImp program = scene.getProgram();
if (program == null) {
return;
}
SymmetricPerspectiveCamera camera = (SymmetricPerspectiveCamera) scene.findFirstCamera().getSgCamera();
this.dragAdapter.setOnscreenRenderTarget(renderTarget);
this.dragAdapter.setOnscreenRenderTarget(program.getOnscreenRenderTarget());
this.dragAdapter.addCameraView(CameraView.MAIN, camera);
this.dragAdapter.makeCameraActive(camera);
this.dragAdapter.setAnimator(this.scene.getProgram().getAnimator());
this.dragAdapter.setAnimator(program.getAnimator());
} else {
dragAdapter.addTargets(visuals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.lgna.story.SThing;
import org.lgna.story.implementation.CameraImp;
import org.lgna.story.implementation.EntityImp;
import org.lgna.story.implementation.ProgramImp;

import java.awt.Dimension;
import java.awt.Point;
Expand All @@ -65,12 +66,14 @@ public static boolean isThisInView(SThing entity, CameraImp camera) {
for (int i = 0; i < points.length; ++i) {
awtPoints[i] = implementation.transformToAwt(points[i], camera);
}
camera.getScene().getProgram().getOnscreenRenderTarget();
return isInView(camera, awtPoints, relativeToCamera);
ProgramImp program = camera.getScene().getProgram();
if (program == null) {
return false;
}
return isInView(program.getOnscreenRenderTarget().getSurfaceSize(), awtPoints, relativeToCamera);
}

private static boolean isInView(CameraImp camera, Point[] awtPoints, Point3[] relativeToCamera) {
Dimension surfaceSize = camera.getScene().getProgram().getOnscreenRenderTarget().getSurfaceSize();
private static boolean isInView(Dimension surfaceSize, Point[] awtPoints, Point3[] relativeToCamera) {
boolean leftOf = false;
boolean rightOf = false;
boolean above = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import edu.cmu.cs.dennisc.render.gl.GlrRenderFactory;
import org.lgna.story.MultipleEventPolicy;
import org.lgna.story.event.*;
import org.lgna.story.implementation.ProgramImp;

import java.util.List;
import java.util.Map;
Expand All @@ -69,7 +70,11 @@ public class TimerEventHandler extends AbstractEventHandler<TimeListener, TimeEv
private final AutomaticDisplayListener automaticDisplayListener = new AutomaticDisplayListener() {
@Override
public void automaticDisplayCompleted(AutomaticDisplayEvent e) {
currentTime = scene.getProgram().getAnimator().getCurrentTime();
ProgramImp program = scene.getProgram();
if (program == null) {
return;
}
currentTime = program.getAnimator().getCurrentTime();
update();
}
};
Expand Down