Code Adjustments and Optimizations

Remove an unused commented const.
Generate all the material using a centralized function, using an array to store the keys. 
Make them deleted by iteration on this array.
Using now defaultFallthrough = true instead of setting albedo to fallthrough.
Replace "materialMappingMode" "projected" for "uv"
Added "ignorePickIntersection": true on the Material entities
This commit is contained in:
Alezia Kurdis 2020-09-23 22:28:52 -04:00 committed by GitHub
parent de21ebf853
commit 826991d6b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -650,7 +650,6 @@ SelectionDisplay = (function() {
const COLOR_ROTATE_CURRENT_RING = { red: 255, green: 99, blue: 9 }; const COLOR_ROTATE_CURRENT_RING = { red: 255, green: 99, blue: 9 };
const COLOR_BOUNDING_EDGE = { red: 128, green: 128, blue: 128 }; const COLOR_BOUNDING_EDGE = { red: 128, green: 128, blue: 128 };
const COLOR_SCALE_CUBE = { red: 160, green: 160, blue: 160 }; const COLOR_SCALE_CUBE = { red: 160, green: 160, blue: 160 };
//const COLOR_SCALE_CUBE_SELECTED = { red: 18, green: 18, blue: 18 };
const COLOR_DEBUG_PICK_PLANE = { red: 255, green: 255, blue: 255 }; const COLOR_DEBUG_PICK_PLANE = { red: 255, green: 255, blue: 255 };
const COLOR_DEBUG_PICK_PLANE_HIT = { red: 255, green: 165, blue: 0 }; const COLOR_DEBUG_PICK_PLANE_HIT = { red: 255, green: 165, blue: 0 };
@ -747,9 +746,9 @@ SelectionDisplay = (function() {
var ctrlPressed = false; var ctrlPressed = false;
that.replaceCollisionsAfterStretch = false; var toolEntityMaterial = [];
var toolEntitiesMaterialData = "{\n \"materialVersion\": 1,\n \"materials\": [\n {\n \"name\": \"0\",\n \"albedo\": \"fallthrough\",\n \"unlit\": true,\n \"model\": \"hifi_pbr\"\n }\n ]\n}"; that.replaceCollisionsAfterStretch = false;
var handlePropertiesTranslateArrowCones = { var handlePropertiesTranslateArrowCones = {
type: "Shape", type: "Shape",
@ -782,66 +781,12 @@ SelectionDisplay = (function() {
Entities.editEntity(handleTranslateZCone, { color: COLOR_BLUE }); Entities.editEntity(handleTranslateZCone, { color: COLOR_BLUE });
Entities.editEntity(handleTranslateZCylinder, { color: COLOR_BLUE }); Entities.editEntity(handleTranslateZCylinder, { color: COLOR_BLUE });
var materialHandleTranslateXCone = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateXCone));
"type": "Material", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateYCone));
"parentID": handleTranslateXCone, toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateZCone));
"name": "tool-material", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateXCylinder));
"parentMaterialName": "0", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateYCylinder));
"materialURL": "materialData", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleTranslateZCylinder));
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleTranslateYCone = Entities.addEntity({
"type": "Material",
"parentID": handleTranslateYCone,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleTranslateZCone = Entities.addEntity({
"type": "Material",
"parentID": handleTranslateZCone,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleTranslateXCylinder = Entities.addEntity({
"type": "Material",
"parentID": handleTranslateXCylinder,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleTranslateYCylinder = Entities.addEntity({
"type": "Material",
"parentID": handleTranslateYCylinder,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleTranslateZCylinder = Entities.addEntity({
"type": "Material",
"parentID": handleTranslateZCylinder,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handlePropertiesRotateRings = { var handlePropertiesRotateRings = {
type: "Gizmo", type: "Gizmo",
@ -873,16 +818,7 @@ SelectionDisplay = (function() {
majorTickMarksColor: COLOR_RED majorTickMarksColor: COLOR_RED
} }
}); });
var materialHandleRotatePitchXRedRing = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleRotatePitchXRedRing));
"type": "Material",
"parentID": handleRotatePitchXRedRing,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleRotateYawYGreenRing = Entities.addEntity(handlePropertiesRotateRings, "local"); var handleRotateYawYGreenRing = Entities.addEntity(handlePropertiesRotateRings, "local");
Entities.editEntity(handleRotateYawYGreenRing, { Entities.editEntity(handleRotateYawYGreenRing, {
@ -894,16 +830,7 @@ SelectionDisplay = (function() {
majorTickMarksColor: COLOR_GREEN majorTickMarksColor: COLOR_GREEN
} }
}); });
var materialHandleRotateYawYGreenRing = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleRotateYawYGreenRing));
"type": "Material",
"parentID": handleRotateYawYGreenRing,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleRotateRollZBlueRing = Entities.addEntity(handlePropertiesRotateRings, "local"); var handleRotateRollZBlueRing = Entities.addEntity(handlePropertiesRotateRings, "local");
Entities.editEntity(handleRotateRollZBlueRing, { Entities.editEntity(handleRotateRollZBlueRing, {
@ -915,16 +842,7 @@ SelectionDisplay = (function() {
majorTickMarksColor: COLOR_BLUE majorTickMarksColor: COLOR_BLUE
} }
}); });
var materialHandleRotateRollZBlueRing = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleRotateRollZBlueRing));
"type": "Material",
"parentID": handleRotateRollZBlueRing,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleRotateCurrentRing = Entities.addEntity({ var handleRotateCurrentRing = Entities.addEntity({
type: "Gizmo", type: "Gizmo",
@ -947,16 +865,7 @@ SelectionDisplay = (function() {
ignorePickIntersection: true, ignorePickIntersection: true,
renderLayer: "front" renderLayer: "front"
}, "local"); }, "local");
var materialHandleRotateCurrentRing = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleRotateCurrentRing));
"type": "Material",
"parentID": handleRotateCurrentRing,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var rotationDegreesDisplay = Entities.addEntity({ var rotationDegreesDisplay = Entities.addEntity({
type: "Text", type: "Text",
@ -994,36 +903,9 @@ SelectionDisplay = (function() {
var handleStretchZCube = Entities.addEntity(handlePropertiesStretchCubes, "local"); var handleStretchZCube = Entities.addEntity(handlePropertiesStretchCubes, "local");
Entities.editEntity(handleStretchZCube, { color: COLOR_BLUE }); Entities.editEntity(handleStretchZCube, { color: COLOR_BLUE });
var materialHandleStretchXCube = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchXCube));
"type": "Material", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchYCube));
"parentID": handleStretchXCube, toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchZCube));
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleStretchYCube = Entities.addEntity({
"type": "Material",
"parentID": handleStretchYCube,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleStretchZCube = Entities.addEntity({
"type": "Material",
"parentID": handleStretchZCube,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handlePropertiesStretchPanel = { var handlePropertiesStretchPanel = {
type: "Shape", type: "Shape",
@ -1041,36 +923,9 @@ SelectionDisplay = (function() {
var handleStretchZPanel = Entities.addEntity(handlePropertiesStretchPanel, "local"); var handleStretchZPanel = Entities.addEntity(handlePropertiesStretchPanel, "local");
Entities.editEntity(handleStretchZPanel, { color: COLOR_BLUE }); Entities.editEntity(handleStretchZPanel, { color: COLOR_BLUE });
var materialHandleStretchXPanel = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchXPanel));
"type": "Material", toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchYPanel));
"parentID": handleStretchXPanel, toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleStretchZPanel));
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleStretchYPanel = Entities.addEntity({
"type": "Material",
"parentID": handleStretchYPanel,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var materialHandleStretchZPanel = Entities.addEntity({
"type": "Material",
"parentID": handleStretchZPanel,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleScaleCube = Entities.addEntity({ var handleScaleCube = Entities.addEntity({
type: "Shape", type: "Shape",
@ -1082,16 +937,7 @@ SelectionDisplay = (function() {
ignorePickIntersection: true, ignorePickIntersection: true,
renderLayer: "front" renderLayer: "front"
}, "local"); }, "local");
var materialHandleScaleCube = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleScaleCube));
"type": "Material",
"parentID": handleScaleCube,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleBoundingBox = Entities.addEntity({ var handleBoundingBox = Entities.addEntity({
type: "Shape", type: "Shape",
@ -1103,16 +949,7 @@ SelectionDisplay = (function() {
ignorePickIntersection: true, ignorePickIntersection: true,
renderLayer: "front" renderLayer: "front"
}, "local"); }, "local");
var materialHandleBoundingBox = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleBoundingBox));
"type": "Material",
"parentID": handleBoundingBox,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
var handleDuplicator = Entities.addEntity({ var handleDuplicator = Entities.addEntity({
type: "Shape", type: "Shape",
@ -1125,16 +962,7 @@ SelectionDisplay = (function() {
ignorePickIntersection: true, ignorePickIntersection: true,
renderLayer: "front" renderLayer: "front"
}, "local"); }, "local");
var materialHandleDuplicator = Entities.addEntity({ toolEntityMaterial.push(addUnlitMaterialOnToolEntity(handleDuplicator));
"type": "Material",
"parentID": handleDuplicator,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "projected",
"materialData": toolEntitiesMaterialData
}, "local");
// setting to 0 alpha for now to keep this hidden vs using visible false // setting to 0 alpha for now to keep this hidden vs using visible false
// because its used as the translate xz tool handle toolEntity // because its used as the translate xz tool handle toolEntity
@ -1777,25 +1605,10 @@ SelectionDisplay = (function() {
for (var i = 0; i < allToolEntities.length; i++) { for (var i = 0; i < allToolEntities.length; i++) {
Entities.deleteEntity(allToolEntities[i]); Entities.deleteEntity(allToolEntities[i]);
} }
Entities.deleteEntity(materialHandleTranslateXCone);
Entities.deleteEntity(materialHandleTranslateYCone); for (i = 0; i < toolEntityMaterial.length; i++) {
Entities.deleteEntity(materialHandleTranslateZCone); Entities.deleteEntity(toolEntityMaterial[i]);
Entities.deleteEntity(materialHandleTranslateXCylinder); }
Entities.deleteEntity(materialHandleTranslateYCylinder);
Entities.deleteEntity(materialHandleTranslateZCylinder);
Entities.deleteEntity(materialHandleStretchXCube);
Entities.deleteEntity(materialHandleStretchYCube);
Entities.deleteEntity(materialHandleStretchZCube);
Entities.deleteEntity(materialHandleStretchXPanel);
Entities.deleteEntity(materialHandleStretchYPanel);
Entities.deleteEntity(materialHandleStretchZPanel);
Entities.deleteEntity(materialHandleScaleCube);
Entities.deleteEntity(materialHandleBoundingBox);
Entities.deleteEntity(materialHandleDuplicator);
Entities.deleteEntity(materialHandleRotatePitchXRedRing);
Entities.deleteEntity(materialHandleRotateYawYGreenRing);
Entities.deleteEntity(materialHandleRotateRollZBlueRing);
Entities.deleteEntity(materialHandleRotateCurrentRing);
that.clearDebugPickPlane(); that.clearDebugPickPlane();
}; };
@ -2401,6 +2214,22 @@ SelectionDisplay = (function() {
debugPickPlaneHits = []; debugPickPlaneHits = [];
}; };
function addUnlitMaterialOnToolEntity(toolEntityParentID) {
var toolEntitiesMaterialData = "{\n \"materialVersion\": 1,\n \"materials\": [\n {\n \"name\": \"0\",\n \"defaultFallthrough\": true,\n \"unlit\": true,\n \"model\": \"hifi_pbr\"\n }\n ]\n}";
var materialEntityID = Entities.addEntity({
"type": "Material",
"parentID": toolEntityParentID,
"name": "tool-material",
"parentMaterialName": "0",
"materialURL": "materialData",
"priority": 1,
"materialMappingMode": "uv",
"ignorePickIntersection": true,
"materialData": toolEntitiesMaterialData
}, "local");
return materialEntityID;
}
// TOOL DEFINITION: HANDLE TRANSLATE XZ TOOL // TOOL DEFINITION: HANDLE TRANSLATE XZ TOOL
function addHandleTranslateXZTool(toolEntity, mode, doDuplicate) { function addHandleTranslateXZTool(toolEntity, mode, doDuplicate) {
var initialPick = null; var initialPick = null;