Thanks for reply, Jorge. I really appreciate your help!
I'll try today to load a simpler model. May i use ".osg" model or ".osgt"?
It's possible to try to load directly a ".dae" model?
Yesterday, i've downloaded "OpenSceneGraph-Data-3.0.0", unzipped and put in my
HTC sdcard.
I tried all ".osg" and "osgt" examples; this is the result:
Model visible Texture visible
avatar.osg --> No No
axes.osgt --> Yes No
bignathan.ogs --> No No
cessna.ogs --> Yes No
cessna.ogst --> Yes No
cessnafire.ogs --> Yes No
cessnafire.ogst --> Yes No
clock.ogst --> Yes No
cow.ogs --> Yes No
cow.ogsy --> Yes No
cube_mapped_torus --> Yes No
dumptruck.ogs --> Yes No
dumptruck.ogst --> Yes No
example.ogs --> No No
fountain.ogst --> Yes No
glider.ogs --> Yes No
glider.ogst --> Yes No
glsl_confetti.ogst --> No No
glsl_julia.ogst --> Yes No
glsl_mandelbrot.ogs --> Yes No
glsl_simple.ogs --> No No
Jansens.ogs --> No No
lz.ogs --> Yes No
lz.ogst --> Yes No
morphing.ogs --> No No
morphtarget_shape0 --> Yes No
morphtarget_shape1 --> Yes No
nathan.ogs --> No No
osgcool.ogst --> Yes No
robot.ogs --> No No
skydome.ogst --> Yes No
SmokeBox.ogs --> Yes No
spaceship.ogs --> Yes No
All model are too advanced for android frameword or i do something wrong?
Another try: I like to start from the beginning.
I've tried to convert BasicGeometry tutorial, for learn.
I took osgAndroidExampleGLES2 for project base. I modified OsgMainApp like this:
Code:
#include "OsgMainApp.hpp"
#include <osg/PositionAttitudeTransform>
OsgMainApp::OsgMainApp(){
_lodScale = 1.0f;
_prevFrame = 0;
_initialized = false;
_clean_scene = false;
}
OsgMainApp::~OsgMainApp(){
}
//Initialization function
void OsgMainApp::initOsgWindow(int x,int y,int width,int height){
__android_log_write(ANDROID_LOG_ERROR, "OSGANDROID", "Initializing
geometry");
osg::notify(osg::ALWAYS)<<"Testing"<<std::endl;
_viewer = new osgViewer::Viewer();
_viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height);
_viewer->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
_root = new osg::Group();
_pyramidGeode = new osg::Geode();
_pyramidGeometry = new osg::Geometry();
//OsgMainApp::loadObjects();
// switch off lighting as we haven't assigned any normals.
_root->getOrCreateStateSet()->setMode(GL_LIGHTING,
osg::StateAttribute::OFF);
_viewer->realize();
_viewer->addEventHandler(new osgViewer::StatsHandler);
_viewer->addEventHandler(new
osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()));
_viewer->addEventHandler(new osgViewer::ThreadingHandler);
_viewer->addEventHandler(new osgViewer::LODScaleHandler);
_manipulator = new osgGA::KeySwitchMatrixManipulator;
_manipulator->addMatrixManipulator( '1', "Trackball", new
osgGA::TrackballManipulator() );
_manipulator->addMatrixManipulator( '2', "Flight", new
osgGA::FlightManipulator() );
_manipulator->addMatrixManipulator( '3', "Drive", new
osgGA::DriveManipulator() );
_manipulator->addMatrixManipulator( '4', "Terrain", new
osgGA::TerrainManipulator() );
_manipulator->addMatrixManipulator( '5', "Orbit", new
osgGA::OrbitManipulator() );
_manipulator->addMatrixManipulator( '6', "FirstPerson", new
osgGA::FirstPersonManipulator() );
_manipulator->addMatrixManipulator( '7', "Spherical", new
osgGA::SphericalManipulator() );
_viewer->setCameraManipulator( _manipulator.get() );
//_viewer->getViewerStats()->collectStats("scene", true);
_initialized = true;
__android_log_write(ANDROID_LOG_ERROR, "OSGANDROID", "END INIT");
}
//Draw
void OsgMainApp::draw(){
//Associate the pyramid geometry with the pyramid geode
// Add the pyramid geode to the root node of the scene graph.
_pyramidGeode->addDrawable(_pyramidGeometry);
_root->addChild(_pyramidGeode);
OsgMainApp::loadObjects();
//The final step is to set up and enter a simulation loop.
_viewer->setSceneData( _root );
_viewer->frame();
}
void OsgMainApp::loadObjects(){
//Declare an array of vertices. Each vertex will be represented by
//a triple -- an instances of the vec3 class. An instance of
//osg::Vec3Array can be used to store these triples. Since
//osg::Vec3Array is derived from the STL vector class, we can use the
//push_back method to add array elements. Push back adds elements to
//the end of the vector, thus the index of first element entered is
//zero, the second entries index is 1, etc.
//Using a right-handed coordinate system with 'z' up, array
//elements zero..four below represent the 5 points required to create
//a simple pyramid.
__android_log_write(ANDROID_LOG_ERROR, "OSGANDROID", "Loading objects");
osg::Vec3Array* pyramidVertices = new osg::Vec3Array;
pyramidVertices->push_back( osg::Vec3( 0, 0, 0) ); // front left
pyramidVertices->push_back( osg::Vec3(10, 0, 0) ); // front right
pyramidVertices->push_back( osg::Vec3(10,10, 0) ); // back right
pyramidVertices->push_back( osg::Vec3( 0,10, 0) ); // back left
pyramidVertices->push_back( osg::Vec3( 5, 5,10) ); // peak
//Associate this set of vertices with the geometry associated with the
//geode we added to the scene.
_pyramidGeometry->setVertexArray( pyramidVertices );
//Next, create a primitive set and add it to the pyramid geometry.
//Use the first four points of the pyramid to define the base using an
//instance of the DrawElementsUint class. Again this class is derived
//from the STL vector, so the push_back method will add elements in
//sequential order. To ensure proper backface cullling, vertices
//should be specified in counterclockwise order. The arguments for the
//constructor are the enumerated type for the primitive
//(same as the OpenGL primitive enumerated types), and the index in
//the vertex array to start from.
osg::DrawElementsUInt* pyramidBase =
new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
pyramidBase->push_back(3);
pyramidBase->push_back(2);
pyramidBase->push_back(1);
pyramidBase->push_back(0);
_pyramidGeometry->addPrimitiveSet(pyramidBase);
//Repeat the same for each of the four sides. Again, vertices are
//specified in counter-clockwise order.
osg::DrawElementsUInt* pyramidFaceOne =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceOne->push_back(0);
pyramidFaceOne->push_back(1);
pyramidFaceOne->push_back(4);
_pyramidGeometry->addPrimitiveSet(pyramidFaceOne);
osg::DrawElementsUInt* pyramidFaceTwo =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceTwo->push_back(1);
pyramidFaceTwo->push_back(2);
pyramidFaceTwo->push_back(4);
_pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);
osg::DrawElementsUInt* pyramidFaceThree =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceThree->push_back(2);
pyramidFaceThree->push_back(3);
pyramidFaceThree->push_back(4);
_pyramidGeometry->addPrimitiveSet(pyramidFaceThree);
osg::DrawElementsUInt* pyramidFaceFour =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
pyramidFaceFour->push_back(3);
pyramidFaceFour->push_back(0);
pyramidFaceFour->push_back(4);
_pyramidGeometry->addPrimitiveSet(pyramidFaceFour);
//Declare and load an array of Vec4 elements to store colors.
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 green
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 blue
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 4 red
//The next step is to associate the array of colors with the geometry,
//assign the color indices created above to the geometry and set the
//binding mode to _PER_VERTEX.
_pyramidGeometry->setColorArray(colors);
_pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
//Now that we have created a geometry node and added it to the scene
//we can reuse this geometry. For example, if we wanted to put a
//second pyramid 15 units to the right of the first one, we could add
//this geode as the child of a transform node in our scene graph.
// Declare and initialize a transform node.
osg::PositionAttitudeTransform* pyramidTwoXForm =
new osg::PositionAttitudeTransform();
// Use the 'addChild' method of the osg::Group class to
// add the transform as a child of the root node and the
// pyramid node as a child of the transform.
_root->addChild(pyramidTwoXForm);
pyramidTwoXForm->addChild(_pyramidGeode);
// Declare and initialize a Vec3 instance to change the
// position of the model in the scene
osg::Vec3 pyramidTwoPosition(15,0,0);
pyramidTwoXForm->setPosition( pyramidTwoPosition );
}
//Events
void OsgMainApp::keyboardDown(int key){
_viewer->getEventQueue()->keyPress(key);
}
void OsgMainApp::keyboardUp(int key){
_viewer->getEventQueue()->keyRelease(key);
}
Result: Nothing happend! The activity start, "init" goes, "draw" goes, but my
device screen remains blue. Nothing has drawn.
I'm wrong here too?
Sorry, but i'm too noob :)
Thanks in advance for the help!
Jorge Izquierdo Ciges wrote:
> Giulio, there has been some changes in the handling of textures/projective
> textures. Cow it's usually a model that gave me errors because of that. Just
> try simple models withouth textures first and learn step by step.
>
>
[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45631#45631
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org