Page 1 of 2

cfg and scn paths

Posted: Tue Mar 26, 2019 9:18 am
by nigec
My Python project has a scene folder, all the examples have the path "scene.file = scenes/cornell/cornell.scn" so it will work fine
But if I export from Blender or whatever I just get the scn name, so unless I manually add the path to the files or move my project into the folder I'm stuck
How do I open a cfg file with the full path so it will load the scn file content in Python
I've done a search and not found anything

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 10:21 am
by Dade
You can use the "File name resolver" to add paths to the list of places where LuxCore will look. You can add a new path by calling LuxCore API function AddFileNameResolverPath(path):

https://github.com/LuxCoreRender/LuxCor ... ore.h#L149

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 1:02 pm
by nigec
I don't appear to be able to get it to work

I suck at C++ (and python really) but I found this in luxcoreui.cpp:

Code: Select all

		if (configFileName.compare("") != 0) {
			// Clear the file name resolver list
			luxcore::ClearFileNameResolverPaths();
			// Add the current directory to the list of place where to look for files
			luxcore::AddFileNameResolverPath(".");
			// Add the .cfg directory to the list of place where to look for files
			boost::filesystem::path path(configFileName);
			luxcore::AddFileNameResolverPath(path.parent_path().generic_string());
		}
so

Code: Select all

			boost::filesystem::path path(configFileName);
			luxcore::AddFileNameResolverPath(path.parent_path().generic_string());
Is there a conversion happening to get path.parent_path().generic_string()?
Is this the folder path?

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 1:19 pm
by Dade
Are you working in Python or C++ ?
nigec wrote: Tue Mar 26, 2019 1:02 pm Is there a conversion happening to get path.parent_path().generic_string()?
Yes, it gets the parent directory of where the current render.cfg file is (.parent_path()) and than convert the Boost "path" object to a generic string (.generic_string()).
nigec wrote: Tue Mar 26, 2019 1:02 pm Is this the folder path?
Yes, you have to pass to luxcore::AddFileNameResolverPath() a string with the directory to add to the list of places where to look. Be careful with if the string identify and absolute or relative path.

LuxCoreUI adds to the list the current path (i.e. ".") and the directory where the render.cfg file is. I assume you need to do the same.

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 1:47 pm
by nigec
I'm working with Python, I was just looking for something in context, all the Python examples preload the scene.. even the pyside example :)
I still haven't got it working.. its not a good day... lol

I'll try a simple script rather than trying to add it to my current project

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 2:22 pm
by Dade
Check the log output, you should have something like:

Code: Select all

[LuxCore][0.003] File Name Resolver Configuration: 
[LuxCore][0.003]   .
[LuxCore][0.003]   scenes/cornell
The list should include the directory where scene.scn file is.

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 2:52 pm
by nigec
Yes that works, so its something to do with how I'm loading the cfg file

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 5:05 pm
by nigec
Still no joy:

Code: Select all

	print("RenderConfig and RenderSession examples (requires scenes directory)...")
	
	pyluxcore.AddFileNameResolverPath(".")
	pyluxcore.AddFileNameResolverPath("scenes/cornell")
	cfgFileName ="cornell.cfg"
	props = pyluxcore.Properties(cfgFileName)

	# Change the render engine to PATHCPU
	props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))

	config = pyluxcore.RenderConfig(props)cornell.cfg
	session = pyluxcore.RenderSession(config)

	session.Start()
the following works with a the path scenes/cornell/cornell.cfg

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 7:02 pm
by nigec
Here's an example I did with guizero I don't really understand why its not working, I've tried everything I can think of with the path.. could it be a python issue?

Code: Select all

from guizero import *
import random
import time
import sys
import os
from array import *
sys.path.append("./lib")
import pyluxcore
count = 0

def loadscene():
    print("LuxCore %s" % pyluxcore.Version())
    pyluxcore.Init()
    print("RenderConfig and RenderSession examples (requires scenes directory)...")
    session.Start()
    counter_loop()

def counter_loop():
    global count   
    startTime = count
    #Update statistics     
    if count < 5:
        button.disable()
        session.UpdateStats()
        stats = session.GetStats()
        print("[Elapsed time: %3d/5sec][Samples %4d][Avg. samples/sec % 3.2fM on %.1fK tris]" % (
        stats.Get("stats.renderengine.time").GetFloat(),
        stats.Get("stats.renderengine.pass").GetInt(),
        (stats.Get("stats.renderengine.total.samplesec").GetFloat() / 1000000.0),
        (stats.Get("stats.dataset.trianglecount").GetFloat() / 1000.0)))
        count += 1
        counter.value = count
        app.after(1000, counter_loop)
    else:
        button.enable()
        count = 0
        session.Stop()
        session.GetFilm().Save()   
        picture = Picture(app, image="RGB_IMAGEPIPELINE_0.png")

app = App(title="counter")
pyluxcore.ClearFileNameResolverPaths()
pyluxcore.AddFileNameResolverPath(".")
pyluxcore.AddFileNameResolverPath("scenes/cornell")
props = pyluxcore.Properties("cornell.cfg")
#props = pyluxcore.Properties("scenes/cornell/cornell.cfg")
props.Set(pyluxcore.Property("renderengine.type", ["PATHCPU"]))
props.Set(pyluxcore.Property("film.outputs.0.type", ["RGB_IMAGEPIPELINE"]))
props.Set(pyluxcore.Property("film.outputs.0.filename", ["RGB_IMAGEPIPELINE_0.png"]))
config = pyluxcore.RenderConfig(props)
session = pyluxcore.RenderSession(config)
title_box = Box(app, width="fill", align="top", border=True)
title = Text(title_box, text="Header")
title_box.text_color="white"
title_box.bg="grey"
button = PushButton(app, command=loadscene, text="start loop")
counter = Text(app, "stopped")
app.display()

Re: cfg and scn paths

Posted: Tue Mar 26, 2019 7:12 pm
by B.Y.O.B.
Have you tried using an absolute path instead of "scenes/cornell"?
Is "scenes/cornell" even a valid path?
If it is a valid relative path, maybe you are starting the script from the wrong location?