Browse Source

Fix spheres and textures

* Use v2 meshes now that exporter creates them
* Add textures to resource locations
* Added model and texture for material preview
pitch-detection
Macoy Madson 12 months ago
parent
commit
6938cb1e73
  1. 2
      Dependencies/ogre-next
  2. 22
      src/Ogre.cake
  3. 8
      src/OgreInitialize.cake
  4. BIN
      test/assets/MaterialSphere.blend
  5. BIN
      test/assets/Monkey.blend
  6. 3
      test/data/Materials/Textures/License.txt
  7. BIN
      test/data/Materials/Textures/SaintPetersBasilica.dds
  8. BIN
      test/data/Models/Sphere.mesh
  9. BIN
      test/data/Models/Suzanne.mesh
  10. 44
      test/src/OgreHlms.cpp
  11. 4
      test/src/VocalGame.cake

2
Dependencies/ogre-next

@ -1 +1 @@
Subproject commit 52b754a393eb26b0ab09e5c62bebf0c9a880495c
Subproject commit 3dceaab8f45e71b5f9ee68f7666b522c558396ae

22
src/Ogre.cake

@ -52,7 +52,8 @@
(defstruct scene-node
node (* (in Ogre SceneNode)))
(defun ogre-load-mesh (name (* (const char)) &return mesh-handle)
;; If you get "cannot find serializer" you need to change which of these functions you use
(defun ogre-load-mesh-from-v1 (name (* (const char)) &return mesh-handle)
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
;; Load the v1 mesh. Notice the v1 namespace
;; Also notice the HBU_STATIC flag; since the HBU_WRITE_ONLY
@ -90,6 +91,25 @@
(var mesh-handle mesh-handle (array item))
(return mesh-handle))
;; If you get "cannot find serializer" you need to change which of these functions you use
(defun ogre-load-mesh (name (* (const char)) &return mesh-handle)
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
(var v2Mesh Ogre::MeshPtr
(on-call (call (in Ogre MeshManager getSingleton)) load
name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME))
;; Create an Item with the model we just imported.
;; Notice we use the name of the imported model. We could also use the overload
;; with the mesh pointer:
;; item = scene-manager->createItem( v2Mesh, Ogre::SCENE_DYNAMIC );
(var item (* Ogre::Item) (on-call-ptr scene-manager createItem
name Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME
Ogre::SCENE_DYNAMIC))
(var mesh-handle mesh-handle (array item))
(return mesh-handle))
(defun ogre-node-from-item (mesh-handle mesh-handle &return scene-node)
(var new-scene-node scene-node (array null))
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))

8
src/OgreInitialize.cake

@ -1,7 +1,8 @@
;; Most of this file comes from the Ogre 2 basic project. It's customized now. Once I get more
;; familiar with Ogre, I'll probably try to move this file into Ogre.cake or something, which
;; currently acts as my "custom code"/integration file
(import &comptime-only "Macros.cake")
;; #pragma GCC diagnostic push
;; #pragma GCC diagnostic ignored "-Woverloaded-virtual"
(c-import
"OgreArchiveManager.h"
"OgreCamera.h"
@ -21,7 +22,6 @@
"Compositor/OgreCompositorManager2.h"
"OgreWindowEventUtilities.h")
;; #pragma GCC diagnostic pop
(forward-declare
(namespace Ogre
@ -220,6 +220,8 @@
(call (in Ogre ResourceGroupManager getSingleton)))
(on-call resource-group-manager addResourceLocation
"data/Models" "FileSystem" "Models")
(on-call resource-group-manager addResourceLocation
"data/Materials/Textures" "FileSystem" "Textures")
(scope ;; Materials
;; I had to read https://forums.ogre3d.org/viewtopic.php?f=5&t=94769 before figuring out

BIN
test/assets/MaterialSphere.blend

Binary file not shown.

BIN
test/assets/Monkey.blend

Binary file not shown.

3
test/data/Materials/Textures/License.txt

@ -0,0 +1,3 @@
The following textures are (C) by Emil Persson (aka Humus) under Creative Commons Attribution 3.0 Unported License:
* Saint Peter's Basilica - SaintPetersBasilica.dds - http://www.humus.name/index.php?page=Textures&ID=106

BIN
test/data/Materials/Textures/SaintPetersBasilica.dds

Binary file not shown.

BIN
test/data/Models/Sphere.mesh

Binary file not shown.

BIN
test/data/Models/Suzanne.mesh

Binary file not shown.

44
test/src/OgreHlms.cpp

@ -32,20 +32,11 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
Ogre::TextureGpuManager* textureMgr = root->getRenderSystem()->getTextureGpuManager();
Ogre::SceneNode* rootSceneNode = sceneManager->getRootSceneNode();
// Convert the sphere mesh (doesn't work due to material)
// const Ogre::String meshNameV2 = ("sphere.mesh" + Ogre::String(" Imported"));
// {
// Ogre::v1::MeshPtr meshV1 = Ogre::v1::MeshManager::getSingleton().load(
// "sphere.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::v1::HardwareBuffer::HBU_STATIC, Ogre::v1::HardwareBuffer::HBU_STATIC);
// bool halfPosition = true;
// bool halfUVs = true;
// bool useQTangents = true;
// Ogre::MeshPtr v2Mesh = Ogre::MeshManager::getSingleton().createByImportingV1(
// meshNameV2, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, meshV1.get(),
// halfPosition, halfUVs, useQTangents);
// meshV1->unload();
// }
const Ogre::String meshNameV2 = "Sphere.mesh";
{
Ogre::MeshPtr v2Mesh = Ogre::MeshManager::getSingleton().load(
"Sphere.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
}
for (int x = 0; x < numX; ++x)
{
@ -68,18 +59,19 @@ void ogreCreatePbsSpheres(Ogre::Root* root, Ogre::SceneManager* sceneManager)
datablock->setRoughness(std::max(0.02f, x / std::max(1.0f, (float)(numX - 1))));
datablock->setFresnel(Ogre::Vector3(z / std::max(1.0f, (float)(numZ - 1))), false);
// Ogre::Item* item = nullptr;
// {
// item = sceneManager->createItem(
// meshNameV2, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::SCENE_DYNAMIC);
// }
// TODO this is a hack that relies on ogre-load-mesh being called some time before this
// This is because "sphere.mesh" is an old-style mesh which I need a convertor for or something
Ogre::Item* item = sceneManager->createItem(
"Suzanne.mesh Imported", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::SCENE_DYNAMIC);
Ogre::Item* item = nullptr;
{
item = sceneManager->createItem(
meshNameV2, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
Ogre::SCENE_DYNAMIC);
}
// // TODO this is a hack that relies on ogre-load-mesh being called some time before this
// // This is because "sphere.mesh" is an old-style mesh which I need a converter for or something
// Ogre::Item* item = sceneManager->createItem(
// "Suzanne.mesh Imported", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
// Ogre::SCENE_DYNAMIC);
item->setDatablock(datablock);
item->setVisibilityFlags(0x000000002);

4
test/src/VocalGame.cake

@ -312,7 +312,9 @@
(set g-light-node (ogre-create-light))
(when g-ogre-root
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager)))
(printf "Creating PBS spheres\n")
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager))
(printf "Creating PBS spheres done\n"))
(set initialized true))

Loading…
Cancel
Save