Пример #1
0
void MaterialEntityItem::applyMaterial() {
    _retryApply = false;
    graphics::MaterialPointer material = getMaterial();
    QUuid parentID = getClientOnly() ? getOwningAvatarID() : getParentID();
    if (!material || parentID.isNull()) {
        return;
    }
    Transform textureTransform;
    textureTransform.setTranslation(glm::vec3(_materialMappingPos, 0));
    textureTransform.setRotation(glm::vec3(0, 0, glm::radians(_materialMappingRot)));
    textureTransform.setScale(glm::vec3(_materialMappingScale, 1));
    material->setTextureTransforms(textureTransform);

    graphics::MaterialLayer materialLayer = graphics::MaterialLayer(material, getPriority());

    // Our parent could be an entity, an avatar, or an overlay
    if (EntityTree::addMaterialToEntity(parentID, materialLayer, getParentMaterialName().toStdString())) {
        return;
    }

    if (EntityTree::addMaterialToAvatar(parentID, materialLayer, getParentMaterialName().toStdString())) {
        return;
    }

    if (EntityTree::addMaterialToOverlay(parentID, materialLayer, getParentMaterialName().toStdString())) {
        return;
    }

    // if we've reached this point, we couldn't find our parent, so we need to try again later
    _retryApply = true;
}
Пример #2
0
void MaterialEntityItem::setParentID(const QUuid& parentID) {
    if (getParentID() != parentID) {
        removeMaterial();
        EntityItem::setParentID(parentID);
        applyMaterial();
    }
}
Пример #3
0
void MaterialEntityItem::removeMaterial() {
    graphics::MaterialPointer material = getMaterial();
    if (!material) {
        return;
    }
    QUuid parentID = getParentID();
    if (parentID.isNull()) {
        return;
    }

    // Our parent could be an entity, an avatar, or an overlay
    if (EntityTree::removeMaterialFromEntity(parentID, material, getParentMaterialName().toStdString())) {
        return;
    }

    if (EntityTree::removeMaterialFromAvatar(parentID, material, getParentMaterialName().toStdString())) {
        return;
    }

    if (EntityTree::removeMaterialFromOverlay(parentID, material, getParentMaterialName().toStdString())) {
        return;
    }

    // if a remove fails, our parent is gone, so we don't need to retry
}
Пример #4
0
	void PlantBlockActor::rebuildAllPlantBlock()
	{
		mandatoryUnLoadNode();
		osg::ref_ptr<PlantBlock> childBlock = new PlantBlock(_projectName, getParentID());
		childBlock->setName(getName());
		childBlock->rebuild();
		childBlock->resetTransform(0);
		addChild(childBlock);
	}
Пример #5
0
	void PlantBlockActor::mandatoryLoadNodeSynchronous(const StringList& exclusionList)
	{
		if (_relativePath.empty() || _modelFileName.empty())
			return;
		if (getNumChildren() > 0)
			removeChildren(0, getNumChildren());
		std::string fullFileName = _relativePath;
		fullFileName.append(_modelFileName);
		osg::ref_ptr<osg::Node> node = g_SystemContext._resourceLoader->getNodeByName(fullFileName, false);
		if (node.valid())
		{
			PlantBlock* pBlock = new PlantBlock(_projectName, getParentID());
			pBlock->buildPlantBlock(node, false);
			addChild(pBlock);
		}
	}
Пример #6
0
  InputTextItem::InputTextItem(Device* d, Grids::Value* val,
                               QGraphicsItem *parent, QGraphicsScene *scene ) :
  QGraphicsTextItem(parent, scene), Object(d, val) {

    /* Only send text information once per second. */
    /* Sending key data as fast as the user typed it crashed my server. */
    key_delay = 250;
    /* After this time a newline is added and the text is sent as an itput. */
    input_time = 2250;

    this->d = d;

    //d->getNoticeWindow()->write(0, tr("Creating InputTextItem"));

    const Grids::Value& temp_val = *val;

    text_color = QColor( getAttrFromValue(temp_val)["text_color"][0u].asInt(),
                         getAttrFromValue(temp_val)["text_color"][1u].asInt(),
                         getAttrFromValue(temp_val)["text_color"][2u].asInt(),
                         getAttrFromValue(temp_val)["text_color"][3u].asInt() );

    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemIsSelectable);
    setFlag(QGraphicsItem::ItemIsFocusable);
    setFlag(QGraphicsItem::ItemSendsScenePositionChanges);

    setCursor(Qt::IBeamCursor);

    /* If I created this item, select it and add a cursor. */
    if(d->myChild(getParentID())){
      //QMutexLocker locker(&focus_mutex);
      setSelected(1);
      setFocus(Qt::OtherFocusReason);
    }

    /* This sets up an loop. */
    startTimer(0);
    keys_unsent = 0;
    input_unsent = 0;
    last_key_press.start();
  }
Пример #7
0
void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
    auto ownerEntity = _ownerEntity.lock();
    if (!ownerEntity) {
        qDebug() << "AvatarActionHold::doKinematicUpdate -- no owning entity";
        return;
    }
    if (ownerEntity->getParentID() != QUuid()) {
        // if the held entity has been given a parent, stop acting on it.
        return;
    }

    void* physicsInfo = ownerEntity->getPhysicsInfo();
    if (!physicsInfo) {
        qDebug() << "AvatarActionHold::doKinematicUpdate -- no owning physics info";
        return;
    }
    ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
    btRigidBody* rigidBody = motionState ? motionState->getRigidBody() : nullptr;
    if (!rigidBody) {
        qDebug() << "AvatarActionHold::doKinematicUpdate -- no rigidBody";
        return;
    }

    withWriteLock([&]{
        if (_previousSet &&
            _positionalTarget != _previousPositionalTarget) { // don't average in a zero velocity if we get the same data
            glm::vec3 oneFrameVelocity = (_positionalTarget - _previousPositionalTarget) / deltaTimeStep;

            _measuredLinearVelocities[_measuredLinearVelocitiesIndex++] = oneFrameVelocity;
            if (_measuredLinearVelocitiesIndex >= AvatarActionHold::velocitySmoothFrames) {
                _measuredLinearVelocitiesIndex = 0;
            }
        }

        glm::vec3 measuredLinearVelocity;
        for (int i = 0; i < AvatarActionHold::velocitySmoothFrames; i++) {
            // there is a bit of lag between when someone releases the trigger and when the software reacts to
            // the release.  we calculate the velocity from previous frames but we don't include several
            // of the most recent.
            //
            // if _measuredLinearVelocitiesIndex is
            //     0 -- ignore i of 3 4 5
            //     1 -- ignore i of 4 5 0
            //     2 -- ignore i of 5 0 1
            //     3 -- ignore i of 0 1 2
            //     4 -- ignore i of 1 2 3
            //     5 -- ignore i of 2 3 4

            // This code is now disabled, but I'm leaving it commented-out because I suspect it will come back.
            // if ((i + 1) % AvatarActionHold::velocitySmoothFrames == _measuredLinearVelocitiesIndex ||
            //     (i + 2) % AvatarActionHold::velocitySmoothFrames == _measuredLinearVelocitiesIndex ||
            //     (i + 3) % AvatarActionHold::velocitySmoothFrames == _measuredLinearVelocitiesIndex) {
            //     continue;
            // }

            measuredLinearVelocity += _measuredLinearVelocities[i];
        }
        measuredLinearVelocity /= (float)(AvatarActionHold::velocitySmoothFrames
                                          // - 3  // 3 because of the 3 we skipped, above
                                          );

        if (_kinematicSetVelocity) {
            rigidBody->setLinearVelocity(glmToBullet(measuredLinearVelocity));
            rigidBody->setAngularVelocity(glmToBullet(_angularVelocityTarget));
        }

        btTransform worldTrans = rigidBody->getWorldTransform();
        worldTrans.setOrigin(glmToBullet(_positionalTarget));
        worldTrans.setRotation(glmToBullet(_rotationalTarget));
        rigidBody->setWorldTransform(worldTrans);

        motionState->dirtyInternalKinematicChanges();

        _previousPositionalTarget = _positionalTarget;
        _previousRotationalTarget = _rotationalTarget;
        _previousDeltaTimeStep = deltaTimeStep;
        _previousSet = true;
    });

    forceBodyNonStatic();
    activateBody(true);
}