Can't use global variable inside tree.enumNodeFragments() delegate The Next CEO of Stack OverflowWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var”?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?
Return the Closest Prime Number
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
What's the point of interval inversion?
Is it okay to store user locations?
Too much space between section and text in a twocolumn document
How long to clear the 'suck zone' of a turbofan after start is initiated?
Trouble understanding the speech of overseas colleagues
What is the point of a new vote on May's deal when the indicative votes suggest she will not win?
Why Were Madagascar and New Zealand Discovered So Late?
If the heap is initialized for security, then why is the stack uninitialized?
Why do remote companies require working in the US?
How do we know the LHC results are robust?
Grabbing quick drinks
How to make a software documentation "officially" citable?
How to use tikz in fbox?
Opposite of a diet
What can we do to stop prior company from asking us questions?
How should I support this large drywall patch?
Apart from "berlinern", do any other German dialects have a corresponding verb?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
A pseudo-riley?
Why did we only see the N-1 starfighters in one film?
How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?
Inappropriate reference requests from Journal reviewers
Can't use global variable inside tree.enumNodeFragments() delegate
The Next CEO of Stack OverflowWhat is the scope of variables in JavaScript?JavaScript closure inside loops – simple practical exampleWhat's the difference between using “let” and “var”?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