Mercurial > hg > Members > tatsuki > Alice
changeset 378:ac3cf96f4426 multicast
add scooter object with CreateObject and AddObject
author | sugi |
---|---|
date | Mon, 09 Jun 2014 21:28:47 +0900 |
parents | ca093d55a886 |
children | b162da6aa0c2 |
files | src/main/java/alice/test/topology/aquarium/fx/AddObject.java src/main/java/alice/test/topology/aquarium/fx/Aquarium.java src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java src/main/java/alice/test/topology/aquarium/fx/CreateObject.java src/main/java/alice/test/topology/aquarium/fx/FishInfo.java |
diffstat | 5 files changed, 114 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/fx/AddObject.java Mon Jun 09 21:28:47 2014 +0900 @@ -0,0 +1,49 @@ +package alice.test.topology.aquarium.fx; + +import javafx.application.Platform; +import javafx.collections.ObservableList; +import javafx.scene.Group; +import javafx.scene.Node; +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class AddObject extends CodeSegment { + // add Object on javaFx Scene + private Receiver info = ids.create(CommandType.TAKE); // ObservableList instance. + private Receiver info1 = ids.create(CommandType.TAKE); + private Receiver info2 = ids.create(CommandType.TAKE); + private boolean executed = false; + + public AddObject(){ + info.setKey("objList"); + info1.setKey("addOffer"); + info2.setKey("root"); + } + + @Override + public void run() { + if (!executed) { + executed = true; + // javafx's Scene can be accessed only FX application thread. + Platform.runLater(this); + } else { + boolean duplication = false; + Node obj = info1.asClass(Node.class); + Group obj1 = info2.asClass(Group.class); + obj1.getChildren().add(obj); + System.out.println(obj.getId()); + ObservableList<Node> objList = info.asClass(ObservableList.class); +// for (Node n : objList){ +// if (n.getId().equals(obj.getId())) +// duplication = true; +// } +// if (!duplication) { +// objList.add(obj); +// } + ods.flip(info1); + } + } + + +}
--- a/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java Mon Jun 09 20:15:46 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/Aquarium.java Mon Jun 09 21:28:47 2014 +0900 @@ -3,12 +3,7 @@ import java.io.IOException; import alice.codesegment.OutputDataSegment; -import com.interactivemesh.jfx.importer.obj.ObjModelImporter; - import javafx.application.Application; -import javafx.beans.binding.When; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.ObservableList; import javafx.event.EventHandler; import javafx.scene.Group; @@ -20,8 +15,6 @@ import javafx.scene.SubScene; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; -import javafx.scene.shape.DrawMode; -import javafx.scene.shape.MeshView; import javafx.scene.transform.Rotate; import javafx.scene.transform.Translate; import javafx.stage.Stage; @@ -46,7 +39,7 @@ } }); - addFishObject(); + //addFishObject(); ods.put("objList", objList); primaryStage.setScene(scene); primaryStage.show(); @@ -54,6 +47,7 @@ private Parent createContent(){ Group root = new Group(); + ods.put("root", root); objList = root.getChildren(); // Create and position camera @@ -74,27 +68,6 @@ return parent; } - private void addFishObject(){ - BooleanProperty showWireframe = new SimpleBooleanProperty(false); - ObjModelImporter objImporter = new ObjModelImporter(); - objImporter.read(getClass().getClassLoader().getResource("objects/Scooter-smgrps.obj")); - - MeshView[] dukeMesh = objImporter.getImport(); - objImporter.close(); - - Group fish = new Group(); - for (MeshView _dukeMesh : dukeMesh) { - fish.getChildren().addAll(_dukeMesh); - _dukeMesh.drawModeProperty().bind(new When(showWireframe).then(DrawMode.LINE).otherwise(DrawMode.FILL)); - } - fish.setScaleX(2); // twice size - fish.setScaleY(2); - fish.setScaleZ(2); - - new SetTranslate(myName+"Fish"); - ods.put(myName+"Fish", fish); - objList.add(fish); - } public static void main(String[] args) { launch(args);
--- a/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Mon Jun 09 20:15:46 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java Mon Jun 09 21:28:47 2014 +0900 @@ -23,9 +23,15 @@ // use view scope //String type = matcher.group(1); - //int num = new Integer(matcher.group(2)); + //int num = new Integer(matcher.group(2)); + + FishInfo fishInfo = new FishInfo(0,0,0); + fishInfo.setName(name); + fishInfo.setSize(2); + ods.put("fishData", fishInfo); new CreateObject(); + new AddObject(); String[] args = {name}; Aquarium.main(args); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/topology/aquarium/fx/CreateObject.java Mon Jun 09 21:28:47 2014 +0900 @@ -0,0 +1,50 @@ +package alice.test.topology.aquarium.fx; + +import javafx.beans.binding.When; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.scene.Group; +import javafx.scene.shape.DrawMode; +import javafx.scene.shape.MeshView; + +import com.interactivemesh.jfx.importer.obj.ObjModelImporter; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class CreateObject extends CodeSegment{ + + private Receiver info = ids.create(CommandType.TAKE); + + public CreateObject(){ + info.setKey("fishData"); + } + + @Override + public void run() { + FishInfo fishInfo = info.asClass(FishInfo.class); + + BooleanProperty showWireframe = new SimpleBooleanProperty(false); + ObjModelImporter objImporter = new ObjModelImporter(); + objImporter.read(getClass().getClassLoader().getResource("objects/Scooter-smgrps.obj")); + + MeshView[] dukeMesh = objImporter.getImport(); + objImporter.close(); + + Group obj = new Group(); + for (MeshView _dukeMesh : dukeMesh) { + obj.getChildren().addAll(_dukeMesh); + _dukeMesh.drawModeProperty().bind(new When(showWireframe).then(DrawMode.LINE).otherwise(DrawMode.FILL)); + } + obj.setScaleX(fishInfo.size); // twice size + obj.setScaleY(fishInfo.size); + obj.setScaleZ(fishInfo.size); + obj.setId(fishInfo.name); + + new SetTranslate(fishInfo.name+"Fish"); + ods.put("addOffer", obj); + } + + +}
--- a/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java Mon Jun 09 20:15:46 2014 +0900 +++ b/src/main/java/alice/test/topology/aquarium/fx/FishInfo.java Mon Jun 09 21:28:47 2014 +0900 @@ -9,6 +9,8 @@ public double y = 0; public double z = 0; public String name; + public int size = 1; + public String type = "defalut"; // use select object type. after implement may be... public FishInfo(double x,double y,double z){ this.x = x; @@ -20,6 +22,10 @@ this.name = name; } + public void setSize(int size){ + this.size = size; + } + public double getX(){ return this.x; }