Normand Briere
2019-09-17 54adfcbf93eb477bedeec45409f36cf7e102b790
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
/**
 * Make a donation http://sourceforge.net/donate/index.php?group_id=98797
 * Microcrowd
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * Contact Josh DeFord jdeford@microcrowd.com
 */
 
package com.microcrowd.loader.java3d.max3ds.chunks;
 
import javax.media.j3d.Transform3D;
import javax.vecmath.Point3f;
import com.microcrowd.loader.java3d.max3ds.ChunkChopper;
 
/**
 * Extracts the local coordinate that will act 
 * as a shape's axis that will be used by the mesh 
 * info chunk.
 */
public class AxisChunk extends Chunk
{
    private float value;
 
    /**
     * Loads the local coordinate system for the current mesh.
     *
     * @param chopper the ChunkChopper containing the state of the parser. 
     *
     * The location of the local coordinate system is defined relative to 
     * positions and rotations at frame 0.  But the orientation is absolutely
     * defined.
     *
     * With either 3x3 or 4x4 rotation, translation, there
     * is a simple relationship between each matrix and the resulting coordinate
     * system. The first three columns of the matrix define the direction vector of the
     * X, Y and Z axii respectively.
     * If a 4x4 matrix is defined as:
     * <code>
     *     | A B C D |
     * M = | E F G H |
     *     | I J K L |
     *     | M N O P |
     * </code>
     * Then the direction vector for each axis is as follows:
     *
     * <code>
     * X-axis = [ A E I ]
     * Y-axis = [ B F J ]
     * Z-axis = [ C G K ]
     * </code>
     *
     * @return the actual number of bytes read.  
     */
    public void loadData(ChunkChopper chopper)
    {
        Point3f xAxis  = new Point3f();
        xAxis  = chopper.getPoint();
        Point3f zAxis  = chopper.getPoint();
        Point3f yAxis  = chopper.getPoint();
        Point3f origin = chopper.getPoint();
 
        Transform3D transform = new Transform3D(new double[]{
            xAxis.x,  xAxis.y,  xAxis.z, origin.x, 
            yAxis.x,  yAxis.y,  yAxis.z, origin.y,  
            -zAxis.x,  -zAxis.y,  -zAxis.z, origin.z,
            0,0,0,1});
        String meshName = chopper.getObjectName();
        chopper.getKeyFramer().setCoordinateSystem(meshName, transform);
    }
}