Example #1
0
	static void parse_textures(const char* json, Array<TextureData>& textures, Array<char>& names, Array<char>& dynamic, CompileOptions& opts)
	{
		TempAllocator4096 ta;
		JsonObject object(ta);
		sjson::parse(json, object);

		auto begin = json_object::begin(object);
		auto end = json_object::end(object);

		for (; begin != end; ++begin)
		{
			const FixedString key = begin->pair.first;
			const char* value     = begin->pair.second;

			DynamicString texture(ta);
			sjson::parse_string(value, texture);
			RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_TEXTURE, texture.c_str(), opts);

			TextureHandle th;
			th.sampler_handle = 0;
			th.texture_handle = 0;

			const u32 sampler_name_offset = array::size(names);
			array::push(names, key.data(), key.length());
			array::push_back(names, '\0');

			TextureData td;
			td.sampler_name_offset = sampler_name_offset;
			td.id                  = sjson::parse_resource_id(value);
			td.data_offset         = reserve_dynamic_data(th, dynamic);

			array::push_back(textures, td);
		}
	}
Example #2
0
	void compile(const char* path, CompileOptions& opts)
	{
		Buffer buf = opts.read(path);

		TempAllocator1024 ta;
		JsonObject boot(ta);
		sjson::parse(buf, boot);

		const char* boot_script_json  = boot["boot_script"];
		const char* boot_package_json = boot["boot_package"];
		RESOURCE_COMPILER_ASSERT(boot_script_json != NULL, opts, "'boot_script' must be specified.");
		RESOURCE_COMPILER_ASSERT(boot_package_json != NULL, opts, "'boot_package' must be specified.");

		DynamicString boot_script(ta);
		DynamicString boot_package(ta);
		sjson::parse_string(boot_script_json, boot_script);
		sjson::parse_string(boot_package_json, boot_package);
		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT, boot_script.c_str(), opts);
		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_PACKAGE, boot_package.c_str(), opts);

		opts.write(buf);
	}
Example #3
0
	Buffer compile_collider(const char* json, CompileOptions& opts)
	{
		TempAllocator4096 ta;
		JsonObject obj(ta);
		sjson::parse(json, obj);

		DynamicString type(ta);
		sjson::parse_string(obj["shape"], type);

		ColliderType::Enum st = shape_type_to_enum(type.c_str());
		RESOURCE_COMPILER_ASSERT(st != ColliderType::COUNT
			, opts
			, "Unknown shape type: '%s'"
			, type.c_str()
			);

		ColliderDesc cd;
		cd.type        = st;
		cd.shape_class = sjson::parse_string_id(obj["class"]);
		cd.material    = sjson::parse_string_id(obj["material"]);
		cd.local_tm    = MATRIX4X4_IDENTITY;
		cd.size        = 0;

		DynamicString scene(ta);
		DynamicString name(ta);
		sjson::parse_string(obj["scene"], scene);
		sjson::parse_string(obj["name"], name);
		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH, scene.c_str(), opts);
		scene += "." RESOURCE_EXTENSION_MESH;

		Buffer file = opts.read(scene.c_str());
		JsonObject json_mesh(ta);
		JsonObject geometries(ta);
		JsonObject nodes(ta);
		JsonObject node(ta);
		sjson::parse(file, json_mesh);
		sjson::parse(json_mesh["geometries"], geometries);
		sjson::parse(json_mesh["nodes"], nodes);
		sjson::parse(nodes[name.c_str()], node);
		const char* mesh = geometries[name.c_str()];

		Matrix4x4 matrix_local = sjson::parse_matrix4x4(node["matrix_local"]);
		cd.local_tm = matrix_local;

		Array<Vector3> mesh_data(default_allocator());

		switch (cd.type)
		{
			case ColliderType::SPHERE:      compile_sphere(mesh, cd); break;
			case ColliderType::CAPSULE:     compile_capsule(mesh, cd); break;
			case ColliderType::BOX:         compile_box(mesh, cd); break;
			case ColliderType::CONVEX_HULL: compile_convex_hull(mesh, mesh_data); break;
			case ColliderType::MESH:
			case ColliderType::HEIGHTFIELD:
			{
				RESOURCE_COMPILER_ASSERT(false, opts, "Not implemented yet");
				break;
			}
		}

		cd.size = sizeof(Vector3)*array::size(mesh_data);

		Buffer buf(default_allocator());
		array::push(buf, (char*)&cd, sizeof(cd));

		if (array::size(mesh_data))
			array::push(buf, (char*)array::begin(mesh_data), sizeof(Vector3)*array::size(mesh_data));

		return buf;
	}