mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:26:40 +00:00 
			
		
		
		
	
						commit
						3ef40676bc
					
				
					 3 changed files with 39 additions and 15 deletions
				
			
		| 
						 | 
					@ -36,14 +36,9 @@ namespace MWClass
 | 
				
			||||||
        objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
 | 
					        objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!model.empty())
 | 
					        if (!model.empty())
 | 
				
			||||||
            objects.insertMesh(ptr, "meshes\\" + model);
 | 
					            objects.insertMesh(ptr, "meshes\\" + model, true);
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
        const int color = ref->mBase->mData.mColor;
 | 
					            objects.insertLight(ptr, NULL);
 | 
				
			||||||
        const float r = ((color >> 0) & 0xFF) / 255.0f;
 | 
					 | 
				
			||||||
        const float g = ((color >> 8) & 0xFF) / 255.0f;
 | 
					 | 
				
			||||||
        const float b = ((color >> 16) & 0xFF) / 255.0f;
 | 
					 | 
				
			||||||
        const float radius = float (ref->mBase->mData.mRadius);
 | 
					 | 
				
			||||||
        objects.insertLight (ptr, r, g, b, radius);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
 | 
					    void Light::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,18 @@ void Objects::clearSceneNode (Ogre::SceneNode *node)
 | 
				
			||||||
    for (int i=node->numAttachedObjects()-1; i>=0; --i)
 | 
					    for (int i=node->numAttachedObjects()-1; i>=0; --i)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Ogre::MovableObject *object = node->getAttachedObject (i);
 | 
					        Ogre::MovableObject *object = node->getAttachedObject (i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // for entities, destroy any objects attached to bones
 | 
				
			||||||
 | 
					        if (object->getTypeFlags () == Ogre::SceneManager::ENTITY_TYPE_MASK)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Ogre::Entity* ent = static_cast<Ogre::Entity*>(object);
 | 
				
			||||||
 | 
					            Ogre::Entity::ChildObjectListIterator children = ent->getAttachedObjectIterator ();
 | 
				
			||||||
 | 
					            while (children.hasMoreElements())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                mRenderer.getScene ()->destroyMovableObject (children.getNext ());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node->detachObject (object);
 | 
					        node->detachObject (object);
 | 
				
			||||||
        mRenderer.getScene()->destroyMovableObject (object);
 | 
					        mRenderer.getScene()->destroyMovableObject (object);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -87,7 +99,7 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_)
 | 
				
			||||||
    mIsStatic = static_;
 | 
					    mIsStatic = static_;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
 | 
					void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
 | 
					    Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
 | 
				
			||||||
    assert(insert);
 | 
					    assert(insert);
 | 
				
			||||||
| 
						 | 
					@ -204,17 +216,29 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
 | 
				
			||||||
            iter++;
 | 
					            iter++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (light)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        insertLight(ptr, entities.mSkelBase);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius)
 | 
					void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle());
 | 
					    Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle());
 | 
				
			||||||
    assert(insert);
 | 
					    assert(insert);
 | 
				
			||||||
    Ogre::Light *light = mRenderer.getScene()->createLight();
 | 
					 | 
				
			||||||
    light->setDiffuseColour (r, g, b);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
 | 
					    MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const int color = ref->mBase->mData.mColor;
 | 
				
			||||||
 | 
					    const float r = ((color >> 0) & 0xFF) / 255.0f;
 | 
				
			||||||
 | 
					    const float g = ((color >> 8) & 0xFF) / 255.0f;
 | 
				
			||||||
 | 
					    const float b = ((color >> 16) & 0xFF) / 255.0f;
 | 
				
			||||||
 | 
					    const float radius = float (ref->mBase->mData.mRadius);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ogre::Light *light = mRenderer.getScene()->createLight();
 | 
				
			||||||
 | 
					    light->setDiffuseColour (r, g, b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LightInfo info;
 | 
					    LightInfo info;
 | 
				
			||||||
    info.name = light->getName();
 | 
					    info.name = light->getName();
 | 
				
			||||||
    info.radius = radius;
 | 
					    info.radius = radius;
 | 
				
			||||||
| 
						 | 
					@ -265,7 +289,12 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f
 | 
				
			||||||
        light->setAttenuation(r*10, 0, 0, attenuation);
 | 
					        light->setAttenuation(r*10, 0, 0, attenuation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // If there's an AttachLight bone, attach the light to that, otherwise attach it to the base scene node
 | 
				
			||||||
 | 
					    if (skelBase && skelBase->getSkeleton ()->hasBone ("AttachLight"))
 | 
				
			||||||
 | 
					        skelBase->attachObjectToBone ("AttachLight", light);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
        insert->attachObject(light);
 | 
					        insert->attachObject(light);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mLights.push_back(info);
 | 
					    mLights.push_back(info);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,8 +73,8 @@ public:
 | 
				
			||||||
    Objects(OEngine::Render::OgreRenderer& renderer): mRenderer (renderer), mIsStatic(false) {}
 | 
					    Objects(OEngine::Render::OgreRenderer& renderer): mRenderer (renderer), mIsStatic(false) {}
 | 
				
			||||||
    ~Objects(){}
 | 
					    ~Objects(){}
 | 
				
			||||||
    void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
 | 
					    void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
 | 
				
			||||||
    void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh);
 | 
					    void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light=false);
 | 
				
			||||||
    void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius);
 | 
					    void insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void enableLights();
 | 
					    void enableLights();
 | 
				
			||||||
    void disableLights();
 | 
					    void disableLights();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue