159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * To change this template, choose Tools | Templates 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * and open the template in the editor. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.scene; 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Transform; 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SimpleBatchNode comes with some restrictions, but can yield better performances. 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Geometries to be batched has to be attached directly to the BatchNode 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * You can't attach a Node to a SimpleBatchNode 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SimpleBatchNode is recommended when you have a large number of geometries using the same material that does not require a complex scene graph structure. 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @see BatchNode 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author Nehon 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class SimpleBatchNode extends BatchNode { 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public SimpleBatchNode() { 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super(); 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public SimpleBatchNode(String name) { 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super(name); 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public int attachChild(Spatial child) { 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (!(child instanceof Geometry)) { 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta throw new UnsupportedOperationException("BatchNode is BatchMode.Simple only support child of type Geometry, use BatchMode.Complex to use a complex structure"); 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return super.attachChild(child); 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected void setTransformRefresh() { 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta refreshFlags |= RF_TRANSFORM; 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setBoundRefresh(); 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (Batch batch : batches.values()) { 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta batch.geometry.setTransformRefresh(); 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected Transform getTransforms(Geometry geom){ 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return geom.getLocalTransform(); 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void batch() { 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta doBatch(); 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 57