3D技術研究所Wiki > 公開物 > JFBXSDK > JFBXSDK Getting Started

FBX SDK Programmer's Guide > Getting Started > Your First FBX SDK Program
JFBXSDKを使ってC++コードをJavaコードへ置き換えます。

ドキュメントはこちらです。 http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/

目次


ソースコード

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
import net.npe.fbx.FbxDouble3;
import net.npe.fbx.FbxIOSettings;
import net.npe.fbx.FbxImporter;
import net.npe.fbx.FbxManager;
import net.npe.fbx.FbxNode;
import net.npe.fbx.FbxNodeAttribute;
import net.npe.fbx.FbxScene;

import static net.npe.fbx.Statics.IOSROOT;

public class FBXNodeTest {
    
    static {
        System.loadLibrary("jfbxsdk");
    }
    
    /**
     * Main function - loads the hard-coded fbx file,
     * and prints its contents in an xml format to stdout.
     */
    public static void main(String [] args) {
        
        // Change the following filename to a suitable filename value.
        String filename = "E:/data/fbx/cube.fbx";
        
        // Initialize the SDK manager. This object handles all our memory management.
        FbxManager manager = FbxManager.create();
        
        // Create the IO settings object.
        FbxIOSettings ios = FbxIOSettings.create(manager, IOSROOT);
        manager.setIOSettings(ios);
        
        // Create an importer using the SDK manager.
        FbxImporter importer = FbxImporter.create(manager, "");

        // Use the first argument as the filename for the importer.
        if(!importer.initialize(filename, -1, manager.getIOSettings())) {
            System.out.println("Call to FbxImporter.initialize() failed.");
            System.out.println("Error returned: "+importer.getStatus().getErrorString());
            System.exit(-1);
        }
        
        // Create a new scene so that it can be populated by the imported file.
        FbxScene scene = FbxScene.create(manager, "myScene");
        
        // Import the contents of the file into the scene.
        importer.imports(scene);
        
        // The file is imported; so get rid of the importer.
        importer.destroy();
        
        // Print the nodes of the scene and their attributes recursively.
        // Note that we are not printing the root node because it should
        // not contain any attributes.
        FbxNode rootNode = scene.getRootNode();
        printNode(rootNode);
        
        // Destroy the SDK manager and all the other objects it was handling.
        manager.destroy();
        
    }
    
    /**
     * Print a node, its attributes, and all its children recursively.
     */
    private static void printNode(FbxNode node) {
        
        printTabs();
        
        String nodeName = node.getName();
        FbxDouble3 translation = node.getLclTranslation().get();
        FbxDouble3 rotation = node.getLclRotation().get();
        FbxDouble3 scaling = node.getLclScaling().get();
        
        // Print the contents of the node.
        System.out.println(
            "<node "+
                "name='"+nodeName+"' "+
                "translation='("+translation.at(0)+", "+translation.at(1)+", "+translation.at(2)+")' "+
                "rotation='("+rotation.at(0)+", "+rotation.at(1)+", "+rotation.at(2)+")' "+
                "scaling='("+scaling.at(0)+", "+scaling.at(1)+", "+scaling.at(2)+")'"+
            ">"
        );
        
        numTabs++;
        
        // Print the node's attributes.
        for(int i=0; i<node.getNodeAttributeCount(); i++) {
            printAttribute(node.getNodeAttributeByIndex(i));
        }
        
        // Recursively print the children.
        for(int i=0; i<node.getChildCount(); i++) {
            printNode(node.getChild(i));
        }
        
        numTabs--;
        printTabs();
        System.out.println("</node>");
    }
    
    /**
     * Print an attribute.
     */
    private static void printAttribute(FbxNodeAttribute attribute) {
        
        String typeName = getAttributeTypeName(attribute.getAttributeType());
        String attrName = attribute.getName();
        printTabs();
        
        System.out.println("<attribute type='"+typeName+"' name='"+attrName+"'/>");
        
    }
    
    /**
     * Return a string-based representation based on the attribute type.
     */
    private static String getAttributeTypeName(FbxNodeAttribute.Type type) {
        switch(type) {
        case UNKNOWN: return "unknown";
        case NULL: return "null";
        case MARKER: return "marker";
        case SKELETON: return "skeleton";
        case MESH: return "mesh";
        case NURBS: return "nurbs";
        case PATCH: return "patch";
        case CAMERA: return "camera";
        case CAMERA_STEREO: return "camera stereo";
        case CAMERA_SWITCHER: return "camera switcher";
        case LIGHT: return "light";
        case OPTICAL_REFERENCE: return "optical reference";
        case OPTICAL_MARKER: return "optical marker";
        case NURBS_CURVE: return "nurbs curve";
        case TRIM_NURBS_SURFACE: return "trim nurbs surface";
        case BOUNDARY: return "boundary";
        case NURBS_SURFACE: return "nurbs surface";
        case SHAPE: return "shape";
        case LOD_GROUP: return "lodgroup";
        case SUB_DIV: return "subdiv";
        case CACHED_EFFECT: return "cached effect";
        case LINE: return "line";
        default: return "unidentified";
        }
    }
    
    /**
     * Print the required number of tabs.
     */
    private static void printTabs() {
        for(int i=0; i<numTabs; i++) {
            System.out.print("\t");
        }
    }
    
    /* Tab character ("\t") counter */
    private static int numTabs = 0;

}

実行結果

成功時

1
2
3
4
5
<node name='RootNode' translation='(0.0, 0.0, 0.0)' rotation='(0.0, 0.0, 0.0)' scaling='(1.0, 1.0, 1.0)'>
    <node name='cube' translation='(0.0, 0.0, 0.0)' rotation='(0.0, 0.0, 0.0)' scaling='(1.0, 1.0, 1.0)'>
        <attribute type='mesh' name=''/>
    </node>
</node>

インポート失敗時

1
2
Call to FbxImporter.initialize() failed.
Error returned: Unexpected file type


関連ページ


スポンサードリンク

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS