Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
/jsplat-examples/.project
/jsplat-examples/.settings
/jsplat-examples/.classpath

/jsplat-examples/data/*
!/jsplat-examples/data/unitCube-ascii.ply


/jsplat-examples-gltf/target
/jsplat-examples-gltf/.project
/jsplat-examples-gltf/.settings
/jsplat-examples-gltf/.classpath
/jsplat-examples-gltf/data/*


/jsplat/target
/jsplat/.project
/jsplat/.settings
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Java libraries for Gaussian splats.
- [`jsplat-io-gltf`](./jsplat-io-gltf) - glTF with [`KHR_gaussian_splatting`](https://github.com/KhronosGroup/glTF/pull/2490)
- [`jsplat-io-gltf-spz`](./jsplat-io-gltf-spz) - glTF with [`KHR_spz_gaussian_splatting_compression_spz_2`](https://github.com/KhronosGroup/glTF/pull/2531)
- [`jsplat-io-sog`](./jsplat-io-sog) - [SOG Format](https://developer.playcanvas.com/user-manual/gaussian-splatting/formats/sog/), with a basic reader and an **experimental** (and slow) writer.
- [`jsplat-processing`](./jsplat-processing) - Experimental library for basic processing operations on splats

A basic viewer implementation can be found in [`jsplat-viewer`](./jsplat-viewer),
with the actual implementation based on LWJGL in [`jsplat-viewer-lwjgl`](./jsplat-viewer-lwjgl).
Expand Down
149 changes: 149 additions & 0 deletions jsplat-app/src/main/java/de/javagl/jsplat/app/DataSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* www.javagl.de - JSplat
*
* Copyright 2025 Marco Hutter - http://www.javagl.de
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package de.javagl.jsplat.app;

import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

import de.javagl.jsplat.MutableSplat;
import de.javagl.jsplat.Splat;
import de.javagl.jsplat.Splats;
import de.javagl.jsplat.processing.SplatTransforms;

/**
* Internal representation of a splat data set inside the UI
*/
class DataSet
{
/**
* A name for the data set, to be displayed in the UI
*/
private final String name;

/**
* The initial (untransformed) splats
*/
private final List<? extends Splat> initialSplats;

/**
* The SH degree of the initial splats
*/
private final int shDegree;

/**
* The current transform that is applied to the splats
*/
private Transform currentTransform;

/**
* The current splats, computed from the initial ones using the transform
*/
private final List<MutableSplat> currentSplats;

/**
* Default constructor
*
* @param name The name, for display purposes
* @param initialSplats The initial splats
*/
DataSet(String name, List<? extends Splat> initialSplats)
{
this.name = Objects.requireNonNull(name, "The name may not be null");
this.initialSplats = Objects.requireNonNull(initialSplats,
"The initialSplats may not be null");
if (initialSplats.isEmpty())
{
this.shDegree = 0;
}
else
{
this.shDegree = initialSplats.get(0).getShDegree();
}
this.currentTransform = new Transform();
this.currentSplats = Splats.copyList(initialSplats);
}

/**
* Set the transform that should be applied to the initial splats to obtain
* the transformed splats
*
* @param transform The transform
*/
void setTransform(Transform transform)
{
this.currentTransform = transform;
float[] matrix = Transforms.toMatrix(transform);
int shDimensions = Splats.dimensionsForDegree(shDegree);
Consumer<MutableSplat> t =
SplatTransforms.createTransform(matrix, shDimensions);
for (int i = 0; i < initialSplats.size(); i++)
{
Splat initialSplat = initialSplats.get(i);
MutableSplat currentSplat = currentSplats.get(i);
Splats.setAny(initialSplat, currentSplat);
t.accept(currentSplat);
}
}

/**
* Returns the SH degree of the splats
*
* @return The degree
*/
int getShDegree()
{
return shDegree;
}

/**
* Returns the current transform of this data set
*
* @return The transform
*/
Transform getTransform()
{
return currentTransform;
}

/**
* Returns the current splats, with the current transform applied to them
*
* @return The splats
*/
List<MutableSplat> getCurrentSplats()
{
return currentSplats;
}

@Override
public String toString()
{
return name + " (" + initialSplats.size() + " splats)";
}

}
176 changes: 176 additions & 0 deletions jsplat-app/src/main/java/de/javagl/jsplat/app/DataSetsPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* www.javagl.de - JSplat
*
* Copyright 2025 Marco Hutter - http://www.javagl.de
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package de.javagl.jsplat.app;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.AbstractList;
import java.util.List;
import java.util.function.Consumer;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;

/**
* A panel for maintaining a list of splat data sets
*/
class DataSetsPanel extends JPanel
{
/**
* Serial UID
*/
private static final long serialVersionUID = -3477336710371239875L;

/**
* The list showing the data sets
*/
private final JList<DataSet> list;

/**
* The list model for the data sets
*/
private DefaultListModel<DataSet> listModel;

/**
* The button to remove the selected data set
*/
private JButton removeSelectedButton;

/**
* Creates a new instance
*
* @param removalCallback A callback that will receive removed data sets
*/
DataSetsPanel(Consumer<DataSet> removalCallback)
{
super(new BorderLayout());
listModel = new DefaultListModel<DataSet>();
list = new JList<DataSet>(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(list);
add(scrollPane, BorderLayout.CENTER);

JPanel p = new JPanel(new FlowLayout());
removeSelectedButton = new JButton("Remove");
removeSelectedButton.setEnabled(false);
removeSelectedButton.addActionListener(e ->
{
DataSet removedDataSet = getSelectedDataSet();
removeDataSet(removedDataSet);
removalCallback.accept(removedDataSet);
});
p.add(removeSelectedButton);
add(p, BorderLayout.SOUTH);
}

/**
* Add a listener to be informed about selection changes in the list
*
* @param listener The listener
*/
void addSelectionListener(ListSelectionListener listener)
{
list.addListSelectionListener(listener);
}

/**
* Add the given data set
*
* @param dataSet The data set
*/
void addDataSet(DataSet dataSet)
{
listModel.addElement(dataSet);
list.setSelectedIndex(listModel.size() - 1);
removeSelectedButton.setEnabled(true);
}

/**
* Remove the given data set
*
* @param dataSet The data set
*/
void removeDataSet(DataSet dataSet)
{
int oldIndex = list.getSelectedIndex();
listModel.removeElement(dataSet);
if (oldIndex == 0)
{
list.setSelectedIndex(0);
}
else
{
list.setSelectedIndex(oldIndex - 1);
}
if (listModel.getSize() == 0)
{
removeSelectedButton.setEnabled(false);
}
}

/**
* Returns the data set that is currently selected (or <code>null</code>
* if the list is empty)
*
* @return The selected data set
*/
DataSet getSelectedDataSet()
{
DataSet selectedDataSet = list.getSelectedValue();
return selectedDataSet;
}

/**
* Returns a list of the data sets in this panel
*
* @return The list
*/
List<DataSet> getDataSets()
{
return new AbstractList<DataSet>()
{
@Override
public DataSet get(int index)
{
return listModel.getElementAt(index);
}

@Override
public int size()
{
return listModel.getSize();
}
};
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import de.javagl.jsplat.app.common.ExtensionBasedSaveOptions;

/**
* A panel that serves as an accessory for the save file chooser, to select the
* compression that should be applied in GLB files
Expand Down
Loading