OSDN Git Service

Merge branch 'mmdwork2' into work3
[mikumikustudio/MikuMikuStudio.git] / engine / src / mmd / projectkyoto / jme3 / mmd / JointConverter.java
1 /*
2  * Copyright (c) 2011 Kazuhiko Kobayashi All rights reserved. <p/>
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5  * 
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer. <p/> *
8  * Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution. <p/> * Neither the
11  * name of 'MMDLoaderJME' nor the names of its contributors may be used to
12  * endorse or promote products derived from this software without specific
13  * prior written permission. <p/> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
14  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 package projectkyoto.jme3.mmd;
26
27 import com.jme3.asset.AssetManager;
28 import com.jme3.material.Material;
29 import com.jme3.math.ColorRGBA;
30 import com.jme3.math.Vector3f;
31 import com.jme3.renderer.queue.RenderQueue.Bucket;
32 import com.jme3.scene.Geometry;
33 import com.jme3.scene.Mesh;
34 import com.jme3.scene.Node;
35 import com.jme3.scene.shape.Line;
36 import projectkyoto.mmd.file.PMDJoint;
37 import projectkyoto.mmd.file.PMDModel;
38
39 /**
40  *
41  * @author kobayasi
42  */
43 public class JointConverter {
44
45     PMDModel model;
46     Node node;
47     AssetManager assetManager;
48
49     public JointConverter(PMDModel model, AssetManager assetManager) {
50         this.model = model;
51         this.assetManager = assetManager;
52     }
53
54     public Node convert(String nodeName) {
55         node = new Node(nodeName);
56         for (PMDJoint joint : model.getJointList().getJointArray()) {
57             createJointGeom(joint);
58         }
59         return node;
60     }
61
62     public void createJointGeom(PMDJoint joint) {
63         Geometry geom = new Geometry(joint.getJointName());
64         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
65         Mesh mesh;
66         mesh = new Line(Vector3f.ZERO, Vector3f.ZERO);
67         mat.setColor("Color", ColorRGBA.White);
68         geom.setMesh(mesh);
69         geom.setMaterial(mat);
70 //        mat.getAdditionalRenderState().setWireframe(true);
71         mat.getAdditionalRenderState().setDepthTest(false);
72
73         geom.setQueueBucket(Bucket.Transparent);
74
75         node.attachChild(geom);
76     }
77 }