简体   繁体   中英

JME: Import a Cinema 4d Model with texture to jMonkey Projekt

my problem is:

i have made a 3D model with texture in Cinema 4d ( similiar to this one : http://preview.turbosquid.com/Preview/2011/03/30__13_54_17/space%20shuttle%206.jpgeec17db2-6651-453c-9d27-ea1908e3c7dfLarge.jpg )

Now i want to export it to my jMonkeyEngine to set it up in my scene and to animate it.

I tried to export my model as a .obj-file and load it into my projekt (just the .obj-file).

The result is that i have no textures! What do i wrong?

 package mygame;


import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**
 * test
 * @author normenhansen
 */
public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {

        //Modell laden
        Spatial spaceShuttle =assetManager.loadModel("Models/test/space.obj");


        //Skalieren
        spaceShuttle.scale(0.005f, 0.005f, 0.005f);


        //Szenenbaum erstellen
        Node sceneNode = new Node("sceneNode");
        Node geometryNode = new Node("geometryNode");
        Node lightNode = new Node("lightNode");

        sceneNode.attachChild(lightNode);
        sceneNode.attachChild(geometryNode);
        rootNode.attachChild(sceneNode);   

        //neue Elemente in den Baum Einfügen
        geometryNode.attachChild(spaceShuttle);

        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
        sun.setColor(ColorRGBA.White);
        rootNode.addLight(sun);


    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}

You're not doing anything wrong. C4D exports just the .obj, but no .mtl by default. I know that's true for C4D R11.5 and R12, not sure about newer ones.

You'll can write a script to export the .mtl as well. Here's a Python snippet for reference:

#save mtl
mcount = 0;
mtl = ''
for tag in op.GetTags():  
    if(tag.GetType() == 5616): #texture tag
       mcount += 1
       m = tag.GetMaterial()
       mtl += 'newmtl '+clean(m.GetName())+'\n'
       if(m[sy.MATERIAL_COLOR_COLOR]):   mtl += 'Kd ' + str(m[sy.MATERIAL_COLOR_COLOR].x) + ' ' + str(m[sy.MATERIAL_COLOR_COLOR].y) + ' ' + str(m[sy.MATERIAL_COLOR_COLOR].z) + '\n'
       if(m[sy.MATERIAL_SPECULAR_COLOR]):    mtl += 'Ks ' + str(m[sy.MATERIAL_SPECULAR_COLOR].x) + ' ' + str(m[sy.MATERIAL_SPECULAR_COLOR].y) + ' ' + str(m[sy.MATERIAL_SPECULAR_COLOR].z) + '\n'
       if(m[sy.MATERIAL_SPECULAR_BRIGHTNESS]):   mtl += 'Ns ' + str(m[sy.MATERIAL_SPECULAR_BRIGHTNESS]) + '\n'
       if(m[sy.MATERIAL_TRANSPARENCY_BRIGHTNESS]):   mtl += 'd ' + str(m[sy.MATERIAL_TRANSPARENCY_BRIGHTNESS]) + '\n'
       if(m[sy.MATERIAL_COLOR_SHADER]):  mtl += 'map_Kd ' + str(m[sy.MATERIAL_COLOR_SHADER][sy.BITMAPSHADER_FILENAME]) + '\n'
       if(m[sy.MATERIAL_TRANSPARENCY_SHADER]):   mtl += 'map_d ' + str(m[sy.MATERIAL_COLOR_SHADER][sy.BITMAPSHADER_FILENAME]) + '\n'
       if(m[sy.MATERIAL_BUMP_SHADER]):   mtl += 'map_bump ' + str(m[sy.MATERIAL_BUMP_SHADER][sy.BITMAPSHADER_FILENAME]) + '\n'
       mtl += 'illum 0\n\n\n'#TODO: setup the illumination, ambient and optical density
mtl = '# Material Count: '+str(mcount)+'\n'+mtl
file = open(mtlPath,'w')
file.write(mtl)
file.close()

It's part of this old script , but note this is with the old R11.5 C4D Python API, the syntax is a bit different now, so use updated documentation and the above more as a general direction on what properties to look for.

A 'codeless' alternative is to bring your model into a different 3D package which properly exports .obj (and .mtl) like Blender for example. You will need to find an intermediary format that will preserve the material data (you can try 3DS,Collada, FBX I think) but be aware of the difference in units and coordinate systems. Hopefully the model features you need are preserved in the file format you export from C4D and properly imported back into the other 3D package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM