Normand Briere
2019-09-28 c3c47406ac43dafd51e6ad1d7b92a794bd69b7d6
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//import java.util.Vector;
 
class SwitchNode extends Object3D implements java.io.Serializable
{
    static final long serialVersionUID = 6330600721103324217L;
 
    Object3D switchobject;
    Object3D parent; // erreur!!
    
    int mask;
    
    SwitchNode(Object3D object, int mask)
    {
        this.switchobject = object;
        this.mask = mask;
        
        name = "Switch:" + switchobject.name; // + mask;
        
        if (switchobject.get(0).bRep != null) // june 2014
        {
            CreateMaterial();
            switchobject.get(0).bRep.SaveSupports();
            bRep = (BoundaryRep) Grafreed.clone(switchobject.get(0).bRep);
            switchobject.get(0).bRep.RestoreSupports();
        }
        
        for (int i=0; i<switchobject.get(0).size(); i++)
        {
            Object3D duplicate = switchobject.get(0).get(i);
            Object3D par = duplicate.parent;
            duplicate.parent = null;
            duplicate.SaveSupports();
            addChild((Object3D)Grafreed.clone(duplicate));
            duplicate.parent = par;
            duplicate.RestoreSupports();
        }
        
        child = 0;
        
        if (switchobject.count > 1)
            switchobject.count = 1; // hide
    }
    
    //transient boolean restarted;
    transient int countspeed;
 
    transient boolean toggleneutral;
    
    void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
    {
        //System.err.println("Frame # " + frame);
        
        if (switchobject == null)
        {
            // grosse patch!!
            switchobject = parent;
            parent = super.parent;
            
        }
        if (live && Globals.isLIVE() && display.DrawMode() == display.SHADOW)
        {
            if (countspeed <= 0)
            {
                countspeed = speed;
                
                if (toggleneutral || !link2master)
                {
                    do
                    {
                        if (random)
                            child = (int)(Math.random() * switchobject.Size());
                        else
                        {
                            child++;
                            child %= switchobject.Size();
                        }
                    }
                    while(switchobject.get(child).hide);
                }
                else
                {
                    child = 0; // jump to neutral
                    
                    if (Math.random() < 0.5 && name.contains("Faces") && switchobject.Size() > 16)
                    {
                        child = 16; // blink eyes
                        countspeed /= 2;
                    }
                }
                
                toggleneutral ^= true;
                
            }
            else
            {
                if (CameraPane.FAST)
                    countspeed -= CameraPane.STEP;
                else
                    countspeed--;
            }
        }
        
        if (bRep == null)
        {
            // The switch mesh will be used to interpolate poaes (maybe).
            bRep = (BoundaryRep)Grafreed.clone(switchobject.get(0).bRep);
        }
        
        if (CameraPane.SUPPORT && display.DrawMode() == display.SHADOW)
        {
            Update();
        }
        
        super.DrawNode(display, root, selected);
    }
 
    void Update()
    {
        if (mask == 0)
            mask = Object3D.GEOMETRY;
        
        if (mask == Object3D.GEOMETRY)
            switchobject.get(child).resetMaster(false); // for mocap
        
        overwriteThis(switchobject.get(child), mask);
    }
    
    // for slider
    int getNumFrames()
    {
        return switchobject.Size();
    }
    
    Object3D deepCopy()
    {
        SwitchNode e = new SwitchNode(switchobject, mask);
        deepCopySelf(e);
        return e;
    }
 
    protected void deepCopyNode(Object3D other)
    {
        super.deepCopyNode(other);
        SwitchNode bp = (SwitchNode)other;
        bp.child = child;
    }
    
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
        //editWindow = (new SphereEditor(this, deepCopy(), callee)).GetEditor();
        if (newWindow)
        {
            objectUI = new SwitchEditor(this, deepCopy(), callee);
        } else
        {
            objectUI = new SwitchEditor(this, callee);
        }
        editWindow = objectUI.GetEditor();
    }
 
    void Reset()
    {
        child = 0;
    }
    
    void Step()
    {
        child += 1;
        child %= switchobject.Size();
    }
    
    int child;
    int speed;
}