nearly working
This commit is contained in:
@@ -5,38 +5,81 @@ import subprocess
|
|||||||
import pybullet as p
|
import pybullet as p
|
||||||
from pdb import set_trace
|
from pdb import set_trace
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
#subprocess.call(["hardening-check", p.__file__])
|
#subprocess.call(["hardening-check", p.__file__])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
p.connect(p.DIRECT)
|
p.connect(p.DIRECT)
|
||||||
logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "debugTimings")
|
logId = p.startStateLogging(p.STATE_LOGGING_PROFILE_TIMINGS, "debugTimings")
|
||||||
|
|
||||||
plugin_fn = '/home/argusm/lang/bullet3/build/lib.linux-x86_64-3.5/eglRenderer.cpython-35m-x86_64-linux-gnu.so'
|
plugin = True
|
||||||
plugin = p.loadPlugin(plugin_fn,"_tinyRendererPlugin")
|
if plugin:
|
||||||
if plugin < 0:
|
plugin_fn = '/home/argusm/lang/bullet3/build/lib.linux-x86_64-3.5/eglRenderer.cpython-35m-x86_64-linux-gnu.so'
|
||||||
print("\nPlugin Failed to load!\n")
|
plugin = p.loadPlugin(plugin_fn,"_tinyRendererPlugin")
|
||||||
sys.exit()
|
if plugin < 0:
|
||||||
|
print("\nPlugin Failed to load!\n")
|
||||||
|
sys.exit()
|
||||||
|
print("plugin =",plugin)
|
||||||
|
|
||||||
print("plugin =",plugin)
|
path = '/home/argusm/lang/bullet3/examples/pybullet/gym/pybullet_data/duck_vhacd.urdf'
|
||||||
|
p.loadURDF(path,globalScaling=12)
|
||||||
path = '/home/argusm/lang/bullet3/examples/pybullet/gym/pybullet_data/r2d2.urdf'
|
#path = '/home/argusm/lang/gym-grasping/gym_grasping/robots/models/kuka_iiwa/kuka_weiss_bolt.sdf'
|
||||||
path = '/home/argusm/lang/gym-grasping/gym_grasping/robots/models/kuka_iiwa/kuka_weiss_bolt.sdf'
|
#p.loadSDF(path)
|
||||||
#p.loadURDF(path)
|
|
||||||
p.loadSDF(path)
|
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
plot = True
|
camTargetPos = [0,0,0]
|
||||||
|
upAxisIndex = 2
|
||||||
|
nearPlane = 0.01
|
||||||
|
farPlane = 100
|
||||||
|
camDistance = 2
|
||||||
|
pixelWidth = 128
|
||||||
|
pixelHeight = 128
|
||||||
|
fov = 60
|
||||||
|
|
||||||
|
plot = False
|
||||||
|
anim = True
|
||||||
|
if plot:
|
||||||
|
plt.ion()
|
||||||
|
if anim:
|
||||||
|
import matplotlib.animation as manimation
|
||||||
|
FFMpegWriter = manimation.writers['ffmpeg']
|
||||||
|
metadata = dict(title='Movie Test', artist='Matplotlib',
|
||||||
|
comment='Movie support!')
|
||||||
|
writer = FFMpegWriter(fps=15, metadata=metadata)
|
||||||
|
if plot or anim:
|
||||||
|
fig = plt.figure()
|
||||||
|
img = np.random.rand(pixelWidth,pixelHeight)
|
||||||
|
image = plt.imshow(img,interpolation='none',animated=True,label="blah")
|
||||||
|
ax = plt.gca()
|
||||||
|
ax.set_axis_off()
|
||||||
|
ax.set_aspect('equal')
|
||||||
|
plt.subplots_adjust(wspace=0, hspace=0, left=0, bottom=0, right=1, top=1)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for i in range(10):
|
iter = range(0,360,10)
|
||||||
hight, width, img_arr, deept_arr, obj_arr = p.getCameraImage(128,128)
|
with writer.saving(fig, "debug.mp4", len(iter)):
|
||||||
if plot:
|
for i,yaw in enumerate(iter):
|
||||||
plt.imshow(img_arr[:,:,:3])
|
viewMatrix = p.computeViewMatrixFromYawPitchRoll(camTargetPos, camDistance, 0, yaw-90, 0, upAxisIndex)
|
||||||
plt.show()
|
aspect = pixelWidth / pixelHeight;
|
||||||
if i % 100 == 0 and i > 0:
|
projectionMatrix = p.computeProjectionMatrixFOV(fov, aspect, nearPlane, farPlane);
|
||||||
print("FPS",100/(time.time()-start))
|
|
||||||
start = time.time()
|
hight, width, img_arr, deept_arr, obj_arr = p.getCameraImage(pixelWidth,pixelHeight,viewMatrix,projectionMatrix)
|
||||||
|
if plot:
|
||||||
|
image.set_data(img_arr)#np_img_arr)
|
||||||
|
ax.plot([0])
|
||||||
|
#plt.draw()
|
||||||
|
#plt.show()
|
||||||
|
plt.pause(0.01)
|
||||||
|
if anim:
|
||||||
|
image.set_data(img_arr)#np_img_arr)
|
||||||
|
ax.plot([0])
|
||||||
|
writer.grab_frame()
|
||||||
|
|
||||||
|
if i % 100 == 0 and i > 0:
|
||||||
|
print("FPS",100/(time.time()-start))
|
||||||
|
start = time.time()
|
||||||
finally:
|
finally:
|
||||||
p.stopStateLogging(logId)
|
p.stopStateLogging(logId)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ static void printGLString(const char *name, GLenum s) {
|
|||||||
printf("%s = %s\n",name, v);
|
printf("%s = %s\n",name, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct MyTexture2
|
struct MyTexture2
|
||||||
{
|
{
|
||||||
@@ -887,7 +888,6 @@ void TinyRendererVisualShapeConverter::resetCamera(float camDist, float yaw, flo
|
|||||||
m_data->m_camera.setCameraTargetPosition(camPosX,camPosY,camPosZ);
|
m_data->m_camera.setCameraTargetPosition(camPosX,camPosY,camPosZ);
|
||||||
m_data->m_camera.setAspectRatio((float)m_data->m_swWidth/(float)m_data->m_swHeight);
|
m_data->m_camera.setAspectRatio((float)m_data->m_swWidth/(float)m_data->m_swHeight);
|
||||||
m_data->m_camera.update();
|
m_data->m_camera.update();
|
||||||
m_data->m_instancingRenderer->updateCamera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
|
void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
|
||||||
@@ -908,37 +908,39 @@ void TinyRendererVisualShapeConverter::clearBuffers(TGAColor& clearColor)
|
|||||||
|
|
||||||
void TinyRendererVisualShapeConverter::render()
|
void TinyRendererVisualShapeConverter::render()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
//ATTRIBUTE_ALIGNED16(float viewMat[16]);
|
ATTRIBUTE_ALIGNED16(float viewMat[16]);
|
||||||
//ATTRIBUTE_ALIGNED16(float projMat[16]);
|
ATTRIBUTE_ALIGNED16(float projMat[16]);
|
||||||
//m_data->m_camera.getCameraProjectionMatrix(projMat);
|
m_data->m_camera.getCameraProjectionMatrix(projMat);
|
||||||
//m_data->m_camera.getCameraViewMatrix(viewMat);
|
m_data->m_camera.getCameraViewMatrix(viewMat);
|
||||||
|
cout<<viewMat[4*0 + 0]<<" "<<viewMat[4*0+1]<<" "<<viewMat[4*0+2]<<" "<<viewMat[4*0+3] << endl;
|
||||||
|
cout<<viewMat[4*1 + 0]<<" "<<viewMat[4*1+1]<<" "<<viewMat[4*1+2]<<" "<<viewMat[4*1+3] << endl;
|
||||||
|
cout<<viewMat[4*2 + 0]<<" "<<viewMat[4*2+1]<<" "<<viewMat[4*2+2]<<" "<<viewMat[4*2+3] << endl;
|
||||||
|
cout<<viewMat[4*3 + 0]<<" "<<viewMat[4*3+1]<<" "<<viewMat[4*3+2]<<" "<<viewMat[4*3+3] << endl;
|
||||||
|
*/
|
||||||
B3_PROFILE("m_instancingRenderer render");
|
B3_PROFILE("m_instancingRenderer render");
|
||||||
|
m_data->m_instancingRenderer->setActiveCamera(&m_data->m_camera);
|
||||||
m_data->m_instancingRenderer->updateCamera();
|
m_data->m_instancingRenderer->updateCamera();
|
||||||
m_data->m_instancingRenderer->renderScene();
|
m_data->m_instancingRenderer->renderScene();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId, const btTransform& worldTransform, const btVector3& localScaling)
|
|
||||||
{
|
|
||||||
TinyRendererObjectArray** renderObjPtr = m_data->m_swRenderInstances[collisionObjectUniqueId];
|
|
||||||
if (renderObjPtr)
|
|
||||||
{
|
|
||||||
TinyRendererObjectArray* renderObj = *renderObjPtr;
|
|
||||||
renderObj->m_worldTransform = worldTransform;
|
|
||||||
renderObj->m_localScaling = localScaling;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::render(const float viewMat[16], const float projMat[16])
|
void TinyRendererVisualShapeConverter::render(const float viewMat[16], const float projMat[16])
|
||||||
{
|
{
|
||||||
// This code is very similar to that of
|
// This code is very similar to that of
|
||||||
// PhysicsServerCommandProcessor::processRequestCameraImageCommand
|
// PhysicsServerCommandProcessor::processRequestCameraImageCommand
|
||||||
// maybe code from there should be moved.
|
// maybe code from there should be moved.
|
||||||
b3Error("not implemeted, use render()");
|
|
||||||
|
// Tiny allows rendering with viewMat, projMat explicitly, but
|
||||||
|
// GLInstancingRender calls m_activeCamera, so set this.
|
||||||
|
m_data->m_camera.setVRCamera(viewMat,projMat);
|
||||||
|
m_data->m_instancingRenderer->setActiveCamera(&m_data->m_camera);
|
||||||
|
m_data->m_instancingRenderer->updateCamera();
|
||||||
|
m_data->m_instancingRenderer->renderScene();
|
||||||
|
|
||||||
|
cout<<viewMat[4*0 + 0]<<" "<<viewMat[4*0+1]<<" "<<viewMat[4*0+2]<<" "<<viewMat[4*0+3] << endl;
|
||||||
|
cout<<viewMat[4*1 + 0]<<" "<<viewMat[4*1+1]<<" "<<viewMat[4*1+2]<<" "<<viewMat[4*1+3] << endl;
|
||||||
|
cout<<viewMat[4*2 + 0]<<" "<<viewMat[4*2+1]<<" "<<viewMat[4*2+2]<<" "<<viewMat[4*2+3] << endl;
|
||||||
|
cout<<viewMat[4*3 + 0]<<" "<<viewMat[4*3+1]<<" "<<viewMat[4*3+2]<<" "<<viewMat[4*3+3] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyRendererVisualShapeConverter::getWidthAndHeight(int& width, int& height)
|
void TinyRendererVisualShapeConverter::getWidthAndHeight(int& width, int& height)
|
||||||
@@ -1189,3 +1191,14 @@ int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TinyRendererVisualShapeConverter::syncTransform(int collisionObjectUniqueId, const btTransform& worldTransform, const btVector3& localScaling)
|
||||||
|
{
|
||||||
|
TinyRendererObjectArray** renderObjPtr = m_data->m_swRenderInstances[collisionObjectUniqueId];
|
||||||
|
if (renderObjPtr)
|
||||||
|
{
|
||||||
|
TinyRendererObjectArray* renderObj = *renderObjPtr;
|
||||||
|
renderObj->m_worldTransform = worldTransform;
|
||||||
|
renderObj->m_localScaling = localScaling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user