コード例 #1
0
void UAnimSequenceBase::PostLoad()
{
	Super::PostLoad();

	// Convert Notifies to new data
	if( GIsEditor && Notifies.Num() > 0 )
	{
		if(GetLinkerUE4Version() < VER_UE4_CLEAR_NOTIFY_TRIGGERS)
		{
			for(FAnimNotifyEvent Notify : Notifies)
			{
				if(Notify.Notify)
				{
					// Clear end triggers for notifies that are not notify states
					Notify.EndTriggerTimeOffset = 0.0f;
				}
			}
		}
	}

	// Ensure notifies are sorted.
	SortNotifies();

#if WITH_EDITOR
	InitializeNotifyTrack();
#endif
	RefreshCacheData();

	if(USkeleton* Skeleton = GetSkeleton())
	{
		// Fix up the existing curves to work with smartnames
		if(GetLinkerUE4Version() < VER_UE4_SKELETON_ADD_SMARTNAMES)
		{
			for(FFloatCurve& Curve : RawCurveData.FloatCurves)
			{
				// Add the names of the curves into the smartname mapping and store off the curve uid which will be saved next time the sequence saves.
				Skeleton->AddSmartNameAndModify(USkeleton::AnimCurveMappingName, Curve.LastObservedName, Curve.CurveUid);
			}
		}
		else
		{
			VerifyCurveNames<FFloatCurve>(Skeleton, USkeleton::AnimCurveMappingName, RawCurveData.FloatCurves);
		}

#if WITH_EDITOR
		VerifyCurveNames<FTransformCurve>(Skeleton, USkeleton::AnimTrackCurveMappingName, RawCurveData.TransformCurves);
#endif
	}
}
コード例 #2
0
ファイル: car.cpp プロジェクト: basecq/thug
void CCar::display_wheels()
{
	CalculateCarHierarchyMatrices(this->GetSkeleton(),GetModel(),GetCarPhysicsComponent()->m_carRotationX,GetCarPhysicsComponent()->m_wheelRotationX,GetCarPhysicsComponent()->m_wheelRotationY);
	
	// scale down the shadow to nothing...  must be done after all the 
	// children's matrices have been calculated...  this also assumes
	// the shadow is the first matrix...  if it's not, we'd have to
	// search for the correct matrix by name
	if ( !GetCarPhysicsComponent()->m_shadowEnabled )
	{
		Mth::Matrix mat;
		mat.Ident();
		mat.Scale(Mth::Vector(0.0f,0.0f,0.0f,1.0f));
		
		Mth::Matrix* pMatrices = GetSkeleton()->GetMatrices();
		*pMatrices = mat;
	}
}
コード例 #3
0
void FAssetTypeActions_AnimationAsset::OpenAssetEditor( const TArray<UObject*>& InObjects, TSharedPtr<IToolkitHost> EditWithinLevelEditor )
{
	EToolkitMode::Type Mode = EditWithinLevelEditor.IsValid() ? EToolkitMode::WorldCentric : EToolkitMode::Standalone;

	for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt)
	{
		auto AnimAsset = Cast<UAnimationAsset>(*ObjIt);
		if (AnimAsset != NULL)
		{
			USkeleton* AnimSkeleton = AnimAsset->GetSkeleton();
			if (!AnimSkeleton)
			{
				FText ShouldRetargetMessage = LOCTEXT("ShouldRetargetAnimAsset_Message", "Could not find the skeleton for Anim '{AnimName}' Would you like to choose a new one?");

				FFormatNamedArguments Arguments;
				Arguments.Add( TEXT("AnimName"), FText::FromString(AnimAsset->GetName()));

				if ( FMessageDialog::Open(EAppMsgType::YesNo, FText::Format(ShouldRetargetMessage, Arguments)) == EAppReturnType::Yes )
				{
					bool bDuplicateAssets = false;
					TArray<UObject*> AnimAssets;
					AnimAssets.Add(AnimAsset);
					RetargetAssets(AnimAssets, bDuplicateAssets, true, EditWithinLevelEditor);
				}
			}
			else if (AnimSkeleton)
			{
				const bool bBringToFrontIfOpen = false;
				if (IAssetEditorInstance* EditorInstance = FAssetEditorManager::Get().FindEditorForAsset(AnimSkeleton, bBringToFrontIfOpen))
				{
					// The skeleton is already open in an editor.
					// Tell persona that an animation asset was requested
					EditorInstance->FocusWindow(AnimAsset);
				}
				else
				{
					FPersonaModule& PersonaModule = FModuleManager::LoadModuleChecked<FPersonaModule>( "Persona" );
					PersonaModule.CreatePersona(Mode, EditWithinLevelEditor, AnimSkeleton, NULL, AnimAsset, NULL);
				}
			}
		}
	}
}
コード例 #4
0
void UBlendSpaceBase::InitializePerBoneBlend()
{
	const USkeleton* MySkeleton = GetSkeleton();
	// also initialize perbone interpolation data
	for (int32 Id=0; Id<PerBoneBlend.Num(); ++Id) 
	{
		PerBoneBlend[Id].Initialize(MySkeleton);
	}

	struct FCompareFPerBoneInterpolation
	{
		FORCEINLINE bool operator()( const FPerBoneInterpolation& A, const FPerBoneInterpolation& B ) const
		{
			return A.BoneReference.BoneIndex > B.BoneReference.BoneIndex;
		}
	};

	// Sort this by bigger to smaller, then we don't have to worry about checking the best parent
	PerBoneBlend.Sort( FCompareFPerBoneInterpolation() );
}
コード例 #5
0
bool UBlendSpaceBase::ValidateSampleInput(FBlendSample & BlendSample, int32 OriginalIndex) const
{
	// make sure we get same kinds of samples(additive or nonadditive)
	if (SampleData.Num() > 0 && BlendSample.Animation)
	{
		bool bIsAdditive = IsValidAdditive();
		if (bIsAdditive != (BlendSample.Animation->IsValidAdditive()))
		{
			UE_LOG(LogAnimation, Log, TEXT("Adding sample failed. Please add same kinds of sequence (additive/non-additive)."));
			return false;
		}

		// make sure it's same additive if it is additive
		if (bIsAdditive && !IsValidAdditiveInternal(BlendSample.Animation->AdditiveAnimType))
		{
			UE_LOG(LogAnimation, Log, TEXT("Adding sample failed. Please add same kinds of additive sequence (loca/mesh)."));
			return false;
		}
	}

	const USkeleton* MySkeleton = GetSkeleton();
	if (BlendSample.Animation &&
		(! MySkeleton ||
		! BlendSample.Animation->GetSkeleton()->IsCompatible(MySkeleton)))
	{
		UE_LOG(LogAnimation, Log, TEXT("Adding sample failed. Please add same kinds of sequence (additive/non-additive)."));
		return false;
	}

	SnapToBorder(BlendSample);
	// make sure blendsample is within the parameter range
	BlendSample.SampleValue = ClampBlendInput(BlendSample.SampleValue);

	if (IsTooCloseToExistingSamplePoint(BlendSample.SampleValue, OriginalIndex))
	{
		UE_LOG(LogAnimation, Log, TEXT("Adding sample failed. Too close to existing sample point."));
		return false;
	}

	return true;
}
コード例 #6
0
void FAssetTypeActions_AnimationAsset::ExecuteFindSkeleton(TArray<TWeakObjectPtr<UAnimationAsset>> Objects)
{
	TArray<UObject*> ObjectsToSync;
	for (auto ObjIt = Objects.CreateConstIterator(); ObjIt; ++ObjIt)
	{
		auto Object = (*ObjIt).Get();
		if ( Object )
		{
			USkeleton* Skeleton = Object->GetSkeleton();
			if (Skeleton)
			{
				ObjectsToSync.AddUnique(Skeleton);
			}
		}
	}

	if ( ObjectsToSync.Num() > 0 )
	{
		FAssetTools::Get().SyncBrowserToAssets(ObjectsToSync);
	}
}
コード例 #7
0
ファイル: skeletonQuery.cpp プロジェクト: rodeofx/USD
bool
UsdSkelSkeletonQuery::_ComputeJointLocalTransforms(VtMatrix4dArray* xforms,
                                                   UsdTimeCode time,
                                                   bool atRest) const
{
    if(atRest) {
        return _definition->GetJointLocalRestTransforms(xforms);
    }

    if(_animToSkelMapper.IsSparse()) {
        // Animation does not override all values;
        // Need to first fill in bind transforms.
        if (!_definition->GetJointLocalRestTransforms(xforms)) {
            TF_WARN("%s -- Failed computing local space transforms: "
                    "the the animation source (<%s>) is sparse, but the "
                    "'restTransforms' of the Skeleton are either unset, "
                    "or do not match the number of joints.",
                    GetSkeleton().GetPrim().GetPath().GetText(),
                    GetAnimQuery().GetPrim().GetPath().GetText());
            return false;
        }
    }

    VtMatrix4dArray animXforms;
    if(_animQuery.ComputeJointLocalTransforms(&animXforms, time)) {
        return _animToSkelMapper.RemapTransforms(animXforms, xforms);
    } else {
        // Failed to compute anim xforms.
        // Fall back to our rest transforms.
        // These will have already been initialized above,
        // unless we have a non-sparse mapping.
        if (!_animToSkelMapper.IsSparse()) {
            return _definition->GetJointLocalRestTransforms(xforms);
        }
    }
    return true;
}
コード例 #8
0
int main()
{
	Mat src = imread("D:\\pictures\\potato.png");
	imshow("origin", src);
	Mat dst = Otsu(src);

	int height = dst.cols;
	int width = dst.rows;
	uchar* imagedata = new uchar[height * width]();
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			imagedata[i * height + j] = dst.at<uchar>(i, j) > 0 ? 1 : 0;
		}
	}
	GetSkeleton(imagedata, height, width);
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			dst.at<uchar>(i, j) = imagedata[i * height + j] > 0 ? 0 : 255;
		}
	}


	cvtColor(src, src, CV_RGB2GRAY);
	Mat sdst, dst1, dst2;
	dst1 = Boundary(src);
	Mat BigBlankimage = Mat::ones(src.rows, src.cols, CV_8UC1);
	dst2 = BigBlankimage * 255 - dst1;
	int threhold = otsu(dst1) - 28;
	threshold(dst1, sdst, threhold, 255, CV_THRESH_BINARY);
	sdst = BigBlankimage * 255 - sdst;

	imshow("skin", sdst);
	imshow("skeleton", dst);

	waitKey();

}
コード例 #9
0
bool ConcurrentTableSharedStore::store(CStrRef key, CVarRef val, int64 ttl,
                                       bool overwrite /* = true */) {
  bool stats = RuntimeOption::EnableStats && RuntimeOption::EnableAPCStats;
  bool statsDetail = RuntimeOption::EnableAPCSizeStats &&
                     RuntimeOption::EnableAPCSizeGroup;
  StoreValue *sval;
  SharedVariant* var = construct(key, val);
  ReadLock l(m_lock);

  const char *kcp = strdup(key.data());
  bool present;
  time_t expiry;
  {
    Map::accessor acc;
    present = !m_vars.insert(acc, kcp);
    sval = &acc->second;
    if (present) {
      free((void *)kcp);
      if (overwrite || sval->expired()) {
        if (statsDetail) {
          SharedStoreStats::onDelete(key.get(), sval->var, true);
        }
        sval->var->decRef();
        if (RuntimeOption::EnableAPCSizeStats && !check_skip(key.data())) {
          int32 size = var->getSpaceUsage();
          SharedStoreStats::updateDirect(sval->size, size);
          sval->size = size;
        }
      } else {
        var->decRef();
        return false;
      }
    } else {
      if (RuntimeOption::EnableAPCSizeStats) {
        int32 size = var->getSpaceUsage();
        SharedStoreStats::addDirect(key.size(), size);
        sval->size = size;
      }
    }
    sval->set(var, ttl);
    expiry = sval->expiry;
    if (statsDetail) {
      SharedStoreStats::onStore(key.get(), var, ttl, false);
    }
  }
  if (RuntimeOption::ApcExpireOnSets) {
    if (ttl) {
      addToExpirationQueue(key.data(), expiry);
    }
    purgeExpired();
  }
  if (stats) {
    if (present) {
      ServerStats::Log("apc.update", 1);
    } else {
      ServerStats::Log("apc.new", 1);
      if (RuntimeOption::EnableStats && RuntimeOption::EnableAPCKeyStats) {
        string prefix = "apc.new.";
        prefix += GetSkeleton(key);
        ServerStats::Log(prefix, 1);
      }
    }
  }

  return true;
}
コード例 #10
0
ファイル: car.cpp プロジェクト: basecq/thug
void CCar::InitCar( CGeneralManager* p_obj_man, Script::CStruct* pNodeData )
{
	p_obj_man->RegisterObject(*this);

	MovingObjectCreateComponents();

	uint32 skeletonName = CRCD(0x88c21962,"car");
	bool use_skeletal_cars = false;

	if ( pNodeData->GetChecksum( CRCD(0x09794932,"skeletonName"), &skeletonName, false ) )
	{
		use_skeletal_cars = true;
	}

	if ( use_skeletal_cars )
	{
//		m_model_restoration_info.mSkeletonName=skeletonName;
		// component-based
		Dbg_MsgAssert( GetSkeletonComponent() == NULL, ( "Skeleton component already exists" ) );
		Script::CStruct* pSkeletonStruct = new Script::CStruct;
		pSkeletonStruct->AddChecksum( CRCD(0xb6015ea8,"component"), CRC_SKELETON );
		pSkeletonStruct->AddChecksum( CRCD(0x222756d5,"skeleton"), skeletonName );
		this->CreateComponentFromStructure(pSkeletonStruct, NULL);
		delete pSkeletonStruct;

#ifdef	__NOPT_ASSERT__
		Gfx::CSkeleton* pSkeleton = GetSkeletonComponent()->GetSkeleton();
		Dbg_Assert( pSkeleton );
		Dbg_Assert( pSkeleton->GetNumBones() > 0 );
#endif
	}
	else
	{
//		m_model_restoration_info.mSkeletonName=0;
	}	
	
	MovingObjectInit( pNodeData, p_obj_man );
	
	Obj::CModelComponent* pModelComponent = new Obj::CModelComponent;
	this->AddComponent( pModelComponent );
	pModelComponent->InitFromStructure( pNodeData );
	
	Dbg_Assert( GetModel() );

	// set up the skeleton for this car model, if any
	// needs to come after the geom is loaded (because
	// that's where the hierarchy info is)
	if ( use_skeletal_cars )
	{		
		const char* p_model_name;
		pNodeData->GetText( CRCD(0x286a8d26,"model"), &p_model_name, true );

		// sanity check on number of bones in skeleton
		Dbg_MsgAssert( GetModel()->GetNumObjectsInHierarchy()==GetSkeleton()->GetNumBones(), 
					   ( "Expected to find %d bones in the %s skeleton (found %d in %s - %s)",
						 GetSkeleton()->GetNumBones(),
						 Script::FindChecksumName( skeletonName ),
						 GetModel()->GetNumObjectsInHierarchy(),
						 Script::FindChecksumName( GetID() ),
						 p_model_name ) );
		
		GetCarPhysicsComponent()->init_car_skeleton();		
	}
	else
	{
		if ( GetModel()->GetNumObjectsInHierarchy()!=0 )
		{
			uint32 name = 0;
			pNodeData->GetChecksum( CRCD(0xa1dc81f9,"name"), &name, Script::ASSERT );
			Dbg_MsgAssert( 0, ( "Skeletal model requires a skeleton %s", Script::FindChecksumName(name) ) );
		}
	}

	GetCarPhysicsComponent()->InitFromStructure( pNodeData );

	if ( !pNodeData->ContainsFlag( CRCD(0x0bf29bc0,"NoCollision") ) )
	{
		// GJ:  collision component should be added after the model component,
		// because we want the same m_pos/m_matrix that is used for displaying
		// the model
		Dbg_MsgAssert( GetCollisionComponent() == NULL, ( "Collision component already exists" ) );
		Script::CStruct* pCollisionStruct = new Script::CStruct;
		pCollisionStruct->AddChecksum( CRCD(0xb6015ea8,"component"), CRC_COLLISION );
		pCollisionStruct->AddChecksum( CRCD(0x2d7e583b,"collisionMode"), CRCD(0x6aadf154,"geometry") );
		this->CreateComponentFromStructure(pCollisionStruct, NULL);
		delete pCollisionStruct;
	}

	// designer controlled variables:
	// set defaults, to be overridden by script values if they exist:
	GetMotionComponent()->m_max_vel = ( MPH_TO_INCHES_PER_SECOND ( DEFAULT_CAR_MAX_VEL ) );
	GetMotionComponent()->m_acceleration = FEET_TO_INCHES( DEFAULT_CAR_ACCELERATION );
	GetMotionComponent()->m_deceleration = FEET_TO_INCHES( DEFAULT_CAR_DECELERATION );
	
	// stick to ground tests against wheels, rather than origin
	// (eventually, we'll move this functionality into a custom
	// sticktoground component)
	GetMotionComponent()->m_point_stick_to_ground = false;

	GetMotionComponent()->EnsurePathobExists( this );
	GetMotionComponent()->GetPathOb()->m_enter_turn_dist = FEET_TO_INCHES( DEFAULT_CAR_TURN_DIST );
	
	// Add a NodeArrayComponent to the Car, so it will request loading of the associated node array.
	Obj::CNodeArrayComponent *p_node_array_component = new Obj::CNodeArrayComponent;
	this->AddComponent( p_node_array_component );
	p_node_array_component->InitFromStructure( pNodeData );

	if ( !pNodeData->ContainsFlag( CRCD(0x1fb9e477,"NoRail") ) )
	{
		// Add a RailManagerComponent to the Car, so it can be used for grinding etc.
		Obj::CRailManagerComponent *p_rail_manager_component = new Obj::CRailManagerComponent;
		this->AddComponent( p_rail_manager_component );
		p_rail_manager_component->InitFromStructure( pNodeData );
	}

	if ( !pNodeData->ContainsFlag( CRCD(0x59793e2b,"NoSkitch") ) )
	{
		// Add an ObjectHookManagerComponent to the Car, for use by the SkitchComponent.
		Obj::CObjectHookManagerComponent *p_object_hook_manager_component = new Obj::CObjectHookManagerComponent;
		this->AddComponent( p_object_hook_manager_component );
		p_object_hook_manager_component->InitFromStructure( pNodeData );

		// Add a SkitchComponent to the Car, so it can be used for skitching etc.
		Obj::CSkitchComponent *p_skitch_component = new Obj::CSkitchComponent;
		this->AddComponent( p_skitch_component );
		p_skitch_component->InitFromStructure( pNodeData );
	}

	// Finalize the object, saying we've added all the components
	Finalize();
	
	// need to synchronize rendered model's position to initial world position
	GetModelComponent()->FinalizeModelInitialization();

	SetProfileColor(0xc0c000);				// cyan = car
}
コード例 #11
0
ファイル: AnimMontage.cpp プロジェクト: 1vanK/AHRUnrealEngine
void UAnimMontage::PostLoad()
{
	Super::PostLoad();

	// copy deprecated variable to new one, temporary code to keep data copied. Am deleting it right after this
	for ( auto SlotIter = SlotAnimTracks.CreateIterator() ; SlotIter ; ++SlotIter)
	{
		FAnimTrack & Track = (*SlotIter).AnimTrack;
		for ( auto SegIter = Track.AnimSegments.CreateIterator() ; SegIter ; ++SegIter )
		{
			FAnimSegment & Segment = (*SegIter);
			if ( Segment.AnimStartOffset_DEPRECATED!=0.f )
			{
				Segment.AnimStartTime = Segment.AnimStartOffset_DEPRECATED;
				Segment.AnimStartOffset_DEPRECATED = 0.f;
			}
			if ( Segment.AnimEndOffset_DEPRECATED!=0.f )
			{
				Segment.AnimEndTime = Segment.AnimEndOffset_DEPRECATED;
				Segment.AnimEndOffset_DEPRECATED = 0.f;
			}
		}
			}

	for ( auto CompositeIter = CompositeSections.CreateIterator(); CompositeIter; ++CompositeIter )
	{
		FCompositeSection & Composite = (*CompositeIter);
		if (Composite.StarTime_DEPRECATED!=0.f)
		{
			Composite.StartTime = Composite.StarTime_DEPRECATED;
			Composite.StarTime_DEPRECATED = 0.f;
		}
	}

	SortAnimBranchingPointByTime();

	// find preview base pose if it can
#if WITH_EDITORONLY_DATA
	if ( IsValidAdditive() && PreviewBasePose == NULL )
	{
		for (int32 I=0; I<SlotAnimTracks.Num(); ++I)
		{
			if ( SlotAnimTracks[I].AnimTrack.AnimSegments.Num() > 0 )
			{
				UAnimSequence * Sequence = Cast<UAnimSequence>(SlotAnimTracks[I].AnimTrack.AnimSegments[0].AnimReference);
				if ( Sequence && Sequence->RefPoseSeq )
				{
					PreviewBasePose = Sequence->RefPoseSeq;
					MarkPackageDirty();
					break;
				}
			}
		}
	}

	// verify if skeleton matches, otherwise clear it, this can happen if anim sequence has been modified when this hasn't been loaded. 
	USkeleton* MySkeleton = GetSkeleton();
	for (int32 I=0; I<SlotAnimTracks.Num(); ++I)
	{
		if ( SlotAnimTracks[I].AnimTrack.AnimSegments.Num() > 0 )
		{
			UAnimSequence * Sequence = Cast<UAnimSequence>(SlotAnimTracks[I].AnimTrack.AnimSegments[0].AnimReference);
			if ( Sequence && Sequence->GetSkeleton() != MySkeleton )
			{
				SlotAnimTracks[I].AnimTrack.AnimSegments[0].AnimReference = 0;
				MarkPackageDirty();
				break;
			}
		}
	}
#endif // WITH_EDITORONLY_DATA
}
コード例 #12
0
bool ConcurrentTableSharedStore::store(CStrRef key, CVarRef value, int64 ttl,
                                       bool overwrite /* = true */) {
  StoreValue *sval;
  SharedVariant* svar = construct(value);
  ConditionalReadLock l(m_lock, !RuntimeOption::ApcConcurrentTableLockFree ||
                                m_lockingFlag);
  const char *kcp = strdup(key.data());
  bool present;
  time_t expiry = 0;
  bool overwritePrime = false;
  {
    Map::accessor acc;
    present = !m_vars.insert(acc, kcp);
    sval = &acc->second;
    bool update = false;
    if (present) {
      free((void *)kcp);
      if (overwrite || sval->expired()) {
        // if ApcTTLLimit is set, then only primed keys can have expiry == 0
        overwritePrime = (sval->expiry == 0);
        if (sval->inMem()) {
          stats_on_update(key.get(), sval, svar,
                          adjust_ttl(ttl, overwritePrime));
          sval->var->decRef();
          update = true;
        } else {
          // mark the inFile copy invalid since we are updating the key
          sval->sAddr = NULL;
          sval->sSize = 0;
        }
      } else {
        svar->decRef();
        return false;
      }
    }
    int64 adjustedTtl = adjust_ttl(ttl, overwritePrime);
    if (check_noTTL(key.data())) {
      adjustedTtl = 0;
    }
    sval->set(svar, adjustedTtl);
    expiry = sval->expiry;
    if (!update) {
      stats_on_add(key.get(), sval, adjustedTtl, false, false);
    }
  }
  if (expiry) {
    addToExpirationQueue(key.data(), expiry);
  }
  if (RuntimeOption::ApcExpireOnSets) {
    purgeExpired();
  }
  if (present) {
    log_apc(std_apc_update);
  } else {
    log_apc(std_apc_new);
    if (RuntimeOption::EnableStats && RuntimeOption::EnableAPCKeyStats) {
      string prefix = "apc.new." + GetSkeleton(key);
      ServerStats::Log(prefix, 1);
    }
  }
  return true;
}
コード例 #13
0
ファイル: skeletonQuery.cpp プロジェクト: rodeofx/USD
UsdPrim
UsdSkelSkeletonQuery::GetPrim() const
{
    return GetSkeleton().GetPrim();
}