Search in sources :

Example 1 with ComponentTypes

use of gaiasky.render.ComponentTypes in project gaiasky by langurmonkey.

the class SceneGraphNode method getChildrenByComponentType.

public Array<SceneGraphNode> getChildrenByComponentType(ComponentType ct, Array<SceneGraphNode> list) {
    if (children != null) {
        int size = children.size;
        for (int i = 0; i < size; i++) {
            SceneGraphNode child = children.get(i);
            ComponentTypes cct = child.getComponentType();
            if (cct != null && cct.isEnabled(ct))
                list.add(child);
            child.getChildrenByComponentType(ct, list);
        }
    }
    return list;
}
Also used : ComponentTypes(gaiasky.render.ComponentTypes)

Example 2 with ComponentTypes

use of gaiasky.render.ComponentTypes in project gaiasky by langurmonkey.

the class Particle method initialize.

@Override
public void initialize() {
    setDerivedAttributes();
    ct = new ComponentTypes(ComponentType.Galaxies);
    // Relation between our star size and actual star size (normalized for
    // the Sun, 695700 Km of radius
    radius = size * Constants.STAR_SIZE_FACTOR;
}
Also used : ComponentTypes(gaiasky.render.ComponentTypes)

Example 3 with ComponentTypes

use of gaiasky.render.ComponentTypes in project gaiasky by langurmonkey.

the class ConstelBoundariesLoader method loadData.

@Override
public Array<? extends SceneGraphNode> loadData() {
    Array<ConstellationBoundaries> boundaries = new Array<ConstellationBoundaries>();
    int n = 0;
    for (String f : files) {
        try {
            // load boundaries
            FileHandle file = Settings.settings.data.dataFileHandle(f);
            BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
            try {
                // Skip first line
                String line;
                ConstellationBoundaries boundary = new ConstellationBoundaries();
                boundary.ct = new ComponentTypes(ComponentType.Boundaries);
                List<List<Vector3d>> list = new ArrayList<>();
                List<Vector3d> buffer = new ArrayList<>(4);
                String lastName = "";
                int interp = 0;
                while ((line = br.readLine()) != null) {
                    if (!line.startsWith("#")) {
                        String[] tokens = line.split(separator);
                        String name = tokens[2];
                        String type = tokens.length > 3 ? tokens[3] : "O";
                        if (!name.equals(lastName)) {
                            // New line
                            list.add(buffer);
                            buffer = new ArrayList<>(20);
                            lastName = name;
                        }
                        if (type.equals("I")) {
                            interp++;
                        }
                        if ((type.equals("I") && LOAD_INTERPOLATED && interp % INTERPOLATED_MOD == 0) || type.equals("O")) {
                            // Load the data
                            double ra = Parser.parseDouble(tokens[0].trim()) * 15d;
                            double dec = Parser.parseDouble(tokens[1].trim());
                            double dist = 10 * Constants.AU_TO_U;
                            Vector3d point = Coordinates.sphericalToCartesian(Math.toRadians(ra), Math.toRadians(dec), dist, new Vector3d());
                            buffer.add(point);
                            n++;
                        }
                    }
                }
                list.add(buffer);
                boundary.setBoundaries(list);
                boundaries.add(boundary);
            } catch (IOException e) {
                Logger.getLogger(this.getClass()).error(e);
            }
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
    Logger.getLogger(this.getClass()).info(I18n.txt("notif.boundaries.init", n));
    return boundaries;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) ComponentTypes(gaiasky.render.ComponentTypes) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) ConstellationBoundaries(gaiasky.scenegraph.ConstellationBoundaries) Vector3d(gaiasky.util.math.Vector3d) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ComponentTypes

use of gaiasky.render.ComponentTypes in project gaiasky by langurmonkey.

the class ConstellationsLoader method loadData.

@Override
public Array<? extends SceneGraphNode> loadData() {
    Array<SceneGraphNode> constellations = new Array<>();
    for (String f : files) {
        try {
            // Add fade node
            FadeNode constellationsFadeNode = new FadeNode();
            constellationsFadeNode.setPosition(new double[] { 0, 0, 0 });
            constellationsFadeNode.setCt(new String[] { "Constellations" });
            constellationsFadeNode.setFadeout(new double[] { 1.0e2, 2.0e4 });
            constellationsFadeNode.setParent(SceneGraphNode.ROOT_NAME);
            constellationsFadeNode.setName("Constellations");
            constellations.add(constellationsFadeNode);
            // load constellations
            FileHandle file = Settings.settings.data.dataFileHandle(f);
            BufferedReader br = new BufferedReader(new InputStreamReader(file.read()));
            try {
                // Skip first line
                String lastName = "";
                Array<int[]> partial = null;
                int lastid = -1;
                String line;
                String name = null;
                ComponentTypes ct = new ComponentTypes(ComponentType.Constellations);
                while ((line = br.readLine()) != null) {
                    if (!line.startsWith("#")) {
                        String[] tokens = line.split(separator);
                        name = tokens[0].trim();
                        if (!lastName.isEmpty() && !name.equals("JUMP") && !name.equals(lastName)) {
                            // We finished a constellation object
                            Constellation cons = new Constellation(lastName, "Constellations");
                            cons.ct = ct;
                            cons.ids = partial;
                            constellations.add(cons);
                            partial = null;
                            lastid = -1;
                        }
                        if (partial == null) {
                            partial = new Array<>();
                        }
                        // Break point sequence
                        if (name.equals("JUMP") && tokens[1].trim().equals("JUMP")) {
                            lastid = -1;
                        } else {
                            int newid = Parser.parseInt(tokens[1].trim());
                            if (lastid > 0) {
                                partial.add(new int[] { lastid, newid });
                            }
                            lastid = newid;
                            lastName = name;
                        }
                    }
                }
                // Add last
                if (!lastName.isEmpty() && !name.equals("JUMP")) {
                    // We finished a constellation object
                    Constellation cons = new Constellation(lastName, "Constellations");
                    cons.ct = ct;
                    cons.ids = partial;
                    constellations.add(cons);
                }
            } catch (IOException e) {
                Logger.getLogger(this.getClass()).error(e);
            }
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
    Logger.getLogger(this.getClass()).info(I18n.txt("notif.constellations.init", constellations.size));
    return constellations;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ComponentTypes(gaiasky.render.ComponentTypes) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) Constellation(gaiasky.scenegraph.Constellation) BufferedReader(java.io.BufferedReader) FadeNode(gaiasky.scenegraph.FadeNode)

Example 5 with ComponentTypes

use of gaiasky.render.ComponentTypes in project gaiasky by langurmonkey.

the class EventScriptingInterface method addShapeAroundObject.

@Override
public void addShapeAroundObject(String shapeName, String shape, String primitive, double size, String objectName, float r, float g, float b, float a, boolean showLabel, boolean trackObject) {
    if (checkString(shapeName, "shapeName") && checkStringEnum(shape, Shape.class, "shape") && checkStringEnum(primitive, Primitive.class, "primitive") && checkNum(size, 0, Double.MAX_VALUE, "size") && checkObjectName(objectName)) {
        GaiaSky.postRunnable(() -> {
            IFocus object = getFocus(objectName);
            float[] color = new float[] { r, g, b, a };
            int primitiveInt = Primitive.valueOf(primitive.toUpperCase()).equals(Primitive.LINES) ? GL20.GL_LINES : GL20.GL_TRIANGLES;
            final ShapeObject shapeObj;
            if (trackObject) {
                shapeObj = new ShapeObject(new String[] { shapeName.trim() }, "Universe", object, objectName, showLabel, color);
            } else {
                shapeObj = new ShapeObject(new String[] { shapeName.trim() }, "Universe", object.getAbsolutePosition(objectName, new Vector3b()), objectName, showLabel, color);
            }
            shapeObj.ct = new ComponentTypes(ComponentType.Others.ordinal());
            shapeObj.size = (float) (size * Constants.KM_TO_U);
            Map<String, Object> params = new HashMap<>();
            params.put("quality", 25L);
            params.put("divisions", shape.equals("octahedronsphere") ? 3L : 15L);
            params.put("recursion", 3L);
            params.put("diameter", 1.0);
            params.put("width", 1.0);
            params.put("height", 1.0);
            params.put("depth", 1.0);
            params.put("innerradius", 0.6);
            params.put("outerradius", 1.0);
            params.put("sphere-in-ring", false);
            params.put("flip", false);
            shapeObj.setModel(shape, primitiveInt, params);
            shapeObj.doneLoading(GaiaSky.instance.assetManager);
            EventManager.publish(Event.SCENE_GRAPH_ADD_OBJECT_NO_POST_CMD, this, shapeObj, false);
        });
    }
}
Also used : Primitive(gaiasky.interafce.AddShapeDialog.Primitive) ComponentTypes(gaiasky.render.ComponentTypes)

Aggregations

ComponentTypes (gaiasky.render.ComponentTypes)5 FileHandle (com.badlogic.gdx.files.FileHandle)2 Array (com.badlogic.gdx.utils.Array)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Primitive (gaiasky.interafce.AddShapeDialog.Primitive)1 Constellation (gaiasky.scenegraph.Constellation)1 ConstellationBoundaries (gaiasky.scenegraph.ConstellationBoundaries)1 FadeNode (gaiasky.scenegraph.FadeNode)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 Vector3d (gaiasky.util.math.Vector3d)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1