Normand Briere
2019-08-28 547c9203ab5d8e4bee36d1cbb453dfa36bbec4ef
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
//import java.util.Vector;
 
class MorphNode extends Object3D implements java.io.Serializable
{
    static final long serialVersionUID = 0;
 
    Object3D morphobject;
    
// MORPH weights
    double[] morphweights;
    
    MorphNode(Object3D object)
    {
        this.morphobject = object;
        
        name = "Mo:" + morphobject.name;
        
        if (morphobject.get(0).bRep != null) // june 2014
        {
            CreateMaterial();
            morphobject.get(0).bRep.SaveSupports();
            bRep = (BoundaryRep) Grafreed.clone(morphobject.get(0).bRep);
            morphobject.get(0).bRep.RestoreSupports();
        }
        
        for (int i=0; i<morphobject.get(0).size(); i++)
        {
            Object3D duplicate = morphobject.get(0).get(i);
            Object3D par = duplicate.parent;
            duplicate.parent = null;
            Object3D sup = duplicate.support;
            duplicate.support = null;
            addChild((Object3D)Grafreed.clone(duplicate));
            duplicate.parent = par;
            duplicate.support = sup;
        }
        
        morphweights = new double[morphobject.Size()];
        morphweights[0] = 1;
        
        if (morphobject.count > 1)
            morphobject.count = 1; // hide
    }
    
    void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
    {
        //System.err.println("Frame # " + frame);
        
//        if (morphobject == null)
//        {
//            // grosse patch!!
//            morphobject = parent;
//            parent = super.parent;
//            
//        }
        
//        if (bRep == null)
//        {
//            bRep = (BoundaryRep) GrafreeD.clone(morphobject.get(0).bRep);
//        }
        
        if (CameraPane.SUPPORT && display.DrawMode() == display.SHADOW)
        {
            for (int i=0; i<morphobject.Size(); i++)
            {
                if (i == 0 || morphweights[i] != 0)
                    morphobject.get(i).resetMaster(false); // for mocap
            }
            
//            if (bRep != null)
//            {
//                morphobject.resetMaster(false);
//            }
 
            for (int i=0; i<Size(); i++)
            {
                get(i).morphThis(morphobject, i, morphweights);
            }
            
            if (bRep != null)
            {
                morphThis(morphobject, -1, morphweights);
            }
        }
            
        super.DrawNode(display, root, selected);
    }
    
//    void ExtractGeometries()
//    {
//        Object3D o = new Object3D("Geometry:" + this.name);
//        o.bRep = bRep;
//        o.CreateMaterial();
//        parent.addChild(o);
//    }
    
    // for slider
    int getNumFrames()
    {
        return morphobject.Size();
    }
    
    Object3D deepCopy()
    {
        MorphNode e = new MorphNode(morphobject);
        deepCopySelf(e);
        return e;
    }
 
    protected void deepCopySelf(Object3D other)
    {
        super.deepCopySelf(other);
        MorphNode bp = (MorphNode)other;
        
        bp.morphweights = (double[]) Grafreed.clone(morphweights);
    }
    
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
        //editWindow = (new SphereEditor(this, deepCopy(), callee)).GetEditor();
        if (newWindow)
        {
            objectUI = new MorphEditor(this, deepCopy(), callee);
        } else
        {
            objectUI = new MorphEditor(this, callee);
        }
        editWindow = objectUI.GetEditor();
    }
}