mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
updating attachedEntitiesManager to work with new system
This commit is contained in:
parent
ac506dc4b7
commit
73c06b3bf4
4 changed files with 188 additions and 50 deletions
70
scripts/system/assets/images/lock.svg
Normal file
70
scripts/system/assets/images/lock.svg
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="64mm"
|
||||||
|
height="64mm"
|
||||||
|
viewBox="0 0 226.77165 226.77165"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="lock.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1.979899"
|
||||||
|
inkscape:cx="-155"
|
||||||
|
inkscape:cy="122.87157"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="2782"
|
||||||
|
inkscape:window-height="1764"
|
||||||
|
inkscape:window-x="98"
|
||||||
|
inkscape:window-y="36"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-825.59055)">
|
||||||
|
<rect
|
||||||
|
style="fill:#000000;fill-opacity:0;stroke:#000000;stroke-linejoin:round;stroke-opacity:1;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="rect4138"
|
||||||
|
width="97.14286"
|
||||||
|
height="82.85714"
|
||||||
|
x="65.714287"
|
||||||
|
y="929.50507" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 79.296975,928.61852 c -2.192663,1.09633 -0.13398,-39.19338 36.365495,-37.88073 33.84882,1.21733 35.35534,38.3858 35.35534,38.3858"
|
||||||
|
id="path4148"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="csc" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
70
scripts/system/assets/images/unlock.svg
Normal file
70
scripts/system/assets/images/unlock.svg
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="64mm"
|
||||||
|
height="64mm"
|
||||||
|
viewBox="0 0 226.77165 226.77165"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="unlock.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1.979899"
|
||||||
|
inkscape:cx="-155"
|
||||||
|
inkscape:cy="122.87157"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="2782"
|
||||||
|
inkscape:window-height="1764"
|
||||||
|
inkscape:window-x="98"
|
||||||
|
inkscape:window-y="36"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-825.59055)">
|
||||||
|
<rect
|
||||||
|
style="fill:#000000;fill-opacity:0;stroke:#000000;stroke-linejoin:round;stroke-opacity:1;stroke-width:5;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="rect4138"
|
||||||
|
width="97.14286"
|
||||||
|
height="82.85714"
|
||||||
|
x="65.714287"
|
||||||
|
y="929.50507" />
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 142.93659,923.06268 c -2.19267,1.09633 -0.13398,-39.19338 36.36549,-37.88073 33.84882,1.21733 35.35534,38.3858 35.35534,38.3858"
|
||||||
|
id="path4148"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
sodipodi:nodetypes="csc" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
|
@ -22,7 +22,7 @@ var MINIMUM_DROP_DISTANCE_FROM_JOINT = 0.8;
|
||||||
var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0;
|
var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0;
|
||||||
var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES";
|
var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES";
|
||||||
var DRESSING_ROOM_DISTANCE = 2.0;
|
var DRESSING_ROOM_DISTANCE = 2.0;
|
||||||
var SHOW_TOOL_BAR = false;
|
var SHOW_TOOL_BAR = true;
|
||||||
|
|
||||||
// tool bar
|
// tool bar
|
||||||
|
|
||||||
|
@ -30,34 +30,20 @@ if (SHOW_TOOL_BAR) {
|
||||||
var BUTTON_SIZE = 32;
|
var BUTTON_SIZE = 32;
|
||||||
var PADDING = 3;
|
var PADDING = 3;
|
||||||
Script.include(["libraries/toolBars.js"]);
|
Script.include(["libraries/toolBars.js"]);
|
||||||
var toolBar = new ToolBar(0, 0, ToolBar.VERTICAL, "highfidelity.attachedEntities.toolbar", function(screenSize) {
|
|
||||||
return {
|
var toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL, "highfidelity.attachedEntities.toolbar");
|
||||||
x: (BUTTON_SIZE + PADDING),
|
var lockButton = toolBar.addTool({
|
||||||
y: (screenSize.y / 2 - BUTTON_SIZE * 2 + PADDING)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
var saveButton = toolBar.addOverlay("image", {
|
|
||||||
width: BUTTON_SIZE,
|
width: BUTTON_SIZE,
|
||||||
height: BUTTON_SIZE,
|
height: BUTTON_SIZE,
|
||||||
imageURL: ".../save.png",
|
imageURL: Script.resolvePath("assets/images/lock.svg"),
|
||||||
color: {
|
color: {
|
||||||
red: 255,
|
red: 255,
|
||||||
green: 255,
|
green: 255,
|
||||||
blue: 255
|
blue: 255
|
||||||
},
|
},
|
||||||
alpha: 1
|
alpha: 1,
|
||||||
});
|
visible: true
|
||||||
var loadButton = toolBar.addOverlay("image", {
|
}, false);
|
||||||
width: BUTTON_SIZE,
|
|
||||||
height: BUTTON_SIZE,
|
|
||||||
imageURL: ".../load.png",
|
|
||||||
color: {
|
|
||||||
red: 255,
|
|
||||||
green: 255,
|
|
||||||
blue: 255
|
|
||||||
},
|
|
||||||
alpha: 1
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,10 +53,8 @@ function mousePressEvent(event) {
|
||||||
y: event.y
|
y: event.y
|
||||||
});
|
});
|
||||||
|
|
||||||
if (clickedOverlay == saveButton) {
|
if (lockButton === toolBar.clicked(clickedOverlay)) {
|
||||||
manager.saveAttachedEntities();
|
manager.toggleLocked();
|
||||||
} else if (clickedOverlay == loadButton) {
|
|
||||||
manager.loadAttachedEntities();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +76,8 @@ Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
||||||
|
|
||||||
function AttachedEntitiesManager() {
|
function AttachedEntitiesManager() {
|
||||||
|
var clothingLocked = true;
|
||||||
|
|
||||||
this.subscribeToMessages = function() {
|
this.subscribeToMessages = function() {
|
||||||
Messages.subscribe('Hifi-Object-Manipulation');
|
Messages.subscribe('Hifi-Object-Manipulation');
|
||||||
Messages.messageReceived.connect(this.handleWearableMessages);
|
Messages.messageReceived.connect(this.handleWearableMessages);
|
||||||
|
@ -128,19 +114,6 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.avatarIsInDressingRoom = function() {
|
|
||||||
// return true if MyAvatar is near the dressing room
|
|
||||||
var possibleDressingRoom = Entities.findEntities(MyAvatar.position, DRESSING_ROOM_DISTANCE);
|
|
||||||
for (i = 0; i < possibleDressingRoom.length; i++) {
|
|
||||||
var entityID = possibleDressingRoom[i];
|
|
||||||
var props = Entities.getEntityProperties(entityID);
|
|
||||||
if (props.name == 'Hifi-Dressing-Room-Base') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
|
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
|
||||||
// if this is still equipped, just rewrite the position information.
|
// if this is still equipped, just rewrite the position information.
|
||||||
var grabData = getEntityCustomData('grabKey', grabbedEntity, {});
|
var grabData = getEntityCustomData('grabKey', grabbedEntity, {});
|
||||||
|
@ -179,21 +152,23 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestJointIndex != -1) {
|
if (bestJointIndex != -1) {
|
||||||
var wearProps = {
|
var wearProps = Entities.getEntityProperties(grabbedEntity);
|
||||||
parentID: MyAvatar.sessionUUID,
|
wearProps.parentID = MyAvatar.sessionUUID;
|
||||||
parentJointIndex: bestJointIndex
|
wearProps.parentJointIndex = bestJointIndex;
|
||||||
};
|
|
||||||
|
|
||||||
if (bestJointOffset && bestJointOffset.constructor === Array) {
|
if (bestJointOffset && bestJointOffset.constructor === Array) {
|
||||||
if (this.avatarIsInDressingRoom() || bestJointOffset.length < 2) {
|
if (!clothingLocked || bestJointOffset.length < 2) {
|
||||||
this.updateRelativeOffsets(grabbedEntity);
|
this.updateRelativeOffsets(grabbedEntity);
|
||||||
} else {
|
} else {
|
||||||
// don't snap the entity to the preferred position if the avatar is in the dressing room.
|
// don't snap the entity to the preferred position if unlocked
|
||||||
wearProps.localPosition = bestJointOffset[0];
|
wearProps.localPosition = bestJointOffset[0];
|
||||||
wearProps.localRotation = bestJointOffset[1];
|
wearProps.localRotation = bestJointOffset[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Entities.editEntity(grabbedEntity, wearProps);
|
|
||||||
|
// Entities.editEntity(grabbedEntity, wearProps);
|
||||||
|
Entities.deleteEntity(grabbedEntity);
|
||||||
|
Entities.addEntity(wearProps, true);
|
||||||
} else if (props.parentID != NULL_UUID) {
|
} else if (props.parentID != NULL_UUID) {
|
||||||
// drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand.
|
// drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand.
|
||||||
if (props.parentID === MyAvatar.sessionUUID &&
|
if (props.parentID === MyAvatar.sessionUUID &&
|
||||||
|
@ -201,7 +176,11 @@ function AttachedEntitiesManager() {
|
||||||
props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) {
|
props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) {
|
||||||
// this is equipped on a hand -- don't clear the parent.
|
// this is equipped on a hand -- don't clear the parent.
|
||||||
} else {
|
} else {
|
||||||
Entities.editEntity(grabbedEntity, { parentID: NULL_UUID });
|
var wearProps = Entities.getEntityProperties(grabbedEntity);
|
||||||
|
wearProps.parentID = NULL_UUID;
|
||||||
|
wearProps.parentJointIndex = -1;
|
||||||
|
Entities.deleteEntity(grabbedEntity);
|
||||||
|
Entities.addEntity(wearProps, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,6 +200,17 @@ function AttachedEntitiesManager() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.toggleLocked = function() {
|
||||||
|
print("toggleLocked");
|
||||||
|
if (clothingLocked) {
|
||||||
|
clothingLocked = false;
|
||||||
|
toolBar.setImageURL(Script.resolvePath("assets/images/unlock.svg"), lockButton);
|
||||||
|
} else {
|
||||||
|
clothingLocked = true;
|
||||||
|
toolBar.setImageURL(Script.resolvePath("assets/images/lock.svg"), lockButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.saveAttachedEntities = function() {
|
this.saveAttachedEntities = function() {
|
||||||
print("--- saving attached entities ---");
|
print("--- saving attached entities ---");
|
||||||
saveData = [];
|
saveData = [];
|
||||||
|
|
|
@ -56,6 +56,10 @@ Overlay2D = function(properties, overlay) { // overlay is an optional variable
|
||||||
properties.alpha = alpha;
|
properties.alpha = alpha;
|
||||||
Overlays.editOverlay(overlay, { alpha: alpha });
|
Overlays.editOverlay(overlay, { alpha: alpha });
|
||||||
}
|
}
|
||||||
|
this.setImageURL = function(imageURL) {
|
||||||
|
properties.imageURL = imageURL;
|
||||||
|
Overlays.editOverlay(overlay, { imageURL: imageURL });
|
||||||
|
}
|
||||||
this.show = function(doShow) {
|
this.show = function(doShow) {
|
||||||
properties.visible = doShow;
|
properties.visible = doShow;
|
||||||
Overlays.editOverlay(overlay, { visible: doShow });
|
Overlays.editOverlay(overlay, { visible: doShow });
|
||||||
|
@ -254,7 +258,7 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
||||||
}
|
}
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setAlpha = function(alpha, tool) {
|
this.setAlpha = function(alpha, tool) {
|
||||||
if(typeof(tool) === 'undefined') {
|
if(typeof(tool) === 'undefined') {
|
||||||
for(var tool in this.tools) {
|
for(var tool in this.tools) {
|
||||||
|
@ -268,7 +272,11 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
||||||
this.tools[tool].setAlpha(alpha);
|
this.tools[tool].setAlpha(alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setImageURL = function(imageURL, tool) {
|
||||||
|
this.tools[tool].setImageURL(imageURL);
|
||||||
|
}
|
||||||
|
|
||||||
this.setBack = function(color, alpha) {
|
this.setBack = function(color, alpha) {
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
Overlays.editOverlay(this.back, { visible: false });
|
Overlays.editOverlay(this.back, { visible: false });
|
||||||
|
@ -478,4 +486,4 @@ ToolBar = function(x, y, direction, optionalPersistenceKey, optionalInitialPosit
|
||||||
}
|
}
|
||||||
ToolBar.SPACING = 6;
|
ToolBar.SPACING = 6;
|
||||||
ToolBar.VERTICAL = 0;
|
ToolBar.VERTICAL = 0;
|
||||||
ToolBar.HORIZONTAL = 1;
|
ToolBar.HORIZONTAL = 1;
|
||||||
|
|
Loading…
Reference in a new issue