Replies: 1 comment 3 replies
-
use useLoader - it caches your models and makes it way simpler. https://codesandbox.io/s/hungry-easley-lwmpi also check out gltfjsx, this is how you can turn your gltfs into declarative assets |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a project that is using two models. Both loaded from BLOB storage.
const Model1 = (props) => {
const modelSource = props.modelPath + '/Model1 .gltf'
const model1 Manager = new THREE.LoadingManager();
model1Manager.onError = function (url) { console.log('There was an error loading ' + url); };
model1Manager.onLoad = function () { props.callBack() }
const [modelObject, setModelObject] = useState()
useEffect(() => {
let modelLoader = new GLTFLoader(model1Manager);
modelLoader.load(modelSource, setModelObject)
}, [])
return modelObject ? : null
}
export default (Model1);
const Model2 = ( ) => {
const model2Path = "string of the url"
const [ model2Object, setModel2Object] = useState()
const model2Manager = new THREE.LoadingManager();
model2Manager.onError = function (url) { console.log('There was an error loading ' + url); };
useEffect(() => {
const model2Loader = new GLTFLoader(model2Manager);
model2Loader.load(model2Path, setModel2Object)
}, [])
}
export default ( Model2 );
This is the component that uses both models
The only difference between the two is A) model1's path is passed in through props. Because it can be changed. (There are dozens of choices)
B) model2 is a skybox that does not change. But I do set the position and scale. I have commented this out with no change to behaviour in question.
I have two questions.
1st) on a state change both models are re-fetch from BLOB storage. What is the best way to prevent this. I should only need to download them one time.
2nd) When the models are re-rendered there is a very noticeable delay with model2 (it is absent for a full 2 seconds). Model1 is much more complex with 36 textures. While Model2 is simple with 4 textures. Any ideas why?
Beta Was this translation helpful? Give feedback.
All reactions