@Override public JCGLArrayBufferType arrayBuffer() throws IllegalStateException { if (!this.errors.isEmpty()) { throw new IllegalStateException("Array loading has failed"); } return this.array_buffer; }
@Override public SMFByteBufferPackedMesh mesh() throws IllegalStateException { if (this.errors.isEmpty()) { return this.mesh; } throw new IllegalStateException("Buffer packer has failed"); }
@Override public JCGLArrayObjectType arrayObject() throws IllegalStateException { if (!this.errors.isEmpty()) { throw new IllegalStateException("Array loading has failed"); } return this.array_object; }
@Override public JCGLIndexBufferType indexBuffer() throws IllegalStateException { if (!this.errors.isEmpty()) { throw new IllegalStateException("Array loading has failed"); } return this.index_buffer; }
@Override public SMFMemoryMesh mesh() throws IllegalStateException { Preconditions.checkPrecondition( this.finished, "Mesh parsing has not yet finished"); if (this.errors.isEmpty()) { return this.mesh; } throw new IllegalStateException("Mesh parsing failed"); }
/** * _1 = mapping output - last attribute * _2 = mapping output attributes - last attribute * _3 = last attribute of mapping output * * @param mappingOutput * @return */ private static Optional<Tuple3<Optional<String>, javaslang.collection.List<String>, String>> determineMappingOutputAttribute(final MappingAttributePathInstance mappingOutput) { return Optional.ofNullable(mappingOutput) .flatMap(mappingOutput1 -> Optional.ofNullable(mappingOutput1.getAttributePath())) .flatMap(attributePath -> Optional.ofNullable(attributePath.toAttributePath())) .flatMap(attributePathString -> { // .ESCAPE_XML11.with(NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE)).translate( <- also doesn't work final String escapedMappingOutputAP = StringEscapeUtils.escapeXml(attributePathString); final javaslang.collection.List<String> mappingOutputAttributes = javaslang.collection.List.of(escapedMappingOutputAP.split(ATTRIBUTE_DELIMITER)); if (mappingOutputAttributes.isEmpty()) { return Optional.of(Tuple.of(Optional.empty(), mappingOutputAttributes.init(), escapedMappingOutputAP)); } final String lastAttribute = mappingOutputAttributes.last(); final String mappingOutputRoot = mappingOutputAttributes.init().mkString(ATTRIBUTE_DELIMITER); final Optional<String> optionalMappingOutputRoot = Optional.of(mappingOutputRoot).filter(mappingOutputRoot1 -> !mappingOutputRoot1.isEmpty()); return Optional.of(Tuple.of(optionalMappingOutputRoot, mappingOutputAttributes.init(), lastAttribute)); }); }
private void parseMetaDataValues( final long vendor_id, final long schema_id, final long lines) throws Exception { final ArrayList<String> saved_lines = new ArrayList<>(); while ((long) saved_lines.size() < lines) { final Optional<List<String>> line_opt = super.reader.line(); if (!line_opt.isPresent()) { this.onEOF(); return; } this.log().trace("line: {}", line_opt.get()); final List<String> line = line_opt.get(); if (line.isEmpty()) { super.failExpectedGot( "Received an empty line.", "A line of Base64 encoded data.", ""); return; } saved_lines.add(line.toJavaStream().collect(Collectors.joining())); } final byte[] decoded = SMFBase64Lines.fromBase64Lines(saved_lines); if (this.events.onMeta(vendor_id, schema_id, (long) decoded.length)) { this.events.onMetaData(vendor_id, schema_id, decoded); } }
if (line.isEmpty()) { continue;
@Override public void onFinish() { if (this.errors.isEmpty()) { this.mesh = SMFMemoryMesh.builder() .setArrays(this.arrays) .setHeader(this.header) .setTriangles(this.triangles) .setMetadata(this.metadata) .build(); } this.finished = true; }
if (line.isEmpty()) { continue;
@Override public Validation<List<SMFErrorType>, SMFHeader> validate( final SMFHeader header, final SMFSchema schema) { NullCheck.notNull(header, "Header"); NullCheck.notNull(schema, "Schema"); List<SMFErrorType> errors = List.empty(); final Optional<SMFSchemaIdentifier> file_id_opt = header.schemaIdentifier(); if (file_id_opt.isPresent()) { final SMFSchemaIdentifier file_id = file_id_opt.get(); final SMFSchemaIdentifier schema_id = schema.schemaIdentifier(); if (!Objects.equals(schema_id, file_id)) { errors = errors.append(errorWrongSchemaID(schema_id, file_id)); } } errors = checkVerticesAndTriangles(header, schema, errors); errors = checkAttributes(header, schema, errors); errors = checkCoordinateSystem(header, schema, errors); if (errors.isEmpty()) { return valid(header); } return invalid(errors); }
private Validation<List<SMFParseError>, SMFFormatVersion> onParseVersion( final List<String> line) if (line.isEmpty()) { return invalid(List.of(this.makeErrorExpectedGot( "The first line must be a version declaration.",
if (line.isEmpty()) { continue;
@Override public void onFinish() { final JCGLArrayBuffersType g_ab = this.g.getArrayBuffers(); final JCGLIndexBuffersType g_ib = this.g.getIndexBuffers(); if (!this.errors.isEmpty()) { if (this.array_buffer != null) { g_ab.arrayBufferDelete(this.array_buffer); this.array_buffer = null; } if (this.index_buffer != null) { g_ib.indexBufferDelete(this.index_buffer); this.index_buffer = null; } } g_ab.arrayBufferUpdate(this.array_update); g_ib.indexBufferUpdate(this.index_update); this.array_object = this.g.getArrayObjects().arrayObjectAllocate(this.array_object_builder); }
/** * Attempt to parse a command. * * @param file The file, if any * @param line The line * @param text The text * * @return A parsed command or a list of parse errors */ public static Validation<List<SMFParseError>, SMFMemoryMeshFilterType> parse( final Optional<URI> file, final int line, final List<String> text) { NullCheck.notNull(file, "file"); NullCheck.notNull(text, "text"); if (text.isEmpty()) { try { return valid(create()); } catch (final IllegalArgumentException e) { return errorExpectedGotValidation(file, line, makeSyntax(), text); } } return errorExpectedGotValidation(file, line, makeSyntax(), text); }
@Override public void onFinish() { if (this.errors.isEmpty()) { Invariants.checkInvariantI( this.attr_buffers.size(), this.attr_buffers.size() == this.config.size(), x -> "Must have correct number of buffers"); final SMFByteBufferPackedMesh.Builder mb = SMFByteBufferPackedMesh.builder(); for (final Tuple2<Integer, ByteBuffer> p : this.attr_buffers) { mb.addAttributeSets(SMFByteBufferPackedAttributeSet.of( p._1.intValue(), this.config.get(p._1).get(), p._2)); } if (this.tri_buffer != null) { final SMFTriangles triangles = this.header.triangles(); mb.setTriangles(SMFByteBufferPackedTriangles.of( this.tri_buffer, triangles.triangleCount(), Math.toIntExact(triangles.triangleIndexSizeBits()))); } mb.setHeader(this.header); this.mesh = mb.build(); } }
if (errors.isEmpty()) { final SMFTriangles new_triangles = m.header().triangles().withTriangleIndexSizeBits(triangle_size);
Assert.assertTrue(loader.errors().isEmpty());