<commit_before>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.graphics.g3d.loader;

import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.ModelLoader;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation;
import com.badlogic.gdx.graphics.g3d.model.data.ModelData;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMesh;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNode;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodeKeyframe;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart;
import com.badlogic.gdx.graphics.g3d.model.data.ModelTexture;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.BaseJsonReader;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.JsonValue;

public class G3dModelLoader extends ModelLoader<ModelLoader.ModelParameters> {
	public static final short VERSION_HI = 0;
	public static final short VERSION_LO = 1;
	protected final BaseJsonReader reader;

	public G3dModelLoader (final BaseJsonReader reader) {
		this(reader, null);
	}

	public G3dModelLoader (BaseJsonReader reader, FileHandleResolver resolver) {
		super(resolver);
		this.reader = reader;
	}

	@Override
	public ModelData loadModelData (FileHandle fileHandle, ModelLoader.ModelParameters parameters) {
		return parseModel(fileHandle);
	}

	public ModelData parseModel (FileHandle handle) {
		JsonValue json = reader.parse(handle);
		ModelData model = new ModelData();
		JsonValue version = json.require("version");
		model.version[0] = version.getShort(0);
		model.version[1] = version.getShort(1);
		if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO)
			throw new GdxRuntimeException("Model version not supported");

		model.id = json.getString("id", "");
		parseMeshes(model, json);
		parseMaterials(model, json, handle.parent().path());
		parseNodes(model, json);
		parseAnimations(model, json);
		return model;
	}

	private void parseMeshes (ModelData model, JsonValue json) {
		JsonValue meshes = json.get("meshes");
		if (meshes != null) {

			model.meshes.ensureCapacity(meshes.size);
			for (JsonValue mesh = meshes.child; mesh != null; mesh = mesh.next) {
				ModelMesh jsonMesh = new ModelMesh();

				String id = mesh.getString("id", "");
				jsonMesh.id = id;

				JsonValue attributes = mesh.require("attributes");
				jsonMesh.attributes = parseAttributes(attributes);
				jsonMesh.vertices = mesh.require("vertices").asFloatArray();

				JsonValue meshParts = mesh.require("parts");
				Array<ModelMeshPart> parts = new Array<ModelMeshPart>();
				for (JsonValue meshPart = meshParts.child; meshPart != null; meshPart = meshPart.next) {
					ModelMeshPart jsonPart = new ModelMeshPart();
					String partId = meshPart.getString("id", null);
					if (id == null) {
						throw new GdxRuntimeException("Not id given for mesh part");
					}
					for (ModelMeshPart other : parts) {
						if (other.id.equals(partId)) {
							throw new GdxRuntimeException("Mesh part with id '" + partId + "' already in defined");
						}
					}
					jsonPart.id = partId;

					String type = meshPart.getString("type", null);<commit_msg>Update G3dModelLoader.java<commit_after>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.graphics.g3d.loader;

import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.ModelLoader;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation;
import com.badlogic.gdx.graphics.g3d.model.data.ModelData;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMesh;
import com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNode;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodeAnimation;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodeKeyframe;
import com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart;
import com.badlogic.gdx.graphics.g3d.model.data.ModelTexture;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ArrayMap;
import com.badlogic.gdx.utils.BaseJsonReader;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.JsonValue;

public class G3dModelLoader extends ModelLoader<ModelLoader.ModelParameters> {
	public static final short VERSION_HI = 0;
	public static final short VERSION_LO = 1;
	protected final BaseJsonReader reader;

	public G3dModelLoader (final BaseJsonReader reader) {
		this(reader, null);
	}

	public G3dModelLoader (BaseJsonReader reader, FileHandleResolver resolver) {
		super(resolver);
		this.reader = reader;
	}

	@Override
	public ModelData loadModelData (FileHandle fileHandle, ModelLoader.ModelParameters parameters) {
		return parseModel(fileHandle);
	}

	public ModelData parseModel (FileHandle handle) {
		JsonValue json = reader.parse(handle);
		ModelData model = new ModelData();
		JsonValue version = json.require("version");
		model.version[0] = version.getShort(0);
		model.version[1] = version.getShort(1);
		if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO)
			throw new GdxRuntimeException("Model version not supported");

		model.id = json.getString("id", "");
		parseMeshes(model, json);
		parseMaterials(model, json, handle.parent().path());
		parseNodes(model, json);
		parseAnimations(model, json);
		return model;
	}

	private void parseMeshes (ModelData model, JsonValue json) {
		JsonValue meshes = json.get("meshes");
		if (meshes != null) {

			model.meshes.ensureCapacity(meshes.size);
			for (JsonValue mesh = meshes.child; mesh != null; mesh = mesh.next) {
				ModelMesh jsonMesh = new ModelMesh();

				String id = mesh.getString("id", "");
				jsonMesh.id = id;

				JsonValue attributes = mesh.require("attributes");
				jsonMesh.attributes = parseAttributes(attributes);
				jsonMesh.vertices = mesh.require("vertices").asFloatArray();

				JsonValue meshParts = mesh.require("parts");
				Array<ModelMeshPart> parts = new Array<ModelMeshPart>();
				for (JsonValue meshPart = meshParts.child; meshPart != null; meshPart = meshPart.next) {
					ModelMeshPart jsonPart = new ModelMeshPart();
					String partId = meshPart.getString("id", null);
					if (partId == null) {
						throw new GdxRuntimeException("Not id given for mesh part");
					}
					for (ModelMeshPart other : parts) {
						if (other.id.equals(partId)) {
							throw new GdxRuntimeException("Mesh part with id '" + partId + "' already in defined");
						}
					}
					jsonPart.id = partId;

					String type = meshPart.getString("type", null);
{'fraction_non_alphanumeric': 0.14477062172117425, 'fraction_numerical': 0.00792499162852997, 'mean_word_length': 4.791855203619909, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4332475', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2698, 'n_words': 640}