Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


xexuxjy

Member Since 19 Sep 2012
Offline Last Active Today, 01:10 PM

Posts I've Made

In Topic: Xbox 2 error #1

10 December 2014 - 07:43 AM

I'd recommend getting the new visual studio 2013 community edition 

and 

https://msxna.codeplex.com/releases/view/117230

 

for XNA 4.0 that works with it.

 

much better starting point...


In Topic: 'Older' mechanisms for skinned models,vertex weighting, etc. ?

24 November 2014 - 03:21 PM

Thanks very much for that, 

 

What I'm trying to do is use the data from the model files to re-create the models and animations in my own unity project (just for my own amusement). I realise that the data files from the game may not be what the game uses internally. Though interestingly I've been comparing the different versions of the game (GameCube, PS2 and XBox) and they all seem to have their own version of both the texture and model files (though animation data seems consistent across all 3 platforms, but that's a whole other problem...). I suspect that each versions files are fairly close to the final game representation (e.g GC uses GP DisplayLists for position,normal,uv). I've got the skeleton data from each model and managed to rebuild that, which also gave me the clue that bone id's are just a single byte.

 

I've had some luck recently in identifying sections at the end of the basic vertex definitions that have pairs of bytes summing to 256, but wanted to see if having only a max of 2 bones affecting a vertex was a 'normal' thing to have, which from your response it is. The number of pairs summing to 256 doesn't match the number of vertices, nor are each of the pairs unique , so it's proving interesting to drag it all together.

 

Thanks again.


In Topic: Import FBX at Runtime in UNITY.

14 October 2014 - 06:44 AM

If the data is in your resources folder for unity you should be able to load it programatically as a normal resource load, even if it's not added to your scene.

Here's some code I use for loading fbx entities at runtime for weapons and the like. Having said that. loading 7GB of data at runtime isn't going to be much fun....

 public void LoadAndAttachModel(String boneName, String modelName)
    {
        Transform boneTransform = GladiusGlobals.FindChild(boneName, gameObject.transform);
        if (boneTransform != null)
        {
            GameObject load = Instantiate(Resources.Load(GladiusGlobals.ModelsRoot + modelName)) as GameObject;
            if (load != null)
            {
                load.transform.parent = boneTransform;
                load.transform.localPosition = Vector3.zero;
                load.transform.localRotation = Quaternion.Euler(new Vector3(90, 90, 0));
                load.transform.localScale = new Vector3(100f, 100f, 100f);
            }
        }
        else
        {
            Debug.LogWarning("Can't find boneName : " + boneName);
        }
    }

In Topic: Advanced heightfields in Bullet physics

17 September 2014 - 05:54 AM

The Bullet HeightField is a pretty very simple collision object really/ It's usually added as a static object, and it's bounding box doesn't change through simulationSteps so there shouldn't be any performance issues from the bullet library as such.  As you saw all that bullet really does is call back to the HeightMap for processTriangles and getRawHeightFieldValue., if then does a normal Triangle v CollisionShape test for each of the Triangles that the HeightMap gives it. Obvioulsy the finer the resolution in a given area the more triangles it would provide, and the performance hit would be larger.

 

You could fairly simply modify the body of the class, or create your own version of HeightMap that uses masks or whatever. If the AABB of the heightfield doesn't change, you could even do something like lodding with the underlying data for 'far away' sections of your terrian.

I created a version in my xna port of bullet that allowed me to get averaged height values for a given point, and also to modify the underlying data to provide deformable terrain and it all just sat happily in the normal Bullet libraries 


In Topic: Bullet - objects falling through

12 August 2014 - 03:28 AM

Something like the below seemed to work..... apologies as I don't seem to be able to attach the .h/.cpp files

 

BasicDemo.h

/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, 
including commercial applications, and to alter it and redistribute it freely, 
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BASIC_DEMO_H
#define BASIC_DEMO_H

#ifdef _WINDOWS
#include "Win32DemoApplication.h"
#define PlatformDemoApplication Win32DemoApplication
#else
#include "GlutDemoApplication.h"
#define PlatformDemoApplication GlutDemoApplication
#endif

#include "LinearMath/btAlignedObjectArray.h"

class btBroadphaseInterface;
class btCollisionShape;
class btOverlappingPairCache;
class btCollisionDispatcher;
class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;

///BasicDemo is good starting point for learning the code base and porting.

class BasicDemo : public PlatformDemoApplication
{

	//keep the collision shapes, for deletion/cleanup
	btAlignedObjectArray<btCollisionShape*>	m_collisionShapes;

	btBroadphaseInterface*	m_broadphase;

	btCollisionDispatcher*	m_dispatcher;

	btConstraintSolver*	m_solver;

	btDefaultCollisionConfiguration* m_collisionConfiguration;


	btAlignedObjectArray<class BarInfo*>	m_bars;
	btAlignedObjectArray<class btRigidBody*> m_balls;

	public:

	BasicDemo()
	{
	}
	virtual ~BasicDemo()
	{
		exitPhysics();
	}
	void	initPhysics();

	void	exitPhysics();

	void updateBars();

	btRigidBody* buildBall(float radius,const btTransform& t);
	btRigidBody* buildBar(const btVector3& halfExtents, const btTransform& t);

	virtual void clientMoveAndDisplay();

	virtual void displayCallback();
	virtual void	clientResetScene();
	
	static DemoApplication* Create()
	{
		BasicDemo* demo = new BasicDemo;
		demo->myinit();
		demo->initPhysics();
		return demo;
	}

	
};

class BarInfo
{
public :
	btVector3 direction;
	btScalar currentElapsed;
	btScalar lifeTime = 2.0;
	btRigidBody* body;
	btVector3 startPosition;
	btScalar maxRange;

	BarInfo(btRigidBody* theBody);
	void chooseNewDirection();

	void update(btScalar elapsed);
	

};

#endif //BASIC_DEMO_H

BasicDemo.cpp

/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, 
including commercial applications, and to alter it and redistribute it freely, 
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/


///create 125 (5x5x5) dynamic object
#define ARRAY_SIZE_X 5
#define ARRAY_SIZE_Y 5
#define ARRAY_SIZE_Z 5

//maximum number of objects (and allow user to shoot additional boxes)
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)

///scaling of the objects (0.1 = 20 centimeter boxes )
#define SCALING 1.
#define START_POS_X -5
#define START_POS_Y -5
#define START_POS_Z -3

#include "BasicDemo.h"
#include "GlutStuff.h"
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
#include "btBulletDynamicsCommon.h"

#include <stdio.h> //printf debugging
#include "GLDebugDrawer.h"
#include "LinearMath/btAabbUtil2.h"

static GLDebugDrawer gDebugDraw;

///The MyOverlapCallback is used to show how to collect object that overlap with a given bounding box defined by aabbMin and aabbMax. 
///See m_dynamicsWorld->getBroadphase()->aabbTest.
struct	MyOverlapCallback : public btBroadphaseAabbCallback
{
	btVector3 m_queryAabbMin;
	btVector3 m_queryAabbMax;
	
	int m_numOverlap;
	MyOverlapCallback(const btVector3& aabbMin, const btVector3& aabbMax ) : m_queryAabbMin(aabbMin),m_queryAabbMax(aabbMax),m_numOverlap(0)	{}
	virtual bool	process(const btBroadphaseProxy* proxy)
	{
		btVector3 proxyAabbMin,proxyAabbMax;
		btCollisionObject* colObj0 = (btCollisionObject*)proxy->m_clientObject;
		colObj0->getCollisionShape()->getAabb(colObj0->getWorldTransform(),proxyAabbMin,proxyAabbMax);
		if (TestAabbAgainstAabb2(proxyAabbMin,proxyAabbMax,m_queryAabbMin,m_queryAabbMax))
		{
			m_numOverlap++;
		}
		return true;
	}
};

void BasicDemo::clientMoveAndDisplay()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

	//simple dynamics world doesn't handle fixed-time-stepping
	float ms = getDeltaTimeMicroseconds();
	
	///step the simulation
	if (m_dynamicsWorld)
	{
		updateBars();

		m_dynamicsWorld->stepSimulation(ms / 1000000.f);
		//optional but useful: debug drawing
		m_dynamicsWorld->debugDrawWorld();

		//btVector3 aabbMin(1,1,1);
		//btVector3 aabbMax(2,2,2);

		//MyOverlapCallback aabbOverlap(aabbMin,aabbMax);
		//m_dynamicsWorld->getBroadphase()->aabbTest(aabbMin,aabbMax,aabbOverlap);
		//
		//if (aabbOverlap.m_numOverlap)
		//	printf("#aabb overlap = %d\n", aabbOverlap.m_numOverlap);
	}
		
	renderme(); 

	glFlush();

	swapBuffers();

}



void BasicDemo::displayCallback(void) {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

	renderme();

	//optional but useful: debug drawing to detect problems
	if (m_dynamicsWorld)
		m_dynamicsWorld->debugDrawWorld();

	glFlush();
	swapBuffers();
}





void	BasicDemo::initPhysics()
{
	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(SCALING*50.));

	///collision configuration contains default setup for memory, collision setup
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	//m_collisionConfiguration->setConvexConvexMultipointIterations();

	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);

	m_broadphase = new btDbvtBroadphase();

	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
	m_dynamicsWorld->setDebugDrawer(&gDebugDraw);
	
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));

	btVector3 barHalfExtents(1.5, 5, 1.5);
	int numBars = 10;
	float pad = 0.1;
	btTransform t;

	btScalar startX = -1.0;
	btScalar lastX = startX;

	btStaticPlaneShape* leftWall = new btStaticPlaneShape(btVector3(1, 0, 0), 0);


	for (int i = 0; i < numBars; ++i)
	{
		t = btTransform::getIdentity();
		btVector3 origin(lastX, 0, 0);
		t.setOrigin(origin);
		btRigidBody* bar = buildBar(barHalfExtents,t);
		m_bars.push_back(new BarInfo(bar));
		m_dynamicsWorld->addRigidBody(bar);
		bar->setGravity(btVector3(0, 0, 0));
		lastX += ((barHalfExtents.x() * 2.0) + pad*2.0);

	}
	btStaticPlaneShape* rightWall = new btStaticPlaneShape(btVector3(-1, 0, 0), 0);

	t = btTransform::getIdentity();
	btVector3 origin(startX-pad, 0, 0);
	t.setOrigin(origin);
	localCreateRigidBody(0.0, t, leftWall);

	t = btTransform::getIdentity();
	origin=btVector3(lastX-barHalfExtents.x(), 0, 0);
	t.setOrigin(origin);
	localCreateRigidBody(0.0, t, rightWall);


	btScalar range = (lastX-startX);
	btScalar startY = 10.0;


	int numBalls = 100;
	btScalar ballRadius = 0.4;
	for (int i = 0; i < numBalls; ++i)
	{

		t = btTransform::getIdentity();
		double x = startX + static_cast <double> (rand()) / (static_cast <double> (RAND_MAX / range));


		btVector3 origin(x,startY,0);
		t.setOrigin(origin);
		btRigidBody* ball = buildBall(ballRadius,t);
		m_balls.push_back(ball);

		m_dynamicsWorld->addRigidBody(ball);
	}



}
void	BasicDemo::clientResetScene()
{
	exitPhysics();
	initPhysics();
}
	

void	BasicDemo::exitPhysics()
{

	//cleanup in the reverse order of creation/initialization

	//remove the rigidbodies from the dynamics world and delete them
	int i;
	for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
	{
		btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body = btRigidBody::upcast(obj);
		if (body && body->getMotionState())
		{
			delete body->getMotionState();
		}
		m_dynamicsWorld->removeCollisionObject( obj );
		delete obj;
	}

	//delete collision shapes
	for (int j=0;j<m_collisionShapes.size();j++)
	{
		btCollisionShape* shape = m_collisionShapes[j];
		delete shape;
	}
	m_collisionShapes.clear();

	delete m_dynamicsWorld;
	
	delete m_solver;
	
	delete m_broadphase;
	
	delete m_dispatcher;

	delete m_collisionConfiguration;



}

btRigidBody* BasicDemo::buildBar(const btVector3& halfExtents,const btTransform& t)
{
	btCollisionShape* shape = new btBoxShape(halfExtents);
	btVector3 localInertia(0, 0, 0);
	float mass = 100.0;
	shape->calculateLocalInertia(mass, localInertia);

	btDefaultMotionState* myMotionState = new btDefaultMotionState(t);

	btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia);

	btRigidBody* body = new btRigidBody(cInfo);
	body->setGravity(btVector3(0, 0, 0));
	body->setLinearFactor(btVector3(1, 1, 0));
	body->setAngularFactor(btVector3(0, 0, 0));
	body->setActivationState(DISABLE_DEACTIVATION);
	return body;
}

btRigidBody* BasicDemo::buildBall(float radius, const btTransform& t)
{
	btCollisionShape* shape = new btSphereShape(radius);
	btVector3 localInertia(0, 0, 0);
	float mass = 1.0f;
	shape->calculateLocalInertia(mass, localInertia);

	btDefaultMotionState* myMotionState = new btDefaultMotionState(t);


	btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia);

	btRigidBody* body = new btRigidBody(cInfo);
	
	body->setLinearFactor(btVector3(1, 1, 0));
	return body;
}


void BasicDemo::updateBars()
{
	float maxFrameDistance = 1.5;
	float dTime = 1.0 / 60.0;
	int numBars = m_bars.size();
		
	float speedUpFactor = 1;


	for (int i = 0; i<numBars; ++i)
	{
		m_bars[i]->update(dTime);
	}
	
}



BarInfo::BarInfo(btRigidBody* theBody) : currentElapsed(0.0), lifeTime(2.0), body(theBody)
{
	direction.setZero();
	float dist = (rand() % 2 == 1 ? 1 : -1);
	direction[1] = dist;
	// random warmup
	
	double x = static_cast <double> (rand()) / (static_cast <double> (RAND_MAX / lifeTime));

	currentElapsed = x;
	startPosition = theBody->getWorldTransform().getOrigin();
	maxRange = 2.0;

	chooseNewDirection();

}

void BarInfo::update(btScalar elapsed)
{
	float maxFrameDistance = 10.0;

	currentElapsed += elapsed;

	btScalar dist = abs(body->getWorldTransform().getOrigin().y() - startPosition.y());

	if (dist > maxRange)
	{
		// gone too far. reverse direction for now and reset timer
		direction[1] *= -1.0;
		currentElapsed = 0;

		//body->setGravity(btVector3(0, 0, 0));
	}
	//else
	{
		if (currentElapsed > lifeTime)
		{
			chooseNewDirection();
		}

	}

	body->setLinearVelocity(direction);
	body->setAngularVelocity(btVector3(0.0,0.0,0.0));


	//float g = (2 * dist) / (dTime); //dTime = 1/60
	//m_bars[i]->setLinearVelocity(btVector3(0, 0, 0));
	//m_bars[i]->setGravity(btVector3(0, speedUpFactor * g, 0));


}

void BarInfo::chooseNewDirection()
{
	float maxFrameDistance = 10.0;

	float distDirection = (rand() % 2 == 1 ? 1 : -1);

	double x = static_cast <double> (rand()) / (static_cast <double> (RAND_MAX / maxFrameDistance));
	direction[1] = x * distDirection;
	currentElapsed = 0;
}


PARTNERS