mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:29:47 +02:00
Merge branch 'master' into 21334
This commit is contained in:
commit
8480a8e7d5
129 changed files with 6741 additions and 589 deletions
|
@ -24,6 +24,8 @@ public:
|
||||||
AssignmentDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
AssignmentDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AssignmentDynamic();
|
virtual ~AssignmentDynamic();
|
||||||
|
|
||||||
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) override {};
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; }
|
||||||
|
|
114
cmake/modules/FindFBX.cmake
Normal file
114
cmake/modules/FindFBX.cmake
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
# Locate the FBX SDK
|
||||||
|
#
|
||||||
|
# Defines the following variables:
|
||||||
|
#
|
||||||
|
# FBX_FOUND - Found the FBX SDK
|
||||||
|
# FBX_VERSION - Version number
|
||||||
|
# FBX_INCLUDE_DIRS - Include directories
|
||||||
|
# FBX_LIBRARIES - The libraries to link to
|
||||||
|
#
|
||||||
|
# Accepts the following variables as input:
|
||||||
|
#
|
||||||
|
# FBX_VERSION - as a CMake variable, e.g. 2017.0.1
|
||||||
|
# FBX_ROOT - (as a CMake or environment variable)
|
||||||
|
# The root directory of the FBX SDK install
|
||||||
|
|
||||||
|
# adapted from https://github.com/ufz-vislab/VtkFbxConverter/blob/master/FindFBX.cmake
|
||||||
|
# which uses the MIT license (https://github.com/ufz-vislab/VtkFbxConverter/blob/master/LICENSE.txt)
|
||||||
|
|
||||||
|
if (NOT FBX_VERSION)
|
||||||
|
if (WIN32)
|
||||||
|
set(FBX_VERSION 2017.1)
|
||||||
|
else()
|
||||||
|
set(FBX_VERSION 2017.0.1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(REGEX REPLACE "^([0-9]+).*$" "\\1" FBX_VERSION_MAJOR "${FBX_VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*$" "\\1" FBX_VERSION_MINOR "${FBX_VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" FBX_VERSION_PATCH "${FBX_VERSION}")
|
||||||
|
|
||||||
|
set(FBX_MAC_LOCATIONS "/Applications/Autodesk/FBX\ SDK/${FBX_VERSION}")
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
string(REGEX REPLACE "\\\\" "/" WIN_PROGRAM_FILES_X64_DIRECTORY $ENV{ProgramW6432})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(FBX_WIN_LOCATIONS "${WIN_PROGRAM_FILES_X64_DIRECTORY}/Autodesk/FBX/FBX SDK/${FBX_VERSION}")
|
||||||
|
|
||||||
|
set(FBX_SEARCH_LOCATIONS $ENV{FBX_ROOT} ${FBX_ROOT} ${FBX_MAC_LOCATIONS} ${FBX_WIN_LOCATIONS})
|
||||||
|
|
||||||
|
function(_fbx_append_debugs _endvar _library)
|
||||||
|
if (${_library} AND ${_library}_DEBUG)
|
||||||
|
set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
|
||||||
|
else()
|
||||||
|
set(_output ${${_library}})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${_endvar} ${_output} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
set(fbx_compiler clang)
|
||||||
|
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||||
|
set(fbx_compiler gcc4)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(_fbx_find_library _name _lib _suffix)
|
||||||
|
if (MSVC12)
|
||||||
|
set(VS_PREFIX vs2013)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC11)
|
||||||
|
set(VS_PREFIX vs2012)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC10)
|
||||||
|
set(VS_PREFIX vs2010)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC90)
|
||||||
|
set(VS_PREFIX vs2008)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_library(${_name}
|
||||||
|
NAMES ${_lib}
|
||||||
|
HINTS ${FBX_SEARCH_LOCATIONS}
|
||||||
|
PATH_SUFFIXES lib/${fbx_compiler}/${_suffix} lib/${fbx_compiler}/ub/${_suffix} lib/${VS_PREFIX}/x64/${_suffix}
|
||||||
|
)
|
||||||
|
|
||||||
|
mark_as_advanced(${_name})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
find_path(FBX_INCLUDE_DIR fbxsdk.h
|
||||||
|
PATHS ${FBX_SEARCH_LOCATIONS}
|
||||||
|
PATH_SUFFIXES include
|
||||||
|
)
|
||||||
|
mark_as_advanced(FBX_INCLUDE_DIR)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
_fbx_find_library(FBX_LIBRARY libfbxsdk-md release)
|
||||||
|
_fbx_find_library(FBX_LIBRARY_DEBUG libfbxsdk-md debug)
|
||||||
|
elseif (APPLE)
|
||||||
|
find_library(CARBON NAMES Carbon)
|
||||||
|
find_library(SYSTEM_CONFIGURATION NAMES SystemConfiguration)
|
||||||
|
_fbx_find_library(FBX_LIBRARY libfbxsdk.a release)
|
||||||
|
_fbx_find_library(FBX_LIBRARY_DEBUG libfbxsdk.a debug)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FBX DEFAULT_MSG FBX_LIBRARY FBX_INCLUDE_DIR)
|
||||||
|
|
||||||
|
if (FBX_FOUND)
|
||||||
|
set(FBX_INCLUDE_DIRS ${FBX_INCLUDE_DIR})
|
||||||
|
_fbx_append_debugs(FBX_LIBRARIES FBX_LIBRARY)
|
||||||
|
add_definitions(-DFBXSDK_NEW_API)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
add_definitions(-DK_PLUGIN -DK_FBXSDK -DK_NODLL)
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:\"LIBCMT\")
|
||||||
|
set(FBX_LIBRARIES ${FBX_LIBRARIES} Wininet.lib)
|
||||||
|
elseif (APPLE)
|
||||||
|
set(FBX_LIBRARIES ${FBX_LIBRARIES} ${CARBON} ${SYSTEM_CONFIGURATION})
|
||||||
|
endif()
|
||||||
|
endif()
|
|
@ -49,6 +49,8 @@
|
||||||
"id": "ik",
|
"id": "ik",
|
||||||
"type": "inverseKinematics",
|
"type": "inverseKinematics",
|
||||||
"data": {
|
"data": {
|
||||||
|
"solutionSource": "relaxToUnderPoses",
|
||||||
|
"solutionSourceVar": "solutionSource",
|
||||||
"targets": [
|
"targets": [
|
||||||
{
|
{
|
||||||
"jointName": "Hips",
|
"jointName": "Hips",
|
||||||
|
|
70
interface/resources/icons/tablet-icons/raise-hand-a.svg
Normal file
70
interface/resources/icons/tablet-icons/raise-hand-a.svg
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Generated by IcoMoon.io -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||||
|
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"
|
||||||
|
version="1.1"
|
||||||
|
width="50"
|
||||||
|
height="50"
|
||||||
|
viewBox="0 0 50 50"
|
||||||
|
id="svg3713"
|
||||||
|
sodipodi:docname="raise-hand-a.svg"
|
||||||
|
inkscape:version="0.92.1 r15371">
|
||||||
|
<metadata
|
||||||
|
id="metadata3719">
|
||||||
|
<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 />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<defs
|
||||||
|
id="defs3717">
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient6484"
|
||||||
|
osb:paint="solid">
|
||||||
|
<stop
|
||||||
|
style="stop-color:#000000;stop-opacity:1;"
|
||||||
|
offset="0"
|
||||||
|
id="stop6482" />
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1001"
|
||||||
|
id="namedview3715"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="11.8"
|
||||||
|
inkscape:cx="-20"
|
||||||
|
inkscape:cy="23.559322"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg3713" />
|
||||||
|
<path
|
||||||
|
d="m 38.064897,12.746263 c -0.728,0 -1.412,0.196 -2,0.538 v -2.538 c 0,-2.2060002 -1.794,-4.0000002 -4,-4.0000002 -0.824,0 -1.588,0.25 -2.226,0.678 -0.548,-1.558 -2.032,-2.678 -3.774,-2.678 -1.742,0 -3.228,1.12 -3.774,2.678 -0.636,-0.428 -1.402,-0.678 -2.226,-0.678 -2.206,0 -4,1.794 -4,4.0000002 v 14.746 l -2.692,-4.666 c -0.522,-0.95 -1.374,-1.626 -2.398,-1.906 -0.9980001,-0.272 -2.0360001,-0.128 -2.9240001,0.404 -1.814,1.088 -2.506,3.548 -1.54,5.484 0.06,0.122 1.336,2.736 5.3200001,10.7 1.876,3.75 3.934,6.432 6.118,7.968 1.714,1.206 2.898,1.268 3.118,1.268 h 10 c 1.702,0 3.284,-0.554 4.704,-1.644 1.334,-1.026 2.492,-2.51 3.44,-4.408 1.868,-3.736 2.856,-8.904 2.856,-14.948 v -7 c 0,-2.206 -1.794,-4 -4,-4 z m 2,11 c 0,5.734 -0.914,10.592 -2.644,14.052 -1.128,2.256 -3.148,4.948 -6.356,4.948 h -9.98 c -0.078,-0.006 -0.92,-0.1 -2.19,-1.05 -1.266,-0.948 -3.21,-2.944 -5.276,-7.08 -4.0540001,-8.108 -5.3000001,-10.662 -5.3120001,-10.686 -0.002,-0.004 -0.002,-0.006 -0.004,-0.008 -0.502,-1.006 -0.146,-2.324 0.778,-2.878 0.416,-0.25 0.902,-0.316 1.3700001,-0.19 0.498,0.136 0.916,0.472 1.174,0.944 0.004,0.006 0.008,0.014 0.012,0.02 l 3.122,5.41 c 0.638,1.166 1.356,1.656 2.134,1.458 0.78,-0.198 1.174,-0.978 1.174,-2.314 v -15.626 c 0,-1.1020002 0.898,-2.0000002 2,-2.0000002 1.102,0 2,0.898 2,2.0000002 v 13 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 V 8.7462628 c 0,-1.102 0.898,-2 2,-2 1.102,0 2,0.898 2,2 V 23.746263 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 v -13 c 0,-1.1020002 0.898,-2.0000002 2,-2.0000002 1.102,0 2,0.898 2,2.0000002 v 15 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 v -9 c 0,-1.102 0.898,-2 2,-2 1.102,0 2,0.898 2,2 v 7 z"
|
||||||
|
id="path3711"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#000000;stroke-width:1;stroke:#000000;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
inkscape:transform-center-x="0.33898322"
|
||||||
|
inkscape:transform-center-y="-0.6779661" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
60
interface/resources/icons/tablet-icons/raise-hand-i.svg
Normal file
60
interface/resources/icons/tablet-icons/raise-hand-i.svg
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Generated by IcoMoon.io -->
|
||||||
|
|
||||||
|
<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"
|
||||||
|
version="1.1"
|
||||||
|
width="50"
|
||||||
|
height="50"
|
||||||
|
viewBox="0 0 50 50"
|
||||||
|
id="svg3713"
|
||||||
|
sodipodi:docname="raise-hand-i.svg"
|
||||||
|
inkscape:version="0.92.1 r15371">
|
||||||
|
<metadata
|
||||||
|
id="metadata3719">
|
||||||
|
<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 />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<defs
|
||||||
|
id="defs3717" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1001"
|
||||||
|
id="namedview3715"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="11.8"
|
||||||
|
inkscape:cx="-20"
|
||||||
|
inkscape:cy="23.559322"
|
||||||
|
inkscape:window-x="-9"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg3713" />
|
||||||
|
<path
|
||||||
|
d="m 38.064897,12.746263 c -0.728,0 -1.412,0.196 -2,0.538 v -2.538 c 0,-2.2060002 -1.794,-4.0000002 -4,-4.0000002 -0.824,0 -1.588,0.25 -2.226,0.678 -0.548,-1.558 -2.032,-2.678 -3.774,-2.678 -1.742,0 -3.228,1.12 -3.774,2.678 -0.636,-0.428 -1.402,-0.678 -2.226,-0.678 -2.206,0 -4,1.794 -4,4.0000002 v 14.746 l -2.692,-4.666 c -0.522,-0.95 -1.374,-1.626 -2.398,-1.906 -0.9980001,-0.272 -2.0360001,-0.128 -2.9240001,0.404 -1.814,1.088 -2.506,3.548 -1.54,5.484 0.06,0.122 1.336,2.736 5.3200001,10.7 1.876,3.75 3.934,6.432 6.118,7.968 1.714,1.206 2.898,1.268 3.118,1.268 h 10 c 1.702,0 3.284,-0.554 4.704,-1.644 1.334,-1.026 2.492,-2.51 3.44,-4.408 1.868,-3.736 2.856,-8.904 2.856,-14.948 v -7 c 0,-2.206 -1.794,-4 -4,-4 z m 2,11 c 0,5.734 -0.914,10.592 -2.644,14.052 -1.128,2.256 -3.148,4.948 -6.356,4.948 h -9.98 c -0.078,-0.006 -0.92,-0.1 -2.19,-1.05 -1.266,-0.948 -3.21,-2.944 -5.276,-7.08 -4.0540001,-8.108 -5.3000001,-10.662 -5.3120001,-10.686 -0.002,-0.004 -0.002,-0.006 -0.004,-0.008 -0.502,-1.006 -0.146,-2.324 0.778,-2.878 0.416,-0.25 0.902,-0.316 1.3700001,-0.19 0.498,0.136 0.916,0.472 1.174,0.944 0.004,0.006 0.008,0.014 0.012,0.02 l 3.122,5.41 c 0.638,1.166 1.356,1.656 2.134,1.458 0.78,-0.198 1.174,-0.978 1.174,-2.314 v -15.626 c 0,-1.1020002 0.898,-2.0000002 2,-2.0000002 1.102,0 2,0.898 2,2.0000002 v 13 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 V 8.7462628 c 0,-1.102 0.898,-2 2,-2 1.102,0 2,0.898 2,2 V 23.746263 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 v -13 c 0,-1.1020002 0.898,-2.0000002 2,-2.0000002 1.102,0 2,0.898 2,2.0000002 v 15 c 0,0.552 0.448,1 1,1 0.552,0 1,-0.448 1,-1 v -9 c 0,-1.102 0.898,-2 2,-2 1.102,0 2,0.898 2,2 v 7 z"
|
||||||
|
id="path3711"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#ffffff;stroke-width:1;fill-opacity:1;stroke:#fdfdfc;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
inkscape:transform-center-x="0.33898322"
|
||||||
|
inkscape:transform-center-y="-0.6779661" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 394 KiB |
BIN
interface/resources/images/Default-Sky-9-cubemap.ktx
Normal file
BIN
interface/resources/images/Default-Sky-9-cubemap.ktx
Normal file
Binary file not shown.
|
@ -238,8 +238,25 @@ Column {
|
||||||
stackShadowNarrowing: root.stackShadowNarrowing;
|
stackShadowNarrowing: root.stackShadowNarrowing;
|
||||||
shadowHeight: root.stackedCardShadowHeight;
|
shadowHeight: root.stackedCardShadowHeight;
|
||||||
|
|
||||||
hoverThunk: function () { scroll.currentIndex = index; }
|
hoverThunk: function () { scrollToIndex(index); }
|
||||||
unhoverThunk: function () { scroll.currentIndex = -1; }
|
unhoverThunk: function () { scrollToIndex(-1); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NumberAnimation {
|
||||||
|
id: anim;
|
||||||
|
target: scroll;
|
||||||
|
property: "contentX";
|
||||||
|
duration: 250;
|
||||||
|
}
|
||||||
|
function scrollToIndex(index) {
|
||||||
|
anim.running = false;
|
||||||
|
var pos = scroll.contentX;
|
||||||
|
var destPos;
|
||||||
|
scroll.positionViewAtIndex(index, ListView.Contain);
|
||||||
|
destPos = scroll.contentX;
|
||||||
|
anim.from = pos;
|
||||||
|
anim.to = destPos;
|
||||||
|
scroll.currentIndex = index;
|
||||||
|
anim.running = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1438,15 +1438,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
connect(_window, SIGNAL(windowMinimizedChanged(bool)), this, SLOT(windowMinimizedChanged(bool)));
|
connect(_window, SIGNAL(windowMinimizedChanged(bool)), this, SLOT(windowMinimizedChanged(bool)));
|
||||||
qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);
|
qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTimer.elapsed() / 1000.0);
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
{
|
||||||
|
PROFILE_RANGE(render, "Process Default Skybox");
|
||||||
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
|
|
||||||
QString skyboxUrl { PathUtils::resourcesPath() + "images/Default-Sky-9-cubemap.jpg" };
|
auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx";
|
||||||
QString skyboxAmbientUrl { PathUtils::resourcesPath() + "images/Default-Sky-9-ambient.jpg" };
|
|
||||||
|
|
||||||
_defaultSkyboxTexture = textureCache->getImageTexture(skyboxUrl, image::TextureUsage::CUBE_TEXTURE, { { "generateIrradiance", false } });
|
_defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl);
|
||||||
_defaultSkyboxAmbientTexture = textureCache->getImageTexture(skyboxAmbientUrl, image::TextureUsage::CUBE_TEXTURE, { { "generateIrradiance", true } });
|
_defaultSkyboxAmbientTexture = _defaultSkyboxTexture;
|
||||||
|
|
||||||
_defaultSkybox->setCubemap(_defaultSkyboxTexture);
|
_defaultSkybox->setCubemap(_defaultSkyboxTexture);
|
||||||
|
}
|
||||||
|
|
||||||
EntityItem::setEntitiesShouldFadeFunction([this]() {
|
EntityItem::setEntitiesShouldFadeFunction([this]() {
|
||||||
SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
|
SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <avatar/AvatarActionFarGrab.h>
|
#include <avatar/AvatarActionFarGrab.h>
|
||||||
#include <ObjectActionOffset.h>
|
#include <ObjectActionOffset.h>
|
||||||
#include <ObjectActionSpring.h>
|
#include <ObjectActionSpring.h>
|
||||||
|
#include <ObjectActionTractor.h>
|
||||||
#include <ObjectActionTravelOriented.h>
|
#include <ObjectActionTravelOriented.h>
|
||||||
#include <ObjectConstraintHinge.h>
|
#include <ObjectConstraintHinge.h>
|
||||||
#include <ObjectConstraintSlider.h>
|
#include <ObjectConstraintSlider.h>
|
||||||
|
@ -33,6 +34,8 @@ EntityDynamicPointer interfaceDynamicFactory(EntityDynamicType type, const QUuid
|
||||||
return std::make_shared<ObjectActionOffset>(id, ownerEntity);
|
return std::make_shared<ObjectActionOffset>(id, ownerEntity);
|
||||||
case DYNAMIC_TYPE_SPRING:
|
case DYNAMIC_TYPE_SPRING:
|
||||||
return std::make_shared<ObjectActionSpring>(id, ownerEntity);
|
return std::make_shared<ObjectActionSpring>(id, ownerEntity);
|
||||||
|
case DYNAMIC_TYPE_TRACTOR:
|
||||||
|
return std::make_shared<ObjectActionTractor>(id, ownerEntity);
|
||||||
case DYNAMIC_TYPE_HOLD:
|
case DYNAMIC_TYPE_HOLD:
|
||||||
return std::make_shared<AvatarActionHold>(id, ownerEntity);
|
return std::make_shared<AvatarActionHold>(id, ownerEntity);
|
||||||
case DYNAMIC_TYPE_TRAVEL_ORIENTED:
|
case DYNAMIC_TYPE_TRAVEL_ORIENTED:
|
||||||
|
|
|
@ -523,6 +523,8 @@ Menu::Menu() {
|
||||||
avatar.get(), SLOT(setEnableDebugDrawSensorToWorldMatrix(bool)));
|
avatar.get(), SLOT(setEnableDebugDrawSensorToWorldMatrix(bool)));
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderIKTargets, 0, false,
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderIKTargets, 0, false,
|
||||||
avatar.get(), SLOT(setEnableDebugDrawIKTargets(bool)));
|
avatar.get(), SLOT(setEnableDebugDrawIKTargets(bool)));
|
||||||
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderIKConstraints, 0, false,
|
||||||
|
avatar.get(), SLOT(setEnableDebugDrawIKConstraints(bool)));
|
||||||
|
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ActionMotorControl,
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ActionMotorControl,
|
||||||
Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar.get(), SLOT(updateMotionBehaviorFromMenu()),
|
Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar.get(), SLOT(updateMotionBehaviorFromMenu()),
|
||||||
|
|
|
@ -161,6 +161,7 @@ namespace MenuOption {
|
||||||
const QString RenderResolutionQuarter = "1/4";
|
const QString RenderResolutionQuarter = "1/4";
|
||||||
const QString RenderSensorToWorldMatrix = "Show SensorToWorld Matrix";
|
const QString RenderSensorToWorldMatrix = "Show SensorToWorld Matrix";
|
||||||
const QString RenderIKTargets = "Show IK Targets";
|
const QString RenderIKTargets = "Show IK Targets";
|
||||||
|
const QString RenderIKConstraints = "Show IK Constraints";
|
||||||
const QString ResetAvatarSize = "Reset Avatar Size";
|
const QString ResetAvatarSize = "Reset Avatar Size";
|
||||||
const QString ResetSensors = "Reset Sensors";
|
const QString ResetSensors = "Reset Sensors";
|
||||||
const QString RunningScripts = "Running Scripts...";
|
const QString RunningScripts = "Running Scripts...";
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "AvatarActionFarGrab.h"
|
#include "AvatarActionFarGrab.h"
|
||||||
|
|
||||||
AvatarActionFarGrab::AvatarActionFarGrab(const QUuid& id, EntityItemPointer ownerEntity) :
|
AvatarActionFarGrab::AvatarActionFarGrab(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectActionSpring(id, ownerEntity) {
|
ObjectActionTractor(id, ownerEntity) {
|
||||||
_type = DYNAMIC_TYPE_FAR_GRAB;
|
_type = DYNAMIC_TYPE_FAR_GRAB;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "AvatarActionFarGrab::AvatarActionFarGrab";
|
qDebug() << "AvatarActionFarGrab::AvatarActionFarGrab";
|
||||||
|
@ -32,7 +32,7 @@ QByteArray AvatarActionFarGrab::serialize() const {
|
||||||
|
|
||||||
dataStream << DYNAMIC_TYPE_FAR_GRAB;
|
dataStream << DYNAMIC_TYPE_FAR_GRAB;
|
||||||
dataStream << getID();
|
dataStream << getID();
|
||||||
dataStream << ObjectActionSpring::springVersion;
|
dataStream << ObjectActionTractor::tractorVersion;
|
||||||
|
|
||||||
serializeParameters(dataStream);
|
serializeParameters(dataStream);
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ void AvatarActionFarGrab::deserialize(QByteArray serializedArguments) {
|
||||||
|
|
||||||
uint16_t serializationVersion;
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectActionSpring::springVersion) {
|
if (serializationVersion != ObjectActionTractor::tractorVersion) {
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#define hifi_AvatarActionFarGrab_h
|
#define hifi_AvatarActionFarGrab_h
|
||||||
|
|
||||||
#include <EntityItem.h>
|
#include <EntityItem.h>
|
||||||
#include <ObjectActionSpring.h>
|
#include <ObjectActionTractor.h>
|
||||||
|
|
||||||
class AvatarActionFarGrab : public ObjectActionSpring {
|
class AvatarActionFarGrab : public ObjectActionTractor {
|
||||||
public:
|
public:
|
||||||
AvatarActionFarGrab(const QUuid& id, EntityItemPointer ownerEntity);
|
AvatarActionFarGrab(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AvatarActionFarGrab();
|
virtual ~AvatarActionFarGrab();
|
||||||
|
|
|
@ -21,7 +21,7 @@ const int AvatarActionHold::velocitySmoothFrames = 6;
|
||||||
|
|
||||||
|
|
||||||
AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity) :
|
AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectActionSpring(id, ownerEntity)
|
ObjectActionTractor(id, ownerEntity)
|
||||||
{
|
{
|
||||||
_type = DYNAMIC_TYPE_HOLD;
|
_type = DYNAMIC_TYPE_HOLD;
|
||||||
_measuredLinearVelocities.resize(AvatarActionHold::velocitySmoothFrames);
|
_measuredLinearVelocities.resize(AvatarActionHold::velocitySmoothFrames);
|
||||||
|
@ -224,12 +224,12 @@ bool AvatarActionHold::getTarget(float deltaTimeStep, glm::quat& rotation, glm::
|
||||||
|
|
||||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
if (_kinematic) {
|
if (_kinematic) {
|
||||||
if (prepareForSpringUpdate(deltaTimeStep)) {
|
if (prepareForTractorUpdate(deltaTimeStep)) {
|
||||||
doKinematicUpdate(deltaTimeStep);
|
doKinematicUpdate(deltaTimeStep);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
forceBodyNonStatic();
|
forceBodyNonStatic();
|
||||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
ObjectActionTractor::updateActionWorker(deltaTimeStep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
#include <EntityItem.h>
|
#include <EntityItem.h>
|
||||||
#include <AnimPose.h>
|
#include <AnimPose.h>
|
||||||
#include <ObjectActionSpring.h>
|
#include <ObjectActionTractor.h>
|
||||||
|
|
||||||
#include "avatar/MyAvatar.h"
|
#include "avatar/MyAvatar.h"
|
||||||
|
|
||||||
|
|
||||||
class AvatarActionHold : public ObjectActionSpring {
|
class AvatarActionHold : public ObjectActionTractor {
|
||||||
public:
|
public:
|
||||||
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~AvatarActionHold();
|
virtual ~AvatarActionHold();
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#include <PIDController.h>
|
#include <PIDController.h>
|
||||||
#include <SimpleMovingAverage.h>
|
#include <SimpleMovingAverage.h>
|
||||||
#include <shared/RateCounter.h>
|
#include <shared/RateCounter.h>
|
||||||
#include <avatars-renderer/AvatarMotionState.h>
|
|
||||||
#include <avatars-renderer/ScriptAvatar.h>
|
#include <avatars-renderer/ScriptAvatar.h>
|
||||||
|
|
||||||
|
#include "AvatarMotionState.h"
|
||||||
#include "MyAvatar.h"
|
#include "MyAvatar.h"
|
||||||
|
|
||||||
class AudioInjector;
|
class AudioInjector;
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
#include <avatars-renderer/Avatar.h>
|
||||||
#include <ObjectMotionState.h>
|
#include <ObjectMotionState.h>
|
||||||
#include <BulletUtil.h>
|
#include <BulletUtil.h>
|
||||||
|
|
||||||
#include "Avatar.h"
|
|
||||||
|
|
||||||
class AvatarMotionState : public ObjectMotionState {
|
class AvatarMotionState : public ObjectMotionState {
|
||||||
public:
|
public:
|
|
@ -38,6 +38,7 @@
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
#include <AnimDebugDraw.h>
|
#include <AnimDebugDraw.h>
|
||||||
#include <AnimClip.h>
|
#include <AnimClip.h>
|
||||||
|
#include <AnimInverseKinematics.h>
|
||||||
#include <recording/Deck.h>
|
#include <recording/Deck.h>
|
||||||
#include <recording/Recorder.h>
|
#include <recording/Recorder.h>
|
||||||
#include <recording/Clip.h>
|
#include <recording/Clip.h>
|
||||||
|
@ -290,6 +291,11 @@ QByteArray MyAvatar::toByteArrayStateful(AvatarDataDetail dataDetail) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::resetSensorsAndBody() {
|
void MyAvatar::resetSensorsAndBody() {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "resetSensorsAndBody");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qApp->getActiveDisplayPlugin()->resetSensors();
|
qApp->getActiveDisplayPlugin()->resetSensors();
|
||||||
reset(true, false, true);
|
reset(true, false, true);
|
||||||
}
|
}
|
||||||
|
@ -504,6 +510,7 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
|
|
||||||
if (_rig) {
|
if (_rig) {
|
||||||
_rig->setEnableDebugDrawIKTargets(_enableDebugDrawIKTargets);
|
_rig->setEnableDebugDrawIKTargets(_enableDebugDrawIKTargets);
|
||||||
|
_rig->setEnableDebugDrawIKConstraints(_enableDebugDrawIKConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
_skeletonModel->simulate(deltaTime);
|
_skeletonModel->simulate(deltaTime);
|
||||||
|
@ -927,6 +934,10 @@ void MyAvatar::setEnableDebugDrawIKTargets(bool isEnabled) {
|
||||||
_enableDebugDrawIKTargets = isEnabled;
|
_enableDebugDrawIKTargets = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyAvatar::setEnableDebugDrawIKConstraints(bool isEnabled) {
|
||||||
|
_enableDebugDrawIKConstraints = isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::setEnableMeshVisible(bool isEnabled) {
|
void MyAvatar::setEnableMeshVisible(bool isEnabled) {
|
||||||
_skeletonModel->setVisibleInScene(isEnabled, qApp->getMain3DScene());
|
_skeletonModel->setVisibleInScene(isEnabled, qApp->getMain3DScene());
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,6 +521,7 @@ public slots:
|
||||||
void setEnableDebugDrawHandControllers(bool isEnabled);
|
void setEnableDebugDrawHandControllers(bool isEnabled);
|
||||||
void setEnableDebugDrawSensorToWorldMatrix(bool isEnabled);
|
void setEnableDebugDrawSensorToWorldMatrix(bool isEnabled);
|
||||||
void setEnableDebugDrawIKTargets(bool isEnabled);
|
void setEnableDebugDrawIKTargets(bool isEnabled);
|
||||||
|
void setEnableDebugDrawIKConstraints(bool isEnabled);
|
||||||
bool getEnableMeshVisible() const { return _skeletonModel->isVisible(); }
|
bool getEnableMeshVisible() const { return _skeletonModel->isVisible(); }
|
||||||
void setEnableMeshVisible(bool isEnabled);
|
void setEnableMeshVisible(bool isEnabled);
|
||||||
void setUseAnimPreAndPostRotations(bool isEnabled);
|
void setUseAnimPreAndPostRotations(bool isEnabled);
|
||||||
|
@ -706,6 +707,7 @@ private:
|
||||||
bool _enableDebugDrawHandControllers { false };
|
bool _enableDebugDrawHandControllers { false };
|
||||||
bool _enableDebugDrawSensorToWorldMatrix { false };
|
bool _enableDebugDrawSensorToWorldMatrix { false };
|
||||||
bool _enableDebugDrawIKTargets { false };
|
bool _enableDebugDrawIKTargets { false };
|
||||||
|
bool _enableDebugDrawIKConstraints { false };
|
||||||
|
|
||||||
AudioListenerMode _audioListenerMode;
|
AudioListenerMode _audioListenerMode;
|
||||||
glm::vec3 _customListenPosition;
|
glm::vec3 _customListenPosition;
|
||||||
|
|
|
@ -44,14 +44,17 @@ glm::quat MyHead::getCameraOrientation() const {
|
||||||
void MyHead::simulate(float deltaTime) {
|
void MyHead::simulate(float deltaTime) {
|
||||||
auto player = DependencyManager::get<recording::Deck>();
|
auto player = DependencyManager::get<recording::Deck>();
|
||||||
// Only use face trackers when not playing back a recording.
|
// Only use face trackers when not playing back a recording.
|
||||||
if (!player->isPlaying()) {
|
if (player->isPlaying()) {
|
||||||
|
Parent::simulate(deltaTime);
|
||||||
|
} else {
|
||||||
|
computeAudioLoudness(deltaTime);
|
||||||
|
|
||||||
FaceTracker* faceTracker = qApp->getActiveFaceTracker();
|
FaceTracker* faceTracker = qApp->getActiveFaceTracker();
|
||||||
_isFaceTrackerConnected = faceTracker != NULL && !faceTracker->isMuted();
|
_isFaceTrackerConnected = faceTracker && !faceTracker->isMuted();
|
||||||
if (_isFaceTrackerConnected) {
|
if (_isFaceTrackerConnected) {
|
||||||
_transientBlendshapeCoefficients = faceTracker->getBlendshapeCoefficients();
|
_transientBlendshapeCoefficients = faceTracker->getBlendshapeCoefficients();
|
||||||
|
|
||||||
if (typeid(*faceTracker) == typeid(DdeFaceTracker)) {
|
if (typeid(*faceTracker) == typeid(DdeFaceTracker)) {
|
||||||
|
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::UseAudioForMouth)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::UseAudioForMouth)) {
|
||||||
calculateMouthShapes(deltaTime);
|
calculateMouthShapes(deltaTime);
|
||||||
|
|
||||||
|
@ -68,9 +71,19 @@ void MyHead::simulate(float deltaTime) {
|
||||||
}
|
}
|
||||||
applyEyelidOffset(getFinalOrientationInWorldFrame());
|
applyEyelidOffset(getFinalOrientationInWorldFrame());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
computeFaceMovement(deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
auto eyeTracker = DependencyManager::get<EyeTracker>();
|
auto eyeTracker = DependencyManager::get<EyeTracker>();
|
||||||
_isEyeTrackerConnected = eyeTracker->isTracking();
|
_isEyeTrackerConnected = eyeTracker && eyeTracker->isTracking();
|
||||||
|
if (_isEyeTrackerConnected) {
|
||||||
|
// TODO? figure out where EyeTracker data harvested. Move it here?
|
||||||
|
_saccade = glm::vec3();
|
||||||
|
} else {
|
||||||
|
computeEyeMovement(deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Parent::simulate(deltaTime);
|
computeEyePosition();
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,7 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionInternal(const PickR
|
||||||
const QVector<OverlayID>& overlaysToInclude,
|
const QVector<OverlayID>& overlaysToInclude,
|
||||||
const QVector<OverlayID>& overlaysToDiscard,
|
const QVector<OverlayID>& overlaysToDiscard,
|
||||||
bool visibleOnly, bool collidableOnly) {
|
bool visibleOnly, bool collidableOnly) {
|
||||||
|
QReadLocker lock(&_lock);
|
||||||
float bestDistance = std::numeric_limits<float>::max();
|
float bestDistance = std::numeric_limits<float>::max();
|
||||||
bool bestIsFront = false;
|
bool bestIsFront = false;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
|
|
||||||
#include "AnimContext.h"
|
#include "AnimContext.h"
|
||||||
|
|
||||||
AnimContext::AnimContext(bool enableDebugDrawIKTargets, const glm::mat4& geometryToRigMatrix) :
|
AnimContext::AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints,
|
||||||
|
const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix) :
|
||||||
_enableDebugDrawIKTargets(enableDebugDrawIKTargets),
|
_enableDebugDrawIKTargets(enableDebugDrawIKTargets),
|
||||||
_geometryToRigMatrix(geometryToRigMatrix) {
|
_enableDebugDrawIKConstraints(enableDebugDrawIKConstraints),
|
||||||
|
_geometryToRigMatrix(geometryToRigMatrix),
|
||||||
|
_rigToWorldMatrix(rigToWorldMatrix)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,20 @@
|
||||||
|
|
||||||
class AnimContext {
|
class AnimContext {
|
||||||
public:
|
public:
|
||||||
AnimContext(bool enableDebugDrawIKTargets, const glm::mat4& geometryToRigMatrix);
|
AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints,
|
||||||
|
const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix);
|
||||||
|
|
||||||
bool getEnableDebugDrawIKTargets() const { return _enableDebugDrawIKTargets; }
|
bool getEnableDebugDrawIKTargets() const { return _enableDebugDrawIKTargets; }
|
||||||
|
bool getEnableDebugDrawIKConstraints() const { return _enableDebugDrawIKConstraints; }
|
||||||
const glm::mat4& getGeometryToRigMatrix() const { return _geometryToRigMatrix; }
|
const glm::mat4& getGeometryToRigMatrix() const { return _geometryToRigMatrix; }
|
||||||
|
const glm::mat4& getRigToWorldMatrix() const { return _rigToWorldMatrix; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool _enableDebugDrawIKTargets { false };
|
bool _enableDebugDrawIKTargets { false };
|
||||||
|
bool _enableDebugDrawIKConstraints{ false };
|
||||||
glm::mat4 _geometryToRigMatrix;
|
glm::mat4 _geometryToRigMatrix;
|
||||||
|
glm::mat4 _rigToWorldMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AnimContext_h
|
#endif // hifi_AnimContext_h
|
||||||
|
|
|
@ -399,6 +399,13 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
|
||||||
//virtual
|
//virtual
|
||||||
const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars, const AnimContext& context, float dt, Triggers& triggersOut, const AnimPoseVec& underPoses) {
|
const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars, const AnimContext& context, float dt, Triggers& triggersOut, const AnimPoseVec& underPoses) {
|
||||||
|
|
||||||
|
// allows solutionSource to be overridden by an animVar
|
||||||
|
auto solutionSource = animVars.lookup(_solutionSourceVar, (int)_solutionSource);
|
||||||
|
|
||||||
|
if (context.getEnableDebugDrawIKConstraints()) {
|
||||||
|
debugDrawConstraints(context);
|
||||||
|
}
|
||||||
|
|
||||||
const float MAX_OVERLAY_DT = 1.0f / 30.0f; // what to clamp delta-time to in AnimInverseKinematics::overlay
|
const float MAX_OVERLAY_DT = 1.0f / 30.0f; // what to clamp delta-time to in AnimInverseKinematics::overlay
|
||||||
if (dt > MAX_OVERLAY_DT) {
|
if (dt > MAX_OVERLAY_DT) {
|
||||||
dt = MAX_OVERLAY_DT;
|
dt = MAX_OVERLAY_DT;
|
||||||
|
@ -410,25 +417,7 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
|
||||||
|
|
||||||
PROFILE_RANGE_EX(simulation_animation, "ik/relax", 0xffff00ff, 0);
|
PROFILE_RANGE_EX(simulation_animation, "ik/relax", 0xffff00ff, 0);
|
||||||
|
|
||||||
// relax toward underPoses
|
initRelativePosesFromSolutionSource((SolutionSource)solutionSource, underPoses);
|
||||||
// HACK: this relaxation needs to be constant per-frame rather than per-realtime
|
|
||||||
// in order to prevent IK "flutter" for bad FPS. The bad news is that the good parts
|
|
||||||
// of this relaxation will be FPS dependent (low FPS will make the limbs align slower
|
|
||||||
// in real-time), however most people will not notice this and this problem is less
|
|
||||||
// annoying than the flutter.
|
|
||||||
const float blend = (1.0f / 60.0f) / (0.25f); // effectively: dt / RELAXATION_TIMESCALE
|
|
||||||
int numJoints = (int)_relativePoses.size();
|
|
||||||
for (int i = 0; i < numJoints; ++i) {
|
|
||||||
float dotSign = copysignf(1.0f, glm::dot(_relativePoses[i].rot(), underPoses[i].rot()));
|
|
||||||
if (_accumulators[i].isDirty()) {
|
|
||||||
// this joint is affected by IK --> blend toward underPose rotation
|
|
||||||
_relativePoses[i].rot() = glm::normalize(glm::lerp(_relativePoses[i].rot(), dotSign * underPoses[i].rot(), blend));
|
|
||||||
} else {
|
|
||||||
// this joint is NOT affected by IK --> slam to underPose rotation
|
|
||||||
_relativePoses[i].rot() = underPoses[i].rot();
|
|
||||||
}
|
|
||||||
_relativePoses[i].trans() = underPoses[i].trans();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!underPoses.empty()) {
|
if (!underPoses.empty()) {
|
||||||
// Sometimes the underpose itself can violate the constraints. Rather than
|
// Sometimes the underpose itself can violate the constraints. Rather than
|
||||||
|
@ -604,9 +593,9 @@ void AnimInverseKinematics::clearIKJointLimitHistory() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RotationConstraint* AnimInverseKinematics::getConstraint(int index) {
|
RotationConstraint* AnimInverseKinematics::getConstraint(int index) const {
|
||||||
RotationConstraint* constraint = nullptr;
|
RotationConstraint* constraint = nullptr;
|
||||||
std::map<int, RotationConstraint*>::iterator constraintItr = _constraints.find(index);
|
std::map<int, RotationConstraint*>::const_iterator constraintItr = _constraints.find(index);
|
||||||
if (constraintItr != _constraints.end()) {
|
if (constraintItr != _constraints.end()) {
|
||||||
constraint = constraintItr->second;
|
constraint = constraintItr->second;
|
||||||
}
|
}
|
||||||
|
@ -622,17 +611,19 @@ void AnimInverseKinematics::clearConstraints() {
|
||||||
_constraints.clear();
|
_constraints.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up swing limits around a swingTwistConstraint in an ellipse, where lateralSwingTheta is the swing limit for lateral swings (side to side)
|
// set up swing limits around a swingTwistConstraint in an ellipse, where lateralSwingPhi is the swing limit for lateral swings (side to side)
|
||||||
// anteriorSwingTheta is swing limit for forward and backward swings. (where x-axis of reference rotation is sideways and -z-axis is forward)
|
// anteriorSwingPhi is swing limit for forward and backward swings. (where x-axis of reference rotation is sideways and -z-axis is forward)
|
||||||
static void setEllipticalSwingLimits(SwingTwistConstraint* stConstraint, float lateralSwingTheta, float anteriorSwingTheta) {
|
static void setEllipticalSwingLimits(SwingTwistConstraint* stConstraint, float lateralSwingPhi, float anteriorSwingPhi) {
|
||||||
assert(stConstraint);
|
assert(stConstraint);
|
||||||
const int NUM_SUBDIVISIONS = 8;
|
const int NUM_SUBDIVISIONS = 16;
|
||||||
std::vector<float> minDots;
|
std::vector<float> minDots;
|
||||||
minDots.reserve(NUM_SUBDIVISIONS);
|
minDots.reserve(NUM_SUBDIVISIONS);
|
||||||
float dTheta = TWO_PI / NUM_SUBDIVISIONS;
|
float dTheta = TWO_PI / NUM_SUBDIVISIONS;
|
||||||
float theta = 0.0f;
|
float theta = 0.0f;
|
||||||
for (int i = 0; i < NUM_SUBDIVISIONS; i++) {
|
for (int i = 0; i < NUM_SUBDIVISIONS; i++) {
|
||||||
minDots.push_back(cosf(glm::length(glm::vec2(anteriorSwingTheta * cosf(theta), lateralSwingTheta * sinf(theta)))));
|
float theta_prime = atanf((lateralSwingPhi / anteriorSwingPhi) * tanf(theta));
|
||||||
|
float phi = (cosf(2.0f * theta_prime) * ((lateralSwingPhi - anteriorSwingPhi) / 2.0f)) + ((lateralSwingPhi + anteriorSwingPhi) / 2.0f);
|
||||||
|
minDots.push_back(cosf(phi));
|
||||||
theta += dTheta;
|
theta += dTheta;
|
||||||
}
|
}
|
||||||
stConstraint->setSwingLimits(minDots);
|
stConstraint->setSwingLimits(minDots);
|
||||||
|
@ -640,7 +631,6 @@ static void setEllipticalSwingLimits(SwingTwistConstraint* stConstraint, float l
|
||||||
|
|
||||||
void AnimInverseKinematics::initConstraints() {
|
void AnimInverseKinematics::initConstraints() {
|
||||||
if (!_skeleton) {
|
if (!_skeleton) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// We create constraints for the joints shown here
|
// We create constraints for the joints shown here
|
||||||
// (and their Left counterparts if applicable).
|
// (and their Left counterparts if applicable).
|
||||||
|
@ -744,30 +734,27 @@ void AnimInverseKinematics::initConstraints() {
|
||||||
std::vector<glm::vec3> swungDirections;
|
std::vector<glm::vec3> swungDirections;
|
||||||
float deltaTheta = PI / 4.0f;
|
float deltaTheta = PI / 4.0f;
|
||||||
float theta = 0.0f;
|
float theta = 0.0f;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.25f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.25f, sinf(theta)));
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.0f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.0f, sinf(theta)));
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.25f, sinf(theta))); // posterior
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.25f, sinf(theta))); // posterior
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.0f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.0f, sinf(theta)));
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.25f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.25f, sinf(theta)));
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.5f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.5f, sinf(theta)));
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.5f, sinf(theta))); // anterior
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.5f, sinf(theta))); // anterior
|
||||||
theta += deltaTheta;
|
theta += deltaTheta;
|
||||||
swungDirections.push_back(glm::vec3(mirror * cosf(theta), 0.5f, sinf(theta)));
|
swungDirections.push_back(glm::vec3(mirror * cosf(theta), -0.5f, sinf(theta)));
|
||||||
|
|
||||||
// rotate directions into joint-frame
|
std::vector<float> minDots;
|
||||||
glm::quat invAbsoluteRotation = glm::inverse(absolutePoses[i].rot());
|
for (size_t i = 0; i < swungDirections.size(); i++) {
|
||||||
int numDirections = (int)swungDirections.size();
|
minDots.push_back(glm::dot(glm::normalize(swungDirections[i]), Vectors::UNIT_Y));
|
||||||
for (int j = 0; j < numDirections; ++j) {
|
|
||||||
swungDirections[j] = invAbsoluteRotation * swungDirections[j];
|
|
||||||
}
|
}
|
||||||
stConstraint->setSwingLimits(swungDirections);
|
stConstraint->setSwingLimits(minDots);
|
||||||
|
|
||||||
constraint = static_cast<RotationConstraint*>(stConstraint);
|
constraint = static_cast<RotationConstraint*>(stConstraint);
|
||||||
} else if (0 == baseName.compare("Hand", Qt::CaseSensitive)) {
|
} else if (0 == baseName.compare("Hand", Qt::CaseSensitive)) {
|
||||||
SwingTwistConstraint* stConstraint = new SwingTwistConstraint();
|
SwingTwistConstraint* stConstraint = new SwingTwistConstraint();
|
||||||
|
@ -957,6 +944,32 @@ void AnimInverseKinematics::initConstraints() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimInverseKinematics::initLimitCenterPoses() {
|
||||||
|
assert(_skeleton);
|
||||||
|
_limitCenterPoses.reserve(_skeleton->getNumJoints());
|
||||||
|
for (int i = 0; i < _skeleton->getNumJoints(); i++) {
|
||||||
|
AnimPose pose = _skeleton->getRelativeDefaultPose(i);
|
||||||
|
RotationConstraint* constraint = getConstraint(i);
|
||||||
|
if (constraint) {
|
||||||
|
pose.rot() = constraint->computeCenterRotation();
|
||||||
|
}
|
||||||
|
_limitCenterPoses.push_back(pose);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The limit center rotations for the LeftArm and RightArm form a t-pose.
|
||||||
|
// In order for the elbows to look more natural, we rotate them down by the avatar's sides
|
||||||
|
const float UPPER_ARM_THETA = PI / 3.0f; // 60 deg
|
||||||
|
int leftArmIndex = _skeleton->nameToJointIndex("LeftArm");
|
||||||
|
const glm::quat armRot = glm::angleAxis(UPPER_ARM_THETA, Vectors::UNIT_X);
|
||||||
|
if (leftArmIndex >= 0 && leftArmIndex < (int)_limitCenterPoses.size()) {
|
||||||
|
_limitCenterPoses[leftArmIndex].rot() = _limitCenterPoses[leftArmIndex].rot() * armRot;
|
||||||
|
}
|
||||||
|
int rightArmIndex = _skeleton->nameToJointIndex("RightArm");
|
||||||
|
if (rightArmIndex >= 0 && rightArmIndex < (int)_limitCenterPoses.size()) {
|
||||||
|
_limitCenterPoses[rightArmIndex].rot() = _limitCenterPoses[rightArmIndex].rot() * armRot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) {
|
void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) {
|
||||||
AnimNode::setSkeletonInternal(skeleton);
|
AnimNode::setSkeletonInternal(skeleton);
|
||||||
|
|
||||||
|
@ -973,6 +986,7 @@ void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skele
|
||||||
|
|
||||||
if (skeleton) {
|
if (skeleton) {
|
||||||
initConstraints();
|
initConstraints();
|
||||||
|
initLimitCenterPoses();
|
||||||
_headIndex = _skeleton->nameToJointIndex("Head");
|
_headIndex = _skeleton->nameToJointIndex("Head");
|
||||||
_hipsIndex = _skeleton->nameToJointIndex("Hips");
|
_hipsIndex = _skeleton->nameToJointIndex("Hips");
|
||||||
|
|
||||||
|
@ -989,3 +1003,170 @@ void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skele
|
||||||
_hipsParentIndex = -1;
|
_hipsParentIndex = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static glm::vec3 sphericalToCartesian(float phi, float theta) {
|
||||||
|
float cos_phi = cosf(phi);
|
||||||
|
float sin_phi = sinf(phi);
|
||||||
|
return glm::vec3(sin_phi * cosf(theta), cos_phi, -sin_phi * sinf(theta));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimInverseKinematics::debugDrawConstraints(const AnimContext& context) const {
|
||||||
|
if (_skeleton) {
|
||||||
|
const vec4 RED(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
const vec4 GREEN(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
const vec4 BLUE(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
const vec4 PURPLE(0.5f, 0.0f, 1.0f, 1.0f);
|
||||||
|
const vec4 CYAN(0.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
const vec4 GRAY(0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
const vec4 MAGENTA(1.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
const float AXIS_LENGTH = 2.0f; // cm
|
||||||
|
const float TWIST_LENGTH = 4.0f; // cm
|
||||||
|
const float HINGE_LENGTH = 6.0f; // cm
|
||||||
|
const float SWING_LENGTH = 5.0f; // cm
|
||||||
|
|
||||||
|
AnimPoseVec poses = _skeleton->getRelativeDefaultPoses();
|
||||||
|
|
||||||
|
// copy reference rotations into the relative poses
|
||||||
|
for (int i = 0; i < (int)poses.size(); i++) {
|
||||||
|
const RotationConstraint* constraint = getConstraint(i);
|
||||||
|
if (constraint) {
|
||||||
|
poses[i].rot() = constraint->getReferenceRotation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert relative poses to absolute
|
||||||
|
_skeleton->convertRelativePosesToAbsolute(poses);
|
||||||
|
|
||||||
|
mat4 geomToWorldMatrix = context.getRigToWorldMatrix() * context.getGeometryToRigMatrix();
|
||||||
|
|
||||||
|
// draw each pose and constraint
|
||||||
|
for (int i = 0; i < (int)poses.size(); i++) {
|
||||||
|
// transform local axes into world space.
|
||||||
|
auto pose = poses[i];
|
||||||
|
glm::vec3 xAxis = transformVectorFast(geomToWorldMatrix, pose.rot() * Vectors::UNIT_X);
|
||||||
|
glm::vec3 yAxis = transformVectorFast(geomToWorldMatrix, pose.rot() * Vectors::UNIT_Y);
|
||||||
|
glm::vec3 zAxis = transformVectorFast(geomToWorldMatrix, pose.rot() * Vectors::UNIT_Z);
|
||||||
|
glm::vec3 pos = transformPoint(geomToWorldMatrix, pose.trans());
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + AXIS_LENGTH * xAxis, RED);
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + AXIS_LENGTH * yAxis, GREEN);
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + AXIS_LENGTH * zAxis, BLUE);
|
||||||
|
|
||||||
|
// draw line to parent
|
||||||
|
int parentIndex = _skeleton->getParentIndex(i);
|
||||||
|
if (parentIndex != -1) {
|
||||||
|
glm::vec3 parentPos = transformPoint(geomToWorldMatrix, poses[parentIndex].trans());
|
||||||
|
DebugDraw::getInstance().drawRay(pos, parentPos, GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat parentAbsRot;
|
||||||
|
if (parentIndex != -1) {
|
||||||
|
parentAbsRot = poses[parentIndex].rot();
|
||||||
|
}
|
||||||
|
|
||||||
|
const RotationConstraint* constraint = getConstraint(i);
|
||||||
|
if (constraint) {
|
||||||
|
glm::quat refRot = constraint->getReferenceRotation();
|
||||||
|
const ElbowConstraint* elbowConstraint = dynamic_cast<const ElbowConstraint*>(constraint);
|
||||||
|
if (elbowConstraint) {
|
||||||
|
glm::vec3 hingeAxis = transformVectorFast(geomToWorldMatrix, parentAbsRot * refRot * elbowConstraint->getHingeAxis());
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + HINGE_LENGTH * hingeAxis, MAGENTA);
|
||||||
|
|
||||||
|
// draw elbow constraints
|
||||||
|
glm::quat minRot = glm::angleAxis(elbowConstraint->getMinAngle(), elbowConstraint->getHingeAxis());
|
||||||
|
glm::quat maxRot = glm::angleAxis(elbowConstraint->getMaxAngle(), elbowConstraint->getHingeAxis());
|
||||||
|
|
||||||
|
const int NUM_SWING_STEPS = 10;
|
||||||
|
for (int i = 0; i < NUM_SWING_STEPS + 1; i++) {
|
||||||
|
glm::quat rot = glm::normalize(glm::lerp(minRot, maxRot, i * (1.0f / NUM_SWING_STEPS)));
|
||||||
|
glm::vec3 axis = transformVectorFast(geomToWorldMatrix, parentAbsRot * rot * refRot * Vectors::UNIT_Y);
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + TWIST_LENGTH * axis, CYAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const SwingTwistConstraint* swingTwistConstraint = dynamic_cast<const SwingTwistConstraint*>(constraint);
|
||||||
|
if (swingTwistConstraint) {
|
||||||
|
// twist constraints
|
||||||
|
|
||||||
|
glm::vec3 hingeAxis = transformVectorFast(geomToWorldMatrix, parentAbsRot * refRot * Vectors::UNIT_Y);
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + HINGE_LENGTH * hingeAxis, MAGENTA);
|
||||||
|
|
||||||
|
glm::quat minRot = glm::angleAxis(swingTwistConstraint->getMinTwist(), Vectors::UNIT_Y);
|
||||||
|
glm::quat maxRot = glm::angleAxis(swingTwistConstraint->getMaxTwist(), Vectors::UNIT_Y);
|
||||||
|
|
||||||
|
const int NUM_SWING_STEPS = 10;
|
||||||
|
for (int i = 0; i < NUM_SWING_STEPS + 1; i++) {
|
||||||
|
glm::quat rot = glm::normalize(glm::lerp(minRot, maxRot, i * (1.0f / NUM_SWING_STEPS)));
|
||||||
|
glm::vec3 axis = transformVectorFast(geomToWorldMatrix, parentAbsRot * rot * refRot * Vectors::UNIT_X);
|
||||||
|
DebugDraw::getInstance().drawRay(pos, pos + TWIST_LENGTH * axis, CYAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw swing constraints.
|
||||||
|
const size_t NUM_MIN_DOTS = swingTwistConstraint->getMinDots().size();
|
||||||
|
const float D_THETA = TWO_PI / (NUM_MIN_DOTS - 1);
|
||||||
|
float theta = 0.0f;
|
||||||
|
for (size_t i = 0, j = NUM_MIN_DOTS - 2; i < NUM_MIN_DOTS - 1; j = i, i++, theta += D_THETA) {
|
||||||
|
// compute swing rotation from theta and phi angles.
|
||||||
|
float phi = acosf(swingTwistConstraint->getMinDots()[i]);
|
||||||
|
glm::vec3 swungAxis = sphericalToCartesian(phi, theta);
|
||||||
|
glm::vec3 worldSwungAxis = transformVectorFast(geomToWorldMatrix, parentAbsRot * refRot * swungAxis);
|
||||||
|
glm::vec3 swingTip = pos + SWING_LENGTH * worldSwungAxis;
|
||||||
|
|
||||||
|
float prevPhi = acos(swingTwistConstraint->getMinDots()[j]);
|
||||||
|
float prevTheta = theta - D_THETA;
|
||||||
|
glm::vec3 prevSwungAxis = sphericalToCartesian(prevPhi, prevTheta);
|
||||||
|
glm::vec3 prevWorldSwungAxis = transformVectorFast(geomToWorldMatrix, parentAbsRot * refRot * prevSwungAxis);
|
||||||
|
glm::vec3 prevSwingTip = pos + SWING_LENGTH * prevWorldSwungAxis;
|
||||||
|
|
||||||
|
DebugDraw::getInstance().drawRay(pos, swingTip, PURPLE);
|
||||||
|
DebugDraw::getInstance().drawRay(prevSwingTip, swingTip, PURPLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pose.rot() = constraint->computeCenterRotation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for bones under IK, blend between previous solution (_relativePoses) to targetPoses
|
||||||
|
// for bones NOT under IK, copy directly from underPoses.
|
||||||
|
// mutates _relativePoses.
|
||||||
|
void AnimInverseKinematics::blendToPoses(const AnimPoseVec& targetPoses, const AnimPoseVec& underPoses, float blendFactor) {
|
||||||
|
// relax toward poses
|
||||||
|
int numJoints = (int)_relativePoses.size();
|
||||||
|
for (int i = 0; i < numJoints; ++i) {
|
||||||
|
float dotSign = copysignf(1.0f, glm::dot(_relativePoses[i].rot(), targetPoses[i].rot()));
|
||||||
|
if (_accumulators[i].isDirty()) {
|
||||||
|
// this joint is affected by IK --> blend toward the targetPoses rotation
|
||||||
|
_relativePoses[i].rot() = glm::normalize(glm::lerp(_relativePoses[i].rot(), dotSign * targetPoses[i].rot(), blendFactor));
|
||||||
|
} else {
|
||||||
|
// this joint is NOT affected by IK --> slam to underPoses rotation
|
||||||
|
_relativePoses[i].rot() = underPoses[i].rot();
|
||||||
|
}
|
||||||
|
_relativePoses[i].trans() = underPoses[i].trans();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimInverseKinematics::initRelativePosesFromSolutionSource(SolutionSource solutionSource, const AnimPoseVec& underPoses) {
|
||||||
|
const float RELAX_BLEND_FACTOR = (1.0f / 16.0f);
|
||||||
|
const float COPY_BLEND_FACTOR = 1.0f;
|
||||||
|
switch (solutionSource) {
|
||||||
|
default:
|
||||||
|
case SolutionSource::RelaxToUnderPoses:
|
||||||
|
blendToPoses(underPoses, underPoses, RELAX_BLEND_FACTOR);
|
||||||
|
break;
|
||||||
|
case SolutionSource::RelaxToLimitCenterPoses:
|
||||||
|
blendToPoses(_limitCenterPoses, underPoses, RELAX_BLEND_FACTOR);
|
||||||
|
break;
|
||||||
|
case SolutionSource::PreviousSolution:
|
||||||
|
// do nothing... _relativePoses is already the previous solution
|
||||||
|
break;
|
||||||
|
case SolutionSource::UnderPoses:
|
||||||
|
_relativePoses = underPoses;
|
||||||
|
break;
|
||||||
|
case SolutionSource::LimitCenterPoses:
|
||||||
|
// essentially copy limitCenterPoses over to _relativePoses.
|
||||||
|
blendToPoses(_limitCenterPoses, underPoses, COPY_BLEND_FACTOR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,18 +43,34 @@ public:
|
||||||
|
|
||||||
float getMaxErrorOnLastSolve() { return _maxErrorOnLastSolve; }
|
float getMaxErrorOnLastSolve() { return _maxErrorOnLastSolve; }
|
||||||
|
|
||||||
|
enum class SolutionSource {
|
||||||
|
RelaxToUnderPoses = 0,
|
||||||
|
RelaxToLimitCenterPoses,
|
||||||
|
PreviousSolution,
|
||||||
|
UnderPoses,
|
||||||
|
LimitCenterPoses,
|
||||||
|
NumSolutionSources,
|
||||||
|
};
|
||||||
|
|
||||||
|
void setSolutionSource(SolutionSource solutionSource) { _solutionSource = solutionSource; }
|
||||||
|
void setSolutionSourceVar(const QString& solutionSourceVar) { _solutionSourceVar = solutionSourceVar; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void computeTargets(const AnimVariantMap& animVars, std::vector<IKTarget>& targets, const AnimPoseVec& underPoses);
|
void computeTargets(const AnimVariantMap& animVars, std::vector<IKTarget>& targets, const AnimPoseVec& underPoses);
|
||||||
void solveWithCyclicCoordinateDescent(const std::vector<IKTarget>& targets);
|
void solveWithCyclicCoordinateDescent(const std::vector<IKTarget>& targets);
|
||||||
int solveTargetWithCCD(const IKTarget& target, AnimPoseVec& absolutePoses);
|
int solveTargetWithCCD(const IKTarget& target, AnimPoseVec& absolutePoses);
|
||||||
virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) override;
|
virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) override;
|
||||||
|
void debugDrawConstraints(const AnimContext& context) const;
|
||||||
|
void initRelativePosesFromSolutionSource(SolutionSource solutionSource, const AnimPoseVec& underPose);
|
||||||
|
void blendToPoses(const AnimPoseVec& targetPoses, const AnimPoseVec& underPose, float blendFactor);
|
||||||
|
|
||||||
// for AnimDebugDraw rendering
|
// for AnimDebugDraw rendering
|
||||||
virtual const AnimPoseVec& getPosesInternal() const override { return _relativePoses; }
|
virtual const AnimPoseVec& getPosesInternal() const override { return _relativePoses; }
|
||||||
|
|
||||||
RotationConstraint* getConstraint(int index);
|
RotationConstraint* getConstraint(int index) const;
|
||||||
void clearConstraints();
|
void clearConstraints();
|
||||||
void initConstraints();
|
void initConstraints();
|
||||||
|
void initLimitCenterPoses();
|
||||||
void computeHipsOffset(const std::vector<IKTarget>& targets, const AnimPoseVec& underPoses, float dt);
|
void computeHipsOffset(const std::vector<IKTarget>& targets, const AnimPoseVec& underPoses, float dt);
|
||||||
|
|
||||||
// no copies
|
// no copies
|
||||||
|
@ -85,6 +101,7 @@ protected:
|
||||||
std::vector<IKTargetVar> _targetVarVec;
|
std::vector<IKTargetVar> _targetVarVec;
|
||||||
AnimPoseVec _defaultRelativePoses; // poses of the relaxed state
|
AnimPoseVec _defaultRelativePoses; // poses of the relaxed state
|
||||||
AnimPoseVec _relativePoses; // current relative poses
|
AnimPoseVec _relativePoses; // current relative poses
|
||||||
|
AnimPoseVec _limitCenterPoses; // relative
|
||||||
|
|
||||||
// experimental data for moving hips during IK
|
// experimental data for moving hips during IK
|
||||||
glm::vec3 _hipsOffset { Vectors::ZERO };
|
glm::vec3 _hipsOffset { Vectors::ZERO };
|
||||||
|
@ -100,6 +117,8 @@ protected:
|
||||||
|
|
||||||
float _maxErrorOnLastSolve { FLT_MAX };
|
float _maxErrorOnLastSolve { FLT_MAX };
|
||||||
bool _previousEnableDebugIKTargets { false };
|
bool _previousEnableDebugIKTargets { false };
|
||||||
|
SolutionSource _solutionSource { SolutionSource::RelaxToUnderPoses };
|
||||||
|
QString _solutionSourceVar;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AnimInverseKinematics_h
|
#endif // hifi_AnimInverseKinematics_h
|
||||||
|
|
|
@ -352,6 +352,23 @@ static AnimOverlay::BoneSet stringToBoneSetEnum(const QString& str) {
|
||||||
return AnimOverlay::NumBoneSets;
|
return AnimOverlay::NumBoneSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* solutionSourceStrings[(int)AnimInverseKinematics::SolutionSource::NumSolutionSources] = {
|
||||||
|
"relaxToUnderPoses",
|
||||||
|
"relaxToLimitCenterPoses",
|
||||||
|
"previousSolution",
|
||||||
|
"underPoses",
|
||||||
|
"limitCenterPoses"
|
||||||
|
};
|
||||||
|
|
||||||
|
static AnimInverseKinematics::SolutionSource stringToSolutionSourceEnum(const QString& str) {
|
||||||
|
for (int i = 0; i < (int)AnimInverseKinematics::SolutionSource::NumSolutionSources; i++) {
|
||||||
|
if (str == solutionSourceStrings[i]) {
|
||||||
|
return (AnimInverseKinematics::SolutionSource)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AnimInverseKinematics::SolutionSource::NumSolutionSources;
|
||||||
|
}
|
||||||
|
|
||||||
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||||
|
|
||||||
READ_STRING(boneSet, jsonObj, id, jsonUrl, nullptr);
|
READ_STRING(boneSet, jsonObj, id, jsonUrl, nullptr);
|
||||||
|
@ -457,6 +474,23 @@ AnimNode::Pointer loadInverseKinematicsNode(const QJsonObject& jsonObj, const QS
|
||||||
node->setTargetVars(jointName, positionVar, rotationVar, typeVar);
|
node->setTargetVars(jointName, positionVar, rotationVar, typeVar);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
READ_OPTIONAL_STRING(solutionSource, jsonObj);
|
||||||
|
|
||||||
|
if (!solutionSource.isEmpty()) {
|
||||||
|
AnimInverseKinematics::SolutionSource solutionSourceType = stringToSolutionSourceEnum(solutionSource);
|
||||||
|
if (solutionSourceType != AnimInverseKinematics::SolutionSource::NumSolutionSources) {
|
||||||
|
node->setSolutionSource(solutionSourceType);
|
||||||
|
} else {
|
||||||
|
qCWarning(animation) << "AnimNodeLoader, bad solutionSourceType in \"solutionSource\", id = " << id << ", url = " << jsonUrl.toDisplayString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
READ_OPTIONAL_STRING(solutionSourceVar, jsonObj);
|
||||||
|
|
||||||
|
if (!solutionSourceVar.isEmpty()) {
|
||||||
|
node->setSolutionSourceVar(solutionSourceVar);
|
||||||
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ glm::vec3 AnimPose::xformPoint(const glm::vec3& rhs) const {
|
||||||
return *this * rhs;
|
return *this * rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// really slow
|
// really slow, but accurate for transforms with non-uniform scale
|
||||||
glm::vec3 AnimPose::xformVector(const glm::vec3& rhs) const {
|
glm::vec3 AnimPose::xformVector(const glm::vec3& rhs) const {
|
||||||
glm::vec3 xAxis = _rot * glm::vec3(_scale.x, 0.0f, 0.0f);
|
glm::vec3 xAxis = _rot * glm::vec3(_scale.x, 0.0f, 0.0f);
|
||||||
glm::vec3 yAxis = _rot * glm::vec3(0.0f, _scale.y, 0.0f);
|
glm::vec3 yAxis = _rot * glm::vec3(0.0f, _scale.y, 0.0f);
|
||||||
|
@ -49,6 +49,11 @@ glm::vec3 AnimPose::xformVector(const glm::vec3& rhs) const {
|
||||||
return transInvMat * rhs;
|
return transInvMat * rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// faster, but does not handle non-uniform scale correctly.
|
||||||
|
glm::vec3 AnimPose::xformVectorFast(const glm::vec3& rhs) const {
|
||||||
|
return _rot * (_scale * rhs);
|
||||||
|
}
|
||||||
|
|
||||||
AnimPose AnimPose::operator*(const AnimPose& rhs) const {
|
AnimPose AnimPose::operator*(const AnimPose& rhs) const {
|
||||||
glm::mat4 result;
|
glm::mat4 result;
|
||||||
glm_mat4u_mul(*this, rhs, result);
|
glm_mat4u_mul(*this, rhs, result);
|
||||||
|
|
|
@ -25,7 +25,8 @@ public:
|
||||||
static const AnimPose identity;
|
static const AnimPose identity;
|
||||||
|
|
||||||
glm::vec3 xformPoint(const glm::vec3& rhs) const;
|
glm::vec3 xformPoint(const glm::vec3& rhs) const;
|
||||||
glm::vec3 xformVector(const glm::vec3& rhs) const; // really slow
|
glm::vec3 xformVector(const glm::vec3& rhs) const; // really slow, but accurate for transforms with non-uniform scale
|
||||||
|
glm::vec3 xformVectorFast(const glm::vec3& rhs) const; // faster, but does not handle non-uniform scale correctly.
|
||||||
|
|
||||||
glm::vec3 operator*(const glm::vec3& rhs) const; // same as xformPoint
|
glm::vec3 operator*(const glm::vec3& rhs) const; // same as xformPoint
|
||||||
AnimPose operator*(const AnimPose& rhs) const;
|
AnimPose operator*(const AnimPose& rhs) const;
|
||||||
|
|
|
@ -33,6 +33,23 @@ void blend(size_t numPoses, const AnimPose* a, const AnimPose* b, float alpha, A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::quat averageQuats(size_t numQuats, const glm::quat* quats) {
|
||||||
|
if (numQuats == 0) {
|
||||||
|
return glm::quat();
|
||||||
|
}
|
||||||
|
glm::quat accum = quats[0];
|
||||||
|
glm::quat firstRot = quats[0];
|
||||||
|
for (size_t i = 1; i < numQuats; i++) {
|
||||||
|
glm::quat rot = quats[i];
|
||||||
|
float dot = glm::dot(firstRot, rot);
|
||||||
|
if (dot < 0.0f) {
|
||||||
|
rot = -rot;
|
||||||
|
}
|
||||||
|
accum += rot;
|
||||||
|
}
|
||||||
|
return glm::normalize(accum);
|
||||||
|
}
|
||||||
|
|
||||||
float accumulateTime(float startFrame, float endFrame, float timeScale, float currentFrame, float dt, bool loopFlag,
|
float accumulateTime(float startFrame, float endFrame, float timeScale, float currentFrame, float dt, bool loopFlag,
|
||||||
const QString& id, AnimNode::Triggers& triggersOut) {
|
const QString& id, AnimNode::Triggers& triggersOut) {
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
// this is where the magic happens
|
// this is where the magic happens
|
||||||
void blend(size_t numPoses, const AnimPose* a, const AnimPose* b, float alpha, AnimPose* result);
|
void blend(size_t numPoses, const AnimPose* a, const AnimPose* b, float alpha, AnimPose* result);
|
||||||
|
|
||||||
|
glm::quat averageQuats(size_t numQuats, const glm::quat* quats);
|
||||||
|
|
||||||
float accumulateTime(float startFrame, float endFrame, float timeScale, float currentFrame, float dt, bool loopFlag,
|
float accumulateTime(float startFrame, float endFrame, float timeScale, float currentFrame, float dt, bool loopFlag,
|
||||||
const QString& id, AnimNode::Triggers& triggersOut);
|
const QString& id, AnimNode::Triggers& triggersOut);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
#include "AnimUtil.h"
|
||||||
|
|
||||||
ElbowConstraint::ElbowConstraint() :
|
ElbowConstraint::ElbowConstraint() :
|
||||||
_minAngle(-PI),
|
_minAngle(-PI),
|
||||||
|
@ -77,3 +78,10 @@ bool ElbowConstraint::apply(glm::quat& rotation) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::quat ElbowConstraint::computeCenterRotation() const {
|
||||||
|
const size_t NUM_LIMITS = 2;
|
||||||
|
glm::quat limits[NUM_LIMITS];
|
||||||
|
limits[0] = glm::angleAxis(_minAngle, _axis) * _referenceRotation;
|
||||||
|
limits[1] = glm::angleAxis(_maxAngle, _axis) * _referenceRotation;
|
||||||
|
return averageQuats(NUM_LIMITS, limits);
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@ public:
|
||||||
void setHingeAxis(const glm::vec3& axis);
|
void setHingeAxis(const glm::vec3& axis);
|
||||||
void setAngleLimits(float minAngle, float maxAngle);
|
void setAngleLimits(float minAngle, float maxAngle);
|
||||||
virtual bool apply(glm::quat& rotation) const override;
|
virtual bool apply(glm::quat& rotation) const override;
|
||||||
|
virtual glm::quat computeCenterRotation() const override;
|
||||||
|
|
||||||
|
glm::vec3 getHingeAxis() const { return _axis; }
|
||||||
|
float getMinAngle() const { return _minAngle; }
|
||||||
|
float getMaxAngle() const { return _maxAngle; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec3 _axis;
|
glm::vec3 _axis;
|
||||||
glm::vec3 _perpAxis;
|
glm::vec3 _perpAxis;
|
||||||
|
|
|
@ -305,30 +305,35 @@ void Rig::clearJointAnimationPriority(int index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::clearIKJointLimitHistory() {
|
std::shared_ptr<AnimInverseKinematics> Rig::getAnimInverseKinematicsNode() const {
|
||||||
|
std::shared_ptr<AnimInverseKinematics> result;
|
||||||
if (_animNode) {
|
if (_animNode) {
|
||||||
_animNode->traverse([&](AnimNode::Pointer node) {
|
_animNode->traverse([&](AnimNode::Pointer node) {
|
||||||
// only report clip nodes as valid roles.
|
// only report clip nodes as valid roles.
|
||||||
auto ikNode = std::dynamic_pointer_cast<AnimInverseKinematics>(node);
|
auto ikNode = std::dynamic_pointer_cast<AnimInverseKinematics>(node);
|
||||||
if (ikNode) {
|
if (ikNode) {
|
||||||
ikNode->clearIKJointLimitHistory();
|
result = ikNode;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Rig::clearIKJointLimitHistory() {
|
||||||
|
auto ikNode = getAnimInverseKinematicsNode();
|
||||||
|
if (ikNode) {
|
||||||
|
ikNode->clearIKJointLimitHistory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::setMaxHipsOffsetLength(float maxLength) {
|
void Rig::setMaxHipsOffsetLength(float maxLength) {
|
||||||
_maxHipsOffsetLength = maxLength;
|
_maxHipsOffsetLength = maxLength;
|
||||||
|
auto ikNode = getAnimInverseKinematicsNode();
|
||||||
if (_animNode) {
|
if (ikNode) {
|
||||||
_animNode->traverse([&](AnimNode::Pointer node) {
|
ikNode->setMaxHipsOffsetLength(_maxHipsOffsetLength);
|
||||||
auto ikNode = std::dynamic_pointer_cast<AnimInverseKinematics>(node);
|
|
||||||
if (ikNode) {
|
|
||||||
ikNode->setMaxHipsOffsetLength(_maxHipsOffsetLength);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,7 +941,7 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) {
|
void Rig::updateAnimations(float deltaTime, const glm::mat4& rootTransform, const glm::mat4& rigToWorldTransform) {
|
||||||
|
|
||||||
PROFILE_RANGE_EX(simulation_animation_detail, __FUNCTION__, 0xffff00ff, 0);
|
PROFILE_RANGE_EX(simulation_animation_detail, __FUNCTION__, 0xffff00ff, 0);
|
||||||
PerformanceTimer perfTimer("updateAnimations");
|
PerformanceTimer perfTimer("updateAnimations");
|
||||||
|
@ -949,7 +954,8 @@ void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) {
|
||||||
updateAnimationStateHandlers();
|
updateAnimationStateHandlers();
|
||||||
_animVars.setRigToGeometryTransform(_rigToGeometryTransform);
|
_animVars.setRigToGeometryTransform(_rigToGeometryTransform);
|
||||||
|
|
||||||
AnimContext context(_enableDebugDrawIKTargets, getGeometryToRigTransform());
|
AnimContext context(_enableDebugDrawIKTargets, _enableDebugDrawIKConstraints,
|
||||||
|
getGeometryToRigTransform(), rigToWorldTransform);
|
||||||
|
|
||||||
// evaluate the animation
|
// evaluate the animation
|
||||||
AnimNode::Triggers triggersOut;
|
AnimNode::Triggers triggersOut;
|
||||||
|
@ -1025,10 +1031,12 @@ void Rig::updateFromHeadParameters(const HeadParameters& params, float dt) {
|
||||||
_animVars.set("notIsTalking", !params.isTalking);
|
_animVars.set("notIsTalking", !params.isTalking);
|
||||||
|
|
||||||
if (params.hipsEnabled) {
|
if (params.hipsEnabled) {
|
||||||
|
_animVars.set("solutionSource", (int)AnimInverseKinematics::SolutionSource::RelaxToLimitCenterPoses);
|
||||||
_animVars.set("hipsType", (int)IKTarget::Type::RotationAndPosition);
|
_animVars.set("hipsType", (int)IKTarget::Type::RotationAndPosition);
|
||||||
_animVars.set("hipsPosition", extractTranslation(params.hipsMatrix));
|
_animVars.set("hipsPosition", extractTranslation(params.hipsMatrix));
|
||||||
_animVars.set("hipsRotation", glmExtractRotation(params.hipsMatrix));
|
_animVars.set("hipsRotation", glmExtractRotation(params.hipsMatrix));
|
||||||
} else {
|
} else {
|
||||||
|
_animVars.set("solutionSource", (int)AnimInverseKinematics::SolutionSource::RelaxToUnderPoses);
|
||||||
_animVars.set("hipsType", (int)IKTarget::Type::Unknown);
|
_animVars.set("hipsType", (int)IKTarget::Type::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1440,7 +1448,7 @@ void Rig::computeAvatarBoundingCapsule(
|
||||||
|
|
||||||
// call overlay twice: once to verify AnimPoseVec joints and again to do the IK
|
// call overlay twice: once to verify AnimPoseVec joints and again to do the IK
|
||||||
AnimNode::Triggers triggersOut;
|
AnimNode::Triggers triggersOut;
|
||||||
AnimContext context(false, glm::mat4());
|
AnimContext context(false, false, glm::mat4(), glm::mat4());
|
||||||
float dt = 1.0f; // the value of this does not matter
|
float dt = 1.0f; // the value of this does not matter
|
||||||
ikNode.overlay(animVars, context, dt, triggersOut, _animSkeleton->getRelativeBindPoses());
|
ikNode.overlay(animVars, context, dt, triggersOut, _animSkeleton->getRelativeBindPoses());
|
||||||
AnimPoseVec finalPoses = ikNode.overlay(animVars, context, dt, triggersOut, _animSkeleton->getRelativeBindPoses());
|
AnimPoseVec finalPoses = ikNode.overlay(animVars, context, dt, triggersOut, _animSkeleton->getRelativeBindPoses());
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "SimpleMovingAverage.h"
|
#include "SimpleMovingAverage.h"
|
||||||
|
|
||||||
class Rig;
|
class Rig;
|
||||||
|
class AnimInverseKinematics;
|
||||||
typedef std::shared_ptr<Rig> RigPointer;
|
typedef std::shared_ptr<Rig> RigPointer;
|
||||||
|
|
||||||
// Rig instances are reentrant.
|
// Rig instances are reentrant.
|
||||||
|
@ -111,6 +112,8 @@ public:
|
||||||
void clearJointStates();
|
void clearJointStates();
|
||||||
void clearJointAnimationPriority(int index);
|
void clearJointAnimationPriority(int index);
|
||||||
|
|
||||||
|
std::shared_ptr<AnimInverseKinematics> getAnimInverseKinematicsNode() const;
|
||||||
|
|
||||||
void clearIKJointLimitHistory();
|
void clearIKJointLimitHistory();
|
||||||
void setMaxHipsOffsetLength(float maxLength);
|
void setMaxHipsOffsetLength(float maxLength);
|
||||||
float getMaxHipsOffsetLength() const;
|
float getMaxHipsOffsetLength() const;
|
||||||
|
@ -159,7 +162,7 @@ public:
|
||||||
void computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation, CharacterControllerState ccState);
|
void computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation, CharacterControllerState ccState);
|
||||||
|
|
||||||
// Regardless of who started the animations or how many, update the joints.
|
// Regardless of who started the animations or how many, update the joints.
|
||||||
void updateAnimations(float deltaTime, glm::mat4 rootTransform);
|
void updateAnimations(float deltaTime, const glm::mat4& rootTransform, const glm::mat4& rigToWorldTransform);
|
||||||
|
|
||||||
// legacy
|
// legacy
|
||||||
void inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::quat& targetRotation, float priority,
|
void inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::quat& targetRotation, float priority,
|
||||||
|
@ -228,6 +231,7 @@ public:
|
||||||
const glm::mat4& getGeometryToRigTransform() const { return _geometryToRigTransform; }
|
const glm::mat4& getGeometryToRigTransform() const { return _geometryToRigTransform; }
|
||||||
|
|
||||||
void setEnableDebugDrawIKTargets(bool enableDebugDrawIKTargets) { _enableDebugDrawIKTargets = enableDebugDrawIKTargets; }
|
void setEnableDebugDrawIKTargets(bool enableDebugDrawIKTargets) { _enableDebugDrawIKTargets = enableDebugDrawIKTargets; }
|
||||||
|
void setEnableDebugDrawIKConstraints(bool enableDebugDrawIKConstraints) { _enableDebugDrawIKConstraints = enableDebugDrawIKConstraints; }
|
||||||
|
|
||||||
// input assumed to be in rig space
|
// input assumed to be in rig space
|
||||||
void computeHeadFromHMD(const AnimPose& hmdPose, glm::vec3& headPositionOut, glm::quat& headOrientationOut) const;
|
void computeHeadFromHMD(const AnimPose& hmdPose, glm::vec3& headPositionOut, glm::quat& headOrientationOut) const;
|
||||||
|
@ -338,6 +342,7 @@ protected:
|
||||||
float _maxHipsOffsetLength { 1.0f };
|
float _maxHipsOffsetLength { 1.0f };
|
||||||
|
|
||||||
bool _enableDebugDrawIKTargets { false };
|
bool _enableDebugDrawIKTargets { false };
|
||||||
|
bool _enableDebugDrawIKConstraints { false };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<int, StateHandler> _stateHandlers;
|
QMap<int, StateHandler> _stateHandlers;
|
||||||
|
|
|
@ -38,6 +38,9 @@ public:
|
||||||
/// \brief reset any remembered joint limit history
|
/// \brief reset any remembered joint limit history
|
||||||
virtual void clearHistory() {};
|
virtual void clearHistory() {};
|
||||||
|
|
||||||
|
/// \brief return the rotation that lies at the "center" of all the joint limits.
|
||||||
|
virtual glm::quat computeCenterRotation() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::quat _referenceRotation = glm::quat();
|
glm::quat _referenceRotation = glm::quat();
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
#include "AnimUtil.h"
|
||||||
|
|
||||||
|
|
||||||
const float MIN_MINDOT = -0.999f;
|
const float MIN_MINDOT = -0.999f;
|
||||||
|
@ -430,3 +431,33 @@ void SwingTwistConstraint::dynamicallyAdjustLimits(const glm::quat& rotation) {
|
||||||
void SwingTwistConstraint::clearHistory() {
|
void SwingTwistConstraint::clearHistory() {
|
||||||
_lastTwistBoundary = LAST_CLAMP_NO_BOUNDARY;
|
_lastTwistBoundary = LAST_CLAMP_NO_BOUNDARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::quat SwingTwistConstraint::computeCenterRotation() const {
|
||||||
|
const size_t NUM_TWIST_LIMITS = 2;
|
||||||
|
const size_t NUM_MIN_DOTS = getMinDots().size();
|
||||||
|
std::vector<glm::quat> swingLimits;
|
||||||
|
swingLimits.reserve(NUM_MIN_DOTS);
|
||||||
|
|
||||||
|
glm::quat twistLimits[NUM_TWIST_LIMITS];
|
||||||
|
if (_minTwist != _maxTwist) {
|
||||||
|
// to ensure that twists do not flip the center rotation, we devide twist angle by 2.
|
||||||
|
twistLimits[0] = glm::angleAxis(_minTwist / 2.0f, _referenceRotation * Vectors::UNIT_Y);
|
||||||
|
twistLimits[1] = glm::angleAxis(_maxTwist / 2.0f, _referenceRotation * Vectors::UNIT_Y);
|
||||||
|
}
|
||||||
|
const float D_THETA = TWO_PI / (NUM_MIN_DOTS - 1);
|
||||||
|
float theta = 0.0f;
|
||||||
|
for (size_t i = 0; i < NUM_MIN_DOTS - 1; i++, theta += D_THETA) {
|
||||||
|
// compute swing rotation from theta and phi angles.
|
||||||
|
float phi = acos(getMinDots()[i]);
|
||||||
|
float cos_phi = getMinDots()[i];
|
||||||
|
float sin_phi = sinf(phi);
|
||||||
|
glm::vec3 swungAxis(sin_phi * cosf(theta), cos_phi, -sin_phi * sinf(theta));
|
||||||
|
|
||||||
|
// to ensure that swings > 90 degrees do not flip the center rotation, we devide phi / 2
|
||||||
|
glm::quat swing = glm::angleAxis(phi / 2, glm::normalize(glm::cross(Vectors::UNIT_Y, swungAxis)));
|
||||||
|
swingLimits.push_back(swing);
|
||||||
|
}
|
||||||
|
glm::quat averageSwing = averageQuats(swingLimits.size(), &swingLimits[0]);
|
||||||
|
glm::quat averageTwist = averageQuats(2, twistLimits);
|
||||||
|
return averageSwing * averageTwist * _referenceRotation;
|
||||||
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
virtual void dynamicallyAdjustLimits(const glm::quat& rotation) override;
|
virtual void dynamicallyAdjustLimits(const glm::quat& rotation) override;
|
||||||
|
|
||||||
// for testing purposes
|
// for testing purposes
|
||||||
const std::vector<float>& getMinDots() { return _swingLimitFunction.getMinDots(); }
|
const std::vector<float>& getMinDots() const { return _swingLimitFunction.getMinDots(); }
|
||||||
|
|
||||||
// SwingLimitFunction is an implementation of the constraint check described in the paper:
|
// SwingLimitFunction is an implementation of the constraint check described in the paper:
|
||||||
// "The Parameterization of Joint Rotation with the Unit Quaternion" by Quang Liu and Edmond C. Prakash
|
// "The Parameterization of Joint Rotation with the Unit Quaternion" by Quang Liu and Edmond C. Prakash
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
float getMinDot(float theta) const;
|
float getMinDot(float theta) const;
|
||||||
|
|
||||||
// for testing purposes
|
// for testing purposes
|
||||||
const std::vector<float>& getMinDots() { return _minDots; }
|
const std::vector<float>& getMinDots() const { return _minDots; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the limits are stored in a lookup table with cyclic boundary conditions
|
// the limits are stored in a lookup table with cyclic boundary conditions
|
||||||
|
@ -99,6 +99,11 @@ public:
|
||||||
|
|
||||||
void clearHistory() override;
|
void clearHistory() override;
|
||||||
|
|
||||||
|
virtual glm::quat computeCenterRotation() const override;
|
||||||
|
|
||||||
|
float getMinTwist() const { return _minTwist; }
|
||||||
|
float getMaxTwist() const { return _maxTwist; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float handleTwistBoundaryConditions(float twistAngle) const;
|
float handleTwistBoundaryConditions(float twistAngle) const;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
set(TARGET_NAME avatars-renderer)
|
set(TARGET_NAME avatars-renderer)
|
||||||
AUTOSCRIBE_SHADER_LIB(gpu model render render-utils)
|
AUTOSCRIBE_SHADER_LIB(gpu model render render-utils)
|
||||||
setup_hifi_library(Widgets Network Script)
|
setup_hifi_library(Widgets Network Script)
|
||||||
link_hifi_libraries(shared gpu model animation physics model-networking script-engine render image render-utils)
|
link_hifi_libraries(shared gpu model animation model-networking script-engine render image render-utils)
|
||||||
|
|
||||||
target_bullet()
|
target_bullet()
|
||||||
|
|
|
@ -23,9 +23,10 @@
|
||||||
|
|
||||||
#include "Avatar.h"
|
#include "Avatar.h"
|
||||||
|
|
||||||
|
const float NORMAL_HZ = 60.0f; // the update rate the constant values were tuned for
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static bool fixGaze { false };
|
|
||||||
static bool disableEyelidAdjustment { false };
|
static bool disableEyelidAdjustment { false };
|
||||||
|
|
||||||
Head::Head(Avatar* owningAvatar) :
|
Head::Head(Avatar* owningAvatar) :
|
||||||
|
@ -42,17 +43,11 @@ void Head::reset() {
|
||||||
_baseYaw = _basePitch = _baseRoll = 0.0f;
|
_baseYaw = _basePitch = _baseRoll = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::simulate(float deltaTime) {
|
void Head::computeAudioLoudness(float deltaTime) {
|
||||||
const float NORMAL_HZ = 60.0f; // the update rate the constant values were tuned for
|
|
||||||
|
|
||||||
// grab the audio loudness from the owning avatar, if we have one
|
// grab the audio loudness from the owning avatar, if we have one
|
||||||
float audioLoudness = 0.0f;
|
float audioLoudness = _owningAvatar ? _owningAvatar->getAudioLoudness() : 0.0f;
|
||||||
|
|
||||||
if (_owningAvatar) {
|
// Update audio trailing average for rendering facial animations
|
||||||
audioLoudness = _owningAvatar->getAudioLoudness();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update audio trailing average for rendering facial animations
|
|
||||||
const float AUDIO_AVERAGING_SECS = 0.05f;
|
const float AUDIO_AVERAGING_SECS = 0.05f;
|
||||||
const float AUDIO_LONG_TERM_AVERAGING_SECS = 30.0f;
|
const float AUDIO_LONG_TERM_AVERAGING_SECS = 30.0f;
|
||||||
_averageLoudness = glm::mix(_averageLoudness, audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f));
|
_averageLoudness = glm::mix(_averageLoudness, audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f));
|
||||||
|
@ -63,116 +58,114 @@ void Head::simulate(float deltaTime) {
|
||||||
_longTermAverageLoudness = glm::mix(_longTermAverageLoudness, _averageLoudness, glm::min(deltaTime / AUDIO_LONG_TERM_AVERAGING_SECS, 1.0f));
|
_longTermAverageLoudness = glm::mix(_longTermAverageLoudness, _averageLoudness, glm::min(deltaTime / AUDIO_LONG_TERM_AVERAGING_SECS, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_isFaceTrackerConnected) {
|
float audioAttackAveragingRate = (10.0f - deltaTime * NORMAL_HZ) / 10.0f; // --> 0.9 at 60 Hz
|
||||||
if (!_isEyeTrackerConnected) {
|
_audioAttack = audioAttackAveragingRate * _audioAttack +
|
||||||
// Update eye saccades
|
(1.0f - audioAttackAveragingRate) * fabs((audioLoudness - _longTermAverageLoudness) - _lastLoudness);
|
||||||
const float AVERAGE_MICROSACCADE_INTERVAL = 1.0f;
|
_lastLoudness = (audioLoudness - _longTermAverageLoudness);
|
||||||
const float AVERAGE_SACCADE_INTERVAL = 6.0f;
|
}
|
||||||
const float MICROSACCADE_MAGNITUDE = 0.002f;
|
|
||||||
const float SACCADE_MAGNITUDE = 0.04f;
|
|
||||||
const float NOMINAL_FRAME_RATE = 60.0f;
|
|
||||||
|
|
||||||
if (randFloat() < deltaTime / AVERAGE_MICROSACCADE_INTERVAL) {
|
void Head::computeEyeMovement(float deltaTime) {
|
||||||
_saccadeTarget = MICROSACCADE_MAGNITUDE * randVector();
|
// Update eye saccades
|
||||||
} else if (randFloat() < deltaTime / AVERAGE_SACCADE_INTERVAL) {
|
const float AVERAGE_MICROSACCADE_INTERVAL = 1.0f;
|
||||||
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
const float AVERAGE_SACCADE_INTERVAL = 6.0f;
|
||||||
}
|
const float MICROSACCADE_MAGNITUDE = 0.002f;
|
||||||
_saccade += (_saccadeTarget - _saccade) * pow(0.5f, NOMINAL_FRAME_RATE * deltaTime);
|
const float SACCADE_MAGNITUDE = 0.04f;
|
||||||
} else {
|
const float NOMINAL_FRAME_RATE = 60.0f;
|
||||||
_saccade = glm::vec3();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect transition from talking to not; force blink after that and a delay
|
if (randFloat() < deltaTime / AVERAGE_MICROSACCADE_INTERVAL) {
|
||||||
bool forceBlink = false;
|
_saccadeTarget = MICROSACCADE_MAGNITUDE * randVector();
|
||||||
const float TALKING_LOUDNESS = 100.0f;
|
} else if (randFloat() < deltaTime / AVERAGE_SACCADE_INTERVAL) {
|
||||||
const float BLINK_AFTER_TALKING = 0.25f;
|
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
||||||
_timeWithoutTalking += deltaTime;
|
}
|
||||||
if ((_averageLoudness - _longTermAverageLoudness) > TALKING_LOUDNESS) {
|
_saccade += (_saccadeTarget - _saccade) * pow(0.5f, NOMINAL_FRAME_RATE * deltaTime);
|
||||||
_timeWithoutTalking = 0.0f;
|
|
||||||
} else if (_timeWithoutTalking - deltaTime < BLINK_AFTER_TALKING && _timeWithoutTalking >= BLINK_AFTER_TALKING) {
|
|
||||||
forceBlink = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update audio attack data for facial animation (eyebrows and mouth)
|
// Detect transition from talking to not; force blink after that and a delay
|
||||||
float audioAttackAveragingRate = (10.0f - deltaTime * NORMAL_HZ) / 10.0f; // --> 0.9 at 60 Hz
|
bool forceBlink = false;
|
||||||
_audioAttack = audioAttackAveragingRate * _audioAttack +
|
const float TALKING_LOUDNESS = 100.0f;
|
||||||
(1.0f - audioAttackAveragingRate) * fabs((audioLoudness - _longTermAverageLoudness) - _lastLoudness);
|
const float BLINK_AFTER_TALKING = 0.25f;
|
||||||
_lastLoudness = (audioLoudness - _longTermAverageLoudness);
|
_timeWithoutTalking += deltaTime;
|
||||||
|
if ((_averageLoudness - _longTermAverageLoudness) > TALKING_LOUDNESS) {
|
||||||
|
_timeWithoutTalking = 0.0f;
|
||||||
|
} else if (_timeWithoutTalking - deltaTime < BLINK_AFTER_TALKING && _timeWithoutTalking >= BLINK_AFTER_TALKING) {
|
||||||
|
forceBlink = true;
|
||||||
|
}
|
||||||
|
|
||||||
const float BROW_LIFT_THRESHOLD = 100.0f;
|
const float BLINK_SPEED = 10.0f;
|
||||||
if (_audioAttack > BROW_LIFT_THRESHOLD) {
|
const float BLINK_SPEED_VARIABILITY = 1.0f;
|
||||||
_browAudioLift += sqrtf(_audioAttack) * 0.01f;
|
const float BLINK_START_VARIABILITY = 0.25f;
|
||||||
}
|
const float FULLY_OPEN = 0.0f;
|
||||||
_browAudioLift = glm::clamp(_browAudioLift *= 0.7f, 0.0f, 1.0f);
|
const float FULLY_CLOSED = 1.0f;
|
||||||
|
if (_leftEyeBlinkVelocity == 0.0f && _rightEyeBlinkVelocity == 0.0f) {
|
||||||
const float BLINK_SPEED = 10.0f;
|
// no blinking when brows are raised; blink less with increasing loudness
|
||||||
const float BLINK_SPEED_VARIABILITY = 1.0f;
|
const float BASE_BLINK_RATE = 15.0f / 60.0f;
|
||||||
const float BLINK_START_VARIABILITY = 0.25f;
|
const float ROOT_LOUDNESS_TO_BLINK_INTERVAL = 0.25f;
|
||||||
const float FULLY_OPEN = 0.0f;
|
if (forceBlink || (_browAudioLift < EPSILON && shouldDo(glm::max(1.0f, sqrt(fabs(_averageLoudness - _longTermAverageLoudness)) *
|
||||||
const float FULLY_CLOSED = 1.0f;
|
ROOT_LOUDNESS_TO_BLINK_INTERVAL) / BASE_BLINK_RATE, deltaTime))) {
|
||||||
if (_leftEyeBlinkVelocity == 0.0f && _rightEyeBlinkVelocity == 0.0f) {
|
_leftEyeBlinkVelocity = BLINK_SPEED + randFloat() * BLINK_SPEED_VARIABILITY;
|
||||||
// no blinking when brows are raised; blink less with increasing loudness
|
_rightEyeBlinkVelocity = BLINK_SPEED + randFloat() * BLINK_SPEED_VARIABILITY;
|
||||||
const float BASE_BLINK_RATE = 15.0f / 60.0f;
|
if (randFloat() < 0.5f) {
|
||||||
const float ROOT_LOUDNESS_TO_BLINK_INTERVAL = 0.25f;
|
_leftEyeBlink = BLINK_START_VARIABILITY;
|
||||||
if (forceBlink || (_browAudioLift < EPSILON && shouldDo(glm::max(1.0f, sqrt(fabs(_averageLoudness - _longTermAverageLoudness)) *
|
} else {
|
||||||
ROOT_LOUDNESS_TO_BLINK_INTERVAL) / BASE_BLINK_RATE, deltaTime))) {
|
_rightEyeBlink = BLINK_START_VARIABILITY;
|
||||||
_leftEyeBlinkVelocity = BLINK_SPEED + randFloat() * BLINK_SPEED_VARIABILITY;
|
|
||||||
_rightEyeBlinkVelocity = BLINK_SPEED + randFloat() * BLINK_SPEED_VARIABILITY;
|
|
||||||
if (randFloat() < 0.5f) {
|
|
||||||
_leftEyeBlink = BLINK_START_VARIABILITY;
|
|
||||||
} else {
|
|
||||||
_rightEyeBlink = BLINK_START_VARIABILITY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_leftEyeBlink = glm::clamp(_leftEyeBlink + _leftEyeBlinkVelocity * deltaTime, FULLY_OPEN, FULLY_CLOSED);
|
|
||||||
_rightEyeBlink = glm::clamp(_rightEyeBlink + _rightEyeBlinkVelocity * deltaTime, FULLY_OPEN, FULLY_CLOSED);
|
|
||||||
|
|
||||||
if (_leftEyeBlink == FULLY_CLOSED) {
|
|
||||||
_leftEyeBlinkVelocity = -BLINK_SPEED;
|
|
||||||
|
|
||||||
} else if (_leftEyeBlink == FULLY_OPEN) {
|
|
||||||
_leftEyeBlinkVelocity = 0.0f;
|
|
||||||
}
|
|
||||||
if (_rightEyeBlink == FULLY_CLOSED) {
|
|
||||||
_rightEyeBlinkVelocity = -BLINK_SPEED;
|
|
||||||
|
|
||||||
} else if (_rightEyeBlink == FULLY_OPEN) {
|
|
||||||
_rightEyeBlinkVelocity = 0.0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use data to update fake Faceshift blendshape coefficients
|
|
||||||
calculateMouthShapes(deltaTime);
|
|
||||||
FaceTracker::updateFakeCoefficients(_leftEyeBlink,
|
|
||||||
_rightEyeBlink,
|
|
||||||
_browAudioLift,
|
|
||||||
_audioJawOpen,
|
|
||||||
_mouth2,
|
|
||||||
_mouth3,
|
|
||||||
_mouth4,
|
|
||||||
_transientBlendshapeCoefficients);
|
|
||||||
|
|
||||||
applyEyelidOffset(getOrientation());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_saccade = glm::vec3();
|
_leftEyeBlink = glm::clamp(_leftEyeBlink + _leftEyeBlinkVelocity * deltaTime, FULLY_OPEN, FULLY_CLOSED);
|
||||||
}
|
_rightEyeBlink = glm::clamp(_rightEyeBlink + _rightEyeBlinkVelocity * deltaTime, FULLY_OPEN, FULLY_CLOSED);
|
||||||
if (fixGaze) { // if debug menu turns off, use no saccade
|
|
||||||
_saccade = glm::vec3();
|
if (_leftEyeBlink == FULLY_CLOSED) {
|
||||||
|
_leftEyeBlinkVelocity = -BLINK_SPEED;
|
||||||
|
|
||||||
|
} else if (_leftEyeBlink == FULLY_OPEN) {
|
||||||
|
_leftEyeBlinkVelocity = 0.0f;
|
||||||
|
}
|
||||||
|
if (_rightEyeBlink == FULLY_CLOSED) {
|
||||||
|
_rightEyeBlinkVelocity = -BLINK_SPEED;
|
||||||
|
|
||||||
|
} else if (_rightEyeBlink == FULLY_OPEN) {
|
||||||
|
_rightEyeBlinkVelocity = 0.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyEyelidOffset(getOrientation());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Head::computeFaceMovement(float deltaTime) {
|
||||||
|
// Update audio attack data for facial animation (eyebrows and mouth)
|
||||||
|
const float BROW_LIFT_THRESHOLD = 100.0f;
|
||||||
|
if (_audioAttack > BROW_LIFT_THRESHOLD) {
|
||||||
|
_browAudioLift += sqrtf(_audioAttack) * 0.01f;
|
||||||
|
}
|
||||||
|
_browAudioLift = glm::clamp(_browAudioLift *= 0.7f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// use data to update fake Faceshift blendshape coefficients
|
||||||
|
calculateMouthShapes(deltaTime);
|
||||||
|
FaceTracker::updateFakeCoefficients(_leftEyeBlink,
|
||||||
|
_rightEyeBlink,
|
||||||
|
_browAudioLift,
|
||||||
|
_audioJawOpen,
|
||||||
|
_mouth2,
|
||||||
|
_mouth3,
|
||||||
|
_mouth4,
|
||||||
|
_transientBlendshapeCoefficients);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Head::computeEyePosition() {
|
||||||
_leftEyePosition = _rightEyePosition = getPosition();
|
_leftEyePosition = _rightEyePosition = getPosition();
|
||||||
_eyePosition = getPosition();
|
|
||||||
|
|
||||||
if (_owningAvatar) {
|
if (_owningAvatar) {
|
||||||
auto skeletonModel = static_cast<Avatar*>(_owningAvatar)->getSkeletonModel();
|
auto skeletonModel = static_cast<Avatar*>(_owningAvatar)->getSkeletonModel();
|
||||||
if (skeletonModel) {
|
if (skeletonModel) {
|
||||||
skeletonModel->getEyePositions(_leftEyePosition, _rightEyePosition);
|
skeletonModel->getEyePositions(_leftEyePosition, _rightEyePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_eyePosition = 0.5f * (_leftEyePosition + _rightEyePosition);
|
||||||
|
}
|
||||||
|
|
||||||
_eyePosition = calculateAverageEyePosition();
|
void Head::simulate(float deltaTime) {
|
||||||
|
computeAudioLoudness(deltaTime);
|
||||||
|
computeFaceMovement(deltaTime);
|
||||||
|
computeEyeMovement(deltaTime);
|
||||||
|
computeEyePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::calculateMouthShapes(float deltaTime) {
|
void Head::calculateMouthShapes(float deltaTime) {
|
||||||
|
|
|
@ -83,7 +83,10 @@ public:
|
||||||
float getTimeWithoutTalking() const { return _timeWithoutTalking; }
|
float getTimeWithoutTalking() const { return _timeWithoutTalking; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec3 calculateAverageEyePosition() const { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * 0.5f; }
|
void computeAudioLoudness(float deltaTime);
|
||||||
|
void computeEyeMovement(float deltaTime);
|
||||||
|
void computeFaceMovement(float deltaTime);
|
||||||
|
void computeEyePosition();
|
||||||
|
|
||||||
// disallow copies of the Head, copy of owning Avatar is disallowed too
|
// disallow copies of the Head, copy of owning Avatar is disallowed too
|
||||||
Head(const Head&);
|
Head(const Head&);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
class OtherAvatar : public Avatar {
|
class OtherAvatar : public Avatar {
|
||||||
public:
|
public:
|
||||||
explicit OtherAvatar(QThread* thread, RigPointer rig = nullptr);
|
explicit OtherAvatar(QThread* thread, RigPointer rig = nullptr);
|
||||||
void instantiableAvatar() {};
|
virtual void instantiableAvatar() override {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_OtherAvatar_h
|
#endif // hifi_OtherAvatar_h
|
||||||
|
|
|
@ -445,7 +445,7 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
|
||||||
if (hasFaceTrackerInfo) {
|
if (hasFaceTrackerInfo) {
|
||||||
auto startSection = destinationBuffer;
|
auto startSection = destinationBuffer;
|
||||||
auto faceTrackerInfo = reinterpret_cast<AvatarDataPacket::FaceTrackerInfo*>(destinationBuffer);
|
auto faceTrackerInfo = reinterpret_cast<AvatarDataPacket::FaceTrackerInfo*>(destinationBuffer);
|
||||||
auto blendshapeCoefficients = _headData->getSummedBlendshapeCoefficients();
|
const auto& blendshapeCoefficients = _headData->getSummedBlendshapeCoefficients();
|
||||||
|
|
||||||
faceTrackerInfo->leftEyeBlink = _headData->_leftEyeBlink;
|
faceTrackerInfo->leftEyeBlink = _headData->_leftEyeBlink;
|
||||||
faceTrackerInfo->rightEyeBlink = _headData->_rightEyeBlink;
|
faceTrackerInfo->rightEyeBlink = _headData->_rightEyeBlink;
|
||||||
|
|
|
@ -28,12 +28,6 @@ HeadData::HeadData(AvatarData* owningAvatar) :
|
||||||
_basePitch(0.0f),
|
_basePitch(0.0f),
|
||||||
_baseRoll(0.0f),
|
_baseRoll(0.0f),
|
||||||
_lookAtPosition(0.0f, 0.0f, 0.0f),
|
_lookAtPosition(0.0f, 0.0f, 0.0f),
|
||||||
_isFaceTrackerConnected(false),
|
|
||||||
_isEyeTrackerConnected(false),
|
|
||||||
_leftEyeBlink(0.0f),
|
|
||||||
_rightEyeBlink(0.0f),
|
|
||||||
_averageLoudness(0.0f),
|
|
||||||
_browAudioLift(0.0f),
|
|
||||||
_blendshapeCoefficients(QVector<float>(0, 0.0f)),
|
_blendshapeCoefficients(QVector<float>(0, 0.0f)),
|
||||||
_transientBlendshapeCoefficients(QVector<float>(0, 0.0f)),
|
_transientBlendshapeCoefficients(QVector<float>(0, 0.0f)),
|
||||||
_summedBlendshapeCoefficients(QVector<float>(0, 0.0f)),
|
_summedBlendshapeCoefficients(QVector<float>(0, 0.0f)),
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
void setBlendshapeCoefficients(const QVector<float>& blendshapeCoefficients) { _blendshapeCoefficients = blendshapeCoefficients; }
|
void setBlendshapeCoefficients(const QVector<float>& blendshapeCoefficients) { _blendshapeCoefficients = blendshapeCoefficients; }
|
||||||
|
|
||||||
const glm::vec3& getLookAtPosition() const { return _lookAtPosition; }
|
const glm::vec3& getLookAtPosition() const { return _lookAtPosition; }
|
||||||
void setLookAtPosition(const glm::vec3& lookAtPosition) {
|
void setLookAtPosition(const glm::vec3& lookAtPosition) {
|
||||||
if (_lookAtPosition != lookAtPosition) {
|
if (_lookAtPosition != lookAtPosition) {
|
||||||
_lookAtPositionChanged = usecTimestampNow();
|
_lookAtPositionChanged = usecTimestampNow();
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,12 @@ protected:
|
||||||
glm::vec3 _lookAtPosition;
|
glm::vec3 _lookAtPosition;
|
||||||
quint64 _lookAtPositionChanged { 0 };
|
quint64 _lookAtPositionChanged { 0 };
|
||||||
|
|
||||||
bool _isFaceTrackerConnected;
|
bool _isFaceTrackerConnected { false };
|
||||||
bool _isEyeTrackerConnected;
|
bool _isEyeTrackerConnected { false };
|
||||||
float _leftEyeBlink;
|
float _leftEyeBlink { 0.0f };
|
||||||
float _rightEyeBlink;
|
float _rightEyeBlink { 0.0f };
|
||||||
float _averageLoudness;
|
float _averageLoudness { 0.0f };
|
||||||
float _browAudioLift;
|
float _browAudioLift { 0.0f };
|
||||||
|
|
||||||
QVector<float> _blendshapeCoefficients;
|
QVector<float> _blendshapeCoefficients;
|
||||||
QVector<float> _transientBlendshapeCoefficients;
|
QVector<float> _transientBlendshapeCoefficients;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
QString SAVE_DIRECTORY = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + BuildInfo::MODIFIED_ORGANIZATION + "/" + BuildInfo::INTERFACE_NAME + "/hifi-input-recordings/";
|
QString SAVE_DIRECTORY = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + BuildInfo::MODIFIED_ORGANIZATION + "/" + BuildInfo::INTERFACE_NAME + "/hifi-input-recordings/";
|
||||||
QString FILE_PREFIX_NAME = "input-recording-";
|
QString FILE_PREFIX_NAME = "input-recording-";
|
||||||
QString COMPRESS_EXTENSION = ".tar.gz";
|
QString COMPRESS_EXTENSION = "json.gz";
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
QJsonObject poseToJsonObject(const Pose pose) {
|
QJsonObject poseToJsonObject(const Pose pose) {
|
||||||
|
@ -185,41 +185,42 @@ namespace controller {
|
||||||
filePath.remove(0,8);
|
filePath.remove(0,8);
|
||||||
QFileInfo info(filePath);
|
QFileInfo info(filePath);
|
||||||
QString extension = info.suffix();
|
QString extension = info.suffix();
|
||||||
if (extension != "gz") {
|
if (extension != "gz") {
|
||||||
qWarning() << "can not load file with exentsion of " << extension;
|
qWarning() << "can not load file with exentsion of " << extension;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool success = false;
|
bool success = false;
|
||||||
QJsonObject data = openFile(info.absoluteFilePath(), success);
|
QJsonObject data = openFile(info.absoluteFilePath(), success);
|
||||||
if (success) {
|
if (success) {
|
||||||
_framesRecorded = data["frameCount"].toInt();
|
_framesRecorded = data["frameCount"].toInt();
|
||||||
QJsonArray actionArrayList = data["actionList"].toArray();
|
QJsonArray actionArrayList = data["actionList"].toArray();
|
||||||
QJsonArray poseArrayList = data["poseList"].toArray();
|
QJsonArray poseArrayList = data["poseList"].toArray();
|
||||||
|
|
||||||
for (int actionIndex = 0; actionIndex < actionArrayList.size(); actionIndex++) {
|
for (int actionIndex = 0; actionIndex < actionArrayList.size(); actionIndex++) {
|
||||||
QJsonArray actionState = actionArrayList[actionIndex].toArray();
|
QJsonArray actionState = actionArrayList[actionIndex].toArray();
|
||||||
for (int index = 0; index < actionState.size(); index++) {
|
for (int index = 0; index < actionState.size(); index++) {
|
||||||
_currentFrameActions[index] = actionState[index].toDouble();
|
_currentFrameActions[index] = actionState[index].toDouble();
|
||||||
}
|
}
|
||||||
_actionStateList.push_back(_currentFrameActions);
|
_actionStateList.push_back(_currentFrameActions);
|
||||||
_currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS));
|
_currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int poseIndex = 0; poseIndex < poseArrayList.size(); poseIndex++) {
|
for (int poseIndex = 0; poseIndex < poseArrayList.size(); poseIndex++) {
|
||||||
QJsonArray poseState = poseArrayList[poseIndex].toArray();
|
QJsonArray poseState = poseArrayList[poseIndex].toArray();
|
||||||
for (int index = 0; index < poseState.size(); index++) {
|
for (int index = 0; index < poseState.size(); index++) {
|
||||||
_currentFramePoses[index] = jsonObjectToPose(poseState[index].toObject());
|
_currentFramePoses[index] = jsonObjectToPose(poseState[index].toObject());
|
||||||
}
|
}
|
||||||
_poseStateList.push_back(_currentFramePoses);
|
_poseStateList.push_back(_currentFramePoses);
|
||||||
_currentFramePoses = PoseStates(toInt(Action::NUM_ACTIONS));
|
_currentFramePoses = PoseStates(toInt(Action::NUM_ACTIONS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::stopRecording() {
|
void InputRecorder::stopRecording() {
|
||||||
_recording = false;
|
_recording = false;
|
||||||
|
_framesRecorded = (int)_actionStateList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::startPlayback() {
|
void InputRecorder::startPlayback() {
|
||||||
|
@ -282,7 +283,7 @@ namespace controller {
|
||||||
|
|
||||||
if (_playback) {
|
if (_playback) {
|
||||||
_playCount++;
|
_playCount++;
|
||||||
if (_playCount == _framesRecorded) {
|
if (_playCount == (_framesRecorded - 1)) {
|
||||||
_playCount = 0;
|
_playCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,9 @@ EntityDynamicType EntityDynamicInterface::dynamicTypeFromString(QString dynamicT
|
||||||
if (normalizedDynamicTypeString == "spring") {
|
if (normalizedDynamicTypeString == "spring") {
|
||||||
return DYNAMIC_TYPE_SPRING;
|
return DYNAMIC_TYPE_SPRING;
|
||||||
}
|
}
|
||||||
|
if (normalizedDynamicTypeString == "tractor") {
|
||||||
|
return DYNAMIC_TYPE_TRACTOR;
|
||||||
|
}
|
||||||
if (normalizedDynamicTypeString == "hold") {
|
if (normalizedDynamicTypeString == "hold") {
|
||||||
return DYNAMIC_TYPE_HOLD;
|
return DYNAMIC_TYPE_HOLD;
|
||||||
}
|
}
|
||||||
|
@ -140,6 +143,8 @@ QString EntityDynamicInterface::dynamicTypeToString(EntityDynamicType dynamicTyp
|
||||||
return "offset";
|
return "offset";
|
||||||
case DYNAMIC_TYPE_SPRING:
|
case DYNAMIC_TYPE_SPRING:
|
||||||
return "spring";
|
return "spring";
|
||||||
|
case DYNAMIC_TYPE_TRACTOR:
|
||||||
|
return "tractor";
|
||||||
case DYNAMIC_TYPE_HOLD:
|
case DYNAMIC_TYPE_HOLD:
|
||||||
return "hold";
|
return "hold";
|
||||||
case DYNAMIC_TYPE_TRAVEL_ORIENTED:
|
case DYNAMIC_TYPE_TRAVEL_ORIENTED:
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class EntityItem;
|
class EntityItem;
|
||||||
|
class EntityItemID;
|
||||||
class EntitySimulation;
|
class EntitySimulation;
|
||||||
using EntityItemPointer = std::shared_ptr<EntityItem>;
|
using EntityItemPointer = std::shared_ptr<EntityItem>;
|
||||||
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
|
using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
|
||||||
|
@ -28,6 +29,7 @@ enum EntityDynamicType {
|
||||||
DYNAMIC_TYPE_NONE = 0,
|
DYNAMIC_TYPE_NONE = 0,
|
||||||
DYNAMIC_TYPE_OFFSET = 1000,
|
DYNAMIC_TYPE_OFFSET = 1000,
|
||||||
DYNAMIC_TYPE_SPRING = 2000,
|
DYNAMIC_TYPE_SPRING = 2000,
|
||||||
|
DYNAMIC_TYPE_TRACTOR = 2100,
|
||||||
DYNAMIC_TYPE_HOLD = 3000,
|
DYNAMIC_TYPE_HOLD = 3000,
|
||||||
DYNAMIC_TYPE_TRAVEL_ORIENTED = 4000,
|
DYNAMIC_TYPE_TRAVEL_ORIENTED = 4000,
|
||||||
DYNAMIC_TYPE_HINGE = 5000,
|
DYNAMIC_TYPE_HINGE = 5000,
|
||||||
|
@ -44,6 +46,9 @@ public:
|
||||||
virtual ~EntityDynamicInterface() { }
|
virtual ~EntityDynamicInterface() { }
|
||||||
const QUuid& getID() const { return _id; }
|
const QUuid& getID() const { return _id; }
|
||||||
EntityDynamicType getType() const { return _type; }
|
EntityDynamicType getType() const { return _type; }
|
||||||
|
|
||||||
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) = 0;
|
||||||
|
|
||||||
virtual bool isAction() const { return false; }
|
virtual bool isAction() const { return false; }
|
||||||
virtual bool isConstraint() const { return false; }
|
virtual bool isConstraint() const { return false; }
|
||||||
virtual bool isReadyForAdd() const { return true; }
|
virtual bool isReadyForAdd() const { return true; }
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "RecurseOctreeToMapOperator.h"
|
#include "RecurseOctreeToMapOperator.h"
|
||||||
#include "LogHandler.h"
|
#include "LogHandler.h"
|
||||||
#include "EntityEditFilters.h"
|
#include "EntityEditFilters.h"
|
||||||
|
#include "EntityDynamicFactoryInterface.h"
|
||||||
|
|
||||||
|
|
||||||
static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * 50;
|
static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * 50;
|
||||||
const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour
|
const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour
|
||||||
|
@ -1527,6 +1529,48 @@ void EntityTree::pruneTree() {
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QByteArray EntityTree::remapActionDataIDs(QByteArray actionData, QHash<EntityItemID, EntityItemID>& map) {
|
||||||
|
if (actionData.isEmpty()) {
|
||||||
|
return actionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream serializedActionsStream(actionData);
|
||||||
|
QVector<QByteArray> serializedActions;
|
||||||
|
serializedActionsStream >> serializedActions;
|
||||||
|
|
||||||
|
auto actionFactory = DependencyManager::get<EntityDynamicFactoryInterface>();
|
||||||
|
|
||||||
|
QHash<QUuid, EntityDynamicPointer> remappedActions;
|
||||||
|
foreach(QByteArray serializedAction, serializedActions) {
|
||||||
|
QDataStream serializedActionStream(serializedAction);
|
||||||
|
EntityDynamicType actionType;
|
||||||
|
QUuid oldActionID;
|
||||||
|
serializedActionStream >> actionType;
|
||||||
|
serializedActionStream >> oldActionID;
|
||||||
|
EntityDynamicPointer action = actionFactory->factoryBA(nullptr, serializedAction);
|
||||||
|
if (action) {
|
||||||
|
action->remapIDs(map);
|
||||||
|
remappedActions[action->getID()] = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QByteArray> remappedSerializedActions;
|
||||||
|
|
||||||
|
QHash<QUuid, EntityDynamicPointer>::const_iterator i = remappedActions.begin();
|
||||||
|
while (i != remappedActions.end()) {
|
||||||
|
EntityDynamicPointer action = i.value();
|
||||||
|
QByteArray bytesForAction = action->serialize();
|
||||||
|
remappedSerializedActions << bytesForAction;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray result;
|
||||||
|
QDataStream remappedSerializedActionsStream(&result, QIODevice::WriteOnly);
|
||||||
|
remappedSerializedActionsStream << remappedSerializedActions;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTreePointer localTree,
|
QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTreePointer localTree,
|
||||||
float x, float y, float z) {
|
float x, float y, float z) {
|
||||||
SendEntitiesOperationArgs args;
|
SendEntitiesOperationArgs args;
|
||||||
|
@ -1543,71 +1587,67 @@ QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSen
|
||||||
});
|
});
|
||||||
packetSender->releaseQueuedMessages();
|
packetSender->releaseQueuedMessages();
|
||||||
|
|
||||||
|
// the values from map are used as the list of successfully "sent" entities. If some didn't actually make it,
|
||||||
|
// pull them out. Bogus entries could happen if part of the imported data makes some reference to an entity
|
||||||
|
// that isn't in the data being imported.
|
||||||
|
QHash<EntityItemID, EntityItemID>::iterator i = map.begin();
|
||||||
|
while (i != map.end()) {
|
||||||
|
EntityItemID newID = i.value();
|
||||||
|
if (localTree->findEntityByEntityItemID(newID)) {
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
i = map.erase(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return map.values().toVector();
|
return map.values().toVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extraData) {
|
bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extraData) {
|
||||||
SendEntitiesOperationArgs* args = static_cast<SendEntitiesOperationArgs*>(extraData);
|
SendEntitiesOperationArgs* args = static_cast<SendEntitiesOperationArgs*>(extraData);
|
||||||
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
|
||||||
std::function<const EntityItemID(EntityItemPointer&)> getMapped = [&](EntityItemPointer& item) -> const EntityItemID {
|
|
||||||
EntityItemID oldID = item->getEntityItemID();
|
|
||||||
if (args->map->contains(oldID)) { // Already been handled (e.g., as a parent of somebody that we've processed).
|
|
||||||
return args->map->value(oldID);
|
|
||||||
}
|
|
||||||
EntityItemID newID = QUuid::createUuid();
|
|
||||||
args->map->insert(oldID, newID);
|
|
||||||
|
|
||||||
|
auto getMapped = [&args](EntityItemID oldID) {
|
||||||
|
if (oldID.isNull()) {
|
||||||
|
return EntityItemID();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<EntityItemID, EntityItemID>::iterator iter = args->map->find(oldID);
|
||||||
|
if (iter == args->map->end()) {
|
||||||
|
EntityItemID newID = QUuid::createUuid();
|
||||||
|
args->map->insert(oldID, newID);
|
||||||
|
return newID;
|
||||||
|
}
|
||||||
|
return iter.value();
|
||||||
|
};
|
||||||
|
|
||||||
|
entityTreeElement->forEachEntity([&args, &getMapped, &element](EntityItemPointer item) {
|
||||||
|
EntityItemID oldID = item->getEntityItemID();
|
||||||
|
EntityItemID newID = getMapped(oldID);
|
||||||
EntityItemProperties properties = item->getProperties();
|
EntityItemProperties properties = item->getProperties();
|
||||||
|
|
||||||
EntityItemID oldParentID = properties.getParentID();
|
EntityItemID oldParentID = properties.getParentID();
|
||||||
if (oldParentID.isInvalidID()) { // no parent
|
if (oldParentID.isInvalidID()) { // no parent
|
||||||
properties.setPosition(properties.getPosition() + args->root);
|
properties.setPosition(properties.getPosition() + args->root);
|
||||||
} else {
|
} else {
|
||||||
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
EntityItemPointer parentEntity = args->ourTree->findEntityByEntityItemID(oldParentID);
|
||||||
if (parentEntity) { // map the parent
|
if (parentEntity) { // map the parent
|
||||||
// Warning: (non-tail) recursion of getMapped could blow the call stack if the parent hierarchy is VERY deep.
|
properties.setParentID(getMapped(parentEntity->getID()));
|
||||||
properties.setParentID(getMapped(parentEntity));
|
|
||||||
// But do not add root offset in this case.
|
// But do not add root offset in this case.
|
||||||
} else { // Should not happen, but let's try to be helpful...
|
} else { // Should not happen, but let's try to be helpful...
|
||||||
item->globalizeProperties(properties, "Cannot find %3 parent of %2 %1", args->root);
|
item->globalizeProperties(properties, "Cannot find %3 parent of %2 %1", args->root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!properties.getXNNeighborID().isInvalidID()) {
|
properties.setXNNeighborID(getMapped(properties.getXNNeighborID()));
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getXNNeighborID());
|
properties.setXPNeighborID(getMapped(properties.getXPNeighborID()));
|
||||||
if (neighborEntity) {
|
properties.setYNNeighborID(getMapped(properties.getYNNeighborID()));
|
||||||
properties.setXNNeighborID(getMapped(neighborEntity));
|
properties.setYPNeighborID(getMapped(properties.getYPNeighborID()));
|
||||||
}
|
properties.setZNNeighborID(getMapped(properties.getZNNeighborID()));
|
||||||
}
|
properties.setZPNeighborID(getMapped(properties.getZPNeighborID()));
|
||||||
if (!properties.getXPNeighborID().isInvalidID()) {
|
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getXPNeighborID());
|
QByteArray actionData = properties.getActionData();
|
||||||
if (neighborEntity) {
|
properties.setActionData(remapActionDataIDs(actionData, *args->map));
|
||||||
properties.setXPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!properties.getYNNeighborID().isInvalidID()) {
|
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getYNNeighborID());
|
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setYNNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!properties.getYPNeighborID().isInvalidID()) {
|
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getYPNeighborID());
|
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setYPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!properties.getZNNeighborID().isInvalidID()) {
|
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getZNNeighborID());
|
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setZNNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!properties.getZPNeighborID().isInvalidID()) {
|
|
||||||
auto neighborEntity = args->ourTree->findEntityByEntityItemID(properties.getZPNeighborID());
|
|
||||||
if (neighborEntity) {
|
|
||||||
properties.setZPNeighborID(getMapped(neighborEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set creation time to "now" for imported entities
|
// set creation time to "now" for imported entities
|
||||||
properties.setCreated(usecTimestampNow());
|
properties.setCreated(usecTimestampNow());
|
||||||
|
@ -1623,13 +1663,13 @@ bool EntityTree::sendEntitiesOperation(OctreeElementPointer element, void* extra
|
||||||
// also update the local tree instantly (note: this is not our tree, but an alternate tree)
|
// also update the local tree instantly (note: this is not our tree, but an alternate tree)
|
||||||
if (args->otherTree) {
|
if (args->otherTree) {
|
||||||
args->otherTree->withWriteLock([&] {
|
args->otherTree->withWriteLock([&] {
|
||||||
args->otherTree->addEntity(newID, properties);
|
EntityItemPointer entity = args->otherTree->addEntity(newID, properties);
|
||||||
|
entity->deserializeActions();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return newID;
|
return newID;
|
||||||
};
|
});
|
||||||
|
|
||||||
entityTreeElement->forEachEntity(getMapped);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,8 @@ public:
|
||||||
virtual void dumpTree() override;
|
virtual void dumpTree() override;
|
||||||
virtual void pruneTree() override;
|
virtual void pruneTree() override;
|
||||||
|
|
||||||
|
static QByteArray remapActionDataIDs(QByteArray actionData, QHash<EntityItemID, EntityItemID>& map);
|
||||||
|
|
||||||
QVector<EntityItemID> sendEntities(EntityEditPacketSender* packetSender, EntityTreePointer localTree,
|
QVector<EntityItemID> sendEntities(EntityEditPacketSender* packetSender, EntityTreePointer localTree,
|
||||||
float x, float y, float z);
|
float x, float y, float z);
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,11 @@ void Texture::assignStoredMip(uint16 level, storage::StoragePointer& storage) {
|
||||||
// THen check that the mem texture passed make sense with its format
|
// THen check that the mem texture passed make sense with its format
|
||||||
Size expectedSize = evalStoredMipSize(level, getStoredMipFormat());
|
Size expectedSize = evalStoredMipSize(level, getStoredMipFormat());
|
||||||
auto size = storage->size();
|
auto size = storage->size();
|
||||||
if (storage->size() <= expectedSize) {
|
// NOTE: doing the same thing in all the next block but beeing able to breakpoint with more accuracy
|
||||||
|
if (storage->size() < expectedSize) {
|
||||||
|
_storage->assignMipData(level, storage);
|
||||||
|
_stamp++;
|
||||||
|
} else if (size == expectedSize) {
|
||||||
_storage->assignMipData(level, storage);
|
_storage->assignMipData(level, storage);
|
||||||
_stamp++;
|
_stamp++;
|
||||||
} else if (size > expectedSize) {
|
} else if (size > expectedSize) {
|
||||||
|
@ -468,7 +472,11 @@ void Texture::assignStoredMipFace(uint16 level, uint8 face, storage::StoragePoin
|
||||||
// THen check that the mem texture passed make sense with its format
|
// THen check that the mem texture passed make sense with its format
|
||||||
Size expectedSize = evalStoredMipFaceSize(level, getStoredMipFormat());
|
Size expectedSize = evalStoredMipFaceSize(level, getStoredMipFormat());
|
||||||
auto size = storage->size();
|
auto size = storage->size();
|
||||||
if (size <= expectedSize) {
|
// NOTE: doing the same thing in all the next block but beeing able to breakpoint with more accuracy
|
||||||
|
if (size < expectedSize) {
|
||||||
|
_storage->assignMipFaceData(level, face, storage);
|
||||||
|
_stamp++;
|
||||||
|
} else if (size == expectedSize) {
|
||||||
_storage->assignMipFaceData(level, face, storage);
|
_storage->assignMipFaceData(level, face, storage);
|
||||||
_stamp++;
|
_stamp++;
|
||||||
} else if (size > expectedSize) {
|
} else if (size > expectedSize) {
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "Forward.h"
|
#include "Forward.h"
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
|
|
||||||
|
const int ABSOLUTE_MAX_TEXTURE_NUM_PIXELS = 8192 * 8192;
|
||||||
|
|
||||||
namespace ktx {
|
namespace ktx {
|
||||||
class KTX;
|
class KTX;
|
||||||
using KTXUniquePointer = std::unique_ptr<KTX>;
|
using KTXUniquePointer = std::unique_ptr<KTX>;
|
||||||
|
|
|
@ -542,6 +542,13 @@ bool Texture::evalTextureFormat(const ktx::Header& header, Element& mipFormat, E
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (header.getGLFormat() == ktx::GLFormat::RG && header.getGLType() == ktx::GLType::UNSIGNED_BYTE && header.getTypeSize() == 1) {
|
||||||
|
mipFormat = Format::VEC2NU8_XY;
|
||||||
|
if (header.getGLInternaFormat_Uncompressed() == ktx::GLInternalFormat_Uncompressed::RG8) {
|
||||||
|
texelFormat = Format::VEC2NU8_XY;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else if (header.getGLFormat() == ktx::GLFormat::COMPRESSED_FORMAT && header.getGLType() == ktx::GLType::COMPRESSED_TYPE) {
|
} else if (header.getGLFormat() == ktx::GLFormat::COMPRESSED_FORMAT && header.getGLType() == ktx::GLType::COMPRESSED_TYPE) {
|
||||||
if (header.getGLInternaFormat_Compressed() == ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_S3TC_DXT1_EXT) {
|
if (header.getGLInternaFormat_Compressed() == ktx::GLInternalFormat_Compressed::COMPRESSED_SRGB_S3TC_DXT1_EXT) {
|
||||||
mipFormat = Format::COLOR_COMPRESSED_SRGB;
|
mipFormat = Format::COLOR_COMPRESSED_SRGB;
|
||||||
|
|
|
@ -383,6 +383,7 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) {
|
||||||
} else if (mipFormat == gpu::Element::COLOR_RGBA_32) {
|
} else if (mipFormat == gpu::Element::COLOR_RGBA_32) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGBA);
|
compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(32,
|
compressionOptions.setPixelFormat(32,
|
||||||
0x000000FF,
|
0x000000FF,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
|
@ -393,6 +394,7 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) {
|
||||||
} else if (mipFormat == gpu::Element::COLOR_BGRA_32) {
|
} else if (mipFormat == gpu::Element::COLOR_BGRA_32) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGBA);
|
compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(32,
|
compressionOptions.setPixelFormat(32,
|
||||||
0x00FF0000,
|
0x00FF0000,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
|
@ -403,6 +405,7 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) {
|
||||||
} else if (mipFormat == gpu::Element::COLOR_SRGBA_32) {
|
} else if (mipFormat == gpu::Element::COLOR_SRGBA_32) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGBA);
|
compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(32,
|
compressionOptions.setPixelFormat(32,
|
||||||
0x000000FF,
|
0x000000FF,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
|
@ -411,6 +414,7 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) {
|
||||||
} else if (mipFormat == gpu::Element::COLOR_SBGRA_32) {
|
} else if (mipFormat == gpu::Element::COLOR_SBGRA_32) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGBA);
|
compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(32,
|
compressionOptions.setPixelFormat(32,
|
||||||
0x00FF0000,
|
0x00FF0000,
|
||||||
0x0000FF00,
|
0x0000FF00,
|
||||||
|
@ -419,11 +423,13 @@ void generateMips(gpu::Texture* texture, QImage& image, int face = -1) {
|
||||||
} else if (mipFormat == gpu::Element::COLOR_R_8) {
|
} else if (mipFormat == gpu::Element::COLOR_R_8) {
|
||||||
compressionOptions.setFormat(nvtt::Format_RGB);
|
compressionOptions.setFormat(nvtt::Format_RGB);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(8, 0, 0, 0);
|
compressionOptions.setPixelFormat(8, 0, 0, 0);
|
||||||
} else if (mipFormat == gpu::Element::VEC2NU8_XY) {
|
} else if (mipFormat == gpu::Element::VEC2NU8_XY) {
|
||||||
inputOptions.setNormalMap(true);
|
inputOptions.setNormalMap(true);
|
||||||
compressionOptions.setFormat(nvtt::Format_RGBA);
|
compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||||
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
|
compressionOptions.setPitchAlignment(4);
|
||||||
compressionOptions.setPixelFormat(8, 8, 0, 0);
|
compressionOptions.setPixelFormat(8, 8, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(imagelogging) << "Unknown mip format";
|
qCWarning(imagelogging) << "Unknown mip format";
|
||||||
|
|
|
@ -37,7 +37,8 @@ enum Type {
|
||||||
CUBE_TEXTURE,
|
CUBE_TEXTURE,
|
||||||
OCCLUSION_TEXTURE,
|
OCCLUSION_TEXTURE,
|
||||||
SCATTERING_TEXTURE = OCCLUSION_TEXTURE,
|
SCATTERING_TEXTURE = OCCLUSION_TEXTURE,
|
||||||
LIGHTMAP_TEXTURE
|
LIGHTMAP_TEXTURE,
|
||||||
|
UNUSED_TEXTURE
|
||||||
};
|
};
|
||||||
|
|
||||||
using TextureLoader = std::function<gpu::TexturePointer(const QImage&, const std::string&)>;
|
using TextureLoader = std::function<gpu::TexturePointer(const QImage&, const std::string&)>;
|
||||||
|
|
|
@ -22,6 +22,9 @@ uint32_t Header::evalPadding(size_t byteSize) {
|
||||||
return (uint32_t) (3 - (byteSize + 3) % PACKING_SIZE);// padding ? PACKING_SIZE - padding : 0);
|
return (uint32_t) (3 - (byteSize + 3) % PACKING_SIZE);// padding ? PACKING_SIZE - padding : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Header::checkAlignment(size_t byteSize) {
|
||||||
|
return ((byteSize & 0x3) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
const Header::Identifier ktx::Header::IDENTIFIER {{
|
const Header::Identifier ktx::Header::IDENTIFIER {{
|
||||||
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
||||||
|
@ -114,6 +117,9 @@ size_t Header::evalFaceSize(uint32_t level) const {
|
||||||
}
|
}
|
||||||
size_t Header::evalImageSize(uint32_t level) const {
|
size_t Header::evalImageSize(uint32_t level) const {
|
||||||
auto faceSize = evalFaceSize(level);
|
auto faceSize = evalFaceSize(level);
|
||||||
|
if (!checkAlignment(faceSize)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (numberOfFaces == NUM_CUBEMAPFACES && numberOfArrayElements == 0) {
|
if (numberOfFaces == NUM_CUBEMAPFACES && numberOfArrayElements == 0) {
|
||||||
return faceSize;
|
return faceSize;
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,6 +145,9 @@ ImageDescriptors Header::generateImageDescriptors() const {
|
||||||
size_t imageOffset = 0;
|
size_t imageOffset = 0;
|
||||||
for (uint32_t level = 0; level < numberOfMipmapLevels; ++level) {
|
for (uint32_t level = 0; level < numberOfMipmapLevels; ++level) {
|
||||||
auto imageSize = static_cast<uint32_t>(evalImageSize(level));
|
auto imageSize = static_cast<uint32_t>(evalImageSize(level));
|
||||||
|
if (!checkAlignment(imageSize)) {
|
||||||
|
return ImageDescriptors();
|
||||||
|
}
|
||||||
if (imageSize == 0) {
|
if (imageSize == 0) {
|
||||||
return ImageDescriptors();
|
return ImageDescriptors();
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,6 +309,7 @@ namespace ktx {
|
||||||
static const uint32_t REVERSE_ENDIAN_TEST = 0x01020304;
|
static const uint32_t REVERSE_ENDIAN_TEST = 0x01020304;
|
||||||
|
|
||||||
static uint32_t evalPadding(size_t byteSize);
|
static uint32_t evalPadding(size_t byteSize);
|
||||||
|
static bool checkAlignment(size_t byteSize);
|
||||||
|
|
||||||
Header();
|
Header();
|
||||||
|
|
||||||
|
|
|
@ -148,12 +148,24 @@ namespace ktx {
|
||||||
size_t imageSize = *reinterpret_cast<const uint32_t*>(currentPtr);
|
size_t imageSize = *reinterpret_cast<const uint32_t*>(currentPtr);
|
||||||
currentPtr += sizeof(uint32_t);
|
currentPtr += sizeof(uint32_t);
|
||||||
|
|
||||||
|
auto expectedImageSize = header.evalImageSize((uint32_t) images.size());
|
||||||
|
if (imageSize != expectedImageSize) {
|
||||||
|
break;
|
||||||
|
} else if (!Header::checkAlignment(imageSize)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The image size is the face size, beware!
|
||||||
|
size_t faceSize = imageSize;
|
||||||
|
if (numFaces == NUM_CUBEMAPFACES) {
|
||||||
|
imageSize = NUM_CUBEMAPFACES * faceSize;
|
||||||
|
}
|
||||||
|
|
||||||
// If enough data ahead then capture the pointer
|
// If enough data ahead then capture the pointer
|
||||||
if ((currentPtr - srcBytes) + imageSize <= (srcSize)) {
|
if ((currentPtr - srcBytes) + imageSize <= (srcSize)) {
|
||||||
auto padding = Header::evalPadding(imageSize);
|
auto padding = Header::evalPadding(imageSize);
|
||||||
|
|
||||||
if (numFaces == NUM_CUBEMAPFACES) {
|
if (numFaces == NUM_CUBEMAPFACES) {
|
||||||
size_t faceSize = imageSize / NUM_CUBEMAPFACES;
|
|
||||||
Image::FaceBytes faces(NUM_CUBEMAPFACES);
|
Image::FaceBytes faces(NUM_CUBEMAPFACES);
|
||||||
for (uint32_t face = 0; face < NUM_CUBEMAPFACES; face++) {
|
for (uint32_t face = 0; face < NUM_CUBEMAPFACES; face++) {
|
||||||
faces[face] = currentPtr;
|
faces[face] = currentPtr;
|
||||||
|
@ -166,6 +178,7 @@ namespace ktx {
|
||||||
currentPtr += imageSize + padding;
|
currentPtr += imageSize + padding;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Stop here
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +203,10 @@ namespace ktx {
|
||||||
|
|
||||||
// populate image table
|
// populate image table
|
||||||
result->_images = parseImages(result->getHeader(), result->getTexelsDataSize(), result->getTexelsData());
|
result->_images = parseImages(result->getHeader(), result->getTexelsDataSize(), result->getTexelsData());
|
||||||
|
if (result->_images.size() != result->getHeader().getNumberOfLevels()) {
|
||||||
|
// Fail if the number of images produced doesn't match the header number of levels
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,8 @@ namespace ktx {
|
||||||
if (currentDataSize + sizeof(uint32_t) < allocatedImagesDataSize) {
|
if (currentDataSize + sizeof(uint32_t) < allocatedImagesDataSize) {
|
||||||
uint32_t imageOffset = currentPtr - destBytes;
|
uint32_t imageOffset = currentPtr - destBytes;
|
||||||
size_t imageSize = srcImages[l]._imageSize;
|
size_t imageSize = srcImages[l]._imageSize;
|
||||||
*(reinterpret_cast<uint32_t*> (currentPtr)) = (uint32_t) imageSize;
|
size_t imageFaceSize = srcImages[l]._faceSize;
|
||||||
|
*(reinterpret_cast<uint32_t*> (currentPtr)) = (uint32_t)imageFaceSize; // the imageSize written in the ktx is the FACE size
|
||||||
currentPtr += sizeof(uint32_t);
|
currentPtr += sizeof(uint32_t);
|
||||||
currentDataSize += sizeof(uint32_t);
|
currentDataSize += sizeof(uint32_t);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ KTXCache::KTXCache(const std::string& dir, const std::string& ext) :
|
||||||
}
|
}
|
||||||
|
|
||||||
KTXFilePointer KTXCache::writeFile(const char* data, Metadata&& metadata) {
|
KTXFilePointer KTXCache::writeFile(const char* data, Metadata&& metadata) {
|
||||||
FilePointer file = FileCache::writeFile(data, std::move(metadata));
|
FilePointer file = FileCache::writeFile(data, std::move(metadata), true);
|
||||||
return std::static_pointer_cast<KTXFile>(file);
|
return std::static_pointer_cast<KTXFile>(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -792,6 +792,8 @@ void ImageReader::read() {
|
||||||
texture = gpu::Texture::unserialize(ktxFile->getFilepath());
|
texture = gpu::Texture::unserialize(ktxFile->getFilepath());
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture = textureCache->cacheTextureByHash(hash, texture);
|
texture = textureCache->cacheTextureByHash(hash, texture);
|
||||||
|
} else {
|
||||||
|
qCWarning(modelnetworking) << "Invalid cached KTX " << _url << " under hash " << hash.c_str() << ", recreating...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -835,7 +837,7 @@ void ImageReader::read() {
|
||||||
const char* data = reinterpret_cast<const char*>(memKtx->_storage->data());
|
const char* data = reinterpret_cast<const char*>(memKtx->_storage->data());
|
||||||
size_t length = memKtx->_storage->size();
|
size_t length = memKtx->_storage->size();
|
||||||
auto& ktxCache = textureCache->_ktxCache;
|
auto& ktxCache = textureCache->_ktxCache;
|
||||||
networkTexture->_file = ktxCache.writeFile(data, KTXCache::Metadata(hash, length));
|
networkTexture->_file = ktxCache.writeFile(data, KTXCache::Metadata(hash, length)); //
|
||||||
if (!networkTexture->_file) {
|
if (!networkTexture->_file) {
|
||||||
qCWarning(modelnetworking) << _url << "file cache failed";
|
qCWarning(modelnetworking) << _url << "file cache failed";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
#include "KTXCache.h"
|
#include "KTXCache.h"
|
||||||
|
|
||||||
const int ABSOLUTE_MAX_TEXTURE_NUM_PIXELS = 8192 * 8192;
|
|
||||||
|
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
class Batch;
|
class Batch;
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,9 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
||||||
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
||||||
QJsonObject dataObject = responseObject["data"].toObject();
|
QJsonObject dataObject = responseObject["data"].toObject();
|
||||||
|
|
||||||
|
// Lookup succeeded, don't keep re-trying it (especially on server restarts)
|
||||||
|
_previousLookup.clear();
|
||||||
|
|
||||||
if (!dataObject.isEmpty()) {
|
if (!dataObject.isEmpty()) {
|
||||||
goToAddressFromObject(dataObject.toVariantMap(), requestReply);
|
goToAddressFromObject(dataObject.toVariantMap(), requestReply);
|
||||||
} else if (responseObject.contains(DATA_OBJECT_DOMAIN_KEY)) {
|
} else if (responseObject.contains(DATA_OBJECT_DOMAIN_KEY)) {
|
||||||
|
@ -739,6 +742,8 @@ void AddressManager::refreshPreviousLookup() {
|
||||||
// if we have a non-empty previous lookup, fire it again now (but don't re-store it in the history)
|
// if we have a non-empty previous lookup, fire it again now (but don't re-store it in the history)
|
||||||
if (!_previousLookup.isEmpty()) {
|
if (!_previousLookup.isEmpty()) {
|
||||||
handleUrl(_previousLookup, LookupTrigger::AttemptedRefresh);
|
handleUrl(_previousLookup, LookupTrigger::AttemptedRefresh);
|
||||||
|
} else {
|
||||||
|
handleUrl(currentAddress(), LookupTrigger::AttemptedRefresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ FilePointer FileCache::addFile(Metadata&& metadata, const std::string& filepath)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePointer FileCache::writeFile(const char* data, File::Metadata&& metadata) {
|
FilePointer FileCache::writeFile(const char* data, File::Metadata&& metadata, bool overwrite) {
|
||||||
assert(_initialized);
|
assert(_initialized);
|
||||||
|
|
||||||
std::string filepath = getFilepath(metadata.key);
|
std::string filepath = getFilepath(metadata.key);
|
||||||
|
@ -107,8 +107,13 @@ FilePointer FileCache::writeFile(const char* data, File::Metadata&& metadata) {
|
||||||
// if file already exists, return it
|
// if file already exists, return it
|
||||||
FilePointer file = getFile(metadata.key);
|
FilePointer file = getFile(metadata.key);
|
||||||
if (file) {
|
if (file) {
|
||||||
qCWarning(file_cache, "[%s] Attempted to overwrite %s", _dirname.c_str(), metadata.key.c_str());
|
if (!overwrite) {
|
||||||
return file;
|
qCWarning(file_cache, "[%s] Attempted to overwrite %s", _dirname.c_str(), metadata.key.c_str());
|
||||||
|
return file;
|
||||||
|
} else {
|
||||||
|
qCWarning(file_cache, "[%s] Overwriting %s", _dirname.c_str(), metadata.key.c_str());
|
||||||
|
file.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSaveFile saveFile(QString::fromStdString(filepath));
|
QSaveFile saveFile(QString::fromStdString(filepath));
|
||||||
|
|
|
@ -80,7 +80,7 @@ protected:
|
||||||
/// must be called after construction to create the cache on the fs and restore persisted files
|
/// must be called after construction to create the cache on the fs and restore persisted files
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
FilePointer writeFile(const char* data, Metadata&& metadata);
|
FilePointer writeFile(const char* data, Metadata&& metadata, bool overwrite = false);
|
||||||
FilePointer getFile(const Key& key);
|
FilePointer getFile(const Key& key);
|
||||||
|
|
||||||
/// create a file
|
/// create a file
|
||||||
|
|
|
@ -42,41 +42,6 @@ ObjectActionSpring::~ObjectActionSpring() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SpatiallyNestablePointer ObjectActionSpring::getOther() {
|
|
||||||
SpatiallyNestablePointer other;
|
|
||||||
withWriteLock([&]{
|
|
||||||
if (_otherID == QUuid()) {
|
|
||||||
// no other
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
other = _other.lock();
|
|
||||||
if (other && other->getID() == _otherID) {
|
|
||||||
// other is already up-to-date
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (other) {
|
|
||||||
// we have a pointer to other, but it's wrong
|
|
||||||
other.reset();
|
|
||||||
_other.reset();
|
|
||||||
}
|
|
||||||
// we have an other-id but no pointer to other cached
|
|
||||||
QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
|
|
||||||
if (!parentFinder) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EntityItemPointer ownerEntity = _ownerEntity.lock();
|
|
||||||
if (!ownerEntity) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bool success;
|
|
||||||
_other = parentFinder->find(_otherID, success, ownerEntity->getParentTree());
|
|
||||||
if (success) {
|
|
||||||
other = _other.lock();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return other;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ObjectActionSpring::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
bool ObjectActionSpring::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
||||||
glm::vec3& linearVelocity, glm::vec3& angularVelocity,
|
glm::vec3& linearVelocity, glm::vec3& angularVelocity,
|
||||||
float& linearTimeScale, float& angularTimeScale) {
|
float& linearTimeScale, float& angularTimeScale) {
|
||||||
|
|
|
@ -47,10 +47,6 @@ protected:
|
||||||
glm::vec3 _linearVelocityTarget;
|
glm::vec3 _linearVelocityTarget;
|
||||||
glm::vec3 _angularVelocityTarget;
|
glm::vec3 _angularVelocityTarget;
|
||||||
|
|
||||||
EntityItemID _otherID;
|
|
||||||
SpatiallyNestableWeakPointer _other;
|
|
||||||
SpatiallyNestablePointer getOther();
|
|
||||||
|
|
||||||
virtual bool prepareForSpringUpdate(btScalar deltaTimeStep);
|
virtual bool prepareForSpringUpdate(btScalar deltaTimeStep);
|
||||||
|
|
||||||
void serializeParameters(QDataStream& dataStream) const;
|
void serializeParameters(QDataStream& dataStream) const;
|
||||||
|
|
378
libraries/physics/src/ObjectActionTractor.cpp
Normal file
378
libraries/physics/src/ObjectActionTractor.cpp
Normal file
|
@ -0,0 +1,378 @@
|
||||||
|
//
|
||||||
|
// ObjectActionTractor.cpp
|
||||||
|
// libraries/physics/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2015-5-8
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "QVariantGLM.h"
|
||||||
|
|
||||||
|
#include "ObjectActionTractor.h"
|
||||||
|
|
||||||
|
#include "PhysicsLogging.h"
|
||||||
|
|
||||||
|
const float TRACTOR_MAX_SPEED = 10.0f;
|
||||||
|
const float MAX_TRACTOR_TIMESCALE = 600.0f; // 10 min is a long time
|
||||||
|
|
||||||
|
const uint16_t ObjectActionTractor::tractorVersion = 1;
|
||||||
|
|
||||||
|
|
||||||
|
ObjectActionTractor::ObjectActionTractor(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
|
ObjectAction(DYNAMIC_TYPE_TRACTOR, id, ownerEntity),
|
||||||
|
_positionalTarget(glm::vec3(0.0f)),
|
||||||
|
_desiredPositionalTarget(glm::vec3(0.0f)),
|
||||||
|
_linearTimeScale(FLT_MAX),
|
||||||
|
_positionalTargetSet(true),
|
||||||
|
_rotationalTarget(glm::quat()),
|
||||||
|
_desiredRotationalTarget(glm::quat()),
|
||||||
|
_angularTimeScale(FLT_MAX),
|
||||||
|
_rotationalTargetSet(true) {
|
||||||
|
#if WANT_DEBUG
|
||||||
|
qCDebug(physics) << "ObjectActionTractor::ObjectActionTractor";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectActionTractor::~ObjectActionTractor() {
|
||||||
|
#if WANT_DEBUG
|
||||||
|
qCDebug(physics) << "ObjectActionTractor::~ObjectActionTractor";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectActionTractor::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
||||||
|
glm::vec3& linearVelocity, glm::vec3& angularVelocity,
|
||||||
|
float& linearTimeScale, float& angularTimeScale) {
|
||||||
|
SpatiallyNestablePointer other = getOther();
|
||||||
|
withReadLock([&]{
|
||||||
|
linearTimeScale = _linearTimeScale;
|
||||||
|
angularTimeScale = _angularTimeScale;
|
||||||
|
|
||||||
|
if (!_otherID.isNull()) {
|
||||||
|
if (other) {
|
||||||
|
rotation = _desiredRotationalTarget * other->getRotation();
|
||||||
|
position = other->getRotation() * _desiredPositionalTarget + other->getPosition();
|
||||||
|
} else {
|
||||||
|
// we should have an "other" but can't find it, so disable the tractor.
|
||||||
|
linearTimeScale = FLT_MAX;
|
||||||
|
angularTimeScale = FLT_MAX;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rotation = _desiredRotationalTarget;
|
||||||
|
position = _desiredPositionalTarget;
|
||||||
|
}
|
||||||
|
linearVelocity = glm::vec3();
|
||||||
|
angularVelocity = glm::vec3();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectActionTractor::prepareForTractorUpdate(btScalar deltaTimeStep) {
|
||||||
|
auto ownerEntity = _ownerEntity.lock();
|
||||||
|
if (!ownerEntity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat rotation;
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::vec3 linearVelocity;
|
||||||
|
glm::vec3 angularVelocity;
|
||||||
|
|
||||||
|
bool linearValid = false;
|
||||||
|
int linearTractorCount = 0;
|
||||||
|
bool angularValid = false;
|
||||||
|
int angularTractorCount = 0;
|
||||||
|
|
||||||
|
QList<EntityDynamicPointer> tractorDerivedActions;
|
||||||
|
tractorDerivedActions.append(ownerEntity->getActionsOfType(DYNAMIC_TYPE_TRACTOR));
|
||||||
|
tractorDerivedActions.append(ownerEntity->getActionsOfType(DYNAMIC_TYPE_FAR_GRAB));
|
||||||
|
tractorDerivedActions.append(ownerEntity->getActionsOfType(DYNAMIC_TYPE_HOLD));
|
||||||
|
|
||||||
|
foreach (EntityDynamicPointer action, tractorDerivedActions) {
|
||||||
|
std::shared_ptr<ObjectActionTractor> tractorAction = std::static_pointer_cast<ObjectActionTractor>(action);
|
||||||
|
glm::quat rotationForAction;
|
||||||
|
glm::vec3 positionForAction;
|
||||||
|
glm::vec3 linearVelocityForAction;
|
||||||
|
glm::vec3 angularVelocityForAction;
|
||||||
|
float linearTimeScale;
|
||||||
|
float angularTimeScale;
|
||||||
|
bool success = tractorAction->getTarget(deltaTimeStep,
|
||||||
|
rotationForAction, positionForAction,
|
||||||
|
linearVelocityForAction, angularVelocityForAction,
|
||||||
|
linearTimeScale, angularTimeScale);
|
||||||
|
if (success) {
|
||||||
|
if (angularTimeScale < MAX_TRACTOR_TIMESCALE) {
|
||||||
|
angularValid = true;
|
||||||
|
angularTractorCount++;
|
||||||
|
angularVelocity += angularVelocityForAction;
|
||||||
|
if (tractorAction.get() == this) {
|
||||||
|
// only use the rotation for this action
|
||||||
|
rotation = rotationForAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linearTimeScale < MAX_TRACTOR_TIMESCALE) {
|
||||||
|
linearValid = true;
|
||||||
|
linearTractorCount++;
|
||||||
|
position += positionForAction;
|
||||||
|
linearVelocity += linearVelocityForAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((angularValid && angularTractorCount > 0) || (linearValid && linearTractorCount > 0)) {
|
||||||
|
withWriteLock([&]{
|
||||||
|
if (linearValid && linearTractorCount > 0) {
|
||||||
|
position /= linearTractorCount;
|
||||||
|
linearVelocity /= linearTractorCount;
|
||||||
|
_positionalTarget = position;
|
||||||
|
_linearVelocityTarget = linearVelocity;
|
||||||
|
_positionalTargetSet = true;
|
||||||
|
_active = true;
|
||||||
|
}
|
||||||
|
if (angularValid && angularTractorCount > 0) {
|
||||||
|
angularVelocity /= angularTractorCount;
|
||||||
|
_rotationalTarget = rotation;
|
||||||
|
_angularVelocityTarget = angularVelocity;
|
||||||
|
_rotationalTargetSet = true;
|
||||||
|
_active = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return linearValid || angularValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ObjectActionTractor::updateActionWorker(btScalar deltaTimeStep) {
|
||||||
|
if (!prepareForTractorUpdate(deltaTimeStep)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
withReadLock([&]{
|
||||||
|
auto ownerEntity = _ownerEntity.lock();
|
||||||
|
if (!ownerEntity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* physicsInfo = ownerEntity->getPhysicsInfo();
|
||||||
|
if (!physicsInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
|
||||||
|
btRigidBody* rigidBody = motionState->getRigidBody();
|
||||||
|
if (!rigidBody) {
|
||||||
|
qCDebug(physics) << "ObjectActionTractor::updateActionWorker no rigidBody";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_linearTimeScale < MAX_TRACTOR_TIMESCALE) {
|
||||||
|
btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
|
||||||
|
btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
|
||||||
|
float offsetLength = offset.length();
|
||||||
|
if (offsetLength > FLT_EPSILON) {
|
||||||
|
float speed = glm::min(offsetLength / _linearTimeScale, TRACTOR_MAX_SPEED);
|
||||||
|
targetVelocity = (-speed / offsetLength) * offset;
|
||||||
|
if (speed > rigidBody->getLinearSleepingThreshold()) {
|
||||||
|
forceBodyNonStatic();
|
||||||
|
rigidBody->activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this action is aggresively critically damped and defeats the current velocity
|
||||||
|
rigidBody->setLinearVelocity(targetVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_angularTimeScale < MAX_TRACTOR_TIMESCALE) {
|
||||||
|
btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
btQuaternion bodyRotation = rigidBody->getOrientation();
|
||||||
|
auto alignmentDot = bodyRotation.dot(glmToBullet(_rotationalTarget));
|
||||||
|
const float ALMOST_ONE = 0.99999f;
|
||||||
|
if (glm::abs(alignmentDot) < ALMOST_ONE) {
|
||||||
|
btQuaternion target = glmToBullet(_rotationalTarget);
|
||||||
|
if (alignmentDot < 0.0f) {
|
||||||
|
target = -target;
|
||||||
|
}
|
||||||
|
// if dQ is the incremental rotation that gets an object from Q0 to Q1 then:
|
||||||
|
//
|
||||||
|
// Q1 = dQ * Q0
|
||||||
|
//
|
||||||
|
// solving for dQ gives:
|
||||||
|
//
|
||||||
|
// dQ = Q1 * Q0^
|
||||||
|
btQuaternion deltaQ = target * bodyRotation.inverse();
|
||||||
|
float speed = deltaQ.getAngle() / _angularTimeScale;
|
||||||
|
targetVelocity = speed * deltaQ.getAxis();
|
||||||
|
if (speed > rigidBody->getAngularSleepingThreshold()) {
|
||||||
|
rigidBody->activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this action is aggresively critically damped and defeats the current velocity
|
||||||
|
rigidBody->setAngularVelocity(targetVelocity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const float MIN_TIMESCALE = 0.1f;
|
||||||
|
|
||||||
|
|
||||||
|
bool ObjectActionTractor::updateArguments(QVariantMap arguments) {
|
||||||
|
glm::vec3 positionalTarget;
|
||||||
|
float linearTimeScale;
|
||||||
|
glm::quat rotationalTarget;
|
||||||
|
float angularTimeScale;
|
||||||
|
QUuid otherID;
|
||||||
|
|
||||||
|
|
||||||
|
bool needUpdate = false;
|
||||||
|
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
|
||||||
|
withReadLock([&]{
|
||||||
|
// targets are required, tractor-constants are optional
|
||||||
|
bool ok = true;
|
||||||
|
positionalTarget = EntityDynamicInterface::extractVec3Argument("tractor action", arguments, "targetPosition", ok, false);
|
||||||
|
if (!ok) {
|
||||||
|
positionalTarget = _desiredPositionalTarget;
|
||||||
|
}
|
||||||
|
ok = true;
|
||||||
|
linearTimeScale = EntityDynamicInterface::extractFloatArgument("tractor action", arguments, "linearTimeScale", ok, false);
|
||||||
|
if (!ok || linearTimeScale <= 0.0f) {
|
||||||
|
linearTimeScale = _linearTimeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
rotationalTarget = EntityDynamicInterface::extractQuatArgument("tractor action", arguments, "targetRotation", ok, false);
|
||||||
|
if (!ok) {
|
||||||
|
rotationalTarget = _desiredRotationalTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
angularTimeScale =
|
||||||
|
EntityDynamicInterface::extractFloatArgument("tractor action", arguments, "angularTimeScale", ok, false);
|
||||||
|
if (!ok) {
|
||||||
|
angularTimeScale = _angularTimeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
otherID = QUuid(EntityDynamicInterface::extractStringArgument("tractor action",
|
||||||
|
arguments, "otherID", ok, false));
|
||||||
|
if (!ok) {
|
||||||
|
otherID = _otherID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (somethingChanged ||
|
||||||
|
positionalTarget != _desiredPositionalTarget ||
|
||||||
|
linearTimeScale != _linearTimeScale ||
|
||||||
|
rotationalTarget != _desiredRotationalTarget ||
|
||||||
|
angularTimeScale != _angularTimeScale ||
|
||||||
|
otherID != _otherID) {
|
||||||
|
// something changed
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (needUpdate) {
|
||||||
|
withWriteLock([&] {
|
||||||
|
_desiredPositionalTarget = positionalTarget;
|
||||||
|
_linearTimeScale = glm::max(MIN_TIMESCALE, glm::abs(linearTimeScale));
|
||||||
|
_desiredRotationalTarget = rotationalTarget;
|
||||||
|
_angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale));
|
||||||
|
_otherID = otherID;
|
||||||
|
_active = true;
|
||||||
|
|
||||||
|
auto ownerEntity = _ownerEntity.lock();
|
||||||
|
if (ownerEntity) {
|
||||||
|
ownerEntity->setDynamicDataDirty(true);
|
||||||
|
ownerEntity->setDynamicDataNeedsTransmit(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
activateBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap ObjectActionTractor::getArguments() {
|
||||||
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
|
withReadLock([&] {
|
||||||
|
arguments["linearTimeScale"] = _linearTimeScale;
|
||||||
|
arguments["targetPosition"] = glmToQMap(_desiredPositionalTarget);
|
||||||
|
|
||||||
|
arguments["targetRotation"] = glmToQMap(_desiredRotationalTarget);
|
||||||
|
arguments["angularTimeScale"] = _angularTimeScale;
|
||||||
|
|
||||||
|
arguments["otherID"] = _otherID;
|
||||||
|
});
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectActionTractor::serializeParameters(QDataStream& dataStream) const {
|
||||||
|
withReadLock([&] {
|
||||||
|
dataStream << _desiredPositionalTarget;
|
||||||
|
dataStream << _linearTimeScale;
|
||||||
|
dataStream << _positionalTargetSet;
|
||||||
|
dataStream << _desiredRotationalTarget;
|
||||||
|
dataStream << _angularTimeScale;
|
||||||
|
dataStream << _rotationalTargetSet;
|
||||||
|
dataStream << localTimeToServerTime(_expires);
|
||||||
|
dataStream << _tag;
|
||||||
|
dataStream << _otherID;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray ObjectActionTractor::serialize() const {
|
||||||
|
QByteArray serializedActionArguments;
|
||||||
|
QDataStream dataStream(&serializedActionArguments, QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
dataStream << DYNAMIC_TYPE_TRACTOR;
|
||||||
|
dataStream << getID();
|
||||||
|
dataStream << ObjectActionTractor::tractorVersion;
|
||||||
|
|
||||||
|
serializeParameters(dataStream);
|
||||||
|
|
||||||
|
return serializedActionArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectActionTractor::deserializeParameters(QByteArray serializedArguments, QDataStream& dataStream) {
|
||||||
|
withWriteLock([&] {
|
||||||
|
dataStream >> _desiredPositionalTarget;
|
||||||
|
dataStream >> _linearTimeScale;
|
||||||
|
dataStream >> _positionalTargetSet;
|
||||||
|
|
||||||
|
dataStream >> _desiredRotationalTarget;
|
||||||
|
dataStream >> _angularTimeScale;
|
||||||
|
dataStream >> _rotationalTargetSet;
|
||||||
|
|
||||||
|
quint64 serverExpires;
|
||||||
|
dataStream >> serverExpires;
|
||||||
|
_expires = serverTimeToLocalTime(serverExpires);
|
||||||
|
|
||||||
|
dataStream >> _tag;
|
||||||
|
|
||||||
|
dataStream >> _otherID;
|
||||||
|
|
||||||
|
_active = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectActionTractor::deserialize(QByteArray serializedArguments) {
|
||||||
|
QDataStream dataStream(serializedArguments);
|
||||||
|
|
||||||
|
EntityDynamicType type;
|
||||||
|
dataStream >> type;
|
||||||
|
assert(type == getType());
|
||||||
|
|
||||||
|
QUuid id;
|
||||||
|
dataStream >> id;
|
||||||
|
assert(id == getID());
|
||||||
|
|
||||||
|
uint16_t serializationVersion;
|
||||||
|
dataStream >> serializationVersion;
|
||||||
|
if (serializationVersion != ObjectActionTractor::tractorVersion) {
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializeParameters(serializedArguments, dataStream);
|
||||||
|
}
|
56
libraries/physics/src/ObjectActionTractor.h
Normal file
56
libraries/physics/src/ObjectActionTractor.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// ObjectActionTractor.h
|
||||||
|
// libraries/physics/src
|
||||||
|
//
|
||||||
|
// Created by Seth Alves 2017-5-8
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_ObjectActionTractor_h
|
||||||
|
#define hifi_ObjectActionTractor_h
|
||||||
|
|
||||||
|
#include "ObjectAction.h"
|
||||||
|
|
||||||
|
class ObjectActionTractor : public ObjectAction {
|
||||||
|
public:
|
||||||
|
ObjectActionTractor(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
|
virtual ~ObjectActionTractor();
|
||||||
|
|
||||||
|
virtual bool updateArguments(QVariantMap arguments) override;
|
||||||
|
virtual QVariantMap getArguments() override;
|
||||||
|
|
||||||
|
virtual void updateActionWorker(float deltaTimeStep) override;
|
||||||
|
|
||||||
|
virtual QByteArray serialize() const override;
|
||||||
|
virtual void deserialize(QByteArray serializedArguments) override;
|
||||||
|
|
||||||
|
virtual bool getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
||||||
|
glm::vec3& linearVelocity, glm::vec3& angularVelocity,
|
||||||
|
float& linearTimeScale, float& angularTimeScale);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static const uint16_t tractorVersion;
|
||||||
|
|
||||||
|
glm::vec3 _positionalTarget;
|
||||||
|
glm::vec3 _desiredPositionalTarget;
|
||||||
|
float _linearTimeScale;
|
||||||
|
bool _positionalTargetSet;
|
||||||
|
|
||||||
|
glm::quat _rotationalTarget;
|
||||||
|
glm::quat _desiredRotationalTarget;
|
||||||
|
float _angularTimeScale;
|
||||||
|
bool _rotationalTargetSet;
|
||||||
|
|
||||||
|
glm::vec3 _linearVelocityTarget;
|
||||||
|
glm::vec3 _angularVelocityTarget;
|
||||||
|
|
||||||
|
virtual bool prepareForTractorUpdate(btScalar deltaTimeStep);
|
||||||
|
|
||||||
|
void serializeParameters(QDataStream& dataStream) const;
|
||||||
|
void deserializeParameters(QByteArray serializedArguments, QDataStream& dataStream);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ObjectActionTractor_h
|
|
@ -40,7 +40,7 @@ QList<btRigidBody*> ObjectConstraintBallSocket::getRigidBodies() {
|
||||||
result += getRigidBody();
|
result += getRigidBody();
|
||||||
QUuid otherEntityID;
|
QUuid otherEntityID;
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
});
|
});
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
result += getOtherRigidBody(otherEntityID);
|
result += getOtherRigidBody(otherEntityID);
|
||||||
|
@ -76,7 +76,7 @@ btTypedConstraint* ObjectConstraintBallSocket::getConstraint() {
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
constraint = static_cast<btPoint2PointConstraint*>(_constraint);
|
constraint = static_cast<btPoint2PointConstraint*>(_constraint);
|
||||||
pivotInA = _pivotInA;
|
pivotInA = _pivotInA;
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
pivotInB = _pivotInB;
|
pivotInB = _pivotInB;
|
||||||
});
|
});
|
||||||
if (constraint) {
|
if (constraint) {
|
||||||
|
@ -136,7 +136,7 @@ bool ObjectConstraintBallSocket::updateArguments(QVariantMap arguments) {
|
||||||
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("ball-socket constraint",
|
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("ball-socket constraint",
|
||||||
arguments, "otherEntityID", ok, false));
|
arguments, "otherEntityID", ok, false));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -147,7 +147,7 @@ bool ObjectConstraintBallSocket::updateArguments(QVariantMap arguments) {
|
||||||
|
|
||||||
if (somethingChanged ||
|
if (somethingChanged ||
|
||||||
pivotInA != _pivotInA ||
|
pivotInA != _pivotInA ||
|
||||||
otherEntityID != _otherEntityID ||
|
otherEntityID != _otherID ||
|
||||||
pivotInB != _pivotInB) {
|
pivotInB != _pivotInB) {
|
||||||
// something changed
|
// something changed
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
|
@ -157,7 +157,7 @@ bool ObjectConstraintBallSocket::updateArguments(QVariantMap arguments) {
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_pivotInA = pivotInA;
|
_pivotInA = pivotInA;
|
||||||
_otherEntityID = otherEntityID;
|
_otherID = otherEntityID;
|
||||||
_pivotInB = pivotInB;
|
_pivotInB = pivotInB;
|
||||||
|
|
||||||
_active = true;
|
_active = true;
|
||||||
|
@ -178,11 +178,9 @@ bool ObjectConstraintBallSocket::updateArguments(QVariantMap arguments) {
|
||||||
QVariantMap ObjectConstraintBallSocket::getArguments() {
|
QVariantMap ObjectConstraintBallSocket::getArguments() {
|
||||||
QVariantMap arguments = ObjectDynamic::getArguments();
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
if (_constraint) {
|
arguments["pivot"] = glmToQMap(_pivotInA);
|
||||||
arguments["pivot"] = glmToQMap(_pivotInA);
|
arguments["otherEntityID"] = _otherID;
|
||||||
arguments["otherEntityID"] = _otherEntityID;
|
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
||||||
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +198,7 @@ QByteArray ObjectConstraintBallSocket::serialize() const {
|
||||||
dataStream << _tag;
|
dataStream << _tag;
|
||||||
|
|
||||||
dataStream << _pivotInA;
|
dataStream << _pivotInA;
|
||||||
dataStream << _otherEntityID;
|
dataStream << _otherID;
|
||||||
dataStream << _pivotInB;
|
dataStream << _pivotInB;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -232,7 +230,7 @@ void ObjectConstraintBallSocket::deserialize(QByteArray serializedArguments) {
|
||||||
dataStream >> _tag;
|
dataStream >> _tag;
|
||||||
|
|
||||||
dataStream >> _pivotInA;
|
dataStream >> _pivotInA;
|
||||||
dataStream >> _otherEntityID;
|
dataStream >> _otherID;
|
||||||
dataStream >> _pivotInB;
|
dataStream >> _pivotInB;
|
||||||
|
|
||||||
_active = true;
|
_active = true;
|
||||||
|
|
|
@ -38,8 +38,6 @@ protected:
|
||||||
void updateBallSocket();
|
void updateBallSocket();
|
||||||
|
|
||||||
glm::vec3 _pivotInA;
|
glm::vec3 _pivotInA;
|
||||||
|
|
||||||
EntityItemID _otherEntityID;
|
|
||||||
glm::vec3 _pivotInB;
|
glm::vec3 _pivotInB;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,14 @@
|
||||||
#include "ObjectConstraintConeTwist.h"
|
#include "ObjectConstraintConeTwist.h"
|
||||||
#include "PhysicsLogging.h"
|
#include "PhysicsLogging.h"
|
||||||
|
|
||||||
|
const uint16_t CONE_TWIST_VERSION_WITH_UNUSED_PAREMETERS = 1;
|
||||||
const uint16_t ObjectConstraintConeTwist::constraintVersion = 1;
|
const uint16_t ObjectConstraintConeTwist::constraintVersion = 2;
|
||||||
|
const glm::vec3 DEFAULT_CONE_TWIST_AXIS(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
ObjectConstraintConeTwist::ObjectConstraintConeTwist(const QUuid& id, EntityItemPointer ownerEntity) :
|
ObjectConstraintConeTwist::ObjectConstraintConeTwist(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectConstraint(DYNAMIC_TYPE_CONE_TWIST, id, ownerEntity),
|
ObjectConstraint(DYNAMIC_TYPE_CONE_TWIST, id, ownerEntity),
|
||||||
_pivotInA(glm::vec3(0.0f)),
|
_axisInA(DEFAULT_CONE_TWIST_AXIS),
|
||||||
_axisInA(glm::vec3(0.0f))
|
_axisInB(DEFAULT_CONE_TWIST_AXIS)
|
||||||
{
|
{
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qCDebug(physics) << "ObjectConstraintConeTwist::ObjectConstraintConeTwist";
|
qCDebug(physics) << "ObjectConstraintConeTwist::ObjectConstraintConeTwist";
|
||||||
|
@ -40,7 +40,7 @@ QList<btRigidBody*> ObjectConstraintConeTwist::getRigidBodies() {
|
||||||
result += getRigidBody();
|
result += getRigidBody();
|
||||||
QUuid otherEntityID;
|
QUuid otherEntityID;
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
});
|
});
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
result += getOtherRigidBody(otherEntityID);
|
result += getOtherRigidBody(otherEntityID);
|
||||||
|
@ -56,18 +56,12 @@ void ObjectConstraintConeTwist::updateConeTwist() {
|
||||||
float swingSpan1;
|
float swingSpan1;
|
||||||
float swingSpan2;
|
float swingSpan2;
|
||||||
float twistSpan;
|
float twistSpan;
|
||||||
float softness;
|
|
||||||
float biasFactor;
|
|
||||||
float relaxationFactor;
|
|
||||||
|
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
constraint = static_cast<btConeTwistConstraint*>(_constraint);
|
constraint = static_cast<btConeTwistConstraint*>(_constraint);
|
||||||
swingSpan1 = _swingSpan1;
|
swingSpan1 = _swingSpan1;
|
||||||
swingSpan2 = _swingSpan2;
|
swingSpan2 = _swingSpan2;
|
||||||
twistSpan = _twistSpan;
|
twistSpan = _twistSpan;
|
||||||
softness = _softness;
|
|
||||||
biasFactor = _biasFactor;
|
|
||||||
relaxationFactor = _relaxationFactor;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!constraint) {
|
if (!constraint) {
|
||||||
|
@ -76,10 +70,7 @@ void ObjectConstraintConeTwist::updateConeTwist() {
|
||||||
|
|
||||||
constraint->setLimit(swingSpan1,
|
constraint->setLimit(swingSpan1,
|
||||||
swingSpan2,
|
swingSpan2,
|
||||||
twistSpan,
|
twistSpan);
|
||||||
softness,
|
|
||||||
biasFactor,
|
|
||||||
relaxationFactor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +86,7 @@ btTypedConstraint* ObjectConstraintConeTwist::getConstraint() {
|
||||||
constraint = static_cast<btConeTwistConstraint*>(_constraint);
|
constraint = static_cast<btConeTwistConstraint*>(_constraint);
|
||||||
pivotInA = _pivotInA;
|
pivotInA = _pivotInA;
|
||||||
axisInA = _axisInA;
|
axisInA = _axisInA;
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
pivotInB = _pivotInB;
|
pivotInB = _pivotInB;
|
||||||
axisInB = _axisInB;
|
axisInB = _axisInB;
|
||||||
});
|
});
|
||||||
|
@ -109,11 +100,25 @@ btTypedConstraint* ObjectConstraintConeTwist::getConstraint() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glm::length(axisInA) < FLT_EPSILON) {
|
||||||
|
qCWarning(physics) << "cone-twist axis cannot be a zero vector";
|
||||||
|
axisInA = DEFAULT_CONE_TWIST_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInA = glm::normalize(axisInA);
|
||||||
|
}
|
||||||
|
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
// This coneTwist is between two entities... find the other rigid body.
|
// This coneTwist is between two entities... find the other rigid body.
|
||||||
|
|
||||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
if (glm::length(axisInB) < FLT_EPSILON) {
|
||||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInB));
|
qCWarning(physics) << "cone-twist axis cannot be a zero vector";
|
||||||
|
axisInB = DEFAULT_CONE_TWIST_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInB = glm::normalize(axisInB);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat rotA = glm::rotation(DEFAULT_CONE_TWIST_AXIS, axisInA);
|
||||||
|
glm::quat rotB = glm::rotation(DEFAULT_CONE_TWIST_AXIS, axisInB);
|
||||||
|
|
||||||
btTransform frameInA(glmToBullet(rotA), glmToBullet(pivotInA));
|
btTransform frameInA(glmToBullet(rotA), glmToBullet(pivotInA));
|
||||||
btTransform frameInB(glmToBullet(rotB), glmToBullet(pivotInB));
|
btTransform frameInB(glmToBullet(rotB), glmToBullet(pivotInB));
|
||||||
|
@ -127,7 +132,7 @@ btTypedConstraint* ObjectConstraintConeTwist::getConstraint() {
|
||||||
} else {
|
} else {
|
||||||
// This coneTwist is between an entity and the world-frame.
|
// This coneTwist is between an entity and the world-frame.
|
||||||
|
|
||||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
glm::quat rot = glm::rotation(DEFAULT_CONE_TWIST_AXIS, axisInA);
|
||||||
|
|
||||||
btTransform frameInA(glmToBullet(rot), glmToBullet(pivotInA));
|
btTransform frameInA(glmToBullet(rot), glmToBullet(pivotInA));
|
||||||
|
|
||||||
|
@ -157,9 +162,6 @@ bool ObjectConstraintConeTwist::updateArguments(QVariantMap arguments) {
|
||||||
float swingSpan1;
|
float swingSpan1;
|
||||||
float swingSpan2;
|
float swingSpan2;
|
||||||
float twistSpan;
|
float twistSpan;
|
||||||
float softness;
|
|
||||||
float biasFactor;
|
|
||||||
float relaxationFactor;
|
|
||||||
|
|
||||||
bool needUpdate = false;
|
bool needUpdate = false;
|
||||||
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
|
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
|
||||||
|
@ -180,7 +182,7 @@ bool ObjectConstraintConeTwist::updateArguments(QVariantMap arguments) {
|
||||||
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("coneTwist constraint",
|
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("coneTwist constraint",
|
||||||
arguments, "otherEntityID", ok, false));
|
arguments, "otherEntityID", ok, false));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -213,37 +215,15 @@ bool ObjectConstraintConeTwist::updateArguments(QVariantMap arguments) {
|
||||||
twistSpan = _twistSpan;
|
twistSpan = _twistSpan;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
|
||||||
softness = EntityDynamicInterface::extractFloatArgument("coneTwist constraint", arguments, "softness", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
softness = _softness;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = true;
|
|
||||||
biasFactor = EntityDynamicInterface::extractFloatArgument("coneTwist constraint", arguments, "biasFactor", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
biasFactor = _biasFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = true;
|
|
||||||
relaxationFactor =
|
|
||||||
EntityDynamicInterface::extractFloatArgument("coneTwist constraint", arguments, "relaxationFactor", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
relaxationFactor = _relaxationFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (somethingChanged ||
|
if (somethingChanged ||
|
||||||
pivotInA != _pivotInA ||
|
pivotInA != _pivotInA ||
|
||||||
axisInA != _axisInA ||
|
axisInA != _axisInA ||
|
||||||
otherEntityID != _otherEntityID ||
|
otherEntityID != _otherID ||
|
||||||
pivotInB != _pivotInB ||
|
pivotInB != _pivotInB ||
|
||||||
axisInB != _axisInB ||
|
axisInB != _axisInB ||
|
||||||
swingSpan1 != _swingSpan1 ||
|
swingSpan1 != _swingSpan1 ||
|
||||||
swingSpan2 != _swingSpan2 ||
|
swingSpan2 != _swingSpan2 ||
|
||||||
twistSpan != _twistSpan ||
|
twistSpan != _twistSpan) {
|
||||||
softness != _softness ||
|
|
||||||
biasFactor != _biasFactor ||
|
|
||||||
relaxationFactor != _relaxationFactor) {
|
|
||||||
// something changed
|
// something changed
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -253,15 +233,12 @@ bool ObjectConstraintConeTwist::updateArguments(QVariantMap arguments) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_pivotInA = pivotInA;
|
_pivotInA = pivotInA;
|
||||||
_axisInA = axisInA;
|
_axisInA = axisInA;
|
||||||
_otherEntityID = otherEntityID;
|
_otherID = otherEntityID;
|
||||||
_pivotInB = pivotInB;
|
_pivotInB = pivotInB;
|
||||||
_axisInB = axisInB;
|
_axisInB = axisInB;
|
||||||
_swingSpan1 = swingSpan1;
|
_swingSpan1 = swingSpan1;
|
||||||
_swingSpan2 = swingSpan2;
|
_swingSpan2 = swingSpan2;
|
||||||
_twistSpan = twistSpan;
|
_twistSpan = twistSpan;
|
||||||
_softness = softness;
|
|
||||||
_biasFactor = biasFactor;
|
|
||||||
_relaxationFactor = relaxationFactor;
|
|
||||||
|
|
||||||
_active = true;
|
_active = true;
|
||||||
|
|
||||||
|
@ -281,19 +258,14 @@ bool ObjectConstraintConeTwist::updateArguments(QVariantMap arguments) {
|
||||||
QVariantMap ObjectConstraintConeTwist::getArguments() {
|
QVariantMap ObjectConstraintConeTwist::getArguments() {
|
||||||
QVariantMap arguments = ObjectDynamic::getArguments();
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
if (_constraint) {
|
arguments["pivot"] = glmToQMap(_pivotInA);
|
||||||
arguments["pivot"] = glmToQMap(_pivotInA);
|
arguments["axis"] = glmToQMap(_axisInA);
|
||||||
arguments["axis"] = glmToQMap(_axisInA);
|
arguments["otherEntityID"] = _otherID;
|
||||||
arguments["otherEntityID"] = _otherEntityID;
|
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
||||||
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
arguments["otherAxis"] = glmToQMap(_axisInB);
|
||||||
arguments["otherAxis"] = glmToQMap(_axisInB);
|
arguments["swingSpan1"] = _swingSpan1;
|
||||||
arguments["swingSpan1"] = _swingSpan1;
|
arguments["swingSpan2"] = _swingSpan2;
|
||||||
arguments["swingSpan2"] = _swingSpan2;
|
arguments["twistSpan"] = _twistSpan;
|
||||||
arguments["twistSpan"] = _twistSpan;
|
|
||||||
arguments["softness"] = _softness;
|
|
||||||
arguments["biasFactor"] = _biasFactor;
|
|
||||||
arguments["relaxationFactor"] = _relaxationFactor;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
@ -312,15 +284,12 @@ QByteArray ObjectConstraintConeTwist::serialize() const {
|
||||||
|
|
||||||
dataStream << _pivotInA;
|
dataStream << _pivotInA;
|
||||||
dataStream << _axisInA;
|
dataStream << _axisInA;
|
||||||
dataStream << _otherEntityID;
|
dataStream << _otherID;
|
||||||
dataStream << _pivotInB;
|
dataStream << _pivotInB;
|
||||||
dataStream << _axisInB;
|
dataStream << _axisInB;
|
||||||
dataStream << _swingSpan1;
|
dataStream << _swingSpan1;
|
||||||
dataStream << _swingSpan2;
|
dataStream << _swingSpan2;
|
||||||
dataStream << _twistSpan;
|
dataStream << _twistSpan;
|
||||||
dataStream << _softness;
|
|
||||||
dataStream << _biasFactor;
|
|
||||||
dataStream << _relaxationFactor;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return serializedConstraintArguments;
|
return serializedConstraintArguments;
|
||||||
|
@ -339,7 +308,7 @@ void ObjectConstraintConeTwist::deserialize(QByteArray serializedArguments) {
|
||||||
|
|
||||||
uint16_t serializationVersion;
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectConstraintConeTwist::constraintVersion) {
|
if (serializationVersion > ObjectConstraintConeTwist::constraintVersion) {
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -352,15 +321,18 @@ void ObjectConstraintConeTwist::deserialize(QByteArray serializedArguments) {
|
||||||
|
|
||||||
dataStream >> _pivotInA;
|
dataStream >> _pivotInA;
|
||||||
dataStream >> _axisInA;
|
dataStream >> _axisInA;
|
||||||
dataStream >> _otherEntityID;
|
dataStream >> _otherID;
|
||||||
dataStream >> _pivotInB;
|
dataStream >> _pivotInB;
|
||||||
dataStream >> _axisInB;
|
dataStream >> _axisInB;
|
||||||
dataStream >> _swingSpan1;
|
dataStream >> _swingSpan1;
|
||||||
dataStream >> _swingSpan2;
|
dataStream >> _swingSpan2;
|
||||||
dataStream >> _twistSpan;
|
dataStream >> _twistSpan;
|
||||||
dataStream >> _softness;
|
if (serializationVersion == CONE_TWIST_VERSION_WITH_UNUSED_PAREMETERS) {
|
||||||
dataStream >> _biasFactor;
|
float softness, biasFactor, relaxationFactor;
|
||||||
dataStream >> _relaxationFactor;
|
dataStream >> softness;
|
||||||
|
dataStream >> biasFactor;
|
||||||
|
dataStream >> relaxationFactor;
|
||||||
|
}
|
||||||
|
|
||||||
_active = true;
|
_active = true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,16 +40,12 @@ protected:
|
||||||
glm::vec3 _pivotInA;
|
glm::vec3 _pivotInA;
|
||||||
glm::vec3 _axisInA;
|
glm::vec3 _axisInA;
|
||||||
|
|
||||||
EntityItemID _otherEntityID;
|
|
||||||
glm::vec3 _pivotInB;
|
glm::vec3 _pivotInB;
|
||||||
glm::vec3 _axisInB;
|
glm::vec3 _axisInB;
|
||||||
|
|
||||||
float _swingSpan1 { TWO_PI };
|
float _swingSpan1 { TWO_PI };
|
||||||
float _swingSpan2 { TWO_PI };;
|
float _swingSpan2 { TWO_PI };;
|
||||||
float _twistSpan { TWO_PI };;
|
float _twistSpan { TWO_PI };;
|
||||||
float _softness { 1.0f };
|
|
||||||
float _biasFactor {0.3f };
|
|
||||||
float _relaxationFactor { 1.0f };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectConstraintConeTwist_h
|
#endif // hifi_ObjectConstraintConeTwist_h
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
#include "PhysicsLogging.h"
|
#include "PhysicsLogging.h"
|
||||||
|
|
||||||
|
|
||||||
const uint16_t ObjectConstraintHinge::constraintVersion = 1;
|
const uint16_t HINGE_VERSION_WITH_UNUSED_PAREMETERS = 1;
|
||||||
|
const uint16_t ObjectConstraintHinge::constraintVersion = 2;
|
||||||
const glm::vec3 DEFAULT_HINGE_AXIS(1.0f, 0.0f, 0.0f);
|
const glm::vec3 DEFAULT_HINGE_AXIS(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
ObjectConstraintHinge::ObjectConstraintHinge(const QUuid& id, EntityItemPointer ownerEntity) :
|
ObjectConstraintHinge::ObjectConstraintHinge(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
|
@ -40,7 +41,7 @@ QList<btRigidBody*> ObjectConstraintHinge::getRigidBodies() {
|
||||||
result += getRigidBody();
|
result += getRigidBody();
|
||||||
QUuid otherEntityID;
|
QUuid otherEntityID;
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
});
|
});
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
result += getOtherRigidBody(otherEntityID);
|
result += getOtherRigidBody(otherEntityID);
|
||||||
|
@ -56,25 +57,19 @@ void ObjectConstraintHinge::updateHinge() {
|
||||||
glm::vec3 axisInA;
|
glm::vec3 axisInA;
|
||||||
float low;
|
float low;
|
||||||
float high;
|
float high;
|
||||||
float softness;
|
|
||||||
float biasFactor;
|
|
||||||
float relaxationFactor;
|
|
||||||
|
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
axisInA = _axisInA;
|
axisInA = _axisInA;
|
||||||
constraint = static_cast<btHingeConstraint*>(_constraint);
|
constraint = static_cast<btHingeConstraint*>(_constraint);
|
||||||
low = _low;
|
low = _low;
|
||||||
high = _high;
|
high = _high;
|
||||||
biasFactor = _biasFactor;
|
|
||||||
relaxationFactor = _relaxationFactor;
|
|
||||||
softness = _softness;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!constraint) {
|
if (!constraint) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
constraint->setLimit(low, high, softness, biasFactor, relaxationFactor);
|
constraint->setLimit(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,7 +85,7 @@ btTypedConstraint* ObjectConstraintHinge::getConstraint() {
|
||||||
constraint = static_cast<btHingeConstraint*>(_constraint);
|
constraint = static_cast<btHingeConstraint*>(_constraint);
|
||||||
pivotInA = _pivotInA;
|
pivotInA = _pivotInA;
|
||||||
axisInA = _axisInA;
|
axisInA = _axisInA;
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
pivotInB = _pivotInB;
|
pivotInB = _pivotInB;
|
||||||
axisInB = _axisInB;
|
axisInB = _axisInB;
|
||||||
});
|
});
|
||||||
|
@ -159,9 +154,6 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
glm::vec3 axisInB;
|
glm::vec3 axisInB;
|
||||||
float low;
|
float low;
|
||||||
float high;
|
float high;
|
||||||
float softness;
|
|
||||||
float biasFactor;
|
|
||||||
float relaxationFactor;
|
|
||||||
|
|
||||||
bool needUpdate = false;
|
bool needUpdate = false;
|
||||||
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
|
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
|
||||||
|
@ -182,7 +174,7 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("hinge constraint",
|
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("hinge constraint",
|
||||||
arguments, "otherEntityID", ok, false));
|
arguments, "otherEntityID", ok, false));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -209,36 +201,14 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
high = _high;
|
high = _high;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
|
||||||
softness = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments, "softness", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
softness = _softness;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = true;
|
|
||||||
biasFactor = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments, "biasFactor", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
biasFactor = _biasFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = true;
|
|
||||||
relaxationFactor = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments,
|
|
||||||
"relaxationFactor", ok, false);
|
|
||||||
if (!ok) {
|
|
||||||
relaxationFactor = _relaxationFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (somethingChanged ||
|
if (somethingChanged ||
|
||||||
pivotInA != _pivotInA ||
|
pivotInA != _pivotInA ||
|
||||||
axisInA != _axisInA ||
|
axisInA != _axisInA ||
|
||||||
otherEntityID != _otherEntityID ||
|
otherEntityID != _otherID ||
|
||||||
pivotInB != _pivotInB ||
|
pivotInB != _pivotInB ||
|
||||||
axisInB != _axisInB ||
|
axisInB != _axisInB ||
|
||||||
low != _low ||
|
low != _low ||
|
||||||
high != _high ||
|
high != _high) {
|
||||||
softness != _softness ||
|
|
||||||
biasFactor != _biasFactor ||
|
|
||||||
relaxationFactor != _relaxationFactor) {
|
|
||||||
// something changed
|
// something changed
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -248,14 +218,11 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_pivotInA = pivotInA;
|
_pivotInA = pivotInA;
|
||||||
_axisInA = axisInA;
|
_axisInA = axisInA;
|
||||||
_otherEntityID = otherEntityID;
|
_otherID = otherEntityID;
|
||||||
_pivotInB = pivotInB;
|
_pivotInB = pivotInB;
|
||||||
_axisInB = axisInB;
|
_axisInB = axisInB;
|
||||||
_low = low;
|
_low = low;
|
||||||
_high = high;
|
_high = high;
|
||||||
_softness = softness;
|
|
||||||
_biasFactor = biasFactor;
|
|
||||||
_relaxationFactor = relaxationFactor;
|
|
||||||
|
|
||||||
_active = true;
|
_active = true;
|
||||||
|
|
||||||
|
@ -275,18 +242,17 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
|
||||||
QVariantMap ObjectConstraintHinge::getArguments() {
|
QVariantMap ObjectConstraintHinge::getArguments() {
|
||||||
QVariantMap arguments = ObjectDynamic::getArguments();
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
|
arguments["pivot"] = glmToQMap(_pivotInA);
|
||||||
|
arguments["axis"] = glmToQMap(_axisInA);
|
||||||
|
arguments["otherEntityID"] = _otherID;
|
||||||
|
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
||||||
|
arguments["otherAxis"] = glmToQMap(_axisInB);
|
||||||
|
arguments["low"] = _low;
|
||||||
|
arguments["high"] = _high;
|
||||||
if (_constraint) {
|
if (_constraint) {
|
||||||
arguments["pivot"] = glmToQMap(_pivotInA);
|
|
||||||
arguments["axis"] = glmToQMap(_axisInA);
|
|
||||||
arguments["otherEntityID"] = _otherEntityID;
|
|
||||||
arguments["otherPivot"] = glmToQMap(_pivotInB);
|
|
||||||
arguments["otherAxis"] = glmToQMap(_axisInB);
|
|
||||||
arguments["low"] = _low;
|
|
||||||
arguments["high"] = _high;
|
|
||||||
arguments["softness"] = _softness;
|
|
||||||
arguments["biasFactor"] = _biasFactor;
|
|
||||||
arguments["relaxationFactor"] = _relaxationFactor;
|
|
||||||
arguments["angle"] = static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(); // [-PI,PI]
|
arguments["angle"] = static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(); // [-PI,PI]
|
||||||
|
} else {
|
||||||
|
arguments["angle"] = 0.0f;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return arguments;
|
return arguments;
|
||||||
|
@ -303,14 +269,11 @@ QByteArray ObjectConstraintHinge::serialize() const {
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
dataStream << _pivotInA;
|
dataStream << _pivotInA;
|
||||||
dataStream << _axisInA;
|
dataStream << _axisInA;
|
||||||
dataStream << _otherEntityID;
|
dataStream << _otherID;
|
||||||
dataStream << _pivotInB;
|
dataStream << _pivotInB;
|
||||||
dataStream << _axisInB;
|
dataStream << _axisInB;
|
||||||
dataStream << _low;
|
dataStream << _low;
|
||||||
dataStream << _high;
|
dataStream << _high;
|
||||||
dataStream << _softness;
|
|
||||||
dataStream << _biasFactor;
|
|
||||||
dataStream << _relaxationFactor;
|
|
||||||
|
|
||||||
dataStream << localTimeToServerTime(_expires);
|
dataStream << localTimeToServerTime(_expires);
|
||||||
dataStream << _tag;
|
dataStream << _tag;
|
||||||
|
@ -332,7 +295,7 @@ void ObjectConstraintHinge::deserialize(QByteArray serializedArguments) {
|
||||||
|
|
||||||
uint16_t serializationVersion;
|
uint16_t serializationVersion;
|
||||||
dataStream >> serializationVersion;
|
dataStream >> serializationVersion;
|
||||||
if (serializationVersion != ObjectConstraintHinge::constraintVersion) {
|
if (serializationVersion > ObjectConstraintHinge::constraintVersion) {
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -340,14 +303,17 @@ void ObjectConstraintHinge::deserialize(QByteArray serializedArguments) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
dataStream >> _pivotInA;
|
dataStream >> _pivotInA;
|
||||||
dataStream >> _axisInA;
|
dataStream >> _axisInA;
|
||||||
dataStream >> _otherEntityID;
|
dataStream >> _otherID;
|
||||||
dataStream >> _pivotInB;
|
dataStream >> _pivotInB;
|
||||||
dataStream >> _axisInB;
|
dataStream >> _axisInB;
|
||||||
dataStream >> _low;
|
dataStream >> _low;
|
||||||
dataStream >> _high;
|
dataStream >> _high;
|
||||||
dataStream >> _softness;
|
if (serializationVersion == HINGE_VERSION_WITH_UNUSED_PAREMETERS) {
|
||||||
dataStream >> _biasFactor;
|
float softness, biasFactor, relaxationFactor;
|
||||||
dataStream >> _relaxationFactor;
|
dataStream >> softness;
|
||||||
|
dataStream >> biasFactor;
|
||||||
|
dataStream >> relaxationFactor;
|
||||||
|
}
|
||||||
|
|
||||||
quint64 serverExpires;
|
quint64 serverExpires;
|
||||||
dataStream >> serverExpires;
|
dataStream >> serverExpires;
|
||||||
|
|
|
@ -40,7 +40,6 @@ protected:
|
||||||
glm::vec3 _pivotInA;
|
glm::vec3 _pivotInA;
|
||||||
glm::vec3 _axisInA;
|
glm::vec3 _axisInA;
|
||||||
|
|
||||||
EntityItemID _otherEntityID;
|
|
||||||
glm::vec3 _pivotInB;
|
glm::vec3 _pivotInB;
|
||||||
glm::vec3 _axisInB;
|
glm::vec3 _axisInB;
|
||||||
|
|
||||||
|
@ -49,27 +48,9 @@ protected:
|
||||||
|
|
||||||
// https://gamedev.stackexchange.com/questions/71436/what-are-the-parameters-for-bthingeconstraintsetlimit
|
// https://gamedev.stackexchange.com/questions/71436/what-are-the-parameters-for-bthingeconstraintsetlimit
|
||||||
//
|
//
|
||||||
// softness: a negative measure of the friction that determines how much the hinge rotates for a given force. A high
|
// softness: unused
|
||||||
// softness would make the hinge rotate easily like it's oiled then.
|
// biasFactor: unused
|
||||||
// biasFactor: an offset for the relaxed rotation of the hinge. It won't be right in the middle of the low and high angles
|
// relaxationFactor: unused
|
||||||
// anymore. 1.0f is the neural value.
|
|
||||||
// relaxationFactor: a measure of how much force is applied internally to bring the hinge in its central rotation.
|
|
||||||
// This is right in the middle of the low and high angles. For example, consider a western swing door. After
|
|
||||||
// walking through it will swing in both directions but at the end it stays right in the middle.
|
|
||||||
|
|
||||||
// http://javadoc.jmonkeyengine.org/com/jme3/bullet/joints/HingeJoint.html
|
|
||||||
//
|
|
||||||
// _softness - the factor at which the velocity error correction starts operating, i.e. a softness of 0.9 means that
|
|
||||||
// the vel. corr starts at 90% of the limit range.
|
|
||||||
// _biasFactor - the magnitude of the position correction. It tells you how strictly the position error (drift) is
|
|
||||||
// corrected.
|
|
||||||
// _relaxationFactor - the rate at which velocity errors are corrected. This can be seen as the strength of the
|
|
||||||
// limits. A low value will make the the limits more spongy.
|
|
||||||
|
|
||||||
|
|
||||||
float _softness { 0.9f };
|
|
||||||
float _biasFactor { 0.3f };
|
|
||||||
float _relaxationFactor { 1.0f };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ObjectConstraintHinge_h
|
#endif // hifi_ObjectConstraintHinge_h
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
|
|
||||||
const uint16_t ObjectConstraintSlider::constraintVersion = 1;
|
const uint16_t ObjectConstraintSlider::constraintVersion = 1;
|
||||||
|
const glm::vec3 DEFAULT_SLIDER_AXIS(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
ObjectConstraintSlider::ObjectConstraintSlider(const QUuid& id, EntityItemPointer ownerEntity) :
|
ObjectConstraintSlider::ObjectConstraintSlider(const QUuid& id, EntityItemPointer ownerEntity) :
|
||||||
ObjectConstraint(DYNAMIC_TYPE_SLIDER, id, ownerEntity),
|
ObjectConstraint(DYNAMIC_TYPE_SLIDER, id, ownerEntity),
|
||||||
_pointInA(glm::vec3(0.0f)),
|
_axisInA(DEFAULT_SLIDER_AXIS),
|
||||||
_axisInA(glm::vec3(0.0f))
|
_axisInB(DEFAULT_SLIDER_AXIS)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ QList<btRigidBody*> ObjectConstraintSlider::getRigidBodies() {
|
||||||
result += getRigidBody();
|
result += getRigidBody();
|
||||||
QUuid otherEntityID;
|
QUuid otherEntityID;
|
||||||
withReadLock([&]{
|
withReadLock([&]{
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
});
|
});
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
result += getOtherRigidBody(otherEntityID);
|
result += getOtherRigidBody(otherEntityID);
|
||||||
|
@ -77,7 +77,7 @@ btTypedConstraint* ObjectConstraintSlider::getConstraint() {
|
||||||
constraint = static_cast<btSliderConstraint*>(_constraint);
|
constraint = static_cast<btSliderConstraint*>(_constraint);
|
||||||
pointInA = _pointInA;
|
pointInA = _pointInA;
|
||||||
axisInA = _axisInA;
|
axisInA = _axisInA;
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
pointInB = _pointInB;
|
pointInB = _pointInB;
|
||||||
axisInB = _axisInB;
|
axisInB = _axisInB;
|
||||||
});
|
});
|
||||||
|
@ -91,11 +91,25 @@ btTypedConstraint* ObjectConstraintSlider::getConstraint() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glm::length(axisInA) < FLT_EPSILON) {
|
||||||
|
qCWarning(physics) << "slider axis cannot be a zero vector";
|
||||||
|
axisInA = DEFAULT_SLIDER_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInA = glm::normalize(axisInA);
|
||||||
|
}
|
||||||
|
|
||||||
if (!otherEntityID.isNull()) {
|
if (!otherEntityID.isNull()) {
|
||||||
// This slider is between two entities... find the other rigid body.
|
// This slider is between two entities... find the other rigid body.
|
||||||
|
|
||||||
glm::quat rotA = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
if (glm::length(axisInB) < FLT_EPSILON) {
|
||||||
glm::quat rotB = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInB));
|
qCWarning(physics) << "slider axis cannot be a zero vector";
|
||||||
|
axisInB = DEFAULT_SLIDER_AXIS;
|
||||||
|
} else {
|
||||||
|
axisInB = glm::normalize(axisInB);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat rotA = glm::rotation(DEFAULT_SLIDER_AXIS, axisInA);
|
||||||
|
glm::quat rotB = glm::rotation(DEFAULT_SLIDER_AXIS, axisInB);
|
||||||
|
|
||||||
btTransform frameInA(glmToBullet(rotA), glmToBullet(pointInA));
|
btTransform frameInA(glmToBullet(rotA), glmToBullet(pointInA));
|
||||||
btTransform frameInB(glmToBullet(rotB), glmToBullet(pointInB));
|
btTransform frameInB(glmToBullet(rotB), glmToBullet(pointInB));
|
||||||
|
@ -109,7 +123,7 @@ btTypedConstraint* ObjectConstraintSlider::getConstraint() {
|
||||||
} else {
|
} else {
|
||||||
// This slider is between an entity and the world-frame.
|
// This slider is between an entity and the world-frame.
|
||||||
|
|
||||||
glm::quat rot = glm::rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::normalize(axisInA));
|
glm::quat rot = glm::rotation(DEFAULT_SLIDER_AXIS, axisInA);
|
||||||
|
|
||||||
btTransform frameInA(glmToBullet(rot), glmToBullet(pointInA));
|
btTransform frameInA(glmToBullet(rot), glmToBullet(pointInA));
|
||||||
|
|
||||||
|
@ -160,7 +174,7 @@ bool ObjectConstraintSlider::updateArguments(QVariantMap arguments) {
|
||||||
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("slider constraint",
|
otherEntityID = QUuid(EntityDynamicInterface::extractStringArgument("slider constraint",
|
||||||
arguments, "otherEntityID", ok, false));
|
arguments, "otherEntityID", ok, false));
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
otherEntityID = _otherEntityID;
|
otherEntityID = _otherID;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
|
@ -202,7 +216,7 @@ bool ObjectConstraintSlider::updateArguments(QVariantMap arguments) {
|
||||||
if (somethingChanged ||
|
if (somethingChanged ||
|
||||||
pointInA != _pointInA ||
|
pointInA != _pointInA ||
|
||||||
axisInA != _axisInA ||
|
axisInA != _axisInA ||
|
||||||
otherEntityID != _otherEntityID ||
|
otherEntityID != _otherID ||
|
||||||
pointInB != _pointInB ||
|
pointInB != _pointInB ||
|
||||||
axisInB != _axisInB ||
|
axisInB != _axisInB ||
|
||||||
linearLow != _linearLow ||
|
linearLow != _linearLow ||
|
||||||
|
@ -218,7 +232,7 @@ bool ObjectConstraintSlider::updateArguments(QVariantMap arguments) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_pointInA = pointInA;
|
_pointInA = pointInA;
|
||||||
_axisInA = axisInA;
|
_axisInA = axisInA;
|
||||||
_otherEntityID = otherEntityID;
|
_otherID = otherEntityID;
|
||||||
_pointInB = pointInB;
|
_pointInB = pointInB;
|
||||||
_axisInB = axisInB;
|
_axisInB = axisInB;
|
||||||
_linearLow = linearLow;
|
_linearLow = linearLow;
|
||||||
|
@ -244,18 +258,21 @@ bool ObjectConstraintSlider::updateArguments(QVariantMap arguments) {
|
||||||
QVariantMap ObjectConstraintSlider::getArguments() {
|
QVariantMap ObjectConstraintSlider::getArguments() {
|
||||||
QVariantMap arguments = ObjectDynamic::getArguments();
|
QVariantMap arguments = ObjectDynamic::getArguments();
|
||||||
withReadLock([&] {
|
withReadLock([&] {
|
||||||
|
arguments["point"] = glmToQMap(_pointInA);
|
||||||
|
arguments["axis"] = glmToQMap(_axisInA);
|
||||||
|
arguments["otherEntityID"] = _otherID;
|
||||||
|
arguments["otherPoint"] = glmToQMap(_pointInB);
|
||||||
|
arguments["otherAxis"] = glmToQMap(_axisInB);
|
||||||
|
arguments["linearLow"] = _linearLow;
|
||||||
|
arguments["linearHigh"] = _linearHigh;
|
||||||
|
arguments["angularLow"] = _angularLow;
|
||||||
|
arguments["angularHigh"] = _angularHigh;
|
||||||
if (_constraint) {
|
if (_constraint) {
|
||||||
arguments["point"] = glmToQMap(_pointInA);
|
|
||||||
arguments["axis"] = glmToQMap(_axisInA);
|
|
||||||
arguments["otherEntityID"] = _otherEntityID;
|
|
||||||
arguments["otherPoint"] = glmToQMap(_pointInB);
|
|
||||||
arguments["otherAxis"] = glmToQMap(_axisInB);
|
|
||||||
arguments["linearLow"] = _linearLow;
|
|
||||||
arguments["linearHigh"] = _linearHigh;
|
|
||||||
arguments["angularLow"] = _angularLow;
|
|
||||||
arguments["angularHigh"] = _angularHigh;
|
|
||||||
arguments["linearPosition"] = static_cast<btSliderConstraint*>(_constraint)->getLinearPos();
|
arguments["linearPosition"] = static_cast<btSliderConstraint*>(_constraint)->getLinearPos();
|
||||||
arguments["angularPosition"] = static_cast<btSliderConstraint*>(_constraint)->getAngularPos();
|
arguments["angularPosition"] = static_cast<btSliderConstraint*>(_constraint)->getAngularPos();
|
||||||
|
} else {
|
||||||
|
arguments["linearPosition"] = 0.0f;
|
||||||
|
arguments["angularPosition"] = 0.0f;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return arguments;
|
return arguments;
|
||||||
|
@ -275,7 +292,7 @@ QByteArray ObjectConstraintSlider::serialize() const {
|
||||||
|
|
||||||
dataStream << _pointInA;
|
dataStream << _pointInA;
|
||||||
dataStream << _axisInA;
|
dataStream << _axisInA;
|
||||||
dataStream << _otherEntityID;
|
dataStream << _otherID;
|
||||||
dataStream << _pointInB;
|
dataStream << _pointInB;
|
||||||
dataStream << _axisInB;
|
dataStream << _axisInB;
|
||||||
dataStream << _linearLow;
|
dataStream << _linearLow;
|
||||||
|
@ -313,7 +330,7 @@ void ObjectConstraintSlider::deserialize(QByteArray serializedArguments) {
|
||||||
|
|
||||||
dataStream >> _pointInA;
|
dataStream >> _pointInA;
|
||||||
dataStream >> _axisInA;
|
dataStream >> _axisInA;
|
||||||
dataStream >> _otherEntityID;
|
dataStream >> _otherID;
|
||||||
dataStream >> _pointInB;
|
dataStream >> _pointInB;
|
||||||
dataStream >> _axisInB;
|
dataStream >> _axisInB;
|
||||||
dataStream >> _linearLow;
|
dataStream >> _linearLow;
|
||||||
|
|
|
@ -40,7 +40,6 @@ protected:
|
||||||
glm::vec3 _pointInA;
|
glm::vec3 _pointInA;
|
||||||
glm::vec3 _axisInA;
|
glm::vec3 _axisInA;
|
||||||
|
|
||||||
EntityItemID _otherEntityID;
|
|
||||||
glm::vec3 _pointInB;
|
glm::vec3 _pointInB;
|
||||||
glm::vec3 _axisInB;
|
glm::vec3 _axisInB;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,27 @@ ObjectDynamic::ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItem
|
||||||
ObjectDynamic::~ObjectDynamic() {
|
ObjectDynamic::~ObjectDynamic() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectDynamic::remapIDs(QHash<EntityItemID, EntityItemID>& map) {
|
||||||
|
withWriteLock([&]{
|
||||||
|
if (!_id.isNull()) {
|
||||||
|
// just force our ID to something new -- action IDs don't go into the map
|
||||||
|
_id = QUuid::createUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_otherID.isNull()) {
|
||||||
|
QHash<EntityItemID, EntityItemID>::iterator iter = map.find(_otherID);
|
||||||
|
if (iter == map.end()) {
|
||||||
|
// not found, add it
|
||||||
|
QUuid oldOtherID = _otherID;
|
||||||
|
_otherID = QUuid::createUuid();
|
||||||
|
map.insert(oldOtherID, _otherID);
|
||||||
|
} else {
|
||||||
|
_otherID = iter.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
qint64 ObjectDynamic::getEntityServerClockSkew() const {
|
qint64 ObjectDynamic::getEntityServerClockSkew() const {
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
||||||
|
@ -274,3 +295,38 @@ QList<btRigidBody*> ObjectDynamic::getRigidBodies() {
|
||||||
result += getRigidBody();
|
result += getRigidBody();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpatiallyNestablePointer ObjectDynamic::getOther() {
|
||||||
|
SpatiallyNestablePointer other;
|
||||||
|
withWriteLock([&]{
|
||||||
|
if (_otherID == QUuid()) {
|
||||||
|
// no other
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
other = _other.lock();
|
||||||
|
if (other && other->getID() == _otherID) {
|
||||||
|
// other is already up-to-date
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other) {
|
||||||
|
// we have a pointer to other, but it's wrong
|
||||||
|
other.reset();
|
||||||
|
_other.reset();
|
||||||
|
}
|
||||||
|
// we have an other-id but no pointer to other cached
|
||||||
|
QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
|
||||||
|
if (!parentFinder) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityItemPointer ownerEntity = _ownerEntity.lock();
|
||||||
|
if (!ownerEntity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool success;
|
||||||
|
_other = parentFinder->find(_otherID, success, ownerEntity->getParentTree());
|
||||||
|
if (success) {
|
||||||
|
other = _other.lock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
virtual ~ObjectDynamic();
|
virtual ~ObjectDynamic();
|
||||||
|
|
||||||
|
virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) override;
|
||||||
|
|
||||||
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
|
||||||
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
|
||||||
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; }
|
virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override { _ownerEntity = ownerEntity; }
|
||||||
|
@ -67,6 +69,10 @@ protected:
|
||||||
QString _tag;
|
QString _tag;
|
||||||
quint64 _expires { 0 }; // in seconds since epoch
|
quint64 _expires { 0 }; // in seconds since epoch
|
||||||
|
|
||||||
|
EntityItemID _otherID;
|
||||||
|
SpatiallyNestableWeakPointer _other;
|
||||||
|
SpatiallyNestablePointer getOther();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qint64 getEntityServerClockSkew() const;
|
qint64 getEntityServerClockSkew() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1046,7 +1046,8 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||||
//virtual
|
//virtual
|
||||||
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
void Model::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||||
_needsUpdateClusterMatrices = true;
|
_needsUpdateClusterMatrices = true;
|
||||||
_rig->updateAnimations(deltaTime, parentTransform);
|
glm::mat4 rigToWorldTransform = createMatFromQuatAndPos(getRotation(), getTranslation());
|
||||||
|
_rig->updateAnimations(deltaTime, parentTransform, rigToWorldTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::computeMeshPartLocalBounds() {
|
void Model::computeMeshPartLocalBounds() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ Q_LOGGING_CATEGORY(trace_simulation_physics_detail, "trace.simulation.physics.de
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool tracingEnabled() {
|
static bool tracingEnabled() {
|
||||||
return DependencyManager::get<tracing::Tracer>()->isEnabled();
|
return DependencyManager::isSet<tracing::Tracer>() && DependencyManager::get<tracing::Tracer>()->isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
Duration::Duration(const QLoggingCategory& category, const QString& name, uint32_t argbColor, uint64_t payload, const QVariantMap& baseArgs) : _name(name), _category(category) {
|
Duration::Duration(const QLoggingCategory& category, const QString& name, uint32_t argbColor, uint64_t payload, const QVariantMap& baseArgs) : _name(name), _category(category) {
|
||||||
|
|
|
@ -106,6 +106,10 @@ namespace Setting {
|
||||||
return (_isSet) ? _value : other;
|
return (_isSet) ? _value : other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSet() const {
|
||||||
|
return _isSet;
|
||||||
|
}
|
||||||
|
|
||||||
const T& getDefault() const {
|
const T& getDefault() const {
|
||||||
return _defaultValue;
|
return _defaultValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,16 @@ QJsonDocument variantMapToJsonDocument(const QSettings::SettingsMap& map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (variantType) {
|
switch (variantType) {
|
||||||
case QVariant::Map:
|
case QVariant::Map: {
|
||||||
|
auto varmap = variant.toMap();
|
||||||
|
for (auto mapit = varmap.cbegin(); mapit != varmap.cend(); ++mapit) {
|
||||||
|
auto& mapkey = mapit.key();
|
||||||
|
auto& mapvariant = mapit.value();
|
||||||
|
object.insert(key + "/" + mapkey, QJsonValue::fromVariant(mapvariant));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case QVariant::List:
|
case QVariant::List:
|
||||||
case QVariant::Hash: {
|
case QVariant::Hash: {
|
||||||
qCritical() << "Unsupported variant type" << variant.typeName();
|
qCritical() << "Unsupported variant type" << variant.typeName();
|
||||||
|
|
|
@ -21,7 +21,6 @@ namespace Setting {
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void cleanupSettings();
|
|
||||||
|
|
||||||
class Interface {
|
class Interface {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
|
|
||||||
void addSample(T sample) {
|
void addSample(T sample) {
|
||||||
if (numSamples > 0) {
|
if (numSamples > 0) {
|
||||||
average = (sample * WEIGHTING) + (average * ONE_MINUS_WEIGHTING);
|
average = (sample * (T)WEIGHTING) + (average * (T)ONE_MINUS_WEIGHTING);
|
||||||
} else {
|
} else {
|
||||||
average = sample;
|
average = sample;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ StoragePointer FileStorage::create(const QString& filename, size_t size, const u
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStorage::FileStorage(const QString& filename) : _file(filename) {
|
FileStorage::FileStorage(const QString& filename) : _file(filename) {
|
||||||
if (_file.open(QFile::ReadWrite)) {
|
if (_file.open(QFile::ReadOnly)) {
|
||||||
_mapped = _file.map(0, _file.size());
|
_mapped = _file.map(0, _file.size());
|
||||||
if (_mapped) {
|
if (_mapped) {
|
||||||
_valid = true;
|
_valid = true;
|
||||||
|
@ -90,3 +90,34 @@ FileStorage::~FileStorage() {
|
||||||
_file.close();
|
_file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileStorage::ensureWriteAccess() {
|
||||||
|
if (_hasWriteAccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_mapped) {
|
||||||
|
if (!_file.unmap(_mapped)) {
|
||||||
|
throw std::runtime_error("Unable to unmap file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_file.isOpen()) {
|
||||||
|
_file.close();
|
||||||
|
}
|
||||||
|
_valid = false;
|
||||||
|
_mapped = nullptr;
|
||||||
|
|
||||||
|
if (_file.open(QFile::ReadWrite)) {
|
||||||
|
_mapped = _file.map(0, _file.size());
|
||||||
|
if (_mapped) {
|
||||||
|
_valid = true;
|
||||||
|
_hasWriteAccess = true;
|
||||||
|
} else {
|
||||||
|
qCWarning(storagelogging) << "Failed to map file " << _file.fileName();
|
||||||
|
throw std::runtime_error("Failed to map file");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCWarning(storagelogging) << "Failed to open file " << _file.fileName();
|
||||||
|
throw std::runtime_error("Failed to open file");
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,11 +60,14 @@ namespace storage {
|
||||||
FileStorage& operator=(const FileStorage& other) = delete;
|
FileStorage& operator=(const FileStorage& other) = delete;
|
||||||
|
|
||||||
const uint8_t* data() const override { return _mapped; }
|
const uint8_t* data() const override { return _mapped; }
|
||||||
uint8_t* mutableData() override { return _mapped; }
|
uint8_t* mutableData() override { ensureWriteAccess(); return _mapped; }
|
||||||
size_t size() const override { return _file.size(); }
|
size_t size() const override { return _file.size(); }
|
||||||
operator bool() const override { return _valid; }
|
operator bool() const override { return _valid; }
|
||||||
private:
|
private:
|
||||||
|
void ensureWriteAccess();
|
||||||
|
|
||||||
bool _valid { false };
|
bool _valid { false };
|
||||||
|
bool _hasWriteAccess { false };
|
||||||
QFile _file;
|
QFile _file;
|
||||||
uint8_t* _mapped { nullptr };
|
uint8_t* _mapped { nullptr };
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,13 +29,10 @@
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <controllers/UserInputMapper.h>
|
#include <controllers/UserInputMapper.h>
|
||||||
|
|
||||||
#include <controllers/StandardControls.h>
|
#include <controllers/StandardControls.h>
|
||||||
|
|
||||||
#include "OpenVrHelpers.h"
|
|
||||||
|
|
||||||
extern PoseData _nextSimPoseData;
|
extern PoseData _nextSimPoseData;
|
||||||
|
|
||||||
vr::IVRSystem* acquireOpenVrSystem();
|
vr::IVRSystem* acquireOpenVrSystem();
|
||||||
|
@ -59,6 +56,14 @@ static const int CHEST = 3;
|
||||||
|
|
||||||
const char* ViveControllerManager::NAME { "OpenVR" };
|
const char* ViveControllerManager::NAME { "OpenVR" };
|
||||||
|
|
||||||
|
const std::map<vr::ETrackingResult, QString> TRACKING_RESULT_TO_STRING = {
|
||||||
|
{vr::TrackingResult_Uninitialized, QString("vr::TrackingResult_Uninitialized")},
|
||||||
|
{vr::TrackingResult_Calibrating_InProgress, QString("vr::TrackingResult_Calibrating_InProgess")},
|
||||||
|
{vr::TrackingResult_Calibrating_OutOfRange, QString("TrackingResult_Calibrating_OutOfRange")},
|
||||||
|
{vr::TrackingResult_Running_OK, QString("TrackingResult_Running_Ok")},
|
||||||
|
{vr::TrackingResult_Running_OutOfRange, QString("TrackingResult_Running_OutOfRange")}
|
||||||
|
};
|
||||||
|
|
||||||
static glm::mat4 computeOffset(glm::mat4 defaultToReferenceMat, glm::mat4 defaultJointMat, controller::Pose puckPose) {
|
static glm::mat4 computeOffset(glm::mat4 defaultToReferenceMat, glm::mat4 defaultJointMat, controller::Pose puckPose) {
|
||||||
glm::mat4 poseMat = createMatFromQuatAndPos(puckPose.rotation, puckPose.translation);
|
glm::mat4 poseMat = createMatFromQuatAndPos(puckPose.rotation, puckPose.translation);
|
||||||
glm::mat4 referenceJointMat = defaultToReferenceMat * defaultJointMat;
|
glm::mat4 referenceJointMat = defaultToReferenceMat * defaultJointMat;
|
||||||
|
@ -66,7 +71,17 @@ static glm::mat4 computeOffset(glm::mat4 defaultToReferenceMat, glm::mat4 defaul
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sortPucksYPosition(std::pair<uint32_t, controller::Pose> firstPuck, std::pair<uint32_t, controller::Pose> secondPuck) {
|
static bool sortPucksYPosition(std::pair<uint32_t, controller::Pose> firstPuck, std::pair<uint32_t, controller::Pose> secondPuck) {
|
||||||
return (firstPuck.second.translation.y < firstPuck.second.translation.y);
|
return (firstPuck.second.translation.y < secondPuck.second.translation.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString deviceTrackingResultToString(vr::ETrackingResult trackingResult) {
|
||||||
|
QString result;
|
||||||
|
auto iterator = TRACKING_RESULT_TO_STRING.find(trackingResult);
|
||||||
|
|
||||||
|
if (iterator != TRACKING_RESULT_TO_STRING.end()) {
|
||||||
|
return iterator->second;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViveControllerManager::isSupported() const {
|
bool ViveControllerManager::isSupported() const {
|
||||||
|
@ -147,6 +162,15 @@ void ViveControllerManager::pluginUpdate(float deltaTime, const controller::Inpu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViveControllerManager::InputDevice::InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) {
|
||||||
|
createPreferences();
|
||||||
|
|
||||||
|
_configStringMap[Config::Auto] = QString("Auto");
|
||||||
|
_configStringMap[Config::Feet] = QString("Feet");
|
||||||
|
_configStringMap[Config::FeetAndHips] = QString("FeetAndHips");
|
||||||
|
_configStringMap[Config::FeetHipsAndChest] = QString("FeetHipsAndChest");
|
||||||
|
}
|
||||||
|
|
||||||
void ViveControllerManager::InputDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
void ViveControllerManager::InputDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
_poseStateMap.clear();
|
_poseStateMap.clear();
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
|
@ -209,20 +233,36 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCalibratedLimbs();
|
updateCalibratedLimbs();
|
||||||
|
_lastSimPoseData = _nextSimPoseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) {
|
void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
uint32_t poseIndex = controller::TRACKED_OBJECT_00 + deviceIndex;
|
uint32_t poseIndex = controller::TRACKED_OBJECT_00 + deviceIndex;
|
||||||
|
printDeviceTrackingResultChange(deviceIndex);
|
||||||
if (_system->IsTrackedDeviceConnected(deviceIndex) &&
|
if (_system->IsTrackedDeviceConnected(deviceIndex) &&
|
||||||
_system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_GenericTracker &&
|
_system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_GenericTracker &&
|
||||||
_nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid &&
|
_nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid &&
|
||||||
poseIndex <= controller::TRACKED_OBJECT_15) {
|
poseIndex <= controller::TRACKED_OBJECT_15) {
|
||||||
|
|
||||||
// process pose
|
mat4& mat = mat4();
|
||||||
const mat4& mat = _nextSimPoseData.poses[deviceIndex];
|
vec3 linearVelocity = vec3();
|
||||||
const vec3 linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex];
|
vec3 angularVelocity = vec3();
|
||||||
const vec3 angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex];
|
// check if the device is tracking out of range, then process the correct pose depending on the result.
|
||||||
|
if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) {
|
||||||
|
mat = _nextSimPoseData.poses[deviceIndex];
|
||||||
|
linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex];
|
||||||
|
angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex];
|
||||||
|
} else {
|
||||||
|
mat = _lastSimPoseData.poses[deviceIndex];
|
||||||
|
linearVelocity = _lastSimPoseData.linearVelocities[deviceIndex];
|
||||||
|
angularVelocity = _lastSimPoseData.angularVelocities[deviceIndex];
|
||||||
|
|
||||||
|
// make sure that we do not overwrite the pose in the _lastSimPose with incorrect data.
|
||||||
|
_nextSimPoseData.poses[deviceIndex] = _lastSimPoseData.poses[deviceIndex];
|
||||||
|
_nextSimPoseData.linearVelocities[deviceIndex] = _lastSimPoseData.linearVelocities[deviceIndex];
|
||||||
|
_nextSimPoseData.angularVelocities[deviceIndex] = _lastSimPoseData.angularVelocities[deviceIndex];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
controller::Pose pose(extractTranslation(mat), glmExtractRotation(mat), linearVelocity, angularVelocity);
|
controller::Pose pose(extractTranslation(mat), glmExtractRotation(mat), linearVelocity, angularVelocity);
|
||||||
|
|
||||||
|
@ -245,6 +285,7 @@ void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) {
|
void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) {
|
||||||
|
qDebug() << "Puck Calibration: Starting...";
|
||||||
// convert the hmd head from sensor space to avatar space
|
// convert the hmd head from sensor space to avatar space
|
||||||
glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180;
|
glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180;
|
||||||
glm::mat4 sensorToAvatarMat = glm::inverse(inputCalibration.avatarMat) * inputCalibration.sensorToWorldMat;
|
glm::mat4 sensorToAvatarMat = glm::inverse(inputCalibration.avatarMat) * inputCalibration.sensorToWorldMat;
|
||||||
|
@ -264,18 +305,24 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr
|
||||||
glm::mat4 defaultToReferenceMat = currentHead * glm::inverse(inputCalibration.defaultHeadMat);
|
glm::mat4 defaultToReferenceMat = currentHead * glm::inverse(inputCalibration.defaultHeadMat);
|
||||||
|
|
||||||
int puckCount = (int)_validTrackedObjects.size();
|
int puckCount = (int)_validTrackedObjects.size();
|
||||||
|
qDebug() << "Puck Calibration: " << puckCount << " pucks found for calibration";
|
||||||
_config = _preferedConfig;
|
_config = _preferedConfig;
|
||||||
if (_config != Config::Auto && puckCount < MIN_PUCK_COUNT) {
|
if (_config != Config::Auto && puckCount < MIN_PUCK_COUNT) {
|
||||||
|
qDebug() << "Puck Calibration: Failed: Could not meet the minimal # of pucks";
|
||||||
uncalibrate();
|
uncalibrate();
|
||||||
return;
|
return;
|
||||||
} else if (_config == Config::Auto){
|
} else if (_config == Config::Auto){
|
||||||
if (puckCount == MIN_PUCK_COUNT) {
|
if (puckCount == MIN_PUCK_COUNT) {
|
||||||
_config = Config::Feet;
|
_config = Config::Feet;
|
||||||
|
qDebug() << "Puck Calibration: Auto Config: " << configToString(_config) << " configuration";
|
||||||
} else if (puckCount == MIN_FEET_AND_HIPS) {
|
} else if (puckCount == MIN_FEET_AND_HIPS) {
|
||||||
_config = Config::FeetAndHips;
|
_config = Config::FeetAndHips;
|
||||||
|
qDebug() << "Puck Calibration: Auto Config: " << configToString(_config) << " configuration";
|
||||||
} else if (puckCount >= MIN_FEET_HIPS_CHEST) {
|
} else if (puckCount >= MIN_FEET_HIPS_CHEST) {
|
||||||
_config = Config::FeetHipsAndChest;
|
_config = Config::FeetHipsAndChest;
|
||||||
|
qDebug() << "Puck Calibration: Auto Config: " << configToString(_config) << " configuration";
|
||||||
} else {
|
} else {
|
||||||
|
qDebug() << "Puck Calibration: Auto Config Failed: Could not meet the minimal # of pucks";
|
||||||
uncalibrate();
|
uncalibrate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -283,8 +330,6 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr
|
||||||
|
|
||||||
std::sort(_validTrackedObjects.begin(), _validTrackedObjects.end(), sortPucksYPosition);
|
std::sort(_validTrackedObjects.begin(), _validTrackedObjects.end(), sortPucksYPosition);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto& firstFoot = _validTrackedObjects[FIRST_FOOT];
|
auto& firstFoot = _validTrackedObjects[FIRST_FOOT];
|
||||||
auto& secondFoot = _validTrackedObjects[SECOND_FOOT];
|
auto& secondFoot = _validTrackedObjects[SECOND_FOOT];
|
||||||
controller::Pose& firstFootPose = firstFoot.second;
|
controller::Pose& firstFootPose = firstFoot.second;
|
||||||
|
@ -314,10 +359,12 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr
|
||||||
_jointToPuckMap[controller::SPINE2] = _validTrackedObjects[CHEST].first;
|
_jointToPuckMap[controller::SPINE2] = _validTrackedObjects[CHEST].first;
|
||||||
_pucksOffset[_validTrackedObjects[CHEST].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultSpine2, _validTrackedObjects[CHEST].second);
|
_pucksOffset[_validTrackedObjects[CHEST].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultSpine2, _validTrackedObjects[CHEST].second);
|
||||||
} else {
|
} else {
|
||||||
|
qDebug() << "Puck Calibration: " << configToString(_config) << " Config Failed: Could not meet the minimal # of pucks";
|
||||||
uncalibrate();
|
uncalibrate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_calibrated = true;
|
_calibrated = true;
|
||||||
|
qDebug() << "PuckCalibration: " << configToString(_config) << " Configuration Successful";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::InputDevice::uncalibrate() {
|
void ViveControllerManager::InputDevice::uncalibrate() {
|
||||||
|
@ -448,6 +495,14 @@ enum ViveButtonChannel {
|
||||||
RIGHT_APP_MENU
|
RIGHT_APP_MENU
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ViveControllerManager::InputDevice::printDeviceTrackingResultChange(uint32_t deviceIndex) {
|
||||||
|
if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != _lastSimPoseData.vrPoses[deviceIndex].eTrackingResult) {
|
||||||
|
qDebug() << "OpenVR: Device" << deviceIndex << "Tracking Result changed from" <<
|
||||||
|
deviceTrackingResultToString(_lastSimPoseData.vrPoses[deviceIndex].eTrackingResult)
|
||||||
|
<< "to" << deviceTrackingResultToString(_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ViveControllerManager::InputDevice::checkForCalibrationEvent() {
|
bool ViveControllerManager::InputDevice::checkForCalibrationEvent() {
|
||||||
auto& endOfMap = _buttonPressedMap.end();
|
auto& endOfMap = _buttonPressedMap.end();
|
||||||
auto& leftTrigger = _buttonPressedMap.find(controller::LT);
|
auto& leftTrigger = _buttonPressedMap.find(controller::LT);
|
||||||
|
@ -575,26 +630,8 @@ void ViveControllerManager::InputDevice::saveSettings() const {
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ViveControllerManager::InputDevice::configToString() {
|
QString ViveControllerManager::InputDevice::configToString(Config config) {
|
||||||
QString currentConfig;
|
return _configStringMap[config];
|
||||||
switch (_preferedConfig) {
|
|
||||||
case Config::Auto:
|
|
||||||
currentConfig = "Auto";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Config::Feet:
|
|
||||||
currentConfig = "Feet";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Config::FeetAndHips:
|
|
||||||
currentConfig = "FeetAndHips";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Config::FeetHipsAndChest:
|
|
||||||
currentConfig = "FeetHipsAndChest";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return currentConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::InputDevice::setConfigFromString(const QString& value) {
|
void ViveControllerManager::InputDevice::setConfigFromString(const QString& value) {
|
||||||
|
@ -615,7 +652,7 @@ void ViveControllerManager::InputDevice::createPreferences() {
|
||||||
static const QString VIVE_PUCKS_CONFIG = "Vive Pucks Configuration";
|
static const QString VIVE_PUCKS_CONFIG = "Vive Pucks Configuration";
|
||||||
|
|
||||||
{
|
{
|
||||||
auto getter = [this]()->QString { return configToString(); };
|
auto getter = [this]()->QString { return _configStringMap[_preferedConfig]; };
|
||||||
auto setter = [this](const QString& value) { setConfigFromString(value); saveSettings(); };
|
auto setter = [this](const QString& value) { setConfigFromString(value); saveSettings(); };
|
||||||
auto preference = new ComboBoxPreference(VIVE_PUCKS_CONFIG, "Configuration", getter, setter);
|
auto preference = new ComboBoxPreference(VIVE_PUCKS_CONFIG, "Configuration", getter, setter);
|
||||||
QStringList list = (QStringList() << "Auto" << "Feet" << "FeetAndHips" << "FeetHipsAndChest");
|
QStringList list = (QStringList() << "Auto" << "Feet" << "FeetAndHips" << "FeetHipsAndChest");
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <plugins/InputPlugin.h>
|
#include <plugins/InputPlugin.h>
|
||||||
#include <RenderArgs.h>
|
#include <RenderArgs.h>
|
||||||
#include <render/Scene.h>
|
#include <render/Scene.h>
|
||||||
|
#include "OpenVrHelpers.h"
|
||||||
|
|
||||||
namespace vr {
|
namespace vr {
|
||||||
class IVRSystem;
|
class IVRSystem;
|
||||||
|
@ -50,7 +51,7 @@ public:
|
||||||
private:
|
private:
|
||||||
class InputDevice : public controller::InputDevice {
|
class InputDevice : public controller::InputDevice {
|
||||||
public:
|
public:
|
||||||
InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) { createPreferences(); }
|
InputDevice(vr::IVRSystem*& system);
|
||||||
private:
|
private:
|
||||||
// Device functions
|
// Device functions
|
||||||
controller::Input::NamedVector getAvailableInputs() const override;
|
controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
|
@ -76,6 +77,7 @@ private:
|
||||||
void handleHeadPoseEvent(const controller::InputCalibrationData& inputCalibrationData, const mat4& mat, const vec3& linearVelocity,
|
void handleHeadPoseEvent(const controller::InputCalibrationData& inputCalibrationData, const mat4& mat, const vec3& linearVelocity,
|
||||||
const vec3& angularVelocity);
|
const vec3& angularVelocity);
|
||||||
void partitionTouchpad(int sButton, int xAxis, int yAxis, int centerPsuedoButton, int xPseudoButton, int yPseudoButton);
|
void partitionTouchpad(int sButton, int xAxis, int yAxis, int centerPsuedoButton, int xPseudoButton, int yPseudoButton);
|
||||||
|
void printDeviceTrackingResultChange(uint32_t deviceIndex);
|
||||||
|
|
||||||
class FilteredStick {
|
class FilteredStick {
|
||||||
public:
|
public:
|
||||||
|
@ -109,6 +111,8 @@ private:
|
||||||
std::vector<std::pair<uint32_t, controller::Pose>> _validTrackedObjects;
|
std::vector<std::pair<uint32_t, controller::Pose>> _validTrackedObjects;
|
||||||
std::map<uint32_t, glm::mat4> _pucksOffset;
|
std::map<uint32_t, glm::mat4> _pucksOffset;
|
||||||
std::map<int, uint32_t> _jointToPuckMap;
|
std::map<int, uint32_t> _jointToPuckMap;
|
||||||
|
std::map<Config, QString> _configStringMap;
|
||||||
|
PoseData _lastSimPoseData;
|
||||||
// perform an action when the InputDevice mutex is acquired.
|
// perform an action when the InputDevice mutex is acquired.
|
||||||
using Locker = std::unique_lock<std::recursive_mutex>;
|
using Locker = std::unique_lock<std::recursive_mutex>;
|
||||||
template <typename F>
|
template <typename F>
|
||||||
|
@ -126,7 +130,7 @@ private:
|
||||||
bool _timeTilCalibrationSet { false };
|
bool _timeTilCalibrationSet { false };
|
||||||
mutable std::recursive_mutex _lock;
|
mutable std::recursive_mutex _lock;
|
||||||
|
|
||||||
QString configToString();
|
QString configToString(Config config);
|
||||||
void setConfigFromString(const QString& value);
|
void setConfigFromString(const QString& value);
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings() const;
|
void saveSettings() const;
|
||||||
|
|
|
@ -415,7 +415,7 @@ function updateShareInfo(containerID, storyID) {
|
||||||
facebookButton.setAttribute("href", 'https://www.facebook.com/dialog/feed?app_id=1585088821786423&link=' + shareURL);
|
facebookButton.setAttribute("href", 'https://www.facebook.com/dialog/feed?app_id=1585088821786423&link=' + shareURL);
|
||||||
|
|
||||||
twitterButton.setAttribute("target", "_blank");
|
twitterButton.setAttribute("target", "_blank");
|
||||||
twitterButton.setAttribute("href", 'https://twitter.com/intent/tweet?text=I%20just%20took%20a%20snapshot!&url=' + shareURL + '&via=highfidelity&hashtags=VR,HiFi');
|
twitterButton.setAttribute("href", 'https://twitter.com/intent/tweet?text=I%20just%20took%20a%20snapshot!&url=' + shareURL + '&via=highfidelityinc&hashtags=VR,HiFi');
|
||||||
|
|
||||||
hideUploadingMessageAndShare(containerID, storyID);
|
hideUploadingMessageAndShare(containerID, storyID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,6 +341,11 @@ SelectionDisplay = (function() {
|
||||||
green: 120,
|
green: 120,
|
||||||
blue: 120
|
blue: 120
|
||||||
};
|
};
|
||||||
|
var grabberColorCloner = {
|
||||||
|
red: 0,
|
||||||
|
green: 155,
|
||||||
|
blue: 0
|
||||||
|
};
|
||||||
var grabberLineWidth = 0.5;
|
var grabberLineWidth = 0.5;
|
||||||
var grabberSolid = true;
|
var grabberSolid = true;
|
||||||
var grabberMoveUpPosition = {
|
var grabberMoveUpPosition = {
|
||||||
|
@ -406,6 +411,23 @@ SelectionDisplay = (function() {
|
||||||
borderSize: 1.4,
|
borderSize: 1.4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var grabberPropertiesCloner = {
|
||||||
|
position: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
size: grabberSizeCorner,
|
||||||
|
color: grabberColorCloner,
|
||||||
|
alpha: 1,
|
||||||
|
solid: grabberSolid,
|
||||||
|
visible: false,
|
||||||
|
dashed: false,
|
||||||
|
lineWidth: grabberLineWidth,
|
||||||
|
drawInFront: true,
|
||||||
|
borderSize: 1.4,
|
||||||
|
};
|
||||||
|
|
||||||
var spotLightLineProperties = {
|
var spotLightLineProperties = {
|
||||||
color: lightOverlayColor,
|
color: lightOverlayColor,
|
||||||
lineWidth: 1.5,
|
lineWidth: 1.5,
|
||||||
|
@ -583,6 +605,8 @@ SelectionDisplay = (function() {
|
||||||
var grabberPointLightF = Overlays.addOverlay("cube", grabberPropertiesEdge);
|
var grabberPointLightF = Overlays.addOverlay("cube", grabberPropertiesEdge);
|
||||||
var grabberPointLightN = Overlays.addOverlay("cube", grabberPropertiesEdge);
|
var grabberPointLightN = Overlays.addOverlay("cube", grabberPropertiesEdge);
|
||||||
|
|
||||||
|
var grabberCloner = Overlays.addOverlay("cube", grabberPropertiesCloner);
|
||||||
|
|
||||||
var stretchHandles = [
|
var stretchHandles = [
|
||||||
grabberLBN,
|
grabberLBN,
|
||||||
grabberRBN,
|
grabberRBN,
|
||||||
|
@ -629,6 +653,8 @@ SelectionDisplay = (function() {
|
||||||
grabberPointLightR,
|
grabberPointLightR,
|
||||||
grabberPointLightF,
|
grabberPointLightF,
|
||||||
grabberPointLightN,
|
grabberPointLightN,
|
||||||
|
|
||||||
|
grabberCloner
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -970,6 +996,7 @@ SelectionDisplay = (function() {
|
||||||
grabberPointLightCircleX,
|
grabberPointLightCircleX,
|
||||||
grabberPointLightCircleY,
|
grabberPointLightCircleY,
|
||||||
grabberPointLightCircleZ,
|
grabberPointLightCircleZ,
|
||||||
|
|
||||||
].concat(stretchHandles);
|
].concat(stretchHandles);
|
||||||
|
|
||||||
overlayNames[highlightBox] = "highlightBox";
|
overlayNames[highlightBox] = "highlightBox";
|
||||||
|
@ -1016,7 +1043,7 @@ SelectionDisplay = (function() {
|
||||||
|
|
||||||
overlayNames[rotateZeroOverlay] = "rotateZeroOverlay";
|
overlayNames[rotateZeroOverlay] = "rotateZeroOverlay";
|
||||||
overlayNames[rotateCurrentOverlay] = "rotateCurrentOverlay";
|
overlayNames[rotateCurrentOverlay] = "rotateCurrentOverlay";
|
||||||
|
overlayNames[grabberCloner] = "grabberCloner";
|
||||||
var activeTool = null;
|
var activeTool = null;
|
||||||
var grabberTools = {};
|
var grabberTools = {};
|
||||||
|
|
||||||
|
@ -2136,6 +2163,12 @@ SelectionDisplay = (function() {
|
||||||
position: FAR
|
position: FAR
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Overlays.editOverlay(grabberCloner, {
|
||||||
|
visible: true,
|
||||||
|
rotation: rotation,
|
||||||
|
position: EdgeTR
|
||||||
|
});
|
||||||
|
|
||||||
var boxPosition = Vec3.multiplyQbyV(rotation, center);
|
var boxPosition = Vec3.multiplyQbyV(rotation, center);
|
||||||
boxPosition = Vec3.sum(position, boxPosition);
|
boxPosition = Vec3.sum(position, boxPosition);
|
||||||
Overlays.editOverlay(selectionBox, {
|
Overlays.editOverlay(selectionBox, {
|
||||||
|
@ -2293,7 +2326,6 @@ SelectionDisplay = (function() {
|
||||||
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setOverlaysVisible = function(isVisible) {
|
that.setOverlaysVisible = function(isVisible) {
|
||||||
|
@ -2325,7 +2357,7 @@ SelectionDisplay = (function() {
|
||||||
greatestDimension: 0.0,
|
greatestDimension: 0.0,
|
||||||
startingDistance: 0.0,
|
startingDistance: 0.0,
|
||||||
startingElevation: 0.0,
|
startingElevation: 0.0,
|
||||||
onBegin: function(event) {
|
onBegin: function(event,isAltFromGrab) {
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
startPosition = SelectionManager.worldPosition;
|
startPosition = SelectionManager.worldPosition;
|
||||||
var dimensions = SelectionManager.worldDimensions;
|
var dimensions = SelectionManager.worldDimensions;
|
||||||
|
@ -2340,7 +2372,7 @@ SelectionDisplay = (function() {
|
||||||
// Duplicate entities if alt is pressed. This will make a
|
// Duplicate entities if alt is pressed. This will make a
|
||||||
// copy of the selected entities and move the _original_ entities, not
|
// copy of the selected entities and move the _original_ entities, not
|
||||||
// the new ones.
|
// the new ones.
|
||||||
if (event.isAlt) {
|
if (event.isAlt || isAltFromGrab) {
|
||||||
duplicatedEntityIDs = [];
|
duplicatedEntityIDs = [];
|
||||||
for (var otherEntityID in SelectionManager.savedProperties) {
|
for (var otherEntityID in SelectionManager.savedProperties) {
|
||||||
var properties = SelectionManager.savedProperties[otherEntityID];
|
var properties = SelectionManager.savedProperties[otherEntityID];
|
||||||
|
@ -2581,6 +2613,34 @@ SelectionDisplay = (function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addGrabberTool(grabberCloner, {
|
||||||
|
mode: "CLONE",
|
||||||
|
onBegin: function(event) {
|
||||||
|
|
||||||
|
var pickRay = generalComputePickRay(event.x, event.y);
|
||||||
|
var result = Overlays.findRayIntersection(pickRay);
|
||||||
|
translateXZTool.pickPlanePosition = result.intersection;
|
||||||
|
translateXZTool.greatestDimension = Math.max(Math.max(SelectionManager.worldDimensions.x, SelectionManager.worldDimensions.y),
|
||||||
|
SelectionManager.worldDimensions.z);
|
||||||
|
|
||||||
|
translateXZTool.onBegin(event,true);
|
||||||
|
},
|
||||||
|
elevation: function (event) {
|
||||||
|
translateXZTool.elevation(event);
|
||||||
|
},
|
||||||
|
|
||||||
|
onEnd: function (event) {
|
||||||
|
translateXZTool.onEnd(event);
|
||||||
|
},
|
||||||
|
|
||||||
|
onMove: function (event) {
|
||||||
|
translateXZTool.onMove(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var vec3Mult = function(v1, v2) {
|
var vec3Mult = function(v1, v2) {
|
||||||
return {
|
return {
|
||||||
x: v1.x * v2.x,
|
x: v1.x * v2.x,
|
||||||
|
@ -4482,6 +4542,12 @@ SelectionDisplay = (function() {
|
||||||
highlightNeeded = true;
|
highlightNeeded = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case grabberCloner:
|
||||||
|
pickedColor = grabberColorCloner;
|
||||||
|
pickedAlpha = grabberAlpha;
|
||||||
|
highlightNeeded = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (previousHandle) {
|
if (previousHandle) {
|
||||||
Overlays.editOverlay(previousHandle, {
|
Overlays.editOverlay(previousHandle, {
|
||||||
|
|
|
@ -198,7 +198,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var animationData = {};
|
var animationData = {};
|
||||||
function updateAnimationData() {
|
function updateAnimationData(verticalOffset) {
|
||||||
// all we are doing here is moving the right hand to a spot
|
// all we are doing here is moving the right hand to a spot
|
||||||
// that is in front of and a bit above the hips. Basing how
|
// that is in front of and a bit above the hips. Basing how
|
||||||
// far in front as scaling with the avatar's height (say hips
|
// far in front as scaling with the avatar's height (say hips
|
||||||
|
@ -209,6 +209,9 @@
|
||||||
offset = 0.8 * MyAvatar.getAbsoluteJointTranslationInObjectFrame(headIndex).y;
|
offset = 0.8 * MyAvatar.getAbsoluteJointTranslationInObjectFrame(headIndex).y;
|
||||||
}
|
}
|
||||||
animationData.rightHandPosition = Vec3.multiply(offset, {x: -0.25, y: 0.8, z: 1.3});
|
animationData.rightHandPosition = Vec3.multiply(offset, {x: -0.25, y: 0.8, z: 1.3});
|
||||||
|
if (verticalOffset) {
|
||||||
|
animationData.rightHandPosition.y += verticalOffset;
|
||||||
|
}
|
||||||
animationData.rightHandRotation = Quat.fromPitchYawRollDegrees(90, 0, 90);
|
animationData.rightHandRotation = Quat.fromPitchYawRollDegrees(90, 0, 90);
|
||||||
}
|
}
|
||||||
function shakeHandsAnimation() {
|
function shakeHandsAnimation() {
|
||||||
|
@ -347,7 +350,32 @@
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
function findNearestAvatar() {
|
||||||
|
// We only look some max distance away (much larger than the handshake distance, but still...)
|
||||||
|
var minDistance = MAX_AVATAR_DISTANCE * 20;
|
||||||
|
var closestAvatar;
|
||||||
|
AvatarList.getAvatarIdentifiers().forEach(function (id) {
|
||||||
|
var avatar = AvatarList.getAvatar(id);
|
||||||
|
if (avatar && avatar.sessionUUID != MyAvatar.sessionUUID) {
|
||||||
|
var currentDistance = Vec3.distance(avatar.position, MyAvatar.position);
|
||||||
|
if (minDistance > currentDistance) {
|
||||||
|
minDistance = currentDistance;
|
||||||
|
closestAvatar = avatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return closestAvatar;
|
||||||
|
}
|
||||||
|
function adjustAnimationHeight() {
|
||||||
|
var avatar = findNearestAvatar();
|
||||||
|
if (avatar) {
|
||||||
|
var myHeadIndex = MyAvatar.getJointIndex("Head");
|
||||||
|
var otherHeadIndex = avatar.getJointIndex("Head");
|
||||||
|
var diff = (avatar.getJointPosition(otherHeadIndex).y - MyAvatar.getJointPosition(myHeadIndex).y) / 2;
|
||||||
|
print("head height difference: " + diff);
|
||||||
|
updateAnimationData(diff);
|
||||||
|
}
|
||||||
|
}
|
||||||
function findNearestWaitingAvatar() {
|
function findNearestWaitingAvatar() {
|
||||||
var handPosition = getHandPosition(MyAvatar, currentHandJointIndex);
|
var handPosition = getHandPosition(MyAvatar, currentHandJointIndex);
|
||||||
var minDistance = MAX_AVATAR_DISTANCE;
|
var minDistance = MAX_AVATAR_DISTANCE;
|
||||||
|
@ -436,6 +464,10 @@
|
||||||
handStringMessageSend({
|
handStringMessageSend({
|
||||||
key: "waiting",
|
key: "waiting",
|
||||||
});
|
});
|
||||||
|
// potentially adjust height of handshake
|
||||||
|
if (fromKeyboard) {
|
||||||
|
adjustAnimationHeight();
|
||||||
|
}
|
||||||
lookForWaitingAvatar();
|
lookForWaitingAvatar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
43
scripts/tutorials/createFloatingLanternBox.js
Normal file
43
scripts/tutorials/createFloatingLanternBox.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
"use strict";
|
||||||
|
/* jslint vars: true, plusplus: true, forin: true*/
|
||||||
|
/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */
|
||||||
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||||
|
//
|
||||||
|
// createFloatinLanternBox.js
|
||||||
|
//
|
||||||
|
// Created by MrRoboman on 17/05/04
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Creates a crate that spawn floating lanterns
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
var COMPOUND_SHAPE_URL = "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/maracas/woodenCrate_phys.obj";
|
||||||
|
var MODEL_URL = "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/maracas/woodenCrate_VR.fbx";
|
||||||
|
var SCRIPT_URL = Script.resolvePath("./entity_scripts/floatingLanternBox.js?v=" + Date.now());
|
||||||
|
var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2));
|
||||||
|
START_POSITION.y -= .6;
|
||||||
|
var LIFETIME = 3600;
|
||||||
|
var SCALE_FACTOR = 1;
|
||||||
|
|
||||||
|
var lanternBox = {
|
||||||
|
type: "Model",
|
||||||
|
name: "Floating Lantern Box",
|
||||||
|
description: "Spawns Lanterns that float away when grabbed and released!",
|
||||||
|
script: SCRIPT_URL,
|
||||||
|
modelURL: MODEL_URL,
|
||||||
|
shapeType: "Compound",
|
||||||
|
compoundShapeURL: COMPOUND_SHAPE_URL,
|
||||||
|
position: START_POSITION,
|
||||||
|
lifetime: LIFETIME,
|
||||||
|
dimensions: {
|
||||||
|
x: 0.8696 * SCALE_FACTOR,
|
||||||
|
y: 0.58531 * SCALE_FACTOR,
|
||||||
|
z: 0.9264 * SCALE_FACTOR
|
||||||
|
},
|
||||||
|
owningAvatarID: MyAvatar.sessionUUID
|
||||||
|
};
|
||||||
|
|
||||||
|
Entities.addEntity(lanternBox);
|
||||||
|
Script.stop();
|
106
scripts/tutorials/entity_scripts/floatingLantern.js
Normal file
106
scripts/tutorials/entity_scripts/floatingLantern.js
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
"use strict";
|
||||||
|
/* jslint vars: true, plusplus: true, forin: true*/
|
||||||
|
/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */
|
||||||
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||||
|
//
|
||||||
|
// floatinLantern.js
|
||||||
|
//
|
||||||
|
// Created by MrRoboman on 17/05/04
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Makes floating lanterns rise upon being released and corrects their rotation as the fly.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var _this;
|
||||||
|
|
||||||
|
var SLOW_SPIN_THRESHOLD = 0.1;
|
||||||
|
var ROTATION_COMPLETE_THRESHOLD = 0.01;
|
||||||
|
var ROTATION_SPEED = 0.2;
|
||||||
|
var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0};
|
||||||
|
|
||||||
|
|
||||||
|
floatingLantern = function() {
|
||||||
|
_this = this;
|
||||||
|
this.updateConnected = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
floatingLantern.prototype = {
|
||||||
|
|
||||||
|
preload: function(entityID) {
|
||||||
|
this.entityID = entityID;
|
||||||
|
},
|
||||||
|
|
||||||
|
unload: function(entityID) {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
startNearGrab: function() {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
startDistantGrab: function() {
|
||||||
|
this.disconnectUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
|
releaseGrab: function() {
|
||||||
|
Entities.editEntity(this.entityID, {
|
||||||
|
gravity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0.5,
|
||||||
|
z: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function(dt) {
|
||||||
|
var lanternProps = Entities.getEntityProperties(_this.entityID);
|
||||||
|
|
||||||
|
if (lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) {
|
||||||
|
|
||||||
|
var spinningSlowly = (
|
||||||
|
Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD
|
||||||
|
);
|
||||||
|
|
||||||
|
var rotationComplete = (
|
||||||
|
Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD &&
|
||||||
|
Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD
|
||||||
|
);
|
||||||
|
|
||||||
|
if (spinningSlowly && !rotationComplete) {
|
||||||
|
var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt);
|
||||||
|
|
||||||
|
Entities.editEntity(_this.entityID, {
|
||||||
|
rotation: newRotation,
|
||||||
|
angularVelocity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
connectUpdate: function() {
|
||||||
|
if (!this.updateConnected) {
|
||||||
|
this.updateConnected = true;
|
||||||
|
Script.update.connect(this.update);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
disconnectUpdate: function() {
|
||||||
|
if (this.updateConnected) {
|
||||||
|
this.updateConnected = false;
|
||||||
|
Script.update.disconnect(this.update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new floatingLantern();
|
||||||
|
});
|
103
scripts/tutorials/entity_scripts/floatingLanternBox.js
Normal file
103
scripts/tutorials/entity_scripts/floatingLanternBox.js
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
"use strict";
|
||||||
|
/* jslint vars: true, plusplus: true, forin: true*/
|
||||||
|
/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */
|
||||||
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||||
|
//
|
||||||
|
// floatingLanternBox.js
|
||||||
|
//
|
||||||
|
// Created by MrRoboman on 17/05/04
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Spawns new floating lanterns every couple seconds if the old ones have been removed.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var _this;
|
||||||
|
var LANTERN_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Welcome%20Area/Models/chinaLantern_capsule.fbx";
|
||||||
|
var LANTERN_SCRIPT_URL = Script.resolvePath("floatingLantern.js?v=" + Date.now());
|
||||||
|
var LIFETIME = 120;
|
||||||
|
var RESPAWN_INTERVAL = 1000;
|
||||||
|
var MAX_LANTERNS = 4;
|
||||||
|
var SCALE_FACTOR = 1;
|
||||||
|
|
||||||
|
var LANTERN = {
|
||||||
|
type: "Model",
|
||||||
|
name: "Floating Lantern",
|
||||||
|
description: "Spawns Lanterns that float away when grabbed and released!",
|
||||||
|
modelURL: LANTERN_MODEL_URL,
|
||||||
|
script: LANTERN_SCRIPT_URL,
|
||||||
|
dimensions: {
|
||||||
|
x: 0.2049 * SCALE_FACTOR,
|
||||||
|
y: 0.4 * SCALE_FACTOR,
|
||||||
|
z: 0.2049 * SCALE_FACTOR
|
||||||
|
},
|
||||||
|
gravity: {
|
||||||
|
x: 0,
|
||||||
|
y: -1,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
velocity: {
|
||||||
|
x: 0, y: .01, z: 0
|
||||||
|
},
|
||||||
|
linearDampening: 0,
|
||||||
|
shapeType: 'Box',
|
||||||
|
lifetime: LIFETIME,
|
||||||
|
dynamic: true
|
||||||
|
};
|
||||||
|
|
||||||
|
lanternBox = function() {
|
||||||
|
_this = this;
|
||||||
|
};
|
||||||
|
|
||||||
|
lanternBox.prototype = {
|
||||||
|
|
||||||
|
preload: function(entityID) {
|
||||||
|
this.entityID = entityID;
|
||||||
|
var props = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
|
if (props.owningAvatarID === MyAvatar.sessionUUID) {
|
||||||
|
this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unload: function(entityID) {
|
||||||
|
if (this.respawnTimer) {
|
||||||
|
Script.clearInterval(this.respawnTimer);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
spawnAllLanterns: function() {
|
||||||
|
var props = Entities.getEntityProperties(this.entityID);
|
||||||
|
var lanternCount = 0;
|
||||||
|
var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75);
|
||||||
|
|
||||||
|
for (var i = 0; i < nearbyEntities.length; i++) {
|
||||||
|
var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name;
|
||||||
|
if (name === "Floating Lantern") {
|
||||||
|
lanternCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (lanternCount++ < MAX_LANTERNS) {
|
||||||
|
this.spawnLantern();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
spawnLantern: function() {
|
||||||
|
var boxProps = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
|
LANTERN.position = boxProps.position;
|
||||||
|
LANTERN.position.x += Math.random() * .2 - .1;
|
||||||
|
LANTERN.position.y += Math.random() * .2 + .1;
|
||||||
|
LANTERN.position.z += Math.random() * .2 - .1;
|
||||||
|
LANTERN.owningAvatarID = boxProps.owningAvatarID;
|
||||||
|
|
||||||
|
return Entities.addEntity(LANTERN);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new lanternBox();
|
||||||
|
});
|
|
@ -19,3 +19,6 @@ set_target_properties(skeleton-dump PROPERTIES FOLDER "Tools")
|
||||||
|
|
||||||
add_subdirectory(atp-get)
|
add_subdirectory(atp-get)
|
||||||
set_target_properties(atp-get PROPERTIES FOLDER "Tools")
|
set_target_properties(atp-get PROPERTIES FOLDER "Tools")
|
||||||
|
|
||||||
|
add_subdirectory(oven)
|
||||||
|
set_target_properties(oven PROPERTIES FOLDER "Tools")
|
||||||
|
|
19
tools/oven/CMakeLists.txt
Normal file
19
tools/oven/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
set(TARGET_NAME oven)
|
||||||
|
|
||||||
|
setup_hifi_project(Widgets Gui Concurrent)
|
||||||
|
|
||||||
|
link_hifi_libraries(networking shared image gpu ktx)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
package_libraries_for_deployment()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# try to find the FBX SDK but fail silently if we don't
|
||||||
|
# because this tool is not built by default
|
||||||
|
find_package(FBX)
|
||||||
|
if (FBX_FOUND)
|
||||||
|
target_link_libraries(${TARGET_NAME} ${FBX_LIBRARIES})
|
||||||
|
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${FBX_INCLUDE_DIR})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set_target_properties(${TARGET_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE)
|
32
tools/oven/src/Baker.cpp
Normal file
32
tools/oven/src/Baker.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// Baker.cpp
|
||||||
|
// tools/oven/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 4/14/17.
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ModelBakingLoggingCategory.h"
|
||||||
|
|
||||||
|
#include "Baker.h"
|
||||||
|
|
||||||
|
void Baker::handleError(const QString& error) {
|
||||||
|
qCCritical(model_baking).noquote() << error;
|
||||||
|
_errorList.append(error);
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Baker::handleErrors(const QStringList& errors) {
|
||||||
|
// we're appending errors, presumably from a baking operation we called
|
||||||
|
// add those to our list and emit that we are finished
|
||||||
|
_errorList.append(errors);
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Baker::handleWarning(const QString& warning) {
|
||||||
|
qCWarning(model_baking).noquote() << warning;
|
||||||
|
_warningList.append(warning);
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue