Re: Add "o" to OBJWriter output

by Daniels118 » Sat Jul 09, 2022 5:55 pm

Sorry for late response. I looked at the changes and they seems ok, but you know it's up to Emmanuel to decide wether to merge or not into the main stream.
If you decide to make it a plugin you could consider to override the OBJWriter instead of duplicate the whole code. This is how I managed to obtain this result for another project I'm working on:

Code: Select all

public class LDObjWriter extends OBJWriter {
	private boolean firstNode = true;
	private boolean separateObjects = false;
	
	public boolean isSeparateObjects() {
		return separateObjects;
	}
	
	public void setSeparateObjects(boolean separateObjects) {
		this.separateObjects = separateObjects;
	}
	
	@Override
	public void writeNode(Node node) throws IOException, InterruptedIOException {
		writeNode(node, null);
	}
	
	@Override
	public void writeNode(Node node, String nodeName) throws IOException, InterruptedIOException {
		if (firstNode) {
			super.writeNode(null, null);
			firstNode = false;
		}
		if (separateObjects && nodeName != null && !nodeName.isEmpty()) {
			this.out.write("o " + nodeName + "\n");
		}
		super.writeNode(node, nodeName);
	}
	
	public void newObject(String name) throws IOException {
		if (firstNode) {
			super.writeNode(null, null);
			firstNode = false;
		}
		this.out.write("o " + name + "\n");
		separateObjects = false;
	}
}