當前位置: 首頁>>代碼示例>>Java>>正文


Java Model.manageDisposable方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.graphics.g3d.Model.manageDisposable方法的典型用法代碼示例。如果您正苦於以下問題:Java Model.manageDisposable方法的具體用法?Java Model.manageDisposable怎麽用?Java Model.manageDisposable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.graphics.g3d.Model的用法示例。


在下文中一共展示了Model.manageDisposable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadRenderModel

import com.badlogic.gdx.graphics.g3d.Model; //導入方法依賴的package包/類
private Model loadRenderModel(String name) {
	if (models.containsKey(name)) return models.get(name);						

	// FIXME we load the models synchronously cause we are lazy
	int error = 0;
	PointerBuffer modelPointer = PointerBuffer.allocateDirect(1);
	while (true) {
		error = VRRenderModels.VRRenderModels_LoadRenderModel_Async(name, modelPointer);
		if (error != VR.EVRRenderModelError_VRRenderModelError_Loading) break;
	}
	
	if (error != VR.EVRRenderModelError_VRRenderModelError_None) return null;		
	RenderModel renderModel = new RenderModel(modelPointer.getByteBuffer(RenderModel.SIZEOF));
	
	error = 0;
	PointerBuffer texturePointer = PointerBuffer.allocateDirect(1);
	while (true) {
		error = VRRenderModels.VRRenderModels_LoadTexture_Async(renderModel.diffuseTextureId(), texturePointer);
		if (error != VR.EVRRenderModelError_VRRenderModelError_Loading) break;
	}
	
	if (error != VR.EVRRenderModelError_VRRenderModelError_None) {
		VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
		return null;
	}
					
	RenderModelTextureMap renderModelTexture = new RenderModelTextureMap(texturePointer.getByteBuffer(RenderModelTextureMap.SIZEOF));
	
	// convert to a Model				
	Mesh mesh = new Mesh(true, renderModel.unVertexCount(), renderModel.unTriangleCount() * 3, VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0));
	MeshPart meshPart = new MeshPart(name, mesh, 0, renderModel.unTriangleCount() * 3, GL20.GL_TRIANGLES);
	RenderModelVertex.Buffer vertices = renderModel.rVertexData();
	float[] packedVertices = new float[8 * renderModel.unVertexCount()];
	int i = 0;
	while(vertices.remaining() > 0) {
		RenderModelVertex v = vertices.get();			
		packedVertices[i++] = v.vPosition().v(0);
		packedVertices[i++] = v.vPosition().v(1);
		packedVertices[i++] = v.vPosition().v(2);
		
		packedVertices[i++] = v.vNormal().v(0);
		packedVertices[i++] = v.vNormal().v(1);
		packedVertices[i++] = v.vNormal().v(2);
		
		packedVertices[i++] = v.rfTextureCoord().get(0);
		packedVertices[i++] = v.rfTextureCoord().get(1);
	}
	mesh.setVertices(packedVertices);
	short[] indices = new short[renderModel.unTriangleCount() * 3];
	renderModel.IndexData().get(indices);		
	mesh.setIndices(indices);
	
	Pixmap pixmap = new Pixmap(renderModelTexture.unWidth(), renderModelTexture.unHeight(), Format.RGBA8888);
	byte[] pixels = new byte[renderModelTexture.unWidth() * renderModelTexture.unHeight() * 4];
	renderModelTexture.rubTextureMapData(pixels.length).get(pixels);
	pixmap.getPixels().put(pixels);
	pixmap.getPixels().position(0);
	Texture texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), true, true));
	Material material = new Material(new TextureAttribute(TextureAttribute.Diffuse, texture));		
			
	Model model = new Model();
	model.meshes.add(mesh);
	model.meshParts.add(meshPart);
	model.materials.add(material);
	Node node = new Node();
	node.id = name;		
	node.parts.add(new NodePart(meshPart, material));
	model.nodes.add(node);
	model.manageDisposable(mesh);
	model.manageDisposable(texture);
	
	VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
	VRRenderModels.VRRenderModels_FreeTexture(renderModelTexture);

	models.put(name, model);
	
	return model;
}
 
開發者ID:justinmarentette11,項目名稱:Tower-Defense-Galaxy,代碼行數:79,代碼來源:VRContext.java

示例2: create

import com.badlogic.gdx.graphics.g3d.Model; //導入方法依賴的package包/類
@Override
public void create () {
	super.create();
	instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";

	final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
	disposables.add(chassisModel);
	chassisModel.materials.get(0).clear();
	chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
	final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
	disposables.add(wheelModel);
	wheelModel.materials.get(0).clear();
	wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE),
		FloatAttribute.createShininess(128));
	Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
	final Model largeGroundModel = modelBuilder.createBox(
		1000f,
		2f,
		1000f,
		new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute
			.createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
	largeGroundModel.manageDisposable(checkboard);
	disposables.add(largeGroundModel);
	world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));

	BoundingBox bounds = new BoundingBox();
	Vector3 chassisHalfExtents = new Vector3(chassisModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);
	Vector3 wheelHalfExtents = new Vector3(wheelModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);

	world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
	world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));

	world.add("largeground", 0, -1f, 0f);

	chassis = world.add("chassis", 0, 3f, 0);
	wheels[0] = world.add("wheel", 0, 0, 0);
	wheels[1] = world.add("wheel", 0, 0, 0);
	wheels[2] = world.add("wheel", 0, 0, 0);
	wheels[3] = world.add("wheel", 0, 0, 0);

	// Create the vehicle
	raycaster = new btDefaultVehicleRaycaster((btDynamicsWorld)world.collisionWorld);
	tuning = new btVehicleTuning();
	vehicle = new btRaycastVehicle(tuning, (btRigidBody)chassis.body, raycaster);
	chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
	((btDynamicsWorld)world.collisionWorld).addVehicle(vehicle);

	vehicle.setCoordinateSystem(0, 1, 2);

	btWheelInfo wheelInfo;
	Vector3 point = new Vector3();
	Vector3 direction = new Vector3(0, -1, 0);
	Vector3 axis = new Vector3(-1, 0, 0);
	wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis,
		wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
	wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis,
		wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
	wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis,
		wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
	wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis,
		wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
 
開發者ID:Matsemann,項目名稱:eamaster,代碼行數:63,代碼來源:VehicleTest.java


注:本文中的com.badlogic.gdx.graphics.g3d.Model.manageDisposable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。