~ubuntu-branches/debian/experimental/openscenegraph/experimental

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/mdl/MDLReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Luaces
  • Date: 2010-05-03 21:42:01 UTC
  • mfrom: (1.1.9 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100503214201-iy060qxb94vsfv87
Tags: 2.8.3-3
* Added README.source. Thanks Manuel Montecelo.
* Removed FindGDAL.cmake file supplied by upstream since it does not
  detect current libgdal1-1.6.0. The script provided by CMake works
  fine.
* Removed openthreads-doc since OpenThreads documentation is shared with
  OpenSceneGraph's, hence this package was empty.
* Now ccache handling is being done automatically by CMake.
* Drop conflict dependencies with previous versions to let them coexist
  with current ones (Closes: #580079 #580081).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <osg/Group>
5
5
#include <osg/Object>
6
6
#include <osg/Material>
 
7
#include <osg/Math>
7
8
#include <osg/MatrixTransform>
8
9
#include <osg/Node>
9
10
#include <osg/Notify>
191
192
    std::string              tex2Name;
192
193
    ref_ptr<Texture>         texture;
193
194
    ref_ptr<Texture>         texture2;
 
195
    ref_ptr<Material>        material;
194
196
    ref_ptr<BlendFunc>       blend;
195
197
    bool                     translucent;
 
198
    double                   alpha;
196
199
 
197
200
    // Find the material file
198
201
    mtlFileName = std::string(materialName) + ".vmt";
298
301
    // Assume not translucent unless the properties say otherwise
299
302
    translucent = false;
300
303
 
 
304
    // Assume full opacity
 
305
    alpha = 1.0;
 
306
 
301
307
    // Read the material properties next
302
308
    while (!mtlFile->eof())
303
309
    {
341
347
                        translucent = true;
342
348
                }
343
349
            }
 
350
            else if (equalCaseInsensitive(token, "$alpha"))
 
351
            {
 
352
                // Get the translucency setting
 
353
                token = getToken(line, " \t\n\r\"", start);
 
354
 
 
355
                // Interpret the setting
 
356
                if (!token.empty())
 
357
                {
 
358
                   alpha = osg::asciiToDouble(token.c_str());
 
359
                }
 
360
            }
344
361
 
345
362
            // Try the next token
346
363
            token = getToken(line, " \t\n\r\"", start);
379
396
            blend = new BlendFunc(BlendFunc::SRC_ALPHA,
380
397
                                  BlendFunc::ONE_MINUS_SRC_ALPHA);
381
398
            stateSet->setAttributeAndModes(blend.get(), StateAttribute::ON);
 
399
            stateSet->setMode(GL_BLEND, StateAttribute::ON);
382
400
 
383
401
            // Set the rendering hint for this stateset to transparent
384
402
            stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
387
405
    else
388
406
    {
389
407
        // All other shaders fall back to fixed function
390
 
        // TODO:  LightMappedGeneric shader
391
408
 
392
409
        // Create the StateSet
393
410
        stateSet = new StateSet();
394
411
 
 
412
        // Add a material to the state set
 
413
        material = new Material();
 
414
        material->setAmbient(Material::FRONT_AND_BACK,
 
415
                             Vec4(1.0, 1.0, 1.0, 1.0) );
 
416
        material->setDiffuse(Material::FRONT_AND_BACK,
 
417
                             Vec4(1.0, 1.0, 1.0, 1.0) );
 
418
        material->setSpecular(Material::FRONT_AND_BACK,
 
419
                             Vec4(0.0, 0.0, 0.0, 1.0) );
 
420
        material->setShininess(Material::FRONT_AND_BACK, 1.0);
 
421
        material->setEmission(Material::FRONT_AND_BACK,
 
422
                              Vec4(0.0, 0.0, 0.0, 1.0) );
 
423
        material->setAlpha(Material::FRONT_AND_BACK, alpha);
 
424
        stateSet->setAttributeAndModes(material.get(), StateAttribute::ON);
 
425
 
395
426
        // Add the texture attribute (or disable texturing if no base texture)
396
427
        if (texture != NULL)
397
428
        {
399
430
                                                  StateAttribute::ON);
400
431
 
401
432
            // See if the material is translucent
402
 
            if (translucent)
 
433
            if ((translucent) || (alpha < 1.0))
403
434
            {
404
435
                // Add the blending attribute as well
405
436
                blend = new BlendFunc(BlendFunc::SRC_ALPHA,
406
437
                                      BlendFunc::ONE_MINUS_SRC_ALPHA);
407
438
                stateSet->setAttributeAndModes(blend.get(),
408
439
                                               StateAttribute::ON);
 
440
                stateSet->setMode(GL_BLEND, StateAttribute::ON);
409
441
 
410
442
                // Set the rendering hint for this stateset to transparent
411
443
                stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
633
665
        mdlRoot->addBodyPart(partNode);
634
666
    }
635
667
 
636
 
    // Open the VVD file that goes with this model
 
668
    // Open the VVD (vertex data) file that goes with this model
637
669
    vvdFile = findDataFile(getNameLessExtension(file) + ".vvd",
638
670
                           CASE_INSENSITIVE);
639
671
    vvdReader = new VVDReader();
640
672
    vvdReader->readFile(vvdFile);
641
673
 
642
 
    // Open the VTX file that goes with this model (at this point, I don't
643
 
    // see a reason not to always just use the DX9 version)
 
674
    // Open the VTX file (index and primitive data) that goes with this model
 
675
    // (at this point, I don't see a reason not to always just use the DX9
 
676
    // version)
644
677
    vtxFile = findDataFile(getNameLessExtension(file) + ".dx90.vtx",
645
678
                           CASE_INSENSITIVE);
646
679
    vtxReader = new VTXReader(vvdReader, mdlRoot);