package visualiser.layout;

import com.interactivemesh.jfx.importer.obj.ObjModelImporter;
import com.interactivemesh.jfx.importer.tds.TdsModelImporter;
import com.interactivemesh.jfx.importer.x3d.X3dModelImporter;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Shape3D;
import visualiser.Controllers.HostGameController;

import java.net.URL;

/**
 * Created by Gondr on 21/09/2017.
 */
public class Assets3D {

    public static MeshView[] sails;

    public static void loadAssets(){
        loadSails();
    }

    private static void loadSails(){
        sails = new MeshView[40];
        ObjModelImporter objModelImporter = new ObjModelImporter();

        for (int i = 0; i < sails.length; i++){
            String path = String.format("assets/Sails/V1.3 Sail_%06d.obj", i + 1);
            System.out.println(path);
            URL asset = Assets3D.class.getClassLoader().getResource(path);
            objModelImporter.read(asset);
            if (objModelImporter.getImport().length > 0) {
                sails[i] = objModelImporter.getImport()[0];
                /*sails[i].setRotationAxis(new Point3D(1, 0, 0));
                sails[i].setRotate(-90);*/
            }
        }
    }

    public static Shape3D getBoat(){
        X3dModelImporter x3dModelImporter = new X3dModelImporter();
        String path = "assets/V1.3 Complete Boat without Sail and Rotated.x3d";
        URL asset = Assets3D.class.getClassLoader().getResource(path);
        x3dModelImporter.read(asset);
        if (x3dModelImporter.getImport().length > 0) {
            //if (x3dModelImporter.getImport()[0] instanceof MeshView) {
            Group g = (Group)((Group)((Group) x3dModelImporter.getImport()[0]).getChildren().get(0)).getChildren().get(0);
            Shape3D boat = (Shape3D)g.getChildren().get(0);
            return boat;
            /*} else {
                System.err.println("Boat is not a Mesh View 0.0");
            }*/
        }
        return null;
    }

}
