aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core/com/jme3/scene/SimpleBatchNode.java
blob: 0f1ed2939eb2aa96c134eb80f4ca8caed46fc724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jme3.scene;

import com.jme3.math.Transform;

/**
 * 
 * SimpleBatchNode  comes with some restrictions, but can yield better performances.
 * Geometries to be batched has to be attached directly to the BatchNode
 * You can't attach a Node to a SimpleBatchNode
 * SimpleBatchNode is recommended when you have a large number of geometries using the same material that does not require a complex scene graph structure.
 * @see BatchNode
 * @author Nehon
 */
public class SimpleBatchNode extends BatchNode {

    public SimpleBatchNode() {
        super();
    }

    public SimpleBatchNode(String name) {
        super(name);
    }

    @Override
    public int attachChild(Spatial child) {

        if (!(child instanceof Geometry)) {
            throw new UnsupportedOperationException("BatchNode is BatchMode.Simple only support child of type Geometry, use BatchMode.Complex to use a complex structure");
        }

        return super.attachChild(child);
    }

    @Override
    protected void setTransformRefresh() {

        refreshFlags |= RF_TRANSFORM;
        setBoundRefresh();
        for (Batch batch : batches.values()) {
            batch.geometry.setTransformRefresh();
        }
    }
    
     protected Transform getTransforms(Geometry geom){
        return geom.getLocalTransform();
    }

    @Override
    public void batch() {
        doBatch();
    }
}