Can't use global variable inside tree.enumNodeFragments() delegate2019 Community Moderator ElectionWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var” to declare a variable in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?Check if a variable is a string in JavaScriptRead environment variables in Node.jsJavaScript check if variable exists (is defined/initialized)Is there a standard function to check for null, undefined, or blank variables in JavaScript?How to access the correct `this` inside a callback?
Can a druid choose the size of its wild shape beast?
How to create the Curved texte?
how to write formula in word in latex
Why one should not leave fingerprints on bulbs and plugs?
Time travel from stationary position?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
Did Ender ever learn that he killed Stilson and/or Bonzo?
Are there verbs that are neither telic, or atelic?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
An inequality of matrix norm
How do I hide Chekhov's Gun?
Why do Australian milk farmers need to protest supermarkets' milk price?
Opacity of an object in 2.8
Charles Hockett - 'F' article?
How to deal with taxi scam when on vacation?
What are substitutions for coconut in curry?
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
Are all passive ability checks floors for active ability checks?
Why do passenger jet manufacturers design their planes with stall prevention systems?
What should tie a collection of short-stories together?
Brexit - No Deal Rejection
What's the meaning of “spike” in the context of “adrenaline spike”?
What is the significance behind "40 days" that often appears in the Bible?
What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?
Can't use global variable inside tree.enumNodeFragments() delegate
2019 Community Moderator ElectionWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var” to declare a variable in JavaScript?How do you check if a variable is an array in JavaScript?How to determine if variable is 'undefined' or 'null'?Check if a variable is a string in JavaScriptRead environment variables in Node.jsJavaScript check if variable exists (is defined/initialized)Is there a standard function to check for null, undefined, or blank variables in JavaScript?How to access the correct `this` inside a callback?
I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.
highlight(externalId, color, dict)
let viewer = this.viewer;
var dbId = dict[externalId];
let myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
let scaleRatio = 1.005; // this was determined as optimal through visual inspection
var tree = NOP_VIEWER.model.getData().instanceTree;
document.oldMaterials = ;
tree.enumNodeFragments(dbId,
function(fragId)
document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
javascript autodesk-forge autodesk-viewer
add a comment |
I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.
highlight(externalId, color, dict)
let viewer = this.viewer;
var dbId = dict[externalId];
let myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
let scaleRatio = 1.005; // this was determined as optimal through visual inspection
var tree = NOP_VIEWER.model.getData().instanceTree;
document.oldMaterials = ;
tree.enumNodeFragments(dbId,
function(fragId)
document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
javascript autodesk-forge autodesk-viewer
add a comment |
I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.
highlight(externalId, color, dict)
let viewer = this.viewer;
var dbId = dict[externalId];
let myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
let scaleRatio = 1.005; // this was determined as optimal through visual inspection
var tree = NOP_VIEWER.model.getData().instanceTree;
document.oldMaterials = ;
tree.enumNodeFragments(dbId,
function(fragId)
document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
javascript autodesk-forge autodesk-viewer
I trying to save old materials of elements by fragId but can't do this because inside of tree.enumNodeFragments() document nor window isn't accessible.
highlight(externalId, color, dict)
let viewer = this.viewer;
var dbId = dict[externalId];
let myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
let scaleRatio = 1.005; // this was determined as optimal through visual inspection
var tree = NOP_VIEWER.model.getData().instanceTree;
document.oldMaterials = ;
tree.enumNodeFragments(dbId,
function(fragId)
document.oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
let fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
javascript autodesk-forge autodesk-viewer
javascript autodesk-forge autodesk-viewer
asked Mar 7 at 14:02
Anton KosenkoAnton Kosenko
6211
6211
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:
function highlight(externalId, color, dict)
const viewer = this.viewer;
const dbId = dict[externalId];
const myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
const scaleRatio = 1.005; // this was determined as optimal through visual inspection
const tree = NOP_VIEWER.model.getData().instanceTree;
const oldMaterials = ;
tree.enumNodeFragments(dbId, function(fragId)
oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especiallydocument), is not a good practice and could cause different issues. Try using the localoldMaterialsconst instead, and make sure that the callback function insideenumNodeFragmentsactually executes.
– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting aconsole.logordebuggerstatement in it.
– Petr Broz
Mar 7 at 14:55
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045639%2fcant-use-global-variable-inside-tree-enumnodefragments-delegate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:
function highlight(externalId, color, dict)
const viewer = this.viewer;
const dbId = dict[externalId];
const myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
const scaleRatio = 1.005; // this was determined as optimal through visual inspection
const tree = NOP_VIEWER.model.getData().instanceTree;
const oldMaterials = ;
tree.enumNodeFragments(dbId, function(fragId)
oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especiallydocument), is not a good practice and could cause different issues. Try using the localoldMaterialsconst instead, and make sure that the callback function insideenumNodeFragmentsactually executes.
– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting aconsole.logordebuggerstatement in it.
– Petr Broz
Mar 7 at 14:55
|
show 1 more comment
Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:
function highlight(externalId, color, dict)
const viewer = this.viewer;
const dbId = dict[externalId];
const myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
const scaleRatio = 1.005; // this was determined as optimal through visual inspection
const tree = NOP_VIEWER.model.getData().instanceTree;
const oldMaterials = ;
tree.enumNodeFragments(dbId, function(fragId)
oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especiallydocument), is not a good practice and could cause different issues. Try using the localoldMaterialsconst instead, and make sure that the callback function insideenumNodeFragmentsactually executes.
– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting aconsole.logordebuggerstatement in it.
– Petr Broz
Mar 7 at 14:55
|
show 1 more comment
Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:
function highlight(externalId, color, dict)
const viewer = this.viewer;
const dbId = dict[externalId];
const myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
const scaleRatio = 1.005; // this was determined as optimal through visual inspection
const tree = NOP_VIEWER.model.getData().instanceTree;
const oldMaterials = ;
tree.enumNodeFragments(dbId, function(fragId)
oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
Both document and window should be available in the scope of the callback function, however it's not a good practice. Try defining the map of old materials inside the scope of the highlight function:
function highlight(externalId, color, dict)
const viewer = this.viewer;
const dbId = dict[externalId];
const myMaterial = this.createMaterial(color);
// used to rescale and remove the z-fighting
const scaleRatio = 1.005; // this was determined as optimal through visual inspection
const tree = NOP_VIEWER.model.getData().instanceTree;
const oldMaterials = ;
tree.enumNodeFragments(dbId, function(fragId)
oldMaterials[fragId] = viewer.model.getFragmentList().getMaterial(fragId);
viewer.model.getFragmentList().setMaterial(fragId, myMaterial);
/* important technique if you want to remove z-fighting */
const fragProxy = viewer.impl.getFragmentProxy(viewer.model, fragId);
fragProxy.scale = new THREE.Vector3(scaleRatio, scaleRatio, scaleRatio);
fragProxy.updateAnimTransform();
,
true);
viewer.impl.invalidate(true);
answered Mar 7 at 14:26
Petr BrozPetr Broz
1,5372912
1,5372912
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especiallydocument), is not a good practice and could cause different issues. Try using the localoldMaterialsconst instead, and make sure that the callback function insideenumNodeFragmentsactually executes.
– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting aconsole.logordebuggerstatement in it.
– Petr Broz
Mar 7 at 14:55
|
show 1 more comment
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especiallydocument), is not a good practice and could cause different issues. Try using the localoldMaterialsconst instead, and make sure that the callback function insideenumNodeFragmentsactually executes.
– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting aconsole.logordebuggerstatement in it.
– Petr Broz
Mar 7 at 14:55
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I try this sometimes ago. After call tree.enumNodeFragments oldMaterials is empty. viewer.model.getFragmentList().getMaterial(fragId) isn't empty.
– Anton Kosenko
Mar 7 at 14:29
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
I call console.log(document.oldMaterials) or console.log(window.oldMaterials) after tree.enumNodeFragments and in console I see (empty dictionary).
– Anton Kosenko
Mar 7 at 14:38
As I mentioned, referring to a global variable (and especially
document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.– Petr Broz
Mar 7 at 14:43
As I mentioned, referring to a global variable (and especially
document), is not a good practice and could cause different issues. Try using the local oldMaterials const instead, and make sure that the callback function inside enumNodeFragments actually executes.– Petr Broz
Mar 7 at 14:43
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
How I can make sure that the callback function inside enumNodeFragments actually executes?
– Anton Kosenko
Mar 7 at 14:50
What I meant was: confirm that the callback function is actually executed, for example by putting a
console.log or debugger statement in it.– Petr Broz
Mar 7 at 14:55
What I meant was: confirm that the callback function is actually executed, for example by putting a
console.log or debugger statement in it.– Petr Broz
Mar 7 at 14:55
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045639%2fcant-use-global-variable-inside-tree-enumnodefragments-delegate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown